Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IMAP4 and deleting a message

0 views
Skip to first unread message

Wilfredo Sanchez

unread,
Dec 8, 2003, 5:34:34 PM12/8/03
to
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

Martin v. Löwis

unread,
Dec 8, 2003, 6:10:47 PM12/8/03
to
Wilfredo Sanchez <wsan...@apple.com> writes:

> 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

0 new messages