Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > imaplib ... understanding the result from a fetch of RFC822s

Reply
Thread Tools

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

 
 
Max M
Guest
Posts: n/a
 
      11-17-2004
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..."),
')',
]

# mailserver 2

messages = [
('1 (RFC822 {1155}', "Return-path: SNIP..."),
' UID 1)',
('2 (RFC822 {977}', "Return-path: SNIP..."),
' UID 2)',
('3 (RFC822 {1016}', "Return-path: SNIP..."),
' UID 3)',
('4 (RFC822 {1153}', "Return-path: SNIP..."),
' UID 4)',
('5 (RFC822 {732}', 'Mime-Version: SNIP...'),
' UID 5)',
]

It's just a long list which seems to have the structure:

list = [
(envelope start, rfc288-message), envelope-end,
(envelope start, rfc288-message), envelope-end,
(envelope start, rfc288-message), envelope-end,
]

To me this is an odd format. It's sort of a parenthesized list, but not
really.

I guess that I can iterate it like:

for ((envelopeStart, msg), envelopeEnd) in range(0, len(messages), 2):
# do stuff

But I feel a bit uncertain that it won't break in some edge cases.

Does anybody have a clue as to why imaplib returns results like that?


--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
 
Reply With Quote
 
 
 
 
Max M
Guest
Posts: n/a
 
      11-17-2004
Max M wrote:

> I guess that I can iterate it like:
>
> for ((envelopeStart, msg), envelopeEnd) in range(0, len(messages), 2):
> # do stuff


I guess not. I really meant:

for i in range(0, len(results), 2):
((envelopeStart, msg), envelopeEnd) = (results[0], results[1])

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
 
Reply With Quote
 
 
 
 
Donn Cave
Guest
Posts: n/a
 
      11-18-2004
In article <419bb3a7$0$259$>,
Max M <> 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,
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: imaplib fetch message flags Gabriel Genellina Python 1 03-02-2009 08:22 AM
imaplib fetch message flags Rich Healey Python 0 03-02-2009 03:53 AM
Problem with imaplib (weird result if mailbox contains a %) Antoon Pardon Python 5 11-30-2006 05:59 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
Re: imaplib ... understanding the result from a fetch of RFC822s Jp Calderone Python 1 11-19-2004 09:28 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57