Browse Source

P4TB-400: Improved manual key import. Part 5: Finalise public key import.

master
Jörg Knobloch 11 months ago
parent
commit
73e4e55e34
7 changed files with 67 additions and 21 deletions
  1. +6
    -0
      addon/_locales/de/messages.json
  2. +6
    -0
      addon/_locales/en/messages.json
  3. +11
    -0
      addon/content/TbContacts.js
  4. +37
    -3
      addon/content/dialogs/options.js
  5. +2
    -2
      addon/content/dialogs/options.xhtml
  6. +1
    -1
      addon/content/pEpForThunderbird.js
  7. +4
    -15
      addon/content/pepmessengercompose.js

+ 6
- 0
addon/_locales/de/messages.json View File

@ -278,12 +278,18 @@
"optionsImportPromptTitle": {
"message": "PGP Schlüssel-Import"
},
"optionsImportMultiKey": {
"message": "Import von mehreren Schlüsseln nicht unterstützt"
},
"optionsImportError": {
"message": "Fehler beim Schlüssel-Import"
},
"optionsKeyUseError": {
"message": "Schlüssel kann nicht genutzt werden wie ausgewählt"
},
"optionsInvalidEmail": {
"message": "Keine gültige Adresse angegeben"
},
"optionsKeyImportNotPossibleDevGroup": {
"message": "Schlüssel-Import nicht möglich solange das Gerät Mitglied einer Gerätegruppe ist."
},


+ 6
- 0
addon/_locales/en/messages.json View File

@ -278,12 +278,18 @@
"optionsImportPromptTitle": {
"message": "PGP Key import"
},
"optionsImportMultiKey": {
"message": "Multiple key import not supported"
},
"optionsImportError": {
"message": "Error importing key"
},
"optionsKeyUseError": {
"message": "Key cannot be used as selected"
},
"optionsInvalidEmail": {
"message": "No valid address entered"
},
"optionsKeyImportNotPossibleDevGroup": {
"message": "Key import not possible while the device is in a device group."
},


+ 11
- 0
addon/content/TbContacts.js View File

@ -56,6 +56,17 @@ const TbContacts = {
identity.me = true;
return identity;
},
parseAddress(address) {
const hdr = Cc["@mozilla.org/messenger/headerparser;1"].createInstance(Ci.nsIMsgHeaderParser);
const mails = hdr.parseEncodedHeader(address, "utf-8");
return mails.filter((mail) => mail.email).map((mail) => ({
email: mail.email,
// While address entry is in progress, the address can contain
// foo >> foobar@baz.com. We need to strip the part before the >> .
name: mail.name.replace(/.* >> /, ""),
}));
},
};
const EXPORTED_SYMBOLS = ["TbContacts"];

+ 37
- 3
addon/content/dialogs/options.js View File

@ -7,8 +7,10 @@ var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var { pEpUtils } = ChromeUtils.import("chrome://pEp4Tb/content/modules/utils.js");
var { pEp } = ChromeUtils.import("chrome://pEp4Tb/content/modules/pEp.js");
var { pEpController } = ChromeUtils.import("chrome://pEp4Tb/content/pEpController.js");
var { TbContacts } = ChromeUtils.import("chrome://pEp4Tb/content/TbContacts.js");
var gImportResult;
var gFpr;
var pEpOptions = {
openLink(url) {
@ -409,7 +411,15 @@ var pEpOptions = {
}
stream.close();
// TODO: Check for multiple public keys.
// Check for multiple public keys.
if ((streamData.match(/BEGIN PGP PUBLIC KEY BLOCK/g) || []).length > 1) {
Services.prompt.alert(
window,
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
pEpOptions.getLocaleMessage("optionsImportMultiKey"),
);
return;
}
// Send to the engine.
let result;
@ -450,6 +460,8 @@ var pEpOptions = {
button1.removeAttribute("hidden");
let button2 = document.getElementById("cancelKey");
button2.removeAttribute("hidden");
gFpr = fprs[0];
} else {
msg = pEpOptions.getLocaleMessage("optionsImportFingerprint");
const fpr = result[0].fpr.replace(/(....)/g, "$1 ").trim();
@ -499,6 +511,7 @@ var pEpOptions = {
importResult.setAttribute("hidden", "hidden");
let commPartnerAddress = document.getElementById("commPartnerAddress");
commPartnerAddress.value = "";
commPartnerAddress.setAttribute("hidden", "hidden");
let importOptions = document.getElementById("importOptions");
importOptions.setAttribute("hidden", "true");
@ -518,7 +531,7 @@ var pEpOptions = {
case "keep":
for (let i = 0; i < gImportResult.length; i++) {
gImportResult[i].user_id = "pEp_own_userId";
pEpController.set_own_key(gImportResult[i]);
pEpController.synchronise(pEpController.set_own_key(gImportResult[i]));
}
break;
case "switch":
@ -538,7 +551,28 @@ var pEpOptions = {
);
}
} else {
// TODO: pEpController.set_comm_partner_key( some id, some fpr);
// Check valid e-mail.
let email = document.getElementById("commPartnerAddress").value;
if (!email.includes("@", 1) || email.endsWith("@")) {
// Invalid.
Services.prompt.alert(
window,
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
pEpOptions.getLocaleMessage("optionsInvalidEmail"),
);
return;
}
try {
let id = TbContacts.getpEpIdentity(TbContacts.parseAddress(email.trim())[0]);
pEpController.synchronise(pEpController.set_comm_partner_key(id, gFpr));
} catch (err) {
pEpController.log.error(`Key use error: ${err.message}`);
Services.prompt.alert(
window,
pEpOptions.getLocaleMessage("optionsImportPromptTitle"),
pEpOptions.getLocaleMessage("optionsKeyUseError"),
);
}
}
this.cancelKey();


+ 2
- 2
addon/content/dialogs/options.xhtml View File

@ -141,7 +141,7 @@
onclick="pEpOptions.browseForKey();">
</html:button>
</hbox>
<hbox class="button-group">
<hbox>
<html:button id="import"
data-localekey="optionsImport"
onclick="pEpOptions.importKey();">
@ -166,7 +166,7 @@
completeselectedindex="true"
minresultsforpopup="3"
onkeypress="pEpOptions.commPartnerKeyPress(event, this);"/>
<hbox class="button-group">
<hbox>
<html:button id="useKey"
hidden="true"
data-localekey="optionsUseAsSelected"


+ 1
- 1
addon/content/pEpForThunderbird.js View File

@ -116,7 +116,7 @@ class pEpForThunderbird extends pEp {
MailServices.mfn.addListener(this, Ci.nsIMsgFolderNotificationService.msgAdded);
// Check adapter version.
const MIN_REQUIRED_VERSION = "0.22.1";
const MIN_REQUIRED_VERSION = "0.22.3";
let version = this.synchronise(this.serverVersion());
this.log.info(`Adapter version ${version.api_version} (${version.name})`);
let win = Services.wm.getMostRecentWindow("mail:3pane");


+ 4
- 15
addon/content/pepmessengercompose.js View File

@ -16,17 +16,6 @@ var {
const privacyNodeId = "pEp-compose-privacy-bar";
const IMG_FOLDER = "chrome://pEp4Tb/content/resources/images";
function _parseAddress(address) {
const hdr = Cc["@mozilla.org/messenger/headerparser;1"].createInstance(Ci.nsIMsgHeaderParser);
const mails = hdr.parseEncodedHeader(address, "utf-8");
return mails.filter((mail) => mail.email).map((mail) => ({
email: mail.email,
// While address entry is in progress, the address can contain
// foo >> foobar@baz.com. We need to strip the part before the >> .
name: mail.name.replace(/.* >> /, ""),
}));
}
function isPrivate(rating) {
// starting from `PEP_rating_reliable` in
// `_PEP_rating` in the engine message_api.h.
@ -542,10 +531,10 @@ var pEpComposer = {
getAddresses(currentIdentity, compFields) {
const from = { name: currentIdentity.fullName, email: currentIdentity.email };
const to = compFields.to ? _parseAddress(compFields.to) : [];
const cc = compFields.cc ? _parseAddress(compFields.cc) : undefined;
const bcc = compFields.bcc ? _parseAddress(compFields.bcc) : undefined;
const replyTo = compFields.replyTo ? _parseAddress(compFields.replyTo) : undefined;
const to = compFields.to ? TbContacts.parseAddress(compFields.to) : [];
const cc = compFields.cc ? TbContacts.parseAddress(compFields.cc) : undefined;
const bcc = compFields.bcc ? TbContacts.parseAddress(compFields.bcc) : undefined;
const replyTo = compFields.replyTo ? TbContacts.parseAddress(compFields.replyTo) : undefined;
const pEpFrom = TbContacts.getpEpOwnIdentity(from);


Loading…
Cancel
Save