IMAP4 and deleting a message

  • Thread starter Wilfredo Sanchez
  • Start date
W

Wilfredo Sanchez

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
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

Wilfredo Sanchez said:
Can someone hook me up?

I think IMAP does not have the notion of immediately deleting
messages. Instead, you should set the \Deleted flags, e.g. though

M.store(num, "+flags", r"\Deleted")

Then, deleted message will be expunged either as the result of
invoking .expunge(), or as a result of invoking .close().

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top