jonathan
beluch

 

Posted on April 9, 2011.

If you’re like me, you futilely attempt to adhere to inbox zero. Subscribing to a lot of daily emails makes it much harder to keep a clean inbox. I prefer to read these emails, so I don’t have them skip my inbox. However, after 2 or 3 days, I’m not going to read the email if I haven’t already.

Since gmail doesn’t let you auto-archive after a certain date, I made this python script that does just that. You simply set up labels in gmail like this autoarchive:3 where 3 is the age limit in days.

Then simply enter your credentials in the python script, or enter them interactively when the script is run.

The script logs in and gets all your labels similar to the pattern autoarchive:*. Then for each label, it downloads all associated emails that are in your INBOX. It checks the Date header of the email (This can be forged obviously, maybe I’ll check the Received header in the future). If the date is older than the specified age in days, it adds an IMAP flag of \DELETED. In gmail this is how you archive an email, it does not actually delete it.

Check it out on github