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. Advertisements

  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. Advertisements

  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. Advertisements

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. Chuck Amadi
    Replies:
    2
    Views:
    504
    chuck amadi
    Jun 6, 2004
  2. Raghul
    Replies:
    4
    Views:
    827
    Raghul
    Feb 22, 2005
  3. Harry Barker
    Replies:
    2
    Views:
    662
    Alf P. Steinbach
    Apr 19, 2006
  4. Rich Healey

    imaplib fetch message flags

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

    Re: imaplib fetch message flags

    Gabriel Genellina, Mar 2, 2009, in forum: Python
    Replies:
    1
    Views:
    1,750
    Lawrence D'Oliveiro
    Mar 2, 2009
  6. Rogério Brito
    Replies:
    1
    Views:
    949
    Sean DiZazzo
    Sep 9, 2009
  7. crea
    Replies:
    2
    Views:
    610
    Nobody
    Dec 28, 2012
  8. Replies:
    0
    Views:
    345
Loading...