Created
October 9, 2013 12:39
-
-
Save pawurb/6900606 to your computer and use it in GitHub Desktop.
Fighting email checking addiction ...
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
//TODO | |
//https://developers.google.com/apps-script/managing_triggers_programmatically | |
function moveDelayedMessages() { | |
receiveEmails("Delayed Messages"); | |
} | |
// receiveEmails() will take all threads in labelname (Default: 'Delayed messages') | |
// and place them into the mailbox. The intent is for a delayed retrieval of | |
// messages when combined with a script timer. | |
function receiveEmails(labelName) { | |
var runTime = new Date(); | |
Logger.log("Merging emails at "+runTime.toLocaleTimeString()); | |
if (labelName == null) { | |
// The default label to divert messages into | |
labelName = "Delayed Messages"; | |
} | |
// Access the messages under that label | |
var label = GmailApp.getUserLabelByName(labelName); | |
// If the label doesn't exist, then create it | |
if (label == null) { | |
label = GmailApp.createLabel(labelName); | |
} | |
// Move each thread in this label into the inbox | |
var threads = label.getThreads(); | |
for (var i = 0; i < threads.length; i++) | |
{ | |
var thread = threads[i]; | |
// Remove thread from Delayed Messages label | |
thread.removeLabel(label); | |
// Check that the message is not smart-labeled 'Bulk' before moving to the inbox | |
var labels = thread.getLabels(); | |
var isBulk = false; | |
labels = thread.getLabels(); | |
for (var j = 0; j < labels.length; j++) { | |
var l = labels[j]; | |
var name = l.getName(); | |
if ( name == "Bulk" || name == "Promotions" || name == "Social Updates" ) { | |
isBulk = true | |
} | |
} | |
if (!isBulk) { | |
thread.moveToInbox(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment