Skip to content

Instantly share code, notes, and snippets.

@floriangosse
Last active April 22, 2024 07:56
Show Gist options
  • Select an option

  • Save floriangosse/0731e1f3ce466269f6a2f60b32812616 to your computer and use it in GitHub Desktop.

Select an option

Save floriangosse/0731e1f3ce466269f6a2f60b32812616 to your computer and use it in GitHub Desktop.
[Google Apps Script] Gmail: Auto-Archive
var LABEL = 'Auto-Archive';
var OLDER_THEN = '2d';
function archiveIfHasLabelAndOlderEnough() {
var label = GmailApp.getUserLabelByName(LABEL);
// Get all threads which are labeled for auto archive
var threads = GmailApp.search('label:inbox label:' + LABEL + ' older_than:' + OLDER_THEN);
// Process threads
threads.forEach(function (thread) {
thread.moveToArchive();
thread.removeLabel(label);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment