Autore Topic: Recuperare charset di mimepart  (Letto 369 volte)

Online vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Recuperare charset di mimepart
« il: 06 Novembre 2014, 16:05:08 »
Vi riporto questa discussione:


" Dear All,
there is a method to get the charset of a mimepart
( eg. part.ContentType = "plain/text" ) ?
Best Regards
Roberto
"


" I use this code in the EMail function to set the mime. I'm not very sure if
this is what you are asking for:

Codice: gambas [Seleziona]
For Each fich In aAttached
            Exec ["file", "-bi", fich] To mime
            mime = Left(mime, InStr(mime, ";") - 1)
            fname = Right(fich, - RInStr(fich, "/"))
            SmtpC.Add(File.Load(fich), mime, fname)
  Next

Hope this helps.

Regards
Jorge
"


" Thanks Jorge for you fast reply

I have tried with:

Codice: gambas [Seleziona]
s = hPart.Headers["content-type"]
       If InStr(s, "charset") > 0 Then
             bla bla bla (estrapolate "charset" content )
       endif

but is not an excellent solution

Roberto
"


" 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,

--
Benoît Minisini
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Online vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Recuperare charset di mimepart
« Risposta #1 il: 07 Novembre 2014, 15:39:15 »
...continua...


" 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


      
Codice: gambas [Seleziona]
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

Roberto
"


" 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
"
« Ultima modifica: 07 Novembre 2014, 19:22:34 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »