Py3k,email header handling
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed May 11 09:44:17 EDT 2011
On Wed, 11 May 2011 16:04:13 +0800, TheSaint wrote:
> Now python 3.2 (and some version before) started to use byte, rather
> than text strings, almost for all data handling in compliance to
> unicode. My problem arise that my program handle text strings, so I'd
> like to rewrite the code
Before you re-write it, you should run 2to3 over it and see how much it
can do automatically:
http://docs.python.org/library/2to3.html
> My program reads from IMAP4 or POP3 server, I'd prefer that a
> function/class will return either a list or a dictionary which contains
> the following fields:
>
> 'from', 'to', 'cc', 'bcc', 'date', 'subject', 'reply-to', 'message-id'
>
> The list may be organized as tuple (from, its_content,), etc,etc for
> each field, but I think dictionary would be more efficient to use.
>
> 1) is there a way to call the IMAPlib or POPlib and pass the data
> directly to email.parser.HeaderParser to achieve my intention?
I'm afraid I don't understand the question.
> 2) If the above will do, do re.compile compile unicode results? I guess
> yes.
Yes. In Python 3, re.compile("some string") is automatically unicode,
because "some string" is unicode.
> 3) any related documentation...
http://docs.python.org/py3k/library/email.html
http://docs.python.org/py3k/library/re.html
http://docs.python.org/py3k/library/imaplib.html
http://docs.python.org/py3k/library/poplib.html
If you have any more concrete questions, please ask.
--
Steven
More information about the Python-list
mailing list