imaplib ... understanding the result from a fetch of RFC822s

Donn Cave donn at u.washington.edu
Thu Nov 18 18:09:55 CET 2004


In article <419bb3a7$0$259$edfadb0f at dread12.news.tele.dk>,
 Max M <maxm at mxm.dk> wrote:
> I am using the fetch command from the imaplib to fetch messages. I get a 
> result, but I am a bit uncertain as to how I should interpret it.
> 
> The result is described at http://pydoc.org/2.3/imaplib.html as::
> 
> (typ, [data, ...]) = <instance>.fetch(message_set, message_parts)
> 
> In RFC 2060 it says: "The data items to be fetched can be either a 
> single atom or a parenthesized list."
> 
> So I do a fetch like:
> 
>      mailconn.uid('fetch', '1:*', '(RFC822)')
> 
> As a result I receive the following results (from 2 different servers):
> 
> # mailserver 1
> messages = [
>      ('1 (UID 2 RFC822 {616}', "Received: from SNIP..."),
>      ')',
>      ('2 (UID 4 RFC822 {626}', "Received: from SNIP..."),
>      ')',
> ]
...
> Does anybody have a clue as to why imaplib returns results like that?

It has to parse the response that far, in order to read the
whole thing.  That '{616}' is as you probably surmised the
length of the following text, spanning more than a single line,
so imaplib needs that number.  The intent is not to provide
you with a fully parsed IMAP4 response, you're just getting
the data and whatever parsing was needed along the way.  In
a perversely ideal sense, it might have been better to put
the pieces back together and just give you the response as
one string.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list