Last active
April 22, 2024 07:56
-
-
Save floriangosse/0731e1f3ce466269f6a2f60b32812616 to your computer and use it in GitHub Desktop.
[Google Apps Script] Gmail: Auto-Archive
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
| 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