Skip to content

Instantly share code, notes, and snippets.

@ericduran
Created January 9, 2013 22:01
Show Gist options
  • Save ericduran/4497375 to your computer and use it in GitHub Desktop.
Save ericduran/4497375 to your computer and use it in GitHub Desktop.
Enhancing my gmail filters!
/**
* Using Google Apps Script to enhance my gmail filters.
*
* I constantly receive email that are important for a short period of time (When I order food online!!!!) but after
* the email is no longer relative (When I get my food!) I have no need for this email. Sadly they tend to pile up on me
* (I eat a lot).
*
* Anyways you can add this 8hrDelete.gs file to https://script.google.com and set it up on a "Time Driven" trigger at what
* ever time you'll like. I run it at midnight
*/
/**
* Delete all emails tag with "8hr Delete" after 8hr of the last message.
*/
function processLabelInbox() {
var lastDate,
labelName = "8hr delete",
cutOff = (60 * 60 * 8),
currentDate = Date.now(),
label = GmailApp.getUserLabelByName(labelName),
threads = label.getThreads();
for (var i = 0; i < threads.length; i++) {
lastDate = Date.parse(threads[i].getLastMessageDate());
if (lastDate <= (currentDate - cutOff)) {
threads[i].moveToTrash();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment