Skip to content

Instantly share code, notes, and snippets.

@rmatil
Created January 3, 2018 15:24
Show Gist options
  • Save rmatil/015f6c51190175fc9eaaba3a9ba90d66 to your computer and use it in GitHub Desktop.
Save rmatil/015f6c51190175fc9eaaba3a9ba90d66 to your computer and use it in GitHub Desktop.
Archive read emails from a particular Label
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