Skip to content

Commit 5660c6c

Browse files
committed
fix highlighting the multi line from address (#312)
1 parent f3eca19 commit 5660c6c

File tree

3 files changed

+55
-34
lines changed

3 files changed

+55
-34
lines changed

CHANGELOG.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
5.0.0pre1 [2022-05-29]
22
------------------
33
- now requires at least Thunderbird 91
4-
- fixed incompatibility with Thunderbird 102 (#306)
4+
- fixed incompatibility with Thunderbird 102 (#306, #312)
55
- Added support for signing algorithm Ed25519-SHA256 (RFC 8463) (#142)
66
- fixed multiple from addresses being treated as ill-formed (#304)
77
- JSDNS: fixed incompatibility with Thunderbird 101 (#303)

experiments/dkimHeader.js

+48-33
Original file line numberDiff line numberDiff line change
@@ -688,42 +688,53 @@ class DkimFavicon {
688688
*/
689689
class DkimFromAddress {
690690
/**
691-
* Get the element containing the from address (without the following star).
691+
* Get the elements containing the from address (without the following star).
692+
* Can return multiple elements, as newer Thunderbird version have
693+
* both a single line and a multi line from address.
692694
*
693695
* @private
694696
* @param {Document} document
695-
* @returns {HTMLElement?}
697+
* @returns {HTMLElement[]}
696698
*/
697699
static _getFromAddress(document) {
698700
// TB >=102
699701
const fromRecipient0Display = document.getElementById("fromRecipient0Display");
700702
if (fromRecipient0Display) {
701-
return fromRecipient0Display;
703+
// eslint-disable-next-line no-extra-parens
704+
const fromRecipient0 = /** @type {HeaderRecipient?} */ (document.getElementById("fromRecipient0"));
705+
if (!fromRecipient0) {
706+
console.warn("DKIM: multi line from address not found (no fromRecipient0)");
707+
} else if (!fromRecipient0.multiLine) {
708+
console.warn("DKIM: multi line from address not found (fromRecipient0 has no multiLine)");
709+
} else {
710+
return [fromRecipient0Display, fromRecipient0.multiLine];
711+
}
712+
return [fromRecipient0Display];
702713
}
703714

704715
// TB <102
705716
// eslint-disable-next-line no-extra-parens
706717
const expandedFromBox = /** @type {expandedfromBox?} */ (document.getElementById("expandedfromBox"));
707718
if (!expandedFromBox) {
708719
console.debug("DKIM: from address not found (no expandedfromBox)");
709-
return null;
720+
return [];
710721
}
711722
if (!("emailAddresses" in expandedFromBox)) {
712723
console.debug("DKIM: from address not found (no expandedFromBox.emailAddresses)");
713-
return null;
724+
return [];
714725
}
715726
const mailEmailadress = expandedFromBox.emailAddresses.firstElementChild;
716727
if (!mailEmailadress) {
717728
console.debug("DKIM: from address not found (no firstElementChild)");
718-
return null;
729+
return [];
719730
}
720731
const emailValue = mailEmailadress.getElementsByClassName("emaillabel")[0];
721732
if (!emailValue) {
722733
console.debug("DKIM: from address not found (no emaillabel)");
723-
return null;
734+
return [];
724735
}
725736
// eslint-disable-next-line no-extra-parens
726-
return /** @type {HTMLElement} */ (emailValue);
737+
return [/** @type {HTMLElement} */ (emailValue)];
727738
}
728739

729740
/**
@@ -735,13 +746,15 @@ class DkimFromAddress {
735746
* @returns {void}
736747
*/
737748
static setHighlightColor(document, color, backgroundColor) {
738-
const emailValue = this._getFromAddress(document);
739-
if (!emailValue) {
749+
const emailValues = this._getFromAddress(document);
750+
if (!emailValues) {
740751
return;
741752
}
742-
emailValue.style.borderRadius = "3px";
743-
emailValue.style.color = color;
744-
emailValue.style.backgroundColor = backgroundColor;
753+
for (const emailValue of emailValues) {
754+
emailValue.style.borderRadius = "3px";
755+
emailValue.style.color = color;
756+
emailValue.style.backgroundColor = backgroundColor;
757+
}
745758
}
746759

747760
/**
@@ -752,28 +765,30 @@ class DkimFromAddress {
752765
* @returns {void}
753766
*/
754767
static showTooltip(document, show) {
755-
const emailValue = this._getFromAddress(document);
756-
if (!emailValue) {
768+
const emailValues = this._getFromAddress(document);
769+
if (!emailValues) {
757770
return;
758771
}
759-
if (show) {
760-
// save current tooltip if set
761-
const tooltiptext = emailValue.getAttribute("tooltiptext");
762-
if (tooltiptext) {
763-
emailValue.setAttribute("tooltiptextSaved", tooltiptext);
764-
}
765-
emailValue.removeAttribute("tooltiptext");
766-
// set DKIM tooltip
767-
emailValue.setAttribute("tooltip", DkimFavicon.idTooltip);
768-
} else {
769-
if (emailValue.getAttribute("tooltip") === DkimFavicon.idTooltip) {
770-
// remove DKIM tooltip
771-
emailValue.removeAttribute("tooltip");
772-
// restore saved tooltip
773-
const tooltiptextSaved = emailValue.getAttribute("tooltiptextSaved");
774-
if (tooltiptextSaved) {
775-
emailValue.setAttribute("tooltiptext", tooltiptextSaved);
776-
emailValue.removeAttribute("tooltiptextSaved");
772+
for (const emailValue of emailValues) {
773+
if (show) {
774+
// save current tooltip if set
775+
const tooltiptext = emailValue.getAttribute("tooltiptext");
776+
if (tooltiptext) {
777+
emailValue.setAttribute("tooltiptextSaved", tooltiptext);
778+
}
779+
emailValue.removeAttribute("tooltiptext");
780+
// set DKIM tooltip
781+
emailValue.setAttribute("tooltip", DkimFavicon.idTooltip);
782+
} else {
783+
if (emailValue.getAttribute("tooltip") === DkimFavicon.idTooltip) {
784+
// remove DKIM tooltip
785+
emailValue.removeAttribute("tooltip");
786+
// restore saved tooltip
787+
const tooltiptextSaved = emailValue.getAttribute("tooltiptextSaved");
788+
if (tooltiptextSaved) {
789+
emailValue.setAttribute("tooltiptext", tooltiptextSaved);
790+
emailValue.removeAttribute("tooltiptextSaved");
791+
}
777792
}
778793
}
779794
}

experiments/mozilla.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ declare class MozMailMultiEmailheaderfield extends MozXULElement {
330330
declare class MultiRecipientRow extends HTMLDivElement {
331331
recipientsList: HTMLElement;
332332
}
333+
/**
334+
* fromRecipientX in TB >=102
335+
*/
336+
declare class HeaderRecipient extends HTMLLIElement {
337+
multiLine: HTMLElement;
338+
}
333339
type expandedfromBox = MozMailMultiEmailheaderfield | MultiRecipientRow;
334340

335341
interface nsIMsgDBHdr {

0 commit comments

Comments
 (0)