Skip to content

Instantly share code, notes, and snippets.

@fizerkhan
Forked from colinloretz/AwaitingReply.gs
Created January 17, 2018 18:11
Show Gist options
  • Save fizerkhan/aed6f114a8c3f4fcd1c7f4979739df0d to your computer and use it in GitHub Desktop.
Save fizerkhan/aed6f114a8c3f4fcd1c7f4979739df0d to your computer and use it in GitHub Desktop.
AwaitingReply
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