[Gambas-user] Retrieve charset of mimepart
Benoît Minisini
gambas at ...1...
Fri Nov 7 18:55:04 CET 2014
Le 07/11/2014 09:03, roberto a écrit :
> Hi Benoît (it is always a pleasure to read you in mailing list)
>
> we have eg 3 cases:
> 1°->
> "Content-Type: text/plain; charset="iso-8859-1"
>
> print hpart.ContentType
> output-> "text/plain"
> print hpart.Header["Content-type"]
> output-> text/plain; charset="iso-8859-1"
>
> 2°->
> "Content-Type: text/plain; charset=windows-1252; format=flowed"
>
> print hpart.ContentType
> output-> "text/plain"
> print hpart.Header["Content-type"]
> output-> "text/plain; charset=windows-1252; format=flowed"
>
> 3°->
> ->Content-Type: text/plain;
> charset="UTF-8" <-
>
> print hpart.ContentType
> output-> "text/plain"
> print hpart.Header["Content-type"]
> output-> text/plain; charset="UTF-8"
>
> I found the following solution that seems to work, waiting for your
> review with the possibility of using hpart.charset
>
> s = hPart.Headers["content-type"]
> If InStr(s, "charset") > 0 Then
> s = Mid(s, InStr(s, "charset=") + 8)
> s = Left(s, InStr(s & " ", " "))
> s = Replace(s, ";", "")
> s = Trim(Replace(s, Chr(34), ""))
> Try s = Conv(hPart.Data, s, "utf-8")
> If Error Then Message.Error("errore nel decodificare
> una parte mime " & Error.text, "ok")
> Return
> Else
> Return hpart.Data
> Endif
>
> Regards
>
>
>
> Il 06/11/2014 14:46, Benoît Minisini ha scritto:
>> Le 06/11/2014 13:20, roberto a écrit :
>>> Thanks Jorge for you fast reply
>>>
>>> I have tried with:
>>>
>>> s = hPart.Headers["content-type"]
>>> If InStr(s, "charset") > 0 Then
>>> bla bla bla (estrapolate "charset" content )
>>> endif
>>>
>>> but is not an excellent solution
>>>
>> AFAIK, the only place where the charset is specified is in the "charset"
>> part of the Content-Type header (that you can get with the
>> hPart.ContentType property directly).
>>
>> If the charset is not specified, I guess that you must guess!
>>
>> Regards,
>>
>
I didn't realize that the charset was stripped by the ContentType
property, because this property is a direct interface to the gmime library.
Maybe I will add a "Charset" method that extract the optional charset
part for you.
Regards,
--
Benoît Minisini
More information about the User
mailing list