I've been getting a lot of spam emails from various colleges. I wrote a simple Python program to go through my emails, and find all the ones whose sender ends in .edu.
Then, to delete it, I though I was supposed to add the \\Deleted flag to those emails using: Gmail.store(id, "+FLAGS", "\\Deleted"). This did not work, and some of them didn't even disappear from the inbox. 
After more research, I found that instead I had to use Gmail.store(id, "+X-GM-LABELS", "\\Trash"). 
So I updated the program to use that, but now it doesn't see any of the emails that I previously added the \\Deleted flag to.
Is there any way I can reset all those emails and then trash them afterward?
They should be in your All Mail folder. Use the WebUI and search for them and trash them, or select the "[Gmail]\All Mail" folder (watch out for localization, this can change name for non-English users).
Python imaplib recover emails with \\Deleted flag and move to trash