Recent

Author Topic: fetching mail w Synapse decoding utf-8 in subject  (Read 2848 times)

holger.ernst

  • Newbie
  • Posts: 1
fetching mail w Synapse decoding utf-8 in subject
« on: June 18, 2014, 02:48:10 pm »
When I fetch headers via synapse i geh something like this:
Subject:  =?utf-8?Q?=53=43=48=41....
when the subject is provided in UTF-8 (my assumption).
How can I decode that?

Best regards Holger

3mptyCode

  • Newbie
  • Posts: 3
Re: fetching mail w Synapse decoding utf-8 in subject
« Reply #1 on: March 30, 2020, 09:39:11 pm »
Even if your post is not that new, maybe you still like to get a solution or already found a better one ?

At this post you can read my workaround-solution:
https://forum.lazarus.freepascal.org/index.php/topic,47556.0.html

Best regards

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: fetching mail w Synapse decoding utf-8 in subject
« Reply #2 on: March 30, 2020, 11:50:50 pm »
How can I decode that?

Look at RFC 2047.  The text is encoded as follows:

Quote
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="

For each encoded-word in the text (there may be multiple), split it into those 3 pieces, then decode the encoded-text into bytes based on the specified encoding (Q = quoted printable, B = base64), then decode those bytes into a string based on the specified charset, then replace the entire encoded-word with the decoded string.

So, for example:

Code: [Select]
=?utf-8?Q?=53=43=48=41...?=
breaks up into

Code: [Select]
utf-8
Q
=53=43=48=41...

Then "=53=43=48=41...." becomes the byte sequence

Code: [Select]
$53 $43 $48 $41 ...
Which decoded as UTF-8 is the string 'SCHA...'.

This is not very difficult to implement by hand, or you can find a 3rd party MIME library to handle it for you (FYI, Indy has built-in support for this format).
« Last Edit: March 30, 2020, 11:54:28 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018