Bug 1255071 - Don't use base64 encoding for message/rfc822 attachments. r=mkmelin a=jorgk CLOSED TREE
--HG-- extra : transplant_source : %D9m%1F%F6%D1%9D%CB%FE%83Q%E9%B6o%5C%F7%03%FAB%E0%5D
This commit is contained in:
Родитель
3ff4a0c0a2
Коммит
7e6e545292
|
@ -0,0 +1,16 @@
|
|||
From: "Long line writer" <email@longline.invalid>
|
||||
To: <user@example.com>
|
||||
Subject: Long HTML line
|
||||
Date: Wed, 10 Feb 2016 16:45:36 -0600
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/html;
|
||||
charset="us-ascii"
|
||||
Content-Transfer-Encoding: 7bit
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. We like writing long lines. This is 998 long.
|
||||
|
||||
</body>
|
|
@ -0,0 +1,101 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/**
|
||||
* Tests that attached messages (message/rfc822) are correctly sent.
|
||||
* It's easiest to test the forward case.
|
||||
*/
|
||||
|
||||
// mozmake SOLO_TEST=composition/test-forward-rfc822-attach.js mozmill-one
|
||||
|
||||
var MODULE_NAME = "test-forward-rfc822-attach";
|
||||
|
||||
var RELATIVE_ROOT = "../shared-modules";
|
||||
var MODULE_REQUIRES = ["folder-display-helpers", "compose-helpers", "window-helpers"];
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource:///modules/mailServices.js");
|
||||
var os = {};
|
||||
Cu.import('resource://mozmill/stdlib/os.js', os);
|
||||
|
||||
var draftsFolder;
|
||||
|
||||
function setupModule(module) {
|
||||
for (let lib of MODULE_REQUIRES) {
|
||||
collector.getModule(lib).installInto(module);
|
||||
}
|
||||
|
||||
if (!MailServices.accounts
|
||||
.localFoldersServer
|
||||
.rootFolder
|
||||
.containsChildNamed("Drafts")) {
|
||||
create_folder("Drafts", [Ci.nsMsgFolderFlags.Drafts]);
|
||||
}
|
||||
draftsFolder = MailServices.accounts
|
||||
.localFoldersServer
|
||||
.rootFolder
|
||||
.getChildNamed("Drafts");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the full message content.
|
||||
*
|
||||
* @param aMsgHdr: nsIMsgDBHdr object whose text body will be read
|
||||
* @return string with full message source
|
||||
*/
|
||||
function getMsgSource(aMsgHdr) {
|
||||
let msgFolder = aMsgHdr.folder;
|
||||
let msgUri = msgFolder.getUriForMsg(aMsgHdr);
|
||||
|
||||
let messenger = Cc["@mozilla.org/messenger;1"]
|
||||
.createInstance(Ci.nsIMessenger);
|
||||
let streamListener = Cc["@mozilla.org/network/sync-stream-listener;1"]
|
||||
.createInstance(Ci.nsISyncStreamListener);
|
||||
messenger.messageServiceFromURI(msgUri).streamMessage(msgUri,
|
||||
streamListener,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
"",
|
||||
false);
|
||||
let sis = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
sis.init(streamListener.inputStream);
|
||||
const MAX_MESSAGE_LENGTH = 65536;
|
||||
let content = sis.read(MAX_MESSAGE_LENGTH);
|
||||
sis.close();
|
||||
return content;
|
||||
}
|
||||
|
||||
function forwardDirect(aFilePath) {
|
||||
let file = os.getFileForPath(os.abspath(aFilePath,
|
||||
os.getFileForPath(__file__)));
|
||||
let msgc = open_message_from_file(file);
|
||||
|
||||
let cwc = open_compose_with_forward_as_attachments(msgc);
|
||||
|
||||
// Ctrl+S saves as draft.
|
||||
cwc.keypress(null, "s", {shiftKey: false, accelKey: true});
|
||||
|
||||
close_compose_window(cwc);
|
||||
close_window(msgc);
|
||||
|
||||
be_in_folder(draftsFolder);
|
||||
let draftMsg = select_click_row(0);
|
||||
|
||||
let draftMsgContent = getMsgSource(draftMsg);
|
||||
|
||||
if (!draftMsgContent.includes("We like writing long lines.")) {
|
||||
assert_true(false, "Failed to find expected text");
|
||||
}
|
||||
|
||||
press_delete(mc); // clean up the created draft
|
||||
}
|
||||
|
||||
function test_forwarding_long_html_line_as_attachment() {
|
||||
forwardDirect("./long-html-line.eml");
|
||||
}
|
||||
|
||||
function teardownModule() {
|
||||
}
|
|
@ -394,7 +394,7 @@ nsMsgAttachmentHandler::PickEncoding(const char *charset, nsIMsgSend *mime_deliv
|
|||
}
|
||||
}
|
||||
|
||||
if (force_p || (m_max_column > 900)) {
|
||||
if (force_p || (m_max_column > LINELENGTH_ENCODING_THRESHOLD)) {
|
||||
encode_p = true;
|
||||
} else if (UseQuotedPrintable() && m_unprintable_count) {
|
||||
encode_p = true;
|
||||
|
@ -454,7 +454,13 @@ nsMsgAttachmentHandler::PickEncoding(const char *charset, nsIMsgSend *mime_deliv
|
|||
// According to RFC 821 we must always have lines shorter than 998 bytes.
|
||||
// To encode "long lines" use a CTE that will transmit shorter lines.
|
||||
// Switch to base64 if we are not already using "quoted printable".
|
||||
if (m_max_column > 900 && !isUsingQP)
|
||||
|
||||
// We don't do this for message/rfc822 attachments, since we can't
|
||||
// change the original Content-Transfer-Encoding of the message we're
|
||||
// attaching. We rely on the original message complying with RFC 821,
|
||||
// if it doesn't we won't either. Not ideal.
|
||||
if (!m_type.LowerCaseEqualsLiteral(MESSAGE_RFC822) &&
|
||||
m_max_column > LINELENGTH_ENCODING_THRESHOLD && !isUsingQP)
|
||||
m_encoding = ENCODING_BASE64;
|
||||
|
||||
// Now that we've picked an encoding, initialize the filter.
|
||||
|
|
|
@ -629,7 +629,7 @@ nsMsgComposeAndSend::GatherMimeAttachments()
|
|||
// Check one last time for the last line.
|
||||
if (cur_column > max_column)
|
||||
max_column = cur_column;
|
||||
if (max_column > 900 && !isUsingQP) {
|
||||
if (max_column > LINELENGTH_ENCODING_THRESHOLD && !isUsingQP) {
|
||||
// To encode "long lines" use a CTE that will transmit shorter lines.
|
||||
// Switch to base64 if we are not already using "quoted printable".
|
||||
PR_FREEIF(m_attachment1_encoding);
|
||||
|
@ -1046,7 +1046,7 @@ nsMsgComposeAndSend::PreProcessPart(nsMsgAttachmentHandler *ma,
|
|||
if (ma->m_type.IsEmpty())
|
||||
ma->m_type = UNKNOWN_CONTENT_TYPE;
|
||||
|
||||
ma->PickEncoding (mCompFields->GetCharacterSet(), this);
|
||||
ma->PickEncoding(mCompFields->GetCharacterSet(), this);
|
||||
ma->PickCharset();
|
||||
|
||||
part = new nsMsgSendPart(this);
|
||||
|
@ -2374,7 +2374,7 @@ nsMsgComposeAndSend::HackAttachments(nsIArray *attachments,
|
|||
!m_attachments[i]->m_encoding.LowerCaseEqualsLiteral(ENCODING_BINARY))
|
||||
m_attachments[i]->m_already_encoded_p = true;
|
||||
|
||||
if (m_attachments[i]->mURL)
|
||||
if (m_attachments[i]->mURL)
|
||||
msg_pick_real_name(m_attachments[i], nullptr, mCompFields->GetCharacterSet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@
|
|||
- it is of a non-text type (in which case we will use base64); or
|
||||
- The "use QP" option has been selected and high-bit characters exist; or
|
||||
- any NULLs exist in the document; or
|
||||
- any line is longer than 900 bytes.
|
||||
- any line is longer than 990 bytes (see LINELENGTH_ENCODING_THRESHOLD below)
|
||||
and it is not of type message/rfc822.
|
||||
|
||||
- If we are encoding, and more than 10% of the document consists of
|
||||
non-ASCII characters, then we always use base64 instead of QP.
|
||||
|
@ -140,6 +141,9 @@
|
|||
#define TEN_K 10240
|
||||
#define MIME_BUFFER_SIZE 4096 // must be greater than 1000
|
||||
// SMTP (RFC821) limit
|
||||
// Maximum number of bytes we allow in a line before we force
|
||||
// encoding to base64 if not already QR-encoded or of type message/rfc822.
|
||||
#define LINELENGTH_ENCODING_THRESHOLD 990
|
||||
|
||||
//
|
||||
// Utilities for string handling
|
||||
|
|
|
@ -82,7 +82,7 @@ let longMultibyteLine = "\u00E1".repeat(600);
|
|||
let longMultibyteLineCJK = "안".repeat(400);
|
||||
|
||||
// And some Japanese.
|
||||
let longMultibyteLineJapanese = "語".repeat(400);
|
||||
let longMultibyteLineJapanese = "語".repeat(450);
|
||||
|
||||
function* testBodyWithLongLine() {
|
||||
let newline;
|
||||
|
|
Загрузка…
Ссылка в новой задаче