-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathApplyLabels.js
More file actions
42 lines (26 loc) · 742 Bytes
/
Copy pathApplyLabels.js
File metadata and controls
42 lines (26 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function applyLabel() {
const threads = GmailApp.getInboxThreads();
const myLabel = "Medium Stats";
const all_labels = [];
//Logger.log(typeof(all_labels));
GmailApp.getUserLabels().forEach((label)=>{
all_labels.push(label.getName());
})
Logger.log(all_labels);
let tempLabel;
if(all_labels.includes(myLabel)){
tempLabel = GmailApp.getUserLabelByName(myLabel);
}
else{
GmailApp.createLabel(myLabel)
}
Logger.log(tempLabel)
threads.forEach(function(message){
//Logger.log(message);
const first_message = message.getFirstMessageSubject();
if(first_message.includes("Stats for your stories")){
message.addLabel(tempLabel);
//message.moveToArchive();
}
})
}