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
This commit is contained in:
Niraj D 2017-12-18 12:01:02 -05:00 committed by GitHub
parent 78e10befdd
commit a1511a2e3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,17 +54,28 @@ function getEmails() {
d.uns = null d.uns = null
var uns = threads[i].getMessages()[0].getRawContent().match(/^list\-unsubscribe:(.|\r\n\s)+<(https?:\/\/[^>]+)>/im); var uns = threads[i].getMessages()[0].getRawContent().match(/^list\-unsubscribe:(.|\r\n\s)+<(https?:\/\/[^>]+)>/im);
Logger.log(uns+"\n\n")
if(uns) { if(uns) {
d.uns = uns d.uns = uns[uns.length-1]
} else { } else {
var rex = /.*?<a[^>]*href=["'](https?:\/\/[^"']+)["'][^>]*>(.*?)<\/a>.*?/gi var rex = /.*?<a[^>]*href=["'](https?:\/\/[^"']+)["'][^>]*>(.*?)<\/a>.*?/gi
while(u = rex.exec(threads[i].getMessages()[0].getBody())){ while(u = rex.exec(threads[i].getMessages()[0].getBody())){
if(u[0].toLowerCase().indexOf('unsubscribe')!==-1){ if(u[0].toLowerCase().indexOf('unsubscribe')!==-1){
d.uns=u[1] for(var i = u.length-1; i >=0; i--){
if(u[i].substring(0,4)=="http"){
d.uns=u[i]
break break
} }
} }
if(d.uns){
break
}
}
}
}
if(d.uns === null){
Logger.log(d.subject)
} }
data.push(d) data.push(d)
} else { } else {
@ -74,6 +85,7 @@ function getEmails() {
return data; return data;
} }
//run every day to send summary email including emails from last 24 hours //run every day to send summary email including emails from last 24 hours
function noneroll() { function noneroll() {
if(getEmails().length > 0) { if(getEmails().length > 0) {