Reputation: 15
I use this code to delete a messege from my email:
mail.store(id, '+FLAGS', '\\Deleted')
mail.expunge()
And this code is return 'Ok'.
('OK', [None])
I also changed the Settings in my gmail acount to be:
But i still cant delete messeges. Why is it?
Upvotes: 1
Views: 1289
Reputation: 10985
You are mixing 'message sequence numbers' (MSN, what you are calling 'fake ids') and 'unique ids' (UID, which you are calling 'real ids').
It is more convenient to use UIDs everywhere. There are a few commands that come in both MSN and UID versions: FETCH vs UID FETCH, SEARCH vs UID SEARCH, STORE vs UID STORE. You must be consistent, but they otherwise work identically.
So, if you use UID SEARCH, you should use UID STORE:
email.uid('STORE', id, '+FLAGS', '(\\Deleted)')
email.expunge()
Regarding deletion on Gmail, specifically: despite the user setting about deletion, I have found it always just removes the 'Inbox' label (or whatever folder you happen to be in), which will leave it Archived in your All Mail folder or equivalent. To really delete it, you may need to:
(UID) MOVE
, or a combination of a (UID) COPY
and a deletion.Upvotes: 4
Reputation: 15
I solved my problem, but got another one that Ill be happy if someone respond ti this answer with another answer the the question came up :) When I searched for the id of the messege to delete, I searched with the function 'uid' and got the real uid (for example, if I had 500 messeges and deleted all of them, so the next one I get, will be 501, even if my inbox has just one messege in it.). So instead of using:
email.uids('search', 'ALL')
I used:
email.search(None, 'ALL')
When I deleted the messege, I needed to use the not real id. so for example, the 501 messege will be 1 in it "fake id" (or real..see it how you want to see it.) and the next one will be 2, etc...
So, instead of deleting the 501 messege id, I did it for the 1 messege id.
But, the question came up is: Why there are difference between fetching messeges (and then I will be must using 'real id') and deleting them (and then I will be must using 'not real id'.)
Upvotes: 0