I am trying to do something as simple as moving an email from inbox to trash using the imaplib of python. However, I am having some problems and I don't know how to solve them.
After connect and login into the server, I select the INBOX mailbox and I get the ids list this way:
typ, ids = imap_object.search(None, 'INBOX') ids_list = ids.split()
Let's suppose I take an Id from there, X, and let's suppose that that email is part of a conversation. When I do
imap_object.fetch (X, '(RFC822)')
I can see just the message, as I expected, but when I do
imap.store(X, '+FLAGS', r'(\Deleted)')
it deletes all the conversation, not just the message!. Also, I don't want to completely remove the email, I want to send it to trash, so I have tried:
imap.copy(X, '[Gmail]/Papelera') imap.store(X, '+FLAGS', r'(\Deleted)') imap.expunge()
but it copies just the message to trash, and after that it deletes the whole conversation, so I am loosing emails!
QUESTION: How can I delete an email from Gmail using imaplib, without deleting the whole conversation?