MatthewOden.com
Published on

# Post-Processing Gmail

Author

For my inbox, I use gmailctl to create and manage all of my filters. The majority of my rules are simply a combination of labeling, marking them as read, and archiving. I'd wager that 90% of my emails are simply references and reciepts. Nothing that needs to interrupt my day.

Pre-processing emails is great, but that's not really enough to keep my inbox clean. The killer feature I want for email is post-processing. Why don't we have hooks for after I've read a message? What if I want to be notified about an email, but not have it clutter up my inbox? What if I don't want to be notified, but still want to check on messages later?

Google doesn't have any out-of-the-box answers for this, but there is a solution: the apps-scripts lets you call the gmail api, and you can run scripts on an interval. So I wrote a little script to periodically do just that. Anything I’ve read that’s older than 10 days is archived. Any email I want to get notified about (for right now, just order confirmations) goes to my inbox first, and checked on later.

Below, you'll find my current script. Feel free to use it to create something similar.

function gmailAutoArchive() {
const clearThreads = (query) => {

Logger.log(i + 1 + '. ' + thread.getFirstMessageSubject())
})

const batchSize = 100
)
}
}

const queries = [
// Remove anything read that's over 10 days old.
// any order confirmation that's over one day can get archived.
'in:inbox (label:orders-order-confirmation' +
' OR ' +
'label:orders-shipping) AND older_than:5h',
// any unread emails older than a month probably aren't going to be read.