/* 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/. */ var { MessageGenerator } = ChromeUtils.importESModule( "resource://testing-common/mailnews/MessageGenerator.sys.mjs" ); var { EwsServer, RemoteFolder } = ChromeUtils.importESModule( "resource://testing-common/mailnews/EwsServer.sys.mjs" ); var { MailServices } = ChromeUtils.importESModule( "resource:///modules/MailServices.sys.mjs" ); var { HttpServer } = ChromeUtils.importESModule( "resource://testing-common/httpd.sys.mjs" ); const IMAGE_PATH = "/hello.jpg"; var ewsServer; var incomingServer; var httpServer; var imageRequested = false; add_setup(async function () { httpServer = new HttpServer(); // Register a dummy handler that just responds with a 404 Not Found status. // The media will still end up triggering a content blocking policy // (`OpaqueResponseBlocking`) because of the non-2XX response status, but at // this point we'll have already registered that a request has been attempted, // which is all we care about. httpServer.registerPathHandler(IMAGE_PATH, (request, response) => { imageRequested = true; response.setStatusLine("1.1", 404, "Not Found"); }); httpServer.start(-1); // Create a new mock EWS server, and start it. ewsServer = new EwsServer({}); ewsServer.start(); // Create a new account and connect it to the mock EWS server. incomingServer = MailServices.accounts.createIncomingServer( "user", "127.0.0.1", "ews" ); incomingServer.setStringValue( "ews_url", `http://127.0.0.1:${ewsServer.port}/EWS/Exchange.asmx` ); const ewsAccount = MailServices.accounts.createAccount(); ewsAccount.addIdentity(MailServices.accounts.createIdentity()); ewsAccount.incomingServer = incomingServer; // Store the account's credentials into the login manager so we're not // prompted for a password when trying to sync messages. const loginInfo = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance( Ci.nsILoginInfo ); loginInfo.init( "ews://127.0.0.1", null, "ews://127.0.0.1", "user", "password", "", "" ); await Services.logins.addLoginAsync(loginInfo); registerCleanupFunction(() => { ewsServer.stop(); incomingServer.closeCachedConnections(); MailServices.accounts.removeAccount(ewsAccount, false); Services.logins.removeAllLogins(); }); }); function generate_message_body() { var image_url = `http://127.0.0.1:${httpServer.identity.primaryPort}${IMAGE_PATH}`; return ( '\n' + "\n" + "
\n" + "\n" + '\n' + "\n" + '\n' + `