Commit c4ff80bd authored by Patrick Brunschwig's avatar Patrick Brunschwig

Merge branch 'master' of https://gitlab.com/enigmail/enigmail

parents 826fdd5b 00bb3cc9
Pipeline #66417360 passed with stage
in 3 minutes and 26 seconds
......@@ -98,46 +98,17 @@ var EnigmailFixExchangeMsg = {
EnigmailLog.DEBUG("*** start data ***\n'" + data + "'\n***end data***\n");
}
self.determineCreatorApp(data);
try {
let msg = self.getRepairedMessage(data);
let hdrEnd = data.search(/\r?\n\r?\n/);
if (hdrEnd <= 0) {
// cannot find end of header data
reject(0);
return;
}
let hdrLines = data.substr(0, hdrEnd).split(/\r?\n/);
let hdrObj = self.getFixedHeaderData(hdrLines);
if (hdrObj.headers.length === 0 || hdrObj.boundary.length === 0) {
reject(1);
if (msg) {
resolve(msg);
} else
reject(2);
return;
}
let boundary = hdrObj.boundary;
let body;
switch (self.brokenByApp) {
case "exchange":
body = self.getCorrectedExchangeBodyData(data.substr(hdrEnd + 2), boundary);
break;
case "iPGMail":
body = self.getCorrectediPGMailBodyData(data.substr(hdrEnd + 2), boundary);
break;
default:
EnigmailLog.ERROR("fixExchangeMsg.jsm: getMessageBody: unknown appType " + self.brokenByApp + "\n");
reject(99);
return;
}
if (body) {
resolve(hdrObj.headers + "\r\n" + body);
return;
} else {
reject(2);
return;
} catch (ex) {
reject(ex);
}
}
);
......@@ -153,6 +124,45 @@ var EnigmailFixExchangeMsg = {
);
},
getRepairedMessage: function(data) {
this.determineCreatorApp(data);
let hdrEnd = data.search(/\r?\n\r?\n/);
if (hdrEnd <= 0) {
// cannot find end of header data
throw 0;
}
let hdrLines = data.substr(0, hdrEnd).split(/\r?\n/);
let hdrObj = this.getFixedHeaderData(hdrLines);
if (hdrObj.headers.length === 0 || hdrObj.boundary.length === 0) {
throw 1;
}
let boundary = hdrObj.boundary;
let body;
switch (this.brokenByApp) {
case "exchange":
body = this.getCorrectedExchangeBodyData(data.substr(hdrEnd + 2), boundary);
break;
case "iPGMail":
body = this.getCorrectediPGMailBodyData(data.substr(hdrEnd + 2), boundary);
break;
default:
EnigmailLog.ERROR("fixExchangeMsg.jsm: getRepairedMessage: unknown appType " + self.brokenByApp + "\n");
throw 99;
}
if (body) {
return hdrObj.headers + "\r\n" + body;
} else {
throw 2;
}
},
determineCreatorApp: function(msgData) {
// perform extra testing if iPGMail is assumed
if (this.brokenByApp === "exchange") return;
......@@ -347,7 +357,7 @@ var EnigmailFixExchangeMsg = {
let p0 = body.search(/^-----BEGIN PGP MESSAGE-----$/m);
let p1 = body.search(/^-----END PGP MESSAGE-----$/m);
ok = (p0 >= 0 && p1 > p0 + 4);
ok = (p0 >= 0 && p1 > p0 + 32);
}
return ok;
} catch (x) {}
......
......@@ -143,7 +143,7 @@ var EnigmailMime = {
header = hdrValue.join("").split(" ");
}
else {
header = hdrValue.split(" ");
header = hdrValue.split(/ +/);
}
let line = "";
......
This diff is collapsed.
......@@ -12,7 +12,7 @@
do_load_module("file://" + do_get_cwd().path + "/testHelper.js"); /*global TestHelper: false, component: false, withTestGpgHome: false, withEnigmail: false */
TestHelper.loadDirectly("tests/mailHelper.js"); /*global MailHelper: false */
testing("persistentCrypto.jsm"); /*global EnigmailPersistentCrypto: false, Promise: false */
testing("persistentCrypto.jsm"); /*global EnigmailPersistentCrypto: false, Promise: false, EnigmailMime: false */
var EnigmailKeyRing = component("enigmail/keyRing.jsm").EnigmailKeyRing;
/*global MsgHdrToMimeMessage: false, MimeMessage: false, MimeContainer: false, EnigmailStreams: false */
......@@ -70,7 +70,7 @@ test(withTestGpgHome(withEnigmail(function messageIsMovedAndDecrypted() {
loadSecretKey();
MailHelper.cleanMailFolder(MailHelper.rootFolder);
const sourceFolder = MailHelper.createMailFolder("source-box");
MailHelper.loadEmailToMailFolder("resources/encrypted-email.eml", sourceFolder);
MailHelper.loadEmailToMailFolder("resources/encrypted-pgpmime-email.eml", sourceFolder);
const header = MailHelper.fetchFirstMessageHeaderIn(sourceFolder);
const targetFolder = MailHelper.createMailFolder("target-box");
......@@ -85,20 +85,29 @@ test(withTestGpgHome(withEnigmail(function messageIsMovedAndDecrypted() {
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
Assert.ok(dispatchedHeader !== null);
let msgUriSpec = dispatchedHeader.folder.getUriForMsg(dispatchedHeader);
const msgSvc = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger).messageServiceFromURI(msgUriSpec);
let urlObj = {};
msgSvc.GetUrlForUri(msgUriSpec, urlObj, null);
do_test_pending();
MsgHdrToMimeMessage(
dispatchedHeader,
null,
function(header, mime) {
Assert.ok(!mime.isEncrypted);
Assert.assertContains(mime.parts[0].body, "This is encrypted");
EnigmailMime.getMimeTreeFromUrl(
urlObj.value.spec,
true,
function(mimeTree) {
Assert.equal(mimeTree.subParts.length, 1);
if (mimeTree.subParts.length > 0) {
Assert.assertContains(mimeTree.subParts[0].body, "This message is encrypted");
}
do_test_finished();
},
false
);
})));
/*
test(withTestGpgHome(withEnigmail(function messageWithAttachemntIsMovedAndDecrypted() {
loadSecretKey();
loadPublicKey();
......@@ -118,23 +127,71 @@ test(withTestGpgHome(withEnigmail(function messageWithAttachemntIsMovedAndDecryp
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
Assert.ok(dispatchedHeader !== null);
let msgUriSpec = dispatchedHeader.folder.getUriForMsg(dispatchedHeader);
const msgSvc = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger).messageServiceFromURI(msgUriSpec);
let urlObj = {};
msgSvc.GetUrlForUri(msgUriSpec, urlObj, null);
do_test_pending();
MsgHdrToMimeMessage(
dispatchedHeader,
null,
function(header, mime) {
Assert.ok(!mime.isEncrypted);
Assert.assertContains(mime.parts[0].parts[0].body, "This is encrypted");
const atts = extractAttachments(mime);
Assert.ok(!atts[0].isEncrypted);
Assert.assertContains(atts[0].body, "This is an attachment.");
EnigmailMime.getMimeTreeFromUrl(
urlObj.value.spec,
true,
function(mimeTree) {
Assert.assertContains(mimeTree.subParts[0].body, "This is encrypted");
Assert.equal(mimeTree.subParts.length, 2);
if (mimeTree.subParts.length >= 2) {
Assert.assertContains(mimeTree.subParts[1].body, "This is an attachment.");
}
do_test_finished();
},
false
);
})));
*/
test(withTestGpgHome(withEnigmail(function messageWithAttachemntIsMovedAndReEncrypted() {
loadSecretKey();
loadPublicKey();
MailHelper.cleanMailFolder(MailHelper.getRootFolder());
const sourceFolder = MailHelper.createMailFolder("source-box");
MailHelper.loadEmailToMailFolder("resources/encrypted-email-with-attachment.eml", sourceFolder);
const header = MailHelper.fetchFirstMessageHeaderIn(sourceFolder);
const targetFolder = MailHelper.createMailFolder("target-box");
const move = true;
copyListener.OnStopCopy = function(statusCode) {
inspector.exitNestedEventLoop();
};
let keyObj = EnigmailKeyRing.getKeyById("0x65537E212DC19025AD38EDB2781617319CE311C4");
EnigmailPersistentCrypto.dispatchMessages([header], targetFolder.URI, copyListener, move, keyObj);
inspector.enterNestedEventLoop(0);
const dispatchedHeader = MailHelper.fetchFirstMessageHeaderIn(targetFolder);
Assert.ok(dispatchedHeader !== null);
let msgUriSpec = dispatchedHeader.folder.getUriForMsg(dispatchedHeader);
const msgSvc = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger).messageServiceFromURI(msgUriSpec);
let urlObj = {};
msgSvc.GetUrlForUri(msgUriSpec, urlObj, null);
do_test_pending();
EnigmailMime.getMimeTreeFromUrl(
urlObj.value.spec,
true,
function(mimeTree) {
Assert.assertContains(mimeTree.headers._rawHeaders.get("content-type")[0], "multipart/encrypted");
Assert.assertContains(mimeTree.subParts[0].body, "Version: 1");
Assert.equal(mimeTree.subParts.length, 2);
if (mimeTree.subParts.length >= 2) {
Assert.assertContains(mimeTree.subParts[1].body, "---BEGIN PGP MESSAGE---");
}
do_test_finished();
},
false
);
})));
var loadSecretKey = function() {
const secretKey = do_get_file("resources/dev-strike.sec", false);
......
To: Tester 2 <example@domain.invalid>
From: Tester 1 <tester@enigmail.org>
Message-ID: <3299853e-ad1b-236e-e4c1-ecbb266c26cb@gmail.com>
Date: Tue, 19 Jun 2018 23:39:32 +0530
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0)
Gecko/20100101 Thunderbird/52.8.0
MIME-Version: 1.0
Subject: Encrypted Message
Content-Type: multipart/encrypted;
protocol="application/pgp-encrypted";
boundary="UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4"
This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)
--UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4
Content-Type: application/pgp-encrypted
Content-Description: PGP/MIME version identification
Version: 1
--UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4
Content-Type: application/octet-stream; name="encrypted.asc"
Content-Description: OpenPGP encrypted message
Content-Disposition: inline; filename="encrypted.asc"
-----BEGIN PGP MESSAGE-----
hQIMA9U1Yju2Dp5xAQ/6AnDaC/oxD65YSD6I1e5JX3vAzOgB0TL4eTPabl/KZJ6K
8eAWiZubWF7i/EWlEXOYZbWycZC0Vo0mUlSiye4EXB/dnY369r/2UIF6kAEW0d7J
LwMbmg0WMcL+liZSa7HyxajYn8Zb7CohNI4l41KjjYGAbKiJNaK442eEvAQ3fuNp
5/KvV10jwS6fGV3caouTa8aCT8r2U5FdxowuYGGvazLCfPI9aTnz84JgeTutZfW5
B/yBBNDeRxmUEa9c3k+8aH9c5DKYBH4Chp5EMfvlTE/pZdhRd2RcTZsR637FQVgO
FpTHKvOqQNJla4WqGeH9iHOLJh9OAhHkRaiMbbo+072KfwNHqDD4iwjQ04jFIph1
zImMJg79PTgSsjcTRTdvkQiHaIx7pVW1m212JEl4km1lmT/C6NCHxTYfNLooEAs1
6YPbaARnbFTTWjJXfEto7s2PZoX1pZ7GG1MNVpAL6J/puUnmVktj+87bJLkxHQVu
wf3Qq+vcFqB5t63quPMbGbXnHh4P9V+ceWhUhNFSutKWcCmeQL4vxCtL9eOphHEb
1YDHb4FpSlpVJyVUmLh7g/1X3IMCS1HKpiIqJHAUu4FfouAprL5CAfFmCeCRMkqs
/4iR3KtpnwRPwNDgY8Gfy7CL0IdvWZdpyLFaFOPr604Kz2JsJwyxbu1opM3acILS
bgFYYz3p3HwqnGdbnch3+5H3XEToOaeXsH51zSUkR/oq/wNXDWKMKiU5hIUkHYq1
NsC04Y4EHsbpDPo/GqkcdXEx7Dg0sgohqYqoU+iyq+jjyOEZxNEUdboMadxIm879
nu672xjC+wg8rBvFr8jh
=q7pm
-----END PGP MESSAGE-----
--UxEMgGKKbt9SDjSozkXfqI0l07sqCV5I4--
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment