-
-
Save 0x4a/e410aa72fca06fcfafce9f00ff47d82c to your computer and use it in GitHub Desktop.
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
// Original author fwed (contact@fwed.fr) | |
// Modified from | |
// https://gist.github.com/anonymous/2cca33d376f7f924fdaa67891ad098cc | |
// https://medium.com/@fw3d/auto-archive-emails-in-gmail-after-2-days-1ebf0e076b1c | |
function gmailAutocleanup() { | |
var delete_after = "3d"; | |
var archive_after = "1m"; | |
// ifttt Weather | |
gmailBatchDelete("action@ifttt.com", "tomorrow", delete_after); | |
// myheritage | |
gmailBatchDelete("notify2@myheritage.com", "Kalendererinnerungen", delete_after); | |
// gcal | |
gmailBatchDelete("calendar-notification@google.com", "Tägliche Terminübersicht", delete_after); | |
// archive forum notifications | |
gmailBatchArchive("forum@plentymarkets.eu", archive_after); | |
gmailBatchArchive("studio@synesty.com", archive_after); | |
gmailBatchArchive("support@synesty.com", archive_after); | |
gmailBatchArchive("noreply@synesty.com", archive_after); | |
} | |
function gmailBatchDelete(from, subject, older_than) { | |
var threads; | |
var thread; | |
var string = "from:" + from + " subject:" + subject + " older_than:" + older_than; | |
threads = GmailApp.search(string); | |
var num = threads.length; | |
Logger.log("found " + num + " threads older than " + older_than + " for " + from + "\nsearch string = " + string); | |
for(var i = 0; i < threads.length; i++) | |
{ | |
var thread = threads[i]; | |
GmailApp.moveThreadToTrash(thread); | |
} | |
Logger.log("finished deleting " + num + " threads\n"); | |
} | |
function gmailBatchArchive(from, older_than) { | |
var threads; | |
var thread; | |
var string = "from:" + from + " in:inbox -in:starred is:read older_than:" + older_than; | |
threads = GmailApp.search(string); | |
var num = threads.length; | |
Logger.log("found " + num + " threads older than " + older_than + " for " + from + "\nsearch string = " + string); | |
for(var i = 0; i < threads.length; i++) | |
{ | |
var thread = threads[i]; | |
GmailApp.moveThreadToArchive(thread); | |
} | |
Logger.log("finished archiving " + num + " threads\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment