Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > To decode the Subject =?iso-8859-2?Q?=... in email in python

Reply
Thread Tools

To decode the Subject =?iso-8859-2?Q?=... in email in python

 
 
Dan Polansky
Guest
Posts: n/a
 
      04-20-2005
When parsing messages using python's libraries email and mailbox, the
subject is often encoded using some kind of = notation. Apparently, the
encoding used in this notation is specified like =?iso-8859-2?Q?=... or
=?iso-8859-2?B?=. Is there a python library function to decode such a
subject, returning a unicode string? The use would be like

human_readable = cool_library.decode_equals(message['Subject'])

Thank you, Dan

 
Reply With Quote
 
 
 
 
Max M
Guest
Posts: n/a
 
      04-20-2005
Dan Polansky wrote:
> When parsing messages using python's libraries email and mailbox, the
> subject is often encoded using some kind of = notation. Apparently, the
> encoding used in this notation is specified like =?iso-8859-2?Q?=... or
> =?iso-8859-2?B?=. Is there a python library function to decode such a
> subject, returning a unicode string? The use would be like
>
> human_readable = cool_library.decode_equals(message['Subject'])



parts = email.Header.decode_header(header)
new_header = email.Header.make_header(parts)
human_readable = unicode(new_header)



--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
 
Reply With Quote
 
 
 
 
Roman Neuhauser
Guest
Posts: n/a
 
      04-20-2005
# / 2005-04-20 00:30:35 -0700:
> When parsing messages using python's libraries email and mailbox, the
> subject is often encoded using some kind of = notation. Apparently, the
> encoding used in this notation is specified like =?iso-8859-2?Q?=... or
> =?iso-8859-2?B?=.


That's RFC 2047 encoding, both examples introduce an ISO8859-2
string, the first variant says it's ascii-ized using
"Q"uoted-Printable, the other says the string is "B"ase64-encoded.

> Is there a python library function to decode such a
> subject, returning a unicode string? The use would be like
>
> human_readable = cool_library.decode_equals(message['Subject'])


quoting from http://docs.python.org/lib/module-email.Header.html

>>> from email.Header import decode_header
>>> decode_header('=?iso-8859-1?q?p=F6stal?=')

[('p\xf6stal', 'iso-8859-1')]

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991
 
Reply With Quote
 
Neil Hodgson
Guest
Posts: n/a
 
      04-20-2005
Dan Polansky:

> When parsing messages using python's libraries email and mailbox, the
> subject is often encoded using some kind of = notation. Apparently, the
> encoding used in this notation is specified like =?iso-8859-2?Q?=... or
> =?iso-8859-2?B?=. Is there a python library function to decode such a
> subject, returning a unicode string? The use would be like
>
> human_readable = cool_library.decode_equals(message['Subject'])


Here is some code from a front end to Mailman moderation pages:

import email.Header
hdr = email.Header.make_header(email.Header.decode_heade r(sub))

Neil
 
Reply With Quote
 
Dan Polansky
Guest
Posts: n/a
 
      04-22-2005
Max, thanks; that was helpful. Roman, your explanation was helpful as
well. Dan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I decode unicode characters in the subject usingemail.message_from_string()? Roy H. Han Python 18 02-25-2009 06:59 PM
Re: Decode email subjects into unicode Laszlo Nagy Python 3 03-19-2008 10:24 AM
Decode email subjects into unicode Laszlo Nagy Python 1 03-18-2008 04:24 PM
No Subject for this subject George MCAD 0 05-20-2005 10:19 AM
Add/Remove Programs Help Kinda Wierd Do Not Ignore Terrable Subject JustIgnore The Subject Oops Whatever Duh Samuel Townsend Computer Support 0 10-13-2004 12:49 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57