appending messages in imaplib

huw.lynes at gmail.com huw.lynes at gmail.com
Mon Dec 5 09:40:05 EST 2005


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 through this thicket would be to knock up a
quick python script using imaplib to replicate folder structures on the
IMAP server and copy the mails accross.

Accessing the IMAP server is great. I can log in, search for mail,
change folder and fetch mail. but I just can't seem to get .append() to
work. Here is a quick example.

server = IMAP4("mail01")
server.login("huw-l","xxxxxxxxx")
('OK', ['LOGIN completed.'])
server.create("Migration")
('OK', ['CREATE completed.'])
#using a mail client I can verify that the folder was created
server.select("Inbox")
'OK'
r,data = server.fetch('220','(RFC822)')
#data now contains a real mail message off the server
message = data
server.append("Migration",None,None,message)

at which point it just sits there and does nothing. Any ideas greatly
appreciated. I'm assuming that it has something to do with the way I'm
passing it the message but I don't really know where to go from here.

Thanks,
Huw




More information about the Python-list mailing list