IMAP4 and deleting a message

Discussion in 'Python' started by Wilfredo Sanchez, Dec 8, 2003.

  1. 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
    Wilfredo Sanchez, Dec 8, 2003
    #1
    1. Advertising

  2. Wilfredo Sanchez <> 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
    Martin v. =?iso-8859-15?q?L=F6wis?=, Dec 8, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Dalberg

    Free pop3 or IMAP4 control?

    John Dalberg, Sep 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,330
  2. Christian Rothe

    setting email FLAGs in IMAP4 box

    Christian Rothe, Feb 10, 2004, in forum: Python
    Replies:
    0
    Views:
    263
    Christian Rothe
    Feb 10, 2004
  3. Max M

    IMAP4.search by message-id ?

    Max M, Mar 30, 2005, in forum: Python
    Replies:
    2
    Views:
    384
    Sean Dodsworth
    Mar 30, 2005
  4. Tony Meyer

    RE: IMAP4.search by message-id ?

    Tony Meyer, Mar 31, 2005, in forum: Python
    Replies:
    1
    Views:
    855
    Sean Dodsworth
    Mar 31, 2005
  5. Harry Barker
    Replies:
    2
    Views:
    513
    Alf P. Steinbach
    Apr 19, 2006
Loading...

Share This Page