Created
January 3, 2018 15:24
-
-
Save rmatil/015f6c51190175fc9eaaba3a9ba90d66 to your computer and use it in GitHub Desktop.
Archive read emails from a particular 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 moveReadLogglyMailsToArchive() { | |
// Get all inbox emails (the label is applied by a filter matching all incoming conversations) | |
var label = GmailApp.getUserLabelByName("[Loggly Autoarchiver] Inbox"); | |
if (label === null || label === undefined) { | |
// abort | |
return -1; | |
} | |
var threads = label.getThreads(); | |
for (var i = 0; i < threads.length; i++) { | |
// only archive read emails | |
if (! threads[i].isUnread()) | |
{ | |
// remove archiver's inbox label | |
threads[i].removeLabel(label); | |
// but add the archiver's archive label | |
threads[i].addLabel(GmailApp.getUserLabelByName("[Loggly Autoarchiver] Archived")); | |
// move to archive eventually | |
threads[i].moveToArchive(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment