I have a Google Apps Script which searches the inbox for messages from a certain email address, adds a new label and then archives the email so as to remove the inbox tag. I'm wondering, is there an easy way to apply the script to many different email addresses and apply different filing labels without making an individual script or having a bloated single script with all the different email addresses in it?
function _getFilingLabel() {
var label_text = "**folder name for filing**";
var label = GmailApp.getUserLabelByName(label_text);
if (label == null) {
var label = GmailApp.createLabel(label_text);
}
return label;
}
function addfilelabel() {
var label = _getFilingLabel();
var threads = GmailApp.search('from:(**email address here**) label:inbox older_than:30d');
for (var i = 0; i < threads.length; i++) {
label.addToThread(threads[i]);
}
}
/**
* SCAN THROUGH THE "**folder name for filing**" label and unlabel any items that aren't currently in the inbox
*/
function removeinboxlabel() {
// Every thread in label is archived to remove the inbox label.
var threads = GmailApp.search('label:"**folder name for filing**"');
for (var i = 0; i < threads.length; i++) {
threads[i].moveToArchive();
}
}
function incorrectfiled() {
// Checks for items incorrectly filed in folder with activity newer than 30d.
var threads = GmailApp.search('label:"**folder name for filing**" newer_than:30d');
for (var i = 0; i < threads.length; i++) {
threads[i].moveToInbox();
}
}