diff options
| author | Sukhbir Singh <sukhbir@torproject.org> | 2017-12-26 12:11:53 -0500 | 
|---|---|---|
| committer | Sukhbir Singh <sukhbir@torproject.org> | 2017-12-26 22:06:42 -0500 | 
| commit | 3084a2f99dafa173f3d0ee4128e0a43d6ba62b3c (patch) | |
| tree | 9529f8fa64b165633f4c095f1ed5030a148d4b4d | |
| parent | 72468d21084a80420b299d94a6afdd66c2d141e6 (diff) | |
[feat] Display encryption status of email addresses in compose window
When composing an email, display the encryption status for each address.
If the public key for a given address is found, show the "lock" sign
(encrypted) in front of it otherwise show the "unlocked" sign
(unencrypted). This status is fetched using the keymanager.
| -rw-r--r-- | chrome.manifest | 1 | ||||
| -rw-r--r-- | chrome/content/messengercompose.js | 78 | ||||
| -rw-r--r-- | chrome/content/messengercompose.xul | 11 | ||||
| -rw-r--r-- | chrome/skin/lock.png | bin | 0 -> 329 bytes | |||
| -rw-r--r-- | chrome/skin/unlock.png | bin | 0 -> 303 bytes | 
5 files changed, 90 insertions, 0 deletions
| diff --git a/chrome.manifest b/chrome.manifest index 98d7b4b..bbbcc10 100644 --- a/chrome.manifest +++ b/chrome.manifest @@ -4,3 +4,4 @@ locale  bitmask    en-US           chrome/locale/en-US/  overlay chrome://messenger/content/messenger.xul chrome://bitmask/content/accountWizard/bitmaskMessengerOverlay.xul  overlay chrome://messenger/content/AccountManager.xul chrome://bitmask/content/accountWizard/bitmaskAccountManagerOverlay.xul  overlay chrome://messenger/content/am-offline.xul chrome://bitmask/content/preventCaching/bitmaskAmOfflineOverlay.xul +overlay chrome://messenger/content/messengercompose/messengercompose.xul chrome://bitmask/content/messengercompose.xul diff --git a/chrome/content/messengercompose.js b/chrome/content/messengercompose.js new file mode 100644 index 0000000..4b12f64 --- /dev/null +++ b/chrome/content/messengercompose.js @@ -0,0 +1,78 @@ +var composeStateListener = { +  NotifyComposeBodyReady: function() { +  } +}; + +// From addressingWidgetOverlay.js; we use this to call the function to update +// the status of the encryption keys for the various "To" fields.  This is for +// the case where the user presses "Return" or "Tab" and Thunderbird inserts a +// new "To" row, and we then update the encryption key status for each row. +function awRecipientKeyPress(event, element) +{ +  switch(event.keyCode) { +  case KeyEvent.DOM_VK_RETURN: +  case KeyEvent.DOM_VK_TAB: +    // if the user text contains a comma or a line return, ignore +    if (element.value.includes(',')) +    { +      var addresses = element.value; +      element.value = ""; // clear out the current line so we don't try to autocomplete it.. +      parseAndAddAddresses(addresses, awGetPopupElement(awGetRowByInputElement(element)).value); +    } +    else if (event.keyCode == KeyEvent.DOM_VK_TAB) +      awTabFromRecipient(element, event); + +    // Bitmask: update the encryption status. +    checkToField.updateEncryptionStatus(); +    break; +  } +} + +var checkToField = { +  // It is possible to enter all "To" addresses in a single field but since we +  // are displaying the encryption key per field (per row), we need to split a +  // single field into multiple fields if it contains a "," and then check +  // the encryption status for each field. +  splitInput: function(event) { +    let id = event.target.id; +    id = id.slice(id.lastIndexOf('#')+1); + +    let toFieldInput = document.getElementById("addressCol2#" + id); + +    if (toFieldInput.value.includes(",")) { +      let addresses = toFieldInput.value; +      toFieldInput.value = ""; +      parseAndAddAddresses(addresses, awGetPopupElement(awGetRowByInputElement(toFieldInput)).value); +      checkToField.updateEncryptionStatus(); +    } +  }, + +  updateEncryptionStatus: function() { +    for (let i = 1; i <= awGetNumberOfRecipients(); i++) { +      // Get the "To" field which has the email address. +      let toField = document.getElementById("addressCol2#" + i); +      // gCurrentIdentity.email returns the current identity. +      let promise = bitmask.keys.exprt(gCurrentIdentity.email, toField.value); + +      if (toField.value) { +        let image = document.createElement("image"); +        toField.appendChild(image); + +        promise.then(function(data) { +          toField.getElementsByTagName("image")[0].setAttribute("src", +            "chrome://bitmask/skin/lock.png"); +        }).catch(function(error) { +          toField.getElementsByTagName("image")[0].setAttribute("src", +            "chrome://bitmask/skin/unlock.png"); +        }); +      } +      else { +        toField.getElementsByTagName("image")[0].setAttribute("src", ""); +      } +    } +  } +}; + +window.addEventListener("compose-window-init", function(event) { +  gMsgCompose.RegisterStateListener(composeStateListener); +}, true); diff --git a/chrome/content/messengercompose.xul b/chrome/content/messengercompose.xul new file mode 100644 index 0000000..e3fcf34 --- /dev/null +++ b/chrome/content/messengercompose.xul @@ -0,0 +1,11 @@ +<?xml version="1.0"?> + +<overlay id="bitmaskComposeOverlay" +    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + +  <script type="application/javascript" src="chrome://bitmask/content/bitmask.js" /> +  <script type="application/javascript" src="chrome://bitmask/content/messengercompose.js" /> + +  <textbox id="addressCol2#1" oninput="checkToField.splitInput(event);" /> + +</overlay> diff --git a/chrome/skin/lock.png b/chrome/skin/lock.pngBinary files differ new file mode 100644 index 0000000..2a533cb --- /dev/null +++ b/chrome/skin/lock.png diff --git a/chrome/skin/unlock.png b/chrome/skin/unlock.pngBinary files differ new file mode 100644 index 0000000..0dbcd90 --- /dev/null +++ b/chrome/skin/unlock.png | 
