From 20754d54ef9430be9bcdd8250fb1649e336303e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Knobloch?= Date: Fri, 19 Feb 2021 00:43:03 +0100 Subject: [PATCH] Store messageId also in the inner message. It's avaialable in beginCryptoEncapsulation(). --- addon/content/pEpForThunderbird.js | 8 +++++--- addon/content/pEpMimeEncrypt.js | 19 ++++++++++++++----- addon/content/pepmessengercompose.js | 3 +-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/addon/content/pEpForThunderbird.js b/addon/content/pEpForThunderbird.js index fda1c8d..efee96b 100644 --- a/addon/content/pEpForThunderbird.js +++ b/addon/content/pEpForThunderbird.js @@ -664,10 +664,11 @@ class pEpForThunderbird extends pEp { // Copy some headers from the original to the new message. // Starting with https://pep-security.lu/dev/repos/pEp_for_Thunderbird/rev/d3c752abce8c - // we store the references and in-reply-to also in the inner message. - // Sadly at encryption time, the message ID is not yet available, so it can't be used - // as ID for the inner message :-( + // on 7th Sep 2020 in verion 1.1.006-beta we store the references and in-reply-to also + // in the inner message. Starting on 18th Feb. 2021 in version 1.1.101 we store the + // messageId in the inner message. if (this.currentMessage.enc_format == ENC_FORMAT_DECRYPTED) { + // Remove this code soon: Begin >>>>> if (message.id) this.currentMessage.id = message.id; // Only use original in_reply_to if decrypted (inner) message has none. @@ -681,6 +682,7 @@ class pEpForThunderbird extends pEp { (typeof this.currentMessage.references !== "object" || this.currentMessage.references.length == 0)) { this.currentMessage.references = message.references; } + // Remove this code soon: End <<<<< // Append decryption details to internet headers in original opt_fields. if (message.opt_fields) { diff --git a/addon/content/pEpMimeEncrypt.js b/addon/content/pEpMimeEncrypt.js index 014e956..831568d 100644 --- a/addon/content/pEpMimeEncrypt.js +++ b/addon/content/pEpMimeEncrypt.js @@ -42,7 +42,8 @@ MimeEncrypt.prototype = { bccRecipients: null, replyToRecipients: null, originalSubject: null, - originalReferences: null, + references: null, + messageId: null, isDraftOrTemplate: false, passThrough: false, @@ -54,16 +55,23 @@ MimeEncrypt.prototype = { outBuffer: "", // nsIMsgComposeSecure interface - requiresCryptoEncapsulation() { + requiresCryptoEncapsulation(msgIdentity, msgCompFields) { // Only if our handler was registered in pepmessengercompose.js, // we get here and we require encryption. + // Note that if `msgCompFields.subject` is set here, it will affect the + // subject in the message that is sent, but that is too early for us. + // Setting it any later has no effect. + // So we set the subject even earlier in pepmessengercompose.js. return true; }, - beginCryptoEncapsulation(outStream, recipientList, compFields, msgIdentity, sendReport, isDraft) { + beginCryptoEncapsulation(outStream, recipientList, msgCompFields, msgIdentity, sendReport, isDraft) { + // Note that `isDraft` is false when saving as a template, so this is not useful. this.outStream = outStream; this.outStringStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream); this.inspector = Cc["@mozilla.org/jsinspector;1"].createInstance(Ci.nsIJSInspector); + this.references = msgCompFields.references; + this.messageId = msgCompFields.messageId; return null; }, @@ -110,14 +118,15 @@ MimeEncrypt.prototype = { let message = this.controller.synchronise(messagePromise); // Fill in some headers. + message.id = this.messageId.replace(/^<(.*)>$/, "$1"); message.shortmsg = this.originalSubject; message.from = this.fromSender; message.to = this.toRecipients; message.cc = this.ccRecipients; message.bcc = this.bccRecipients; message.reply_to = this.replyToRecipients; - if (this.originalReferences) { - message.references = this.originalReferences.split(" ").map((r) => r.replace(/^<(.*)>$/, "$1")); + if (this.references) { + message.references = this.references.split(" ").map((r) => r.replace(/^<(.*)>$/, "$1")); message.in_reply_to = [message.references[message.references.length - 1]]; } diff --git a/addon/content/pepmessengercompose.js b/addon/content/pepmessengercompose.js index 59d1da8..f8ca606 100644 --- a/addon/content/pepmessengercompose.js +++ b/addon/content/pepmessengercompose.js @@ -537,8 +537,7 @@ var pEpComposer = { this.getAddresses(this.win.gCurrentIdentity, compFields); compSec.isDraftOrTemplate = isDraftOrTemplate; compSec.originalSubject = compFields.subject; - // Note that `compFields.messageId` is empty at this point in time. - compSec.originalReferences = compFields.references; + // We deal with messageId and references in pEpMimeEncrypt.js. compFields.composeSecure = compSec; // This is a hack. We tell the engine whether we want protected subjects,