Mail and web retrieval imaplib, rfc822?

Matthew Barre mbarre at
Wed Mar 22 06:51:13 CET 2000

rfc822 is pretty easy to's an example of how I did it in my
current project, and thanks to those of you who helped! (I've assumed you
have downloaded the message and assigned it to a StringIO object, since your
input object has to be something similar) :

tempmsg2 = rfc822.Message(tempmsg1)  # create new rfc object from StringIO
tmpmsg3 = inemsg(tempmsg2)  # assign rfc message to custom inemsg class

class inemsg:
    def __init__(self,msg):
        (self.msgfromname, self.msgfrom) = msg.getaddr('from')
        self.msgto = msg.getaddr('to')
        self.msgsubject = msg.getheader('subject')
        self.msgdate = msg.getheader('date')
        self.msgtext =

"You will find that many of the truths we hold to depend greatly on a
certain point of view." -Obi Wan Kenobi

> From: "Akhar" <akhar at>
> Newsgroups: comp.lang.python
> Date: Mon, 20 Mar 2000 21:55:38 -0800
> Subject: Mail  and web retrieval imaplib, rfc822?
> Hi, I have been using this forum a lot lately! Thanks to everyone for their
> hel and patience!
> I have yet another question, but let me do a brief recap!! I want to make
> scripts for a web based e-mail reading system, and so I went to use
> and the pop server but as  I later found out while surfing the web and
> through some hacking pop isn't as flexible as I thought for that sort of
> service. but my problem now lies in the imaplib. I can see all my messages
> (wich by the way are more numerous than pop had found) with uid rangin from
> 1 through 10. I thought that converting my scripts from the pop adventure
> would be easy, but as it turns out it isn't I had an re.compile() and for
> loop to retrieve everyting from the message body to the from and subject
> headers. But they do not work with the imaplib it tell me that:
> TypeError: argument 1: expected read-only character buffer, list found
> I heard about who supposedly handles those pesky headers and
> message bodies but I can't find a tutorial or example on how to use the to
> retrieve the 'from', 'subject', 'Cc' and etc...
> Also I can't seem to use the uid() command in imaplib ( at least not
> properly), nor the list() ( it lists everything in my users /homedirectory
> wich is where the mailbox is).
> I just need a few more pointers! Your help has been great!
> Thank you in advance for any help!
> Akhar

More information about the Python-list mailing list