473,383 Members | 2,005 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,383 software developers and data experts.

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

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
Jul 18 '05 #1
2 3144
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
Jul 18 '05 #2
In article <41*********************@dread12.news.tele.dk>,
Max M <ma**@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, do**@u.washington.edu
Jul 18 '05 #3

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

Similar topics

1
by: Colin Brown | last post by:
The Python 2.3 documentation in imaplib says: Internaldate2tuple( datestr) Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time. Returns a time module tuple. Time2Internaldate(...
4
by: Raghul | last post by:
Hi Friends, I am doing project in python.I am new to this. My problem is I want to move the mail message to other folder in the mail using imaplib (E.g) I want to move a message from the inbox...
1
by: Raghul | last post by:
Is it posssible to read only the new messages or unread messages using imaplib in python? If it is possible pls specify the module or give a sample code. Thanks in advance
0
by: Wolfgang Kohnen | last post by:
Hello out there! I am new to python and so far I like it a lot. Now I want to create some IMAP mailboxes on my cyrus imapd, with quotas and each user should be subscribed to her/his own spam...
2
by: huw.lynes | last post by:
So I have the unfortunate task of migrating several hundred users from local mail (mbox and mh) up to an exchange server as part of wearisome SOX compliance nonsense. I thought the best path...
5
by: Antoon Pardon | last post by:
This little program gives IMO a strange result. import imaplib user = "cpapen" cyr = imaplib.IMAP4("imap.vub.ac.be") cyr.login("cyrus", "cOn-A1r") rc, lst = cyr.list('""', "user/%s/*" %...
1
by: csselo | last post by:
Hi I am looking for a code sample which searches mail by date with imaplib example: get email from 01.01.2007 to now how can I change imaplib search parameters?
1
by: aspineux | last post by:
imaplib use exception to report errors, but some problems must be detected by checking the return value ! For example, when trying to append into a mailbox with wrong ACL, imaplib return 'NO',...
2
by: Petri Savolainen | last post by:
Hello, Is there a way to get at the "Received" header(s) or is there something in imaplib or imap server implementations that hides these? If not, what IMAP FETCH command should be used? I've...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.