Deleting email message using imaplib?

B

Bill Sneddon

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'('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
 
M

Mark Roach

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

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
 
B

Bill Sneddon

Mark Roach wrote:

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


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

[...]


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
 

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

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top