diff --git a/mailnews/compose/src/MimeMessageUtils.jsm b/mailnews/compose/src/MimeMessageUtils.jsm index febfbcebf7..9d2d249c81 100644 --- a/mailnews/compose/src/MimeMessageUtils.jsm +++ b/mailnews/compose/src/MimeMessageUtils.jsm @@ -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; diff --git a/mailnews/compose/test/unit/head_compose.js b/mailnews/compose/test/unit/head_compose.js index ab28e12980..9099e8ae7c 100644 --- a/mailnews/compose/test/unit/head_compose.js +++ b/mailnews/compose/test/unit/head_compose.js @@ -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"); }); diff --git a/mailnews/compose/test/unit/test_messageBody.js b/mailnews/compose/test/unit/test_messageBody.js index f9cf868ca7..708ca0f805 100644 --- a/mailnews/compose/test/unit/test_messageBody.js +++ b/mailnews/compose/test/unit/test_messageBody.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 "; + fields.subject = "Test text wrapping"; + fields.body = `${body}`; + 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"); +});