1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-27 19:30:09 -07:00

js/mailhops{,_details}.js: rework Unsubscribe header parsing.

Instead of dropping additional links in the presentation layer, iterate
over all links in the parsing layer and add each link individually.

Some MTAs wrap the links in angle brackets (<>), so make sure to remove
those, since they wouldn't parse as valid XHTML (and also aren't valid
link targets).
This commit is contained in:
Mihai Moldovan 2024-04-17 12:32:33 +02:00
parent 889b4b6e63
commit 5cf488aab9
2 changed files with 14 additions and 5 deletions

View File

@ -379,11 +379,15 @@ class MailHops {
}
}
if (header_unsubscribe) {
auth.push({
type: 'Unsubscribe',
color: 'grey',
link: header_unsubscribe.replace('<', '').replace('>', '').trim()
});
var unsubscribeArr = header_unsubscribe.split(',');
for (var i = 0; i < unsubscribeArr.length; ++i) {
auth.push({
type: 'Unsubscribe',
color: 'grey',
link: unsubscribeArr[i].replace(/</, '').replace(/>/, '').trim()
});
}
}
return auth;
}

View File

@ -147,6 +147,11 @@ function updateContent(msg, noauth) {
}
else if (msg.message.auth[a].link) {
var add = '';
// We only check for a comma in case our base code failed to split
// the header links up correctly.
// Usually, it should work fine and add multiple buttons for
// multiple links.
if (-1 != msg.message.auth[a].link.indexOf(',')) {
add = '<a class="tiny ui label ' + msg.message.auth[a].color + '" href="'+msg.message.auth[a].link.substr(0,msg.message.auth[a].link.indexOf(','))+'" target="_blank">' + msg.message.auth[a].type + '</a>';
}