From 6c9529c2cc3016498db60b509d208f52a18ebb61 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 20 Jun 2024 11:53:34 +0000 Subject: [PATCH] Bug 1896171 - Part 3: Remove constraint on the server URI being an implementor of nsIMsgMailNewsUrl. r=leftmostcat,mkmelin Differential Revision: https://phabricator.services.mozilla.com/D211259 --HG-- extra : rebase_source : 9158bfcbaef26e215bf9d0879cb34e165ff16c5c --- mailnews/compose/src/MessageSend.sys.mjs | 24 +++++++++++++++++++----- rust/ews_xpcom/src/outgoing.rs | 9 ++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/mailnews/compose/src/MessageSend.sys.mjs b/mailnews/compose/src/MessageSend.sys.mjs index fa23210025..5ff3b8774d 100644 --- a/mailnews/compose/src/MessageSend.sys.mjs +++ b/mailnews/compose/src/MessageSend.sys.mjs @@ -657,12 +657,24 @@ export class MessageSend { } } if (isNSSError) { - const u = url.QueryInterface(Ci.nsIMsgMailNewsUrl); + let secInfo = null; + let location = null; + + if (url instanceof Ci.nsIMsgMailNewsUrl) { + // Not all URLs implement nsIMsgMailNewsUrl. Ideally we should not + // share the security info with the consumer by stamping it onto the + // URL, but for now we do what we can with what we have. + secInfo = url.failedSecInfo; + location = url.asciiHostPort; + } else { + location = `${url.host}:${url.port}`; + } + this.notifyListenerOnTransportSecurityError( null, exitCode, - u.failedSecInfo, - u.asciiHostPort + secInfo, + location ); } this.notifyListenerOnStopSending(null, exitCode, null, null); @@ -1411,8 +1423,10 @@ class MsgDeliveryListener { OnStopRunningUrl(url, exitCode) { lazy.MsgUtils.sendLogger.debug(`OnStopRunningUrl; exitCode=${exitCode}`); - const mailUrl = url.QueryInterface(Ci.nsIMsgMailNewsUrl); - mailUrl.UnRegisterListener(this); + + if (url instanceof Ci.nsIMsgMailNewsUrl) { + url.UnRegisterListener(this); + } this._msgSend.sendDeliveryCallback(url, this._isNewsDelivery, exitCode); } diff --git a/rust/ews_xpcom/src/outgoing.rs b/rust/ews_xpcom/src/outgoing.rs index 3a9be6e56a..9d05989cce 100644 --- a/rust/ews_xpcom/src/outgoing.rs +++ b/rust/ews_xpcom/src/outgoing.rs @@ -175,19 +175,14 @@ impl EwsOutgoingServer { xpcom_method!(server_uri => GetServerURI() -> *const nsIURI); fn server_uri(&self) -> Result, nsresult> { let ews_url = self.ews_url.get(); - let ews_url = ews_url.as_ref().ok_or_else(|| { + let ews_url = ews_url.ok_or_else(|| { log::error!( "tried retrieving a URI for the server before initializing it with an EWS URL" ); Err::<(), _>(nserror::NS_ERROR_NOT_INITIALIZED) })?; - // Build an ews:// URI for this server. We do this because the - // MessageSend module expects the URI to be QI-able into - // Ci.nsIMsgMailnewsUrl. - let username = self.username.borrow(); - let host = ews_url.host_str().ok_or(nserror::NS_ERROR_FAILURE)?; - let url = nsCString::from(format!("ews://{username}@{host}")); + let url = nsCString::from(ews_url.as_str()); let io_service = xpcom::get_service::(cstr::cstr!("@mozilla.org/network/io-service;1"))