-
-
Save fizerkhan/aed6f114a8c3f4fcd1c7f4979739df0d to your computer and use it in GitHub Desktop.
AwaitingReply
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 label_awaiting_reply() { | |
var emailAddress = Session.getEffectiveUser().getEmail(); | |
Logger.log(emailAddress); | |
var EMAIL_REGEX = /[a-zA-Z0-9\._\-]+@[a-zA-Z0-9\.\-]+\.[a-z\.A-Z]+/g; | |
var label = GmailApp.createLabel("AwaitingReply"); | |
var d = new Date(); | |
d.setDate(d.getDate() - 7); | |
var dateString = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate(); | |
threads = GmailApp.search("in:Sent after:" + dateString); | |
for (var i = 0; i < threads.length; i++) | |
{ | |
var thread = threads[i]; | |
var lastMessage = thread.getMessages()[thread.getMessageCount()-1]; | |
lastMessageSender = lastMessage.getFrom().match(EMAIL_REGEX)[0]; | |
if (lastMessageSender != emailAddress) | |
{ | |
thread.addLabel(label); | |
Logger.log(lastMessageSender); | |
} | |
} | |
} | |
function doGet(e){ | |
label_awaiting_reply(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment