Created
April 21, 2014 09:26
-
-
Save glebsap/11137445 to your computer and use it in GitHub Desktop.
Google Apps Script for Gmail, creates a label that matches all threads where you are the last sender
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_last_sent_message() { | |
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("LastSentMessage"); | |
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]; | |
var lastMessageSender = lastMessage.getFrom().match(EMAIL_REGEX)[0]; | |
if ((thread.getMessageCount() > 1) && (lastMessageSender == emailAddress)) | |
{ | |
thread.addLabel(label); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you kindly have a look? I'm experiencing some issues: