473,387 Members | 1,597 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,387 software developers and data experts.

character set gobbledy-gook ascii translation ...


I'm parsing a file with the mailbox and email modules and
come across subject headers like:
=?us-ascii?Q?Re=3A=20=5Bosg=2Duser=5D=20Culling=20probl em?=
and
=?gb2312?B?cXVlc3Rpb24gYWJvdXQgbG9hZGluZyBmbHQgbGF yZ2UgdGVycmFpbiA=?=

I've looked at the Charset class but can't figure out how to use it to
convert the above strings to a human readable form. Generally, I
imagine that
there is no guarantee that an encoded string can be rendered meaningfully
in ASCII - but these are posts to an English language mai list so it should
be possible for this restricted case.

I can guess the translation in the first example above but I'm
hoping there is a Python module that'll do it for me.

Any help is much appreciated.

Cheers,
Darran.
Jul 18 '05 #1
1 2106
>>> email.Header.decode_header("=?us-ascii?Q?Re=3A=20=5Bosg=2Duser=5D=20Culling=20probl em?=")
[('Re: [osg-user] Culling problem', 'us-ascii')]
email.Header.decode_header("=?gb2312?B?cXVlc3Rpb24 gYWJvdXQgbG9hZGluZyBmbHQgbGFyZ2UgdGVycmFpbiA=?=") [('question about loading flt large terrain ', 'gb2312')] help(email.Header.decode_header)

Help on function decode_header:

decode_header(header)
Decode a message header value without converting charset.

Returns a list of (decoded_string, charset) pairs containing each of
the decoded parts of the header. Charset is None for non-encoded
parts of the header, otherwise a lower-case string containing the
name of the character set specified in the encoded string.

An email.Errors.HeaderParseError may be raised when certain decoding
error occurs (e.g. a base64 decoding exception).

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBzCp3Jd01MZaTXX0RAgK+AJ40xiymdMBLvsexCNC4zm zEwqr16ACfXkZn
KZVYVeoCxuBx+ZxLVaG94uU=
=g8UI
-----END PGP SIGNATURE-----

Jul 18 '05 #2

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

Similar topics

9
by: Safalra | last post by:
The idea here is relatively simple: a java program (I'm using JDK1.4 if that makes a difference) that loads an HTML file, removes invalid characters (or replaces them in the case of common ones...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
40
by: Shmuel (Seymour J.) Metz | last post by:
I'd like to include some Hebrew names in a web page. HTML 4 doesn't appear to include character attributes for ISO-8859-8. I'd prefer avoiding numeric references, e.g.,...
8
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
7
by: arnuld | last post by:
i am trying to implement C style strings in C++ (from chapter 4 "C++ Primer 4/e"): // reading from std::cin for a c-string // (a null terminated character array) #include <iostream> #include...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
7
by: tempest | last post by:
Hi all. This is a rather long posting but I have some questions concerning the usage of character entities in XML documents and PCI security compliance. The company I work for is using a...
10
by: Paul W | last post by:
Hi all, I have an application that reads data in from a text file and stores it in a database. My problem is that there are some characters in the file that aren't being handled properly. For...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.