Last active
May 2, 2022 20:00
-
-
Save nonsocchi/4689743a3232f8ec859007f0f5a40c20 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
function labelMessagesAsDone(messages) { | |
var labelName = 'scripting-emails'; | |
Logger.log('Processing labels...'); | |
var mylabel = GmailApp.getUserLabelByName(labelName); | |
if (!mylabel) { | |
mylabel = GmailApp.createLabel(labelName); | |
Logger.log("Label doesn't exist, creating new " + labelName); | |
} | |
for (var m = 0; m < messages.length; m++) { | |
mylabel.addToThread(messages[m].getThread()); | |
} | |
} | |
function processTxnEmails() { | |
var messages = getBankEmails(); | |
var txnData = parseMessageBody(messages); | |
saveToSheet(txnData); | |
labelMessagesAsDone(messages); // add this | |
return true; // and this. | |
} | |
// FILTERING EMAILS... | |
function getBankEmails() { | |
// This function searches for messages from emails having subject containing | |
// “GeNS transaction Alert … and your chosen label” | |
var filter = "subject:GeNS transaction Alert AND -label:scripting-emails"; // add label | |
var threads = GmailApp.search(filter, 0, 10); | |
var messages = []; | |
for (var x in threads) { | |
var thread = threads[x] | |
messages.push(thread.getMessages()[0]); | |
} | |
return messages; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment