imaplib and fetch results
Piers Lauder
piers at cs.su.oz.au
Thu Jan 27 21:37:15 EST 2000
On 27 Jan 2000 17:22:29 +0100, Harald Terkelsen wrote:
> I've been playing with the imaplib.py module and found some difference
> in the returned data of the fetch function depending on the
> message_part argument.
>
> The command:
>
> typ, data = M.FETCH('13:17', '(FLAGS envelope)')
>
> returns a list where data[0] is the flags and envelope data from
> message 13, data[1] for message 14 and so on. This is what i would
> expect.
>
> But the result of the following command is somewhat different:
>
> typ, data = M.FETCH('13:17', '(FLAGS body.peek[header.fields (From Subject)])')
>
> Now data[0] contains the information from message 13 as in the previous
> fetch command. I would then assume data[1] to contain the requested
> information for message 14, but it doesn't. Instead data[1] contains
> the character ')'. data[2] contains the data for message 14 and
> data[3] gives me again an ')' and so on.
>
> Does anybody know why it is like this, or is it a bug?
This is a feature, not a bug :-)
The reason is that to fix the problem you are seing I would have to
enhance imaplib to parse all responses from all commands, and that's
something I'd prefer that the user do.
The `correct' way to deal with responses from an IMAP4 server is to
concatenate all the strings returned, and then parse the response per
the RFC.
The server's responses to multi-part commands is to return a series of
packets in the form "description [literal]" and the imaplib returned
data reflects this (you'll see a list item consisting of a tuple of 2
strings). So if the server sends a packet consisting of just a single
')' (presumably terminating a parenthesis in a previous description,
probably after some "literal" data), you'll see it as a single list
item following the one with the data.
Hope that helps!
Piers.
More information about the Python-list
mailing list