Deleting email message using imaplib?

Discussion in 'Python' started by Bill Sneddon, Aug 25, 2003.

  1. Bill Sneddon

    Bill Sneddon Guest

    Anyone have an example they are willing to share that shows
    how to use the store command in imaplib?

    store( message_set, command, flag_list)
    Alters flag dispositions for messages in mailbox.

    I have been unable to find one or get the syntax correct through
    trial and error.

    I can send the command to the server in the following manor.
    The only problem is I can not get the response back from the server.
    I tried the recent() and the responce(code) objects with no success.
    Not sure what the code should be.

    I would be open to a different approach to delete a message if one exist.


    This is example of deleting from PythonWin.


    >>> m.send('A003 STORE 2:4 +FLAGS (\Deleted)')
    >>> m.recent()

    ('OK', ['0'])
    >>> m.expunge()

    Traceback (most recent call last):
    File "<interactive input>", line 1, in ?
    File "C:\Python23\lib\imaplib.py", line 402, in expunge
    typ, dat = self._simple_command(name)
    File "C:\Python23\lib\imaplib.py", line 1000, in _simple_command
    return self._command_complete(name, self._command(name, *args))
    File "C:\Python23\lib\imaplib.py", line 832, in _command_complete
    raise self.abort('command: %s => %s' % (name, val))
    abort: command: EXPUNGE => unexpected response: 'A0032 OK STORE completed'
    >>> m.expunge()

    ('OK', ['2', '2', '2'])


    Thanks for your help. Sorry if this is a FAQ but I looked and could not
    find the answer.

    Bill Sneddon
    Bill Sneddon, Aug 25, 2003
    #1
    1. Advertising

  2. Bill Sneddon

    Mark Roach Guest

    On Mon, 25 Aug 2003 16:14:45 -0400, Bill Sneddon wrote:

    > Anyone have an example they are willing to share that shows
    > how to use the store command in imaplib?

    [...]
    > >>> m.send('A003 STORE 2:4 +FLAGS (\Deleted)')


    here's what I use, works just fine.

    imconn = imaplib.IMAP4(server)
    imconn.login(username, password)
    imconn.select(folder)
    imconn.store(msgid, "+FLAGS", '(\\Deleted)')
    imconn.expunge()


    -Mark
    Mark Roach, Aug 25, 2003
    #2
    1. Advertising

  3. Bill Sneddon

    Bill Sneddon Guest

    Mark Roach wrote:

    Thanks,
    Works for me too. I did not escape the \.
    rookie mistake :)


    Bill

    > On Mon, 25 Aug 2003 16:14:45 -0400, Bill Sneddon wrote:
    >
    >
    >>Anyone have an example they are willing to share that shows
    >>how to use the store command in imaplib?

    >
    > [...]
    >
    >> >>> m.send('A003 STORE 2:4 +FLAGS (\Deleted)')

    >
    >
    > here's what I use, works just fine.
    >
    > imconn = imaplib.IMAP4(server)
    > imconn.login(username, password)
    > imconn.select(folder)
    > imconn.store(msgid, "+FLAGS", '(\\Deleted)')
    > imconn.expunge()
    >
    >
    > -Mark
    Bill Sneddon, Aug 25, 2003
    #3
    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. Raghul
    Replies:
    4
    Views:
    537
    Raghul
    Feb 22, 2005
  2. Tony Meyer
    Replies:
    0
    Views:
    422
    Tony Meyer
    Feb 22, 2005
  3. Rich Healey

    imaplib fetch message flags

    Rich Healey, Mar 2, 2009, in forum: Python
    Replies:
    0
    Views:
    401
    Rich Healey
    Mar 2, 2009
  4. Gabriel Genellina

    Re: imaplib fetch message flags

    Gabriel Genellina, Mar 2, 2009, in forum: Python
    Replies:
    1
    Views:
    1,148
    Lawrence D'Oliveiro
    Mar 2, 2009
  5. Replies:
    0
    Views:
    103
Loading...

Share This Page