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.
@Heady23 "processed 0 threads" just means the conditions in your var 'search' didn't fit any messages in your account. The original script example only fits messages in the inbox old than 'DELETE_AFTER_DAYS' (7 days) by default, so perhaps you have your messages in alternative folder labels? You can consult my modified version in the reply before this for another search example.
Make sure the 'purge' function is working when run manually in the editor first, then the trigger should work as well.