-
-
Save valmayaki/e8144339ceb460e6b6b12814f1500b81 to your computer and use it in GitHub Desktop.
Archive Gmail Regularly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code modified from: http://www.johneday.com/422/time-based-gmail-filters-with-google-apps-script | |
// This is code for a Google Apps Script. You can add the code and give it permissions at script.google.com | |
// Archive every thread in your Inbox that is older than two days, and not starred. | |
function archiveInbox() { | |
var threads = GmailApp.search('label:inbox older_than:2d -in:starred'); | |
for (var i = 0; i < threads.length; i++) { | |
threads[i].moveToArchive(); | |
} | |
} | |
// Archive every thread in your tabs that is older than one day, and not starred. | |
// valid categories include ["primary", "promotions", "social", "updates", "forums"]; | |
function batchArchiveCategories() { | |
var categories = ["social", "promotions", "updates"]; | |
var batchSize = 100 // Process up to 100 threads at once | |
for (i = 0; i < categories.length; i++) { | |
var threads = GmailApp.search('label:inbox category:'+categories[i]+' older_than:1d -in:starred'); | |
for (j = 0; j < threads.length; j+=batchSize) { | |
GmailApp.moveThreadsToArchive(threads.slice(j, j+batchSize)); | |
} | |
} | |
} | |
// To run regularly, click Resources >> Current Project's Triggers. | |
// Choose runAll() and set how often you want the script to execute. | |
function runAll() { | |
batchArchiveCategories(); | |
archiveInbox(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment