473,395 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Decode email subjects into unicode

Hi All,

'm in trouble with decoding email subjects. Here are some examples:
=?koi8-r?B?4tnT1NLP19nQz8zOyc3PIMkgzcHMz9rB1NLB1M7P?=
[Fwd: re:Flags Of The World, Us States, And Military]
=?ISO-8859-2?Q?=E9rdekes?=
=?UTF-8?B?aGliw6Fr?=

I know that "=?UTF-8?B" means UTF-8 + base64 encoding, but I wonder if
there is a standard method in the "email" package to decode these
subjects? I do not want to re-invent the weel.

Thanks,

Laszlo

Mar 18 '08 #1
1 3469
Laszlo Nagy wrote:
I know that "=?UTF-8?B" means UTF-8 + base64 encoding, but I wonder if
there is a standard method in the "email" package to decode these
subjects?
The standard library function email.Header.decode_header will parse these
headers into an encoded bytestring paired with the appropriate encoding
specification, if any. For example:
>>raw_headers = [
.... '=?koi8-r?B?4tnT1NLP19nQz8zOyc3PIMkgzcHMz9rB1NLB1M7P?=',
.... '[Fwd: re:Flags Of The World, Us States, And Military]',
.... '=?ISO-8859-2?Q?=E9rdekes?=',
.... '=?UTF-8?B?aGliw6Fr?=',
.... ]
>>from email.Header import decode_header
for raw_header in raw_headers:
.... for header, encoding in decode_header(raw_header):
.... if encoding is None:
.... print header.decode()
.... else:
.... print header.decode(encoding)
....
Быстровыполнимо и малозатратно
[Fwd: re:Flags Of The World, Us States, And Military]
érdekes
hibák
Jeffrey
Mar 18 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Pratt | last post by:
Recently I have run into an issue with sqlite where I encode strings going into sqlite3 as utf-8. I guess by default sqlite3 is converting this to unicode since when I try to decode I get an...
3
by: Guoqi Zheng | last post by:
Dear sir, I need to decode base64 encoded email. I used below function but it does not work correctly, especially when I need to decode some Characters like Chinese, Can some one point out...
2
by: aurora | last post by:
I have some unicode string with some characters encode using python notation like '\n' for LF. I need to convert that to the actual LF character. There is a 'unicode_escape' codec that seems to...
2
by: rsd | last post by:
Hi, I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux. To do that I need to run http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py script, the idea behind the...
3
by: Laangen_LU | last post by:
Dear Group, my first post to this group, so if I'm on the wrong group, my apologies. I'm trying to send out an email in Chinese lanuage using the mail() function in PHP. Subject and...
4
by: Oleg Parashchenko | last post by:
Hello, I'm working on an unicode-aware application. I like to use "print" to debug programs, but in this case it was nightmare. The most popular result of "print" was: UnicodeDecodeError:...
15
by: glacier | last post by:
I use chinese charactors as an example here. "'\\xc4\\xe3\\xba\\xc3\\xc2\\xf0'" My first question is : what strategy does 'decode' use to tell the way to seperate the words. I mean since s1 is...
1
by: Eric S. Johansson | last post by:
I'm having a problem (Python 2.4) converting strings with random 8-bit characters into an escape form which is 7-bit clean for storage in a database. Here's an example: body =...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.