diff --git a/chrome/content/columnOverlay.js b/chrome/content/columnOverlay.js index fb6e9ba..f51009b 100644 --- a/chrome/content/columnOverlay.js +++ b/chrome/content/columnOverlay.js @@ -75,6 +75,16 @@ let columnHandler = { let ColumnOverlay = { init: () => { console.log("columnOverlay.js: init()"); + + let prefs = Services.prefs.getBranch("extensions.p4tb."); + + //Open options for configuring if this is the first time + if (prefs.getBoolPref("first_run")) { + // let options = window.openDialog("chrome://p4t/content/options.xul", + // "options", "chrome,centerscreen"); + // options.focus(); + } + window.addEventListener("load", columnHandler.onLoadpEp, false); }, destroy: () => { diff --git a/chrome/content/green-shield-white.png b/chrome/content/green-shield-white.png index c24b997..7b617fb 100644 Binary files a/chrome/content/green-shield-white.png and b/chrome/content/green-shield-white.png differ diff --git a/chrome/content/modules/pEp.js b/chrome/content/modules/pEp.js index fe1df0f..bc22b43 100644 --- a/chrome/content/modules/pEp.js +++ b/chrome/content/modules/pEp.js @@ -23,8 +23,10 @@ const ENV_USER = "USER"; const DIR_INCOMING = 0; const DIR_OUTGOING = 1; -const ENC_FORMAT_PEP = 4; + const ENC_FORMAT_NONE = 0; +const ENC_FORMAT_PGP_MIME = 3; +const ENC_FORMAT_PEP = 4; const PEP_PREFIX = "pEp-"; class pEp { @@ -54,7 +56,7 @@ class pEp { /** * Function called on send mail */ - async encryptMail(subject = "", body = "", htmlBody = "", from = "", to = [], cc = [], bcc = [], encodingFormat = ENC_FORMAT_PEP) { + async encryptMail(subject = "", body = "", htmlBody = "", from = "", to = [], cc = [], bcc = [], encodingFormat = ENC_FORMAT_PGP_MIME) { this.log("pEp: encryptMail()", "subject:", subject, "body:", body, "from:", from, "to:", to, "cc: ", cc, "bcc: ", bcc); if (typeof bcc !== "undefined" && bcc.length > 0) { @@ -71,14 +73,11 @@ class pEp { if (cc) { message.setCc(cc) } - if (typeof bcc != "undefined" && bcc.length > 0) { - message.setBcc(bcc); - } - - return await this.encryptMailWithMessage(message); + + return await this.encryptMailWithMessage(message, encodingFormat); } - async encryptMailWithMessage(message, encodingFormat = ENC_FORMAT_PEP) { + async encryptMailWithMessage(message, encodingFormat = ENC_FORMAT_PGP_MIME) { message.dir = DIR_OUTGOING; message.enc_format = encodingFormat; let result = await this.adapter.encrypt_message(message); @@ -130,7 +129,7 @@ class pEp { } async getOngoingRating(from, to = [], cc, bcc) { - this.log("getOngoingRating: ", to, cc, bcc); + this.log("getOngoingRating: ", from, to, cc, bcc); const filteredTo = to.filter( (address) => typeof address === "string" || (typeof address.address !== "undefined" && address.address !== "")); if(filteredTo.length < 1) @@ -218,12 +217,17 @@ pEp.Identity = class { this.fingerprint = fingerprint; } else { - this.user_id = address.user_id; - this.username = address.username; - this.address = address.address; - this.fingerprint = address.fingerprint; + console.log("=============="); + console.log(address); + console.log(typeof address); + console.log("=============="); + Object.assign(this, address); } } + + toMail() { + return this.username + " <" + this.address +">"; + } }; pEp.Attachment = class { @@ -251,9 +255,13 @@ if (typeof btoa === "undefined") { } pEp.Message = class { - constructor(id, short, long, from, to = [], dir = DIR_OUTGOING, enc_format = ENC_FORMAT_PEP, attachmentsArray = [], optFieldsArray = [], formatted_long = undefined) { + constructor(id, short, long, from, to = [], dir = DIR_OUTGOING, enc_format = ENC_FORMAT_PGP_MIME, attachmentsArray = [], optFieldsArray = [], formatted_long = undefined) { if (typeof to === "string") to = [to]; + console.log("=============="); + console.log("NEW MESSAGE"); + console.log(id, short, long, from, to ); + console.log("=============="); this.id = id; this.shortmsg = short; this.longmsg = long; diff --git a/chrome/content/modules/pEpAdapter.js b/chrome/content/modules/pEpAdapter.js index 5396e9f..759e452 100644 --- a/chrome/content/modules/pEpAdapter.js +++ b/chrome/content/modules/pEpAdapter.js @@ -20,6 +20,7 @@ const PEP_WRONG_SEC_TOKEN_CODE = -32600; const JRPC_INTERNAL_ERROR = -32603; const PEP_RESPONSE_OK = 0; +const PEP_ILLEGAL_VALUE = -4; const PEP_UNENCRYPTED = 1024; const PEP_RESPONSE_DECRYPTED = 1026; const PEP_KEY_NOT_FOUND = 0x0201; @@ -100,8 +101,7 @@ class pEpAdapter { ).then((response) => { console.log("pEpAdapter.js: decrypt() success: ", response); - - if ((typeof(response) === "object") && response.hasOwnProperty("error")) { + if ((typeof (response) === "object") && response.hasOwnProperty("error")) { switch (response.error.code) { case PEP_WRONG_SEC_TOKEN_CODE: this.server.reload(); @@ -130,10 +130,9 @@ class pEpAdapter { case(PEP_RESPONSE_OK): case(PEP_RESPONSE_DECRYPTED): - if(response.result.outParams[1].rating === 2) { + if (response.result.outParams[1].rating === 2 || response.result.outParams[1].rating === 3) { decryptedMessage = message; - } - else { + } else { decryptedMessage = response.result.outParams[3]; } decryptedMessage.rating = response.result.outParams[1].rating; @@ -154,16 +153,23 @@ class pEpAdapter { } return decryptedMessage; + }).catch((err) => { + console.log("=============="); + console.log("ERROR", err); + console.log("=============="); }); } async encrypt_message(message) { + console.log("=== ENCRYPTALO ==========="); + console.log(message); + console.log("=============="); let params = [ - message, - [], - ["OP"], - message.enc_format, - 0 + message, // Outgoing encrypted message + [], // Extra keys + ["OP"], // Output message + message.enc_format, // Encoding Format + 0 // Flags ]; this.log("pEpAdapter.js: encrypt_message()", message); return await this.server.callPepAdapter( @@ -175,7 +181,7 @@ class pEpAdapter { this.log("RESPONSE: pEpAdapter.js: encrypt_message()", response); let encryptedMessage = {}; - if ((typeof(response) === "object") && response.hasOwnProperty("error")) { + if ((typeof (response) === "object") && response.hasOwnProperty("error")) { switch (response.error.code) { case PEP_WRONG_SEC_TOKEN_CODE: throw new Error({code: "PEP-ERROR", message: "Invalid Security Token", response}); @@ -208,6 +214,10 @@ class pEpAdapter { this.log("callPepAdapter: 'encrypt' returned with UNENCRYPTED status: ", response); break; + case(PEP_ILLEGAL_VALUE): + encryptedMessage = message; + this.log("callPepAdapter: 'encrypt' returned with illegal value", response.result.return, message); + default: this.log("callPepAdapter: 'encrypt' returned with error: ", response); throw new Error({code: "PEP-ERROR", message: response}); @@ -256,11 +266,11 @@ class pEpAdapter { // ); let cachedMail = this.ratings[identity.address]; - if(cachedMail) { + if (cachedMail) { return cachedMail; } - let params = [ identity, ["OP"] ]; + let params = [identity, ["OP"]]; return await this.server.callPepAdapter( SERVER_TYPE_CALL_FUNC, API_METHOD_IDENTITY_RATING, diff --git a/chrome/content/no-color-shield-white.png b/chrome/content/no-color-shield-white.png index 8d0c267..de2f862 100644 Binary files a/chrome/content/no-color-shield-white.png and b/chrome/content/no-color-shield-white.png differ diff --git a/chrome/content/options.js b/chrome/content/options.js new file mode 100644 index 0000000..e69de29 diff --git a/chrome/content/options.xul b/chrome/content/options.xul new file mode 100644 index 0000000..af54924 --- /dev/null +++ b/chrome/content/options.xul @@ -0,0 +1,55 @@ + + + + + + + +