Guest User

Google Script for Reply-To-Later

a guest
Jun 26th, 2014
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function findEmailsToReplyTo(){
  2.   var threads = GmailApp.getUserLabelByName("_rtl").getThreads();
  3.   var subjs = "";
  4.   for(var i = 0; i < threads.length; i++){
  5.     var MRMsg = threads[i].getMessages()[threads[i].getMessageCount() - 1];
  6.    
  7.     if(MRMsg.getFrom() != "XYZ <xyz@gmail.com>")
  8.     {
  9.       subjs += threads[i].getFirstMessageSubject() + " - ";
  10.       subjs += getNiceFrom(threads[i].getMessages()[0].getFrom()) + "| ";
  11.     }    
  12.   }  
  13.  
  14.   if(subjs.length > 0)
  15.   {
  16.     var email = Session.getActiveUser().getEmail();
  17.     var body = ' ';
  18.     GmailApp.sendEmail(email, subjs, body);
  19.   }
  20. }
  21.  
  22. function getNiceFrom(from) {
  23.   if(from.indexOf("<") > 0 && from.indexOf(">") > 0) {
  24.     return from.substring(0, from.indexOf("<"));
  25.   }
  26. }
  27.  
  28. /**
  29.  * Retrieves all inbox threads and logs the respective subject lines.
  30.  * For more information on using the GMail API, see
  31.  * https://developers.google.com/apps-script/class_gmailapp
  32.  */
  33. function processInbox() {
  34.   // get all threads in inbox
  35.   var threads = GmailApp.getInboxThreads();
  36.   for (var i = 0; i < threads.length; i++) {
  37.     // get all messages in a given thread
  38.     var messages = threads[i].getMessages();
  39.     // iterate over each message
  40.     for (var j = 0; j < messages.length; j++) {
  41.       // log message subject
  42.       Logger.log(messages[j].getSubject());
  43.     }
  44.   }
  45. };
  46.  
  47. /**
  48.  * Retrieves a given user label by name and logs the number of unread threads
  49.  * associated with that that label.
  50.  * For more information on interacting with GMail labels, see
  51.  * https://developers.google.com/apps-script/class_gmaillabel
  52.  */
  53. function processLabel(labelName) {
  54.   // get the label for given name
  55.   var label = GmailApp.getUserLabelByName(labelName);
  56.   // get count of all threads in the given label
  57.   var threadCount = label.getUnreadCount();
  58.   Logger.log(threadCount);
  59. };
  60.  
  61.  
  62. /**
  63.  * Marks the email thread with the specified ID as important.
  64.  * For more information on interacting with GMail threads, see
  65.  * https://developers.google.com/apps-script/class_gmailthread
  66.  */
  67. function markThreadImportant(threadId) {
  68.   var thread = GmailApp.getThreadById(threadId);
  69.   thread.markImportant();
  70. };
Add Comment
Please, Sign In to add comment