Find new messages added to an imap mailbox since I last checked with python libimap2?

Posted by vy32 on Stack Overflow See other posts from Stack Overflow or by vy32
Published on 2010-01-12T06:12:57Z Indexed on 2010/03/25 0:53 UTC
Read the original article Hit count: 475

Filed under:
|
|

I am trying to write a program that monitors an IMAP mailbox and automatically copies every new incoming message into an "Archive" folder. I'm using imaplib2 which implements the IDLE command. Here's my basic program:

M = imaplib2.IMAP4("mail.me.com")
M.login(username,password)
lst = M.list()
assert lst[0]=='OK'
for mbx in lst[1]:
    print "Mailboxes:",mbx

def process(m):
    print "m=",m
    res = M.recent()
    print res


M.select('INBOX')
M.examine(mailbox='INBOX',callback=process)
while True:
    print "Calling idle..."
    M.idle()
    print "back from idle"
M.close()
M.logout()

It prints the mailboxes properly and runs process() when the first change happens to the mailbox. But the response from recent() doesn't make sense to me, and after the first message I never get any other notifications.

Anyone know how to do this?

© Stack Overflow or respective owner

Related posts about python

Related posts about imap