diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/extensions/smime/msgCompSecurityInfo.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/extensions/smime/msgCompSecurityInfo.js')
-rw-r--r-- | comm/mailnews/extensions/smime/msgCompSecurityInfo.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/comm/mailnews/extensions/smime/msgCompSecurityInfo.js b/comm/mailnews/extensions/smime/msgCompSecurityInfo.js new file mode 100644 index 0000000000..eb760a9c58 --- /dev/null +++ b/comm/mailnews/extensions/smime/msgCompSecurityInfo.js @@ -0,0 +1,122 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var gListBox; +var gViewButton; +var gBundle; + +var gCerts = []; + +window.addEventListener("DOMContentLoaded", onLoad); +window.addEventListener("resize", resizeColumns); + +function onLoad() { + let params = window.arguments[0]; + if (!params) { + return; + } + + gListBox = document.getElementById("infolist"); + gViewButton = document.getElementById("viewCertButton"); + gBundle = document.getElementById("bundle_smime_comp_info"); + + let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( + Ci.nsIX509CertDB + ); + + let missing = []; + for (let i = 0; i < params.recipients.length; i++) { + let email = params.recipients[i]; + let dbKey = params.compFields.composeSecure.getCertDBKeyForEmail(email); + + if (dbKey) { + gCerts.push(certdb.findCertByDBKey(dbKey)); + } else { + gCerts.push(null); + } + + if (!gCerts[i]) { + missing.push(params.recipients[i]); + } + } + + for (let i = 0; i < params.recipients.length; ++i) { + let email = document.createXULElement("label"); + email.setAttribute("value", params.recipients[i]); + email.setAttribute("crop", "end"); + email.setAttribute("style", "width: var(--recipientWidth)"); + + let listitem = document.createXULElement("richlistitem"); + listitem.appendChild(email); + + let cert = gCerts[i]; + let statusItem = document.createXULElement("label"); + statusItem.setAttribute( + "value", + gBundle.getString(cert ? "StatusValid" : "StatusNotFound") + ); + statusItem.setAttribute("style", "width: var(--statusWidth)"); + listitem.appendChild(statusItem); + + gListBox.appendChild(listitem); + } + resizeColumns(); +} + +function resizeColumns() { + let list = document.getElementById("infolist"); + let cols = list.getElementsByTagName("treecol"); + list.style.setProperty( + "--recipientWidth", + cols[0].getBoundingClientRect().width + "px" + ); + list.style.setProperty( + "--statusWidth", + cols[1].getBoundingClientRect().width + "px" + ); + list.style.setProperty( + "--issuedWidth", + cols[2].getBoundingClientRect().width + "px" + ); + list.style.setProperty( + "--expireWidth", + cols[3].getBoundingClientRect().width - 5 + "px" + ); +} + +// --- borrowed from pippki.js --- +const PRErrorCodeSuccess = 0; + +const certificateUsageEmailSigner = 0x0010; +const certificateUsageEmailRecipient = 0x0020; + +// A map from the name of a certificate usage to the value of the usage. +const certificateUsages = { + certificateUsageEmailRecipient, +}; + +function onSelectionChange(event) { + gViewButton.disabled = !( + gListBox.selectedItems.length == 1 && certForRow(gListBox.selectedIndex) + ); +} + +function viewCertHelper(parent, cert) { + let url = `about:certificate?cert=${encodeURIComponent( + cert.getBase64DERString() + )}`; + let mail3PaneWindow = Services.wm.getMostRecentWindow("mail:3pane"); + mail3PaneWindow.switchToTabHavingURI(url, true, {}); + parent.close(); +} + +function certForRow(aRowIndex) { + return gCerts[aRowIndex]; +} + +function viewSelectedCert() { + if (!gViewButton.disabled) { + viewCertHelper(window, certForRow(gListBox.selectedIndex)); + } +} |