Maintaining inbox zero and dealing with old emails takes work (for some, too much work!). This Google Apps script lightens the load a bit by automatically archiving or deleting old emails that are cluttering your inbox, based on a schedule you set.
Whipped up by John Day, these time-based Gmail filters will move old read emails to the trash or auto-archive them.
So, for example, you could automatically get rid of expired daily deals emails or other promotional emails that are more than two days old. First, create a Gmail filter that automatically applies the label “delete me” to that semi-spam when it comes in.
Then the Google Apps script, which you’ll need to authorize for your Gmail account, takes care of deleting emails with that label that are older than two days. You can adjust the number of days before messages are moved to the trash in the script (see the delayDays variable and change the 2 to another number) and under the Resources > Current project’s triggers… option, set the script to check your inbox every half hour or other interval.
For those old, read emails you want to keep but move out of your inbox, there’s another function that archives them. (In the script you can also adjust the older_than search to something other than 2d and add or exclude other labels.)
For more details, see John’s post, where he offers the code for you to paste into a new Google Apps Script. I’ve shared this Google Apps script with the two functions pasted in, so you can just make a copy of it to your account and run it per John’s instructions.
Create time-based Gmail filters with Google Apps Script | Johneday via adayzdone