A Google Apps Script script to automatically delete unarchived mail after 7 days that hasn't been starred or marked as important
- Backup your emails using Google Takeout.
- Load this script into a new Google Apps Script project.
- Execute the setPurgeTrigger() function to set a trigger that will call the purge() function every day.
A detailed blog post with more information can be found at https://benbjurstrom.com/purge-email
Thanks to this gist by jamesramsay for getting me started in the right direction.
I noticed that the script was picking up important and starred emails. Perhaps Gmail has updated their label parameters.
In line 76 I changed
in:inbox -in:starred -in:important
to-in:sent -is:starred -is:important
This searches ALL my mail - even archived, and doesn't grab any starred or important threads.