Skip to content

Instantly share code, notes, and snippets.

@colinloretz
Created March 2, 2014 00:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save colinloretz/9299685 to your computer and use it in GitHub Desktop.
Save colinloretz/9299685 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();
}
@colinloretz
Copy link
Author

Also, the fact that this whole thing works was kind of amazing to me since it never appears to ask for permission to Google Mail from Google Docs....

@sbeckeriv
Copy link

To get scripts go to connect more apps when you click create and search for script.

I got lost after step 5.

I clicked "update" then

Resources -> current projects triggers

From there I set it to run every hour. I also ran it manually once. When I manually ran it it asked me for permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment