Bug 1690957 - Fix text wrapping in MessageSend.jsm when mailnews.wraplength is 0. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D105571 --HG-- extra : amend_source : 57692b5d8efc1006f6cc6e573f5904902ee9f95e
This commit is contained in:
Родитель
b2b49bdcbe
Коммит
522e934644
|
@ -115,7 +115,7 @@ var MsgUtils = {
|
|||
*/
|
||||
convertToPlainText(input, formatFlowed) {
|
||||
let wrapWidth = Services.prefs.getIntPref("mailnews.wraplength", 72);
|
||||
if (wrapWidth > 990) {
|
||||
if (wrapWidth == 0 || wrapWidth > 990) {
|
||||
wrapWidth = 990;
|
||||
} else if (wrapWidth < 10) {
|
||||
wrapWidth = 10;
|
||||
|
|
|
@ -260,6 +260,17 @@ function getAttachmentFromContent(aContent) {
|
|||
return attachments[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the body part of an MIME message.
|
||||
* @param {string} content - The message content.
|
||||
* @returns {string}
|
||||
*/
|
||||
function getMessageBody(content) {
|
||||
let separatorIndex = content.indexOf("\r\n\r\n");
|
||||
Assert.equal(content.slice(-2), "\r\n", "Should end with a line break.");
|
||||
return content.slice(separatorIndex + 4, -2);
|
||||
}
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
load(gDEPTH + "mailnews/resources/mailShutdown.js");
|
||||
});
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
add_task(async function setup() {
|
||||
localAccountUtils.loadLocalMailAccount();
|
||||
});
|
||||
localAccountUtils.loadLocalMailAccount();
|
||||
|
||||
/**
|
||||
* Test trailing whitespace is QP encoded.
|
||||
|
@ -88,3 +86,56 @@ add_task(async function testQP() {
|
|||
|
||||
Services.prefs.clearUserPref("mail.strictly_mime");
|
||||
});
|
||||
|
||||
/**
|
||||
* Test plain text body is wrapped correctly with different mailnews.wraplength
|
||||
* pref value.
|
||||
*/
|
||||
add_task(async function testWrapLength() {
|
||||
let identity = getSmtpIdentity(
|
||||
"from@tinderbox.invalid",
|
||||
getBasicSmtpServer()
|
||||
);
|
||||
let CompFields = CC(
|
||||
"@mozilla.org/messengercompose/composefields;1",
|
||||
Ci.nsIMsgCompFields
|
||||
);
|
||||
|
||||
let word = "abcd ";
|
||||
let body = word.repeat(20);
|
||||
|
||||
let fields = new CompFields();
|
||||
fields.to = "Nobody <nobody@tinderbox.invalid>";
|
||||
fields.subject = "Test text wrapping";
|
||||
fields.body = `<html><body>${body}</body></html>`;
|
||||
fields.forcePlainText = true;
|
||||
await richCreateMessage(fields, [], identity);
|
||||
|
||||
let msgData = mailTestUtils.loadMessageToString(
|
||||
gDraftFolder,
|
||||
mailTestUtils.firstMsgHdr(gDraftFolder)
|
||||
);
|
||||
Assert.equal(
|
||||
getMessageBody(msgData),
|
||||
// Default wrap length is 72.
|
||||
word.repeat(14) + "\r\n" + word.repeat(6).trim(),
|
||||
"Text wraps at 72 by default"
|
||||
);
|
||||
|
||||
// 0 means no wrap.
|
||||
Services.prefs.setIntPref("mailnews.wraplength", 0);
|
||||
|
||||
await richCreateMessage(fields, [], identity);
|
||||
|
||||
msgData = mailTestUtils.loadMessageToString(
|
||||
gDraftFolder,
|
||||
mailTestUtils.firstMsgHdr(gDraftFolder)
|
||||
);
|
||||
Assert.equal(
|
||||
getMessageBody(msgData),
|
||||
body.trim(),
|
||||
"Should not wrap when wraplength is 0"
|
||||
);
|
||||
|
||||
Services.prefs.clearUserPref("mailnews.wraplength");
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче