SHARE
TWEET

gmail forward to newsblur rss

adamlogan Jan 24th, 2019 (edited) 208 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //one per line, without http:// etc, just domain-name.com or domainname.com ....
  2. var domains = [
  3.   'dripemail2.com',
  4.   'sendgrid.me',
  5.   'mailchimpapp.net',
  6. ];
  7.  
  8.   //This is not the best solution, a better solution would be to add a filter like this for example => From: #domainname.com
  9.   //and then this app would read your GMail filters and test whether it begins with # to apply the next function if so.. but I couldn't find a way to read GMail settings from here
  10.  
  11. function filterVia() {
  12.   // get all threads in inbox
  13.   var threads = GmailApp.getInboxThreads();
  14.  
  15.   for (var i = 0; i < threads.length; i++) {
  16.     Utilities.sleep(10);
  17.     // get all messages in a given thread
  18.     var messages = threads[i].getMessages();
  19.     // iterate over each message
  20.     for (var j = 0; j < messages.length; j++) {
  21.       // log message subject
  22.       var content = messages[j].getRawContent();
  23.      
  24.       for (var k = 0; k < domains.length; k++) {
  25.         //make domain name as regexp
  26.         var re = new RegExp('\\.|\\-', 'gi');
  27.         var b = domains[k].replace(re, '\\$&');
  28.         var regex = new RegExp("Received\: from .*" + b,'gim');
  29.         var does_match = regex.test(content);
  30.        
  31.         if(does_match){
  32.           //MARK AS READ (maybe spares you an unnecessary notification)
  33.           messages[j].markRead();
  34.          
  35.          
  36.           Logger.log(messages[j].getSubject());
  37.             var subject = messages[j].getSubject();
  38.             Logger.log(messages[j].getBody());
  39.             var body = messages[j].getBody();
  40.             Logger.log(messages[j].getId());
  41.             var id = messages[j].getId();
  42.  
  43.           MailApp.sendEmail({
  44.          to: "namehash@newsletters.newsblur.com",
  45.          subject: subject,
  46.          htmlBody: "https://mail.google.com/mail/u/0/#inbox/"+id+""+body+"",
  47.        });
  48.          
  49.           //DELETE THE MESSAGE
  50.           messages[j].moveToTrash();          
  51.         }
  52.        
  53.       }
  54.     }
  55.   }
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top