From a1511a2e3d9de6b3d0ea36010ac2bd8a66c3d4d0 Mon Sep 17 00:00:00 2001 From: Niraj D Date: Mon, 18 Dec 2017 12:01:02 -0500 Subject: [PATCH] update unsubscribe link logic 1. find the correct link in the array (the one that starts with http) for parsed html text 2. assign the last value instead of the 2nd value in the array for list-unsubscribe --- noneroll.gs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/noneroll.gs b/noneroll.gs index d93365b..945bb6e 100644 --- a/noneroll.gs +++ b/noneroll.gs @@ -54,18 +54,29 @@ function getEmails() { d.uns = null var uns = threads[i].getMessages()[0].getRawContent().match(/^list\-unsubscribe:(.|\r\n\s)+<(https?:\/\/[^>]+)>/im); + Logger.log(uns+"\n\n") if(uns) { - d.uns = uns + d.uns = uns[uns.length-1] } else { var rex = /.*?]*href=["'](https?:\/\/[^"']+)["'][^>]*>(.*?)<\/a>.*?/gi while(u = rex.exec(threads[i].getMessages()[0].getBody())){ if(u[0].toLowerCase().indexOf('unsubscribe')!==-1){ - d.uns=u[1] - break + for(var i = u.length-1; i >=0; i--){ + if(u[i].substring(0,4)=="http"){ + d.uns=u[i] + break + } + } + if(d.uns){ + break + } } } } + if(d.uns === null){ + Logger.log(d.subject) + } data.push(d) } else { break @@ -74,6 +85,7 @@ function getEmails() { return data; } + //run every day to send summary email including emails from last 24 hours function noneroll() { if(getEmails().length > 0) {