Bug 1710043 - Fix converting html to plain text in MimeMessage.jsm. r=mkmelin
nsIParserUtils.convertToPlainText expects a unicode string, but we passed a binary string. Differential Revision: https://phabricator.services.mozilla.com/D114708 --HG-- extra : amend_source : ae19e321faddda1a116b1ab76bda165f8c5cc050
This commit is contained in:
Родитель
3c43c59341
Коммит
586a9d0f46
|
@ -340,10 +340,17 @@ class MimeMessage {
|
|||
"content-type",
|
||||
`text/plain; charset=UTF-8${formatParam}`
|
||||
);
|
||||
plainPart.bodyText = MsgUtils.convertToPlainText(
|
||||
this._bodyText,
|
||||
// nsIParserUtils.convertToPlainText expects unicode string.
|
||||
let plainUnicode = MsgUtils.convertToPlainText(
|
||||
new TextDecoder().decode(
|
||||
jsmime.mimeutils.stringToTypedArray(this._bodyText)
|
||||
),
|
||||
formatFlowed
|
||||
);
|
||||
// MimePart.bodyText should be binary string.
|
||||
plainPart.bodyText = jsmime.mimeutils.typedArrayToString(
|
||||
new TextEncoder().encode(plainUnicode)
|
||||
);
|
||||
|
||||
parts.plainPart = plainPart;
|
||||
}
|
||||
|
|
|
@ -180,3 +180,32 @@ add_task(async function testWrapLength() {
|
|||
|
||||
Services.prefs.clearUserPref("mailnews.wraplength");
|
||||
});
|
||||
|
||||
/**
|
||||
* Test handling of trailing NBSP.
|
||||
*/
|
||||
add_task(async function testNBSP() {
|
||||
let identity = getSmtpIdentity(
|
||||
"from@tinderbox.invalid",
|
||||
getBasicSmtpServer()
|
||||
);
|
||||
let fields = Cc[
|
||||
"@mozilla.org/messengercompose/composefields;1"
|
||||
].createInstance(Ci.nsIMsgCompFields);
|
||||
fields.to = "Nobody <nobody@tinderbox.invalid>";
|
||||
fields.subject = "Test text wrapping";
|
||||
// The character after `test` is NBSP.
|
||||
fields.body = "<html><body>åäö test <br></body></html>";
|
||||
fields.forcePlainText = true;
|
||||
await richCreateMessage(fields, [], identity);
|
||||
|
||||
let msgData = mailTestUtils.loadMessageToUTF16String(
|
||||
gDraftFolder,
|
||||
mailTestUtils.firstMsgHdr(gDraftFolder)
|
||||
);
|
||||
Assert.equal(
|
||||
getMessageBody(msgData),
|
||||
"åäö test",
|
||||
"Trailing NBSP should be removed"
|
||||
);
|
||||
});
|
||||
|
|
|
@ -118,6 +118,13 @@ var mailTestUtils = {
|
|||
return data;
|
||||
},
|
||||
|
||||
// Loads a message to a UTF-16 string.
|
||||
loadMessageToUTF16String(folder, msgHdr, charset) {
|
||||
let str = this.loadMessageToString(folder, msgHdr, charset);
|
||||
let arr = new Uint8Array(Array.from(str, x => x.charCodeAt(0)));
|
||||
return new TextDecoder().decode(arr);
|
||||
},
|
||||
|
||||
// Gets the first message header in a folder.
|
||||
firstMsgHdr(folder) {
|
||||
let enumerator = folder.msgDatabase.EnumerateMessages();
|
||||
|
|
Загрузка…
Ссылка в новой задаче