From 5cf488aab91e5a975f4a4ad01999ca160c21f292 Mon Sep 17 00:00:00 2001 From: Mihai Moldovan Date: Wed, 17 Apr 2024 12:32:33 +0200 Subject: [PATCH] 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). --- js/mailhops.js | 14 +++++++++----- js/mailhops_details.js | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/js/mailhops.js b/js/mailhops.js index 63bb086..d7186d6 100644 --- a/js/mailhops.js +++ b/js/mailhops.js @@ -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(//, '').trim() + }); + } } return auth; } diff --git a/js/mailhops_details.js b/js/mailhops_details.js index 63f9e48..f17944a 100644 --- a/js/mailhops_details.js +++ b/js/mailhops_details.js @@ -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 = '' + msg.message.auth[a].type + ''; }