diff options
Diffstat (limited to '')
-rw-r--r-- | comm/mailnews/mime/test/unit/head_mime.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/comm/mailnews/mime/test/unit/head_mime.js b/comm/mailnews/mime/test/unit/head_mime.js new file mode 100644 index 0000000000..868a7ceace --- /dev/null +++ b/comm/mailnews/mime/test/unit/head_mime.js @@ -0,0 +1,62 @@ +/* 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/. */ + +/** + * Utility code for converting encoded MIME data. + */ + +var { MailServices } = ChromeUtils.import( + "resource:///modules/MailServices.jsm" +); +var { XPCOMUtils } = ChromeUtils.importESModule( + "resource://gre/modules/XPCOMUtils.sys.mjs" +); +var { mailTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/MailTestUtils.jsm" +); +var { PromiseTestUtils } = ChromeUtils.import( + "resource://testing-common/mailnews/PromiseTestUtils.jsm" +); +const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); + +var CC = Components.Constructor; + +// Ensure the profile directory is set up +do_get_profile(); + +var gDEPTH = "../../../../"; + +registerCleanupFunction(function () { + load(gDEPTH + "mailnews/resources/mailShutdown.js"); +}); + +function apply_mime_conversion(msgUri, smimeHeaderSink) { + let service = MailServices.messageServiceFromURI(msgUri); + + // This is what we listen on in the end. + let listener = new PromiseTestUtils.PromiseStreamListener(); + + // Make the underlying channel--we need this for the converter parameter. + let url = service.getUrlForUri(msgUri); + + let channel = Services.io.newChannelFromURI( + url, + null, + Services.scriptSecurityManager.getSystemPrincipal(), + null, + Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, + Ci.nsIContentPolicy.TYPE_OTHER + ); + channel.QueryInterface(Ci.nsIMailChannel).smimeHeaderSink = smimeHeaderSink; + + // Make the MIME converter, using the listener we first set up. + let converter = Cc["@mozilla.org/streamConverters;1"] + .getService(Ci.nsIStreamConverterService) + .asyncConvertData("message/rfc822", "text/html", listener, channel); + + // Now load the message, run it through the converter, and wait for all the + // data to stream through. + channel.asyncOpen(converter); + return listener; +} |