Created
May 2, 2016 20:51
-
-
Save spullara/6015d23a2e028a15355d7de5254800df to your computer and use it in GitHub Desktop.
This looks for all mail labeled "To be archived" that is older than 1 day, archives it and removes the label.
This file contains 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
function archiveMail() { | |
var delayDays = 1 // Enter # of days before messages are archived | |
var maxDate = new Date(); | |
maxDate.setDate(maxDate.getDate()-delayDays); | |
var label = GmailApp.getUserLabelByName("To be archived"); | |
if (label != null) { | |
var threads = label.getThreads(); | |
for (var i = 0; i < threads.length; i++) { | |
if (threads[i].getLastMessageDate()<maxDate) { | |
threads[i].moveToArchive(); | |
threads[i].removeLabel(label); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment