-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmail.js
31 lines (30 loc) · 1.17 KB
/
gmail.js
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
// Modified from http://lyzidiamond.com/posts/github-notifications-google-script/
function processInbox() {
var threads = GmailApp.getInboxThreads(0, 50);
for (var i = 0; i < threads.length; i++) {
var thread = threads[i];
var messages = thread.getMessages();
if (messages && ((messages[0].getFrom()).indexOf("github.com") > -1)) {
if ((messages[0].getFrom()).indexOf("[email protected]") > -1) {
thread.addLabel(GmailApp.getUserLabelByName("Notification"));
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
sortMessage(message, thread);
}
}
thread.moveToArchive();
}
}
}
function sortMessage(message, thread) {
var body = message.getRawContent();
if (body.indexOf("X-GitHub-Reason: mention") > -1) {
thread.addLabel(GmailApp.getUserLabelByName("Direct mention"));
}
if ((body.indexOf("X-GitHub-Reason: author") > -1) || (body.indexOf("X-GitHub-Reason: comment") > -1)) {
thread.addLabel(GmailApp.getUserLabelByName("Participating"));
}
if (body.indexOf("X-GitHub-Reason: team_mention") > -1) {
thread.addLabel(GmailApp.getUserLabelByName("Team mention"));
}
}