delphi - How to receive UTF-8 encoded messages via TIdIMAP4? -


i trying receive emails using indy's tidimap4 component.

here's example code how retrieve messages:

procedure temailform.getmessage(id: string); var   imap: tidimap4;   msg: tidmessage; begin   imap := tidimap4.create(self);   imap.host := 'mailserver';   imap.username := 'username';   imap.password := 'password';   imap.connect(true);   imap.selectmailbox('inbox');   msg := tidmessage.create(self);   imap.uidretrieve(id, msg);   subject.caption := msg.subject;   if (msg.messageparts.count = 0)     msgbody.text := msg.body.text   else if (msg.messageparts[0] tidtext)     msgbody.text := tidtext(msg.messageparts[0]).body.text;   imap.disconnect();   imap.free; end; 

where subject tlabel , msgbody tmemo.

in case email multi-part message messages sent via gmail, body returned tidtext(msg.messageparts[0]).body.text correctly encoded , special characters german umlauts displayed correctly.

though in case email single-part message messages sent via gmx, special characters within message body returned msg.body.text replaced question marks (?).

retrieving message body instead via

imap.uidretrievetext(id, msgtext); 

results in mojibake äöüÃñ².

the expected characters äöüßñ².

fwiw fetching message body via telnet this:

a06 uid fetch 100 (body) * 244 fetch (body ("text" "html" ("charset" "utf-8") nil nil "7bit" 206 2) uid 1 00) a06 ok fetch completed. a07 uid fetch 100 body[text] * 244 fetch (body[text] {206} <html><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body> <div style="font-family: verdana;font-size: 12.0px;"><div>├ñ├Â├╝├ƒ </div></div></body></html>  uid 100 flags (\seen)) a07 ok fetch completed. 

so what's correct way retrieve message body of kind of utf-8 encoded single-part emails? i.e. how decode them correctly?

tidimap4.uidretrieve() uses whatever charset specified in email itself. if single-part email not decoding correctly, not specifying proper charset begin with. have @ raw email data confirm that. mime encoded emails more specify charsets plain text emails are. non-ascii characters subject charset handling, important tidmessage know charset email encoded with.

as uidretrievetext(), not know charset of text/part part being retrieved (that todo item), cannot decode non-ascii characters. uidretrievetext2(), on other hand, fetches email's bodystructure first , locates charset of text/part being retrieved can use charset during decoding.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -