[Info-vax] Mail reading/processing problem, UTF-8

Jan-Erik Soderholm jan-erik.soderholm at telia.com
Sat Aug 20 18:39:56 EDT 2011


Steven Schweda wrote 2011-08-21 00:23:
> On Aug 20, 2:54 pm, Jan-Erik Soderholm<jan-erik.soderh... at telia.com>
> wrote:
>
>> Subject: =?utf-8?B?U8OlbHQgb2JqZWt0OiA0IHN0IFVMTjI4MDMgZGFybGluZ3Rv?=
>>    =?utf-8?B?biBkcml2ZXJzLiBESVAgLCAxMzcyNTc0NjEuIEvDtnBhcmU6IGJlbmd0?=
>>    =?utf-8?B?dy00OA==?=
>> [...]
>> So, how to decode that "=?utf-8?B?U8O......" string into
>> something readable ?
>> [...]
>
>     I know nothing, but a quick Google search led to:
>
>        http://en.wikipedia.org/wiki/MIME
>
> Look for "Encoded-Word".  If you have "?utf-8?B?WXYZ?" and a
> Base64 decoding program, then run "WXYZ" through the program.
> For example, using junk I have lying around:
>

Yes, I was walking that path also for a while, but then decided
to read the Python manual a little better and found the email
module instead.

> alp $ type subj.txt
> U8OlbHQgb2JqZWt0OiA0IHN0IFVMTjI4MDMgZGFybGluZ3Rv
> biBkcml2ZXJzLiBESVAgLCAxMzcyNTc0NjEuIEvDtnBhcmU6IGJlbmd0
> dy00OA==
>
> alp $ b64decode subj.txt tt:
> SÃ¥lt objekt: 4 st ULN2803 darlington drivers. DIP ,
> 137257461. Köpare: bengtw-48
>
>     Does that look plausible?  It doesn't do much with the
> UTF-8 itself, but it does let you see the stuff.

Yes, that is expected... :-)

Now, this makes you having to analyze the subject and first
"decode" the "?utf-8?B?" part to decide what to do with the rest.

As you might see in another post I made just a few min ago, I
found that the email module in Python does all this automaticly.
It deas the correct decode based on the "?B?" part.

What I *realy* need is the "137257461" part that is the
auction number that was finished/sold.

"SÃ¥lt objekt:" is "Sold item" in Swedish... :-)

>
>     I have no idea where I found the b64decode.c and
> b64encode.c programs in my collection (19-DEC-1999), but let
> me know if you can't find anything which works.

There are plain b64de/encode routines in Python. I'm sure
the email modules uses them.

Jan-Erik.



More information about the Info-vax mailing list