Bug 1488356 - replace use of nsUTF8ConverterService in MozMill's get_msg_source(). rs=bustage-fix DONTBUILD BETA_BASE_20180904
authorJorg K <jorgk@jorgk.com>
Tue, 04 Sep 2018 14:03:04 +0200
changeset 32140 88de6bc9d1116a00ffe6907e8f84ee09fdd93ae5
parent 32139 68d9fa38d13dffc5e7658783284776e08b2eedb2
child 32141 68620cede958b1aa79ef7afbb66367203d7f1141
push id2308
push userclokep@gmail.com
push dateWed, 05 Sep 2018 00:34:58 +0000
treeherdercomm-beta@e326b2dcd127 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1488356
Bug 1488356 - replace use of nsUTF8ConverterService in MozMill's get_msg_source(). rs=bustage-fix DONTBUILD
mail/test/mozmill/composition/test-blocked-content.js
mail/test/mozmill/composition/test-charset-upgrade.js
mail/test/mozmill/shared-modules/test-compose-helpers.js
--- a/mail/test/mozmill/composition/test-blocked-content.js
+++ b/mail/test/mozmill/composition/test-blocked-content.js
@@ -106,17 +106,17 @@ function test_paste_file_urls() {
   wait_for_notification_to_show(cwc, kBoxId, kNotificationId);
 
   plan_for_window_close(cwc);
   cwc.window.goDoCommand("cmd_sendLater");
   wait_for_window_close();
 
   be_in_folder(gOutboxFolder);
   let outMsg = select_click_row(0);
-  let outMsgContent = get_msg_source(outMsg, true);
+  let outMsgContent = get_msg_source(outMsg);
 
   assert_true(outMsgContent.includes("file://foo/non-existant"),
     "non-existant file not in content=" + outMsgContent);
 
   assert_false(outMsgContent.includes(tmpFileURL),
     "tmp file url still in content=" + outMsgContent);
 
   assert_true(outMsgContent.includes('id="tmp-img" src="cid:'),
--- a/mail/test/mozmill/composition/test-charset-upgrade.js
+++ b/mail/test/mozmill/composition/test-charset-upgrade.js
@@ -59,17 +59,18 @@ function test_encoding_upgrade_html_comp
   compWin.keypress(null, "s", {shiftKey: false, accelKey: true});
 
   be_in_folder(gDrafts);
   let draftMsg = select_click_row(0);
 
   // Charset should still be the default.
   assert_equals(draftMsg.Charset, "windows-1252");
 
-  let draftMsgContent = get_msg_source(draftMsg, true);
+  // We could pass "windows-1252", but the message is ASCII.
+  let draftMsgContent = get_msg_source(draftMsg);
   if (!draftMsgContent.includes('content="text/html; charset=windows-1252"'))
     throw new Error("Expected content type not in msg; draftMsgContent=" +
                     draftMsgContent);
 
   const CHINESE = "漢皇重色思傾國漢皇重色思傾國";
   type_in_composer(compWin, ["but now, we enter some chinese: " + CHINESE + "\n"]);
 
   // Ctrl+U = Underline (so we can check multipart/alternative gets right,
@@ -81,32 +82,32 @@ function test_encoding_upgrade_html_comp
   // Ctrl+S = save as draft.
   compWin.keypress(null, "s", {shiftKey: false, accelKey: true});
 
   be_in_folder(gDrafts);
   let draftMsg2 = select_click_row(0);
   // Charset should have be upgraded to UTF-8.
   assert_equals(draftMsg2.Charset, "UTF-8");
 
-  let draftMsg2Content = get_msg_source(draftMsg2, true);
+  let draftMsg2Content = get_msg_source(draftMsg2, "UTF-8");
   if (!draftMsg2Content.includes('content="text/html; charset=UTF-8"'))
     throw new Error("Expected content type not in msg; draftMsg2Content=" +
                     draftMsg2Content);
 
   if (!draftMsg2Content.includes(CHINESE))
     throw new Error("Chinese text not in msg; CHINESE=" + CHINESE +
                     ", draftMsg2Content=" + draftMsg2Content);
 
   plan_for_window_close(compWin);
   compWin.window.goDoCommand("cmd_sendLater");
   wait_for_window_close();
 
   be_in_folder(gOutbox);
   let outMsg = select_click_row(0);
-  let outMsgContent = get_msg_source(outMsg, true);
+  let outMsgContent = get_msg_source(outMsg, "UTF-8");
 
   // This message should be multipart/alternative.
   if (!outMsgContent.includes("Content-Type: multipart/alternative"))
     throw new Error("Expected multipart/alternative; content=" + outMsgContent);
 
   let chinesePlainIdx = outMsgContent.indexOf(CHINESE);
   assert_true(chinesePlainIdx > 0, "chinesePlainIdx=" + chinesePlainIdx +
                                    ", outMsgContent=" + outMsgContent);
@@ -153,32 +154,32 @@ function test_encoding_upgrade_plaintext
   // Ctrl+S = Save as Draft.
   compWin.keypress(null, "s", {shiftKey: false, accelKey: true});
 
   be_in_folder(gDrafts);
   let draftMsg2 = select_click_row(0);
   // Charset should have be upgraded to UTF-8.
   assert_equals(draftMsg2.Charset, "UTF-8");
 
-  let draftMsg2Content = get_msg_source(draftMsg2, true);
+  let draftMsg2Content = get_msg_source(draftMsg2, "UTF-8");
   if (draftMsg2Content.includes("<html>"))
     throw new Error("Plaintext draft contained <html>; "+
                     "draftMsg2Content=" + draftMsg2Content);
 
   if (!draftMsg2Content.includes(CHINESE))
     throw new Error("Chinese text not in msg; CHINESE=" + CHINESE +
                     ", draftMsg2Content=" + draftMsg2Content);
 
   plan_for_window_close(compWin);
   compWin.window.goDoCommand("cmd_sendLater");
   wait_for_window_close();
 
   be_in_folder(gOutbox);
   let outMsg = select_click_row(0);
-  let outMsgContent = get_msg_source(outMsg, true);
+  let outMsgContent = get_msg_source(outMsg, "UTF-8");
 
   // This message should be text/plain;
   if (!outMsgContent.includes("Content-Type: text/plain"))
     throw new Error("Expected text/plain; content=" + outMsgContent);
 
   if (!outMsgContent.includes(CHINESE))
     throw new Error("Chinese text not in msg; CHINESE=" + CHINESE +
                     ", outMsgContent=" + outMsgContent);
--- a/mail/test/mozmill/shared-modules/test-compose-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-compose-helpers.js
@@ -449,21 +449,21 @@ function assert_previous_text(aStart, aT
   }
   return textNode;
 }
 
 /**
  * Helper to get the raw contents of a message. It only reads the first 64KiB.
  *
  * @param aMsgHdr  nsIMsgDBHdr addressing a message which will be returned as text.
- * @param aUTF8    True if the contents should be returned in UTF-8.
+ * @param aCharset Charset to use to decode the message.
  *
  * @return         String with the message source.
  */
-function get_msg_source(aMsgHdr, aUTF8 = false) {
+function get_msg_source(aMsgHdr, aCharset = "") {
   let msgUri = aMsgHdr.folder.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,
@@ -475,15 +475,16 @@ function get_msg_source(aMsgHdr, aUTF8 =
 
   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();
 
-  if (!aUTF8)
+  if (!aCharset)
     return content;
 
-  return Cc["@mozilla.org/intl/utf8converterservice;1"]
-           .getService(Ci.nsIUTF8ConverterService)
-           .convertURISpecToUTF8(content, "UTF-8");
+  let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
+                    .createInstance(Ci.nsIScriptableUnicodeConverter);
+  converter.charset = aCharset;
+  return converter.ConvertToUnicode(content);
 }