[Tutor] Moving email between servers
VanL
vlindberg@verio.net
Wed, 02 May 2001 16:54:58 -0600
Hello,
I have got what is pretty simple problem conceptually, but I don't know
how to implement it. I know that some of the semantics aren't quite
right -- that is OK. I will note where the problems are.
(Pseudocode)
M1 = poplib.POP3('server1')
M2 = imaplib.IMAP4('server2')
M1.login(user,pass)
M2.login(user,pass)
folders = M1.listfolders()
^^^^^^^^^^^^^^^^^^^^^^^^^^
# Get a list of a folders
PROBLEM: I can't find out how to get the contents of anything but the
inbox.
for folder in folders:
# create the folder on the new server
M2.create(folder)
# get all messages, move them to the new server
numMsgs = len(M1.list()[1])
for i in range(numMsgs):
for j in M1.retr(i+1)[1]:
M2.append(j)
M1.close()
M2.close()
Essentially, I want to recursively copy all mailfolders and messages
from one server to another. I only have POP3 access to the first
server.
Any ideas? I have looked at the poplib module, but I can't figure out
how to do it.
Thanks,
VanL