Bug 1533320 - introduce nsMsgMailNewsUrl::CreateURL() and override it for mailbox: URLs. r=valentin DONTBUILD
authorJorg K <jorgk@jorgk.com>
Sat, 16 Mar 2019 09:57:54 +0100
changeset 26103 583bb771fcb6
parent 26102 11f46ea9ea72
child 26104 2cf104a9541f
push id15672
push usermozilla@jorgk.com
push dateSat, 16 Mar 2019 08:58:36 +0000
treeherdercomm-central@583bb771fcb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1533320
Bug 1533320 - introduce nsMsgMailNewsUrl::CreateURL() and override it for mailbox: URLs. r=valentin DONTBUILD
mailnews/base/util/nsMsgMailNewsUrl.cpp
mailnews/base/util/nsMsgMailNewsUrl.h
mailnews/local/src/nsMailboxUrl.cpp
mailnews/local/src/nsMailboxUrl.h
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -455,16 +455,25 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetSearc
 ////////////////////////////////////////////////////////////////////////////////////
 
 
 NS_IMETHODIMP nsMsgMailNewsUrl::GetSpec(nsACString &aSpec)
 {
   return m_baseURL->GetSpec(aSpec);
 }
 
+nsresult nsMsgMailNewsUrl::CreateURL(const nsACString& aSpec, nsIURL **aURL)
+{
+  nsCOMPtr<nsIURL> url;
+  nsresult rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(aSpec).Finalize(url);
+  NS_ENSURE_SUCCESS(rv, rv);
+  url.forget(aURL);
+  return NS_OK;
+}
+
 #define FILENAME_PART_LEN 10
 
 nsresult nsMsgMailNewsUrl::SetSpecInternal(const nsACString &aSpec)
 {
   nsAutoCString spec(aSpec);
   // Parse out "filename" attribute if present.
   char *start, *end;
   start = PL_strcasestr(spec.BeginWriting(),"?filename=");
@@ -479,17 +488,17 @@ nsresult nsMsgMailNewsUrl::SetSpecIntern
       mAttachmentFileName = start+FILENAME_PART_LEN;
       *end = '&';
     }
     else
       mAttachmentFileName = start+FILENAME_PART_LEN;
   }
 
   // Now, set the rest.
-  nsresult rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(aSpec).Finalize(m_baseURL);
+  nsresult rv = CreateURL(aSpec, getter_AddRefs(m_baseURL));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Check whether the URL is in normalized form.
   nsCOMPtr <nsIMsgMessageUrl> msgUrl;
   QueryInterface(NS_GET_IID(nsIMsgMessageUrl), getter_AddRefs(msgUrl));
 
   nsAutoCString normalizedSpec;
   if (!msgUrl || NS_FAILED(msgUrl->GetNormalizedSpec(normalizedSpec))) {
--- a/mailnews/base/util/nsMsgMailNewsUrl.h
+++ b/mailnews/base/util/nsMsgMailNewsUrl.h
@@ -65,16 +65,17 @@ protected:
   virtual nsresult SetHostPort(const nsACString &aHostPort);
   virtual nsresult SetHost(const nsACString &aHost);
   virtual nsresult SetPort(int32_t aPort);
   virtual nsresult SetPathQueryRef(const nsACString &aPath);
   virtual nsresult SetRef(const nsACString &aRef);
   virtual nsresult SetFilePath(const nsACString &aFilePath);
   virtual nsresult SetQuery(const nsACString &aQuery);
   virtual nsresult SetQueryWithEncoding(const nsACString &aQuery, const mozilla::Encoding* aEncoding);
+  virtual nsresult CreateURL(const nsACString& aSpec, nsIURL **aURL);  // nsMailboxUrl overrides this.
 
 public:
   class Mutator
       : public nsIURIMutator
       , public BaseURIMutator<nsMsgMailNewsUrl>
   {
     NS_DECL_ISUPPORTS
     NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
--- a/mailnews/local/src/nsMailboxUrl.cpp
+++ b/mailnews/local/src/nsMailboxUrl.cpp
@@ -17,16 +17,17 @@
 #include "nsIMsgHdr.h"
 
 #include "nsIMsgFolder.h"
 #include "prprf.h"
 #include "prmem.h"
 #include "nsIMsgMailSession.h"
 #include "nsNetUtil.h"
 #include "nsIFileURL.h"
+#include "nsIStandardURL.h"
 
 // this is totally lame and MUST be removed by M6
 // the real fix is to attach the URI to the URL as it runs through netlib
 // then grab it and use it on the other side
 #include "nsCOMPtr.h"
 #include "nsMsgBaseCID.h"
 #include "nsIMsgAccountManager.h"
 #include "nsMsgUtils.h"
@@ -163,16 +164,40 @@ NS_IMETHODIMP nsMailboxUrl::GetNormalize
     spec.Append(messageKey);
     PR_Free(messageKey);
   }
 
   aPrincipalSpec.Assign(spec);
   return NS_OK;
 }
 
+nsresult nsMailboxUrl::CreateURL(const nsACString& aSpec, nsIURL **aURL)
+{
+  nsresult rv;
+  nsCOMPtr<nsIURL> url;
+  // Check whether the URL is of the form
+  // mailbox://user@domain@server/folder?number=nn and contains a hostname.
+  // Check for format lacking absolute path.
+  if (PromiseFlatCString(aSpec).Find("///") == kNotFound) {
+    rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID).SetSpec(aSpec).Finalize(url);
+    NS_ENSURE_SUCCESS(rv, rv);
+  } else {
+    // The URL is more like a file URL without a hostname.
+    rv = NS_MutateURI(NS_STANDARDURLMUTATOR_CONTRACTID)
+      .Apply(NS_MutatorMethod(&nsIStandardURLMutator::Init,
+                              nsIStandardURL::URLTYPE_NO_AUTHORITY, -1,
+                              PromiseFlatCString(aSpec),
+                              nullptr, nullptr, nullptr))
+      .Finalize(url);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+  url.forget(aURL);
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsMailboxUrl::SetUri(const char * aURI)
 {
   mURI= aURI;
   return NS_OK;
 }
 
 nsresult nsMailboxUrl::Clone(nsIURI **_retval)
 {
--- a/mailnews/local/src/nsMailboxUrl.h
+++ b/mailnews/local/src/nsMailboxUrl.h
@@ -16,16 +16,17 @@
 #include "nsTArray.h"
 
 class nsMailboxUrl : public nsIMailboxUrl, public nsMsgMailNewsUrl, public nsIMsgMessageUrl, public nsIMsgI18NUrl
 {
 public:
   // nsIMsgMailNewsUrl override
   nsresult SetSpecInternal(const nsACString &aSpec) override;
   nsresult SetQuery(const nsACString &aQuery) override;
+  nsresult CreateURL(const nsACString& aSpec, nsIURL **aURL) override;
 
   // from nsIMailboxUrl:
   NS_IMETHOD SetMailboxParser(nsIStreamListener * aConsumer) override;
   NS_IMETHOD GetMailboxParser(nsIStreamListener ** aConsumer) override;
   NS_IMETHOD SetMailboxCopyHandler(nsIStreamListener *  aConsumer) override;
   NS_IMETHOD GetMailboxCopyHandler(nsIStreamListener ** aConsumer) override;
 
   NS_IMETHOD GetMessageKey(nsMsgKey* aMessageKey) override;