IMAP4 and deleting a message

Wilfredo Sanchez wsanchez at apple.com
Mon Dec 8 17:34:34 EST 2003


  The docs for imaplib are pretty scant, and i guess the library is 
meant for people who already know IMAP well and want low-level access to 
the protocol, as opposed to someone who wants "get me the list of 
messages" and "get me #34".

  I'm one of the latter people, and were it not for the example, I'd 
have no clue how to read messages with the API.  After some poking 
around, I'm still clueless about how to delete the messages I've read:

   import getpass, imaplib

   M = imaplib.IMAP4()
   M.login(getpass.getuser(), getpass.getpass())
   M.select()
   typ, data = M.search(None, 'ALL')
   for num in data[0].split():
       typ, data = M.fetch(num, '(RFC822)')
       print 'Message %s\n%s\n' % (num, data[0][1])
       # DELETE THE MESSAGE HERE
   M.logout()

  Can someone hook me up?

   -wsv




More information about the Python-list mailing list