remove trailing hierarchy delimiter when subscribing to imap folders, r=neil, initial patch by Midspeck@hotmail.com
authorDavid Bienvenu <bienvenu@nventure.com>
Mon, 20 Feb 2012 10:11:05 -0800
changeset 10867 4821565a8f2408109f97414658e5789a6f672525
parent 10866 01e1c291493e1fd9970c3a3af6523fe87e8be71e
child 10868 4f4b9352555e36c9e68c38f5a45863ee0d641349
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil, initial
remove trailing hierarchy delimiter when subscribing to imap folders, r=neil, initial patch by Midspeck@hotmail.com
mailnews/imap/public/nsIImapMailFolderSink.idl
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapProtocol.h
mailnews/imap/src/nsSyncRunnableHelpers.cpp
--- a/mailnews/imap/public/nsIImapMailFolderSink.idl
+++ b/mailnews/imap/public/nsIImapMailFolderSink.idl
@@ -59,17 +59,17 @@ interface ImapOnlineCopyStateType
    const long kFailedDelete = 4;
    const long kReadyForAppendData = 5;
    const long kFailedAppend = 6;
    const long kInterruptedState = 7;
    const long kFailedCopy = 8;
    const long kFailedMove = 9;
 };
 
-[scriptable, uuid(e16c3399-285a-4e1b-8940-c3352200aa9c)]
+[scriptable, uuid(525e1278-a39d-46d6-9dbc-b48c7e1d4faa)]
 interface nsIImapMailFolderSink : nsISupports {
   attribute boolean folderNeedsACLListed;
   attribute boolean folderNeedsSubscribing;
   attribute boolean folderNeedsAdded;
   attribute unsigned long aclFlags;
   attribute long uidValidity;
   /**
    * Whether we have asked the server for this folder's quota information.
@@ -84,17 +84,17 @@ interface nsIImapMailFolderSink : nsISup
    * @param aFolderQuotaUsedKB  Used space, in KB, on this folder's quota root.
    * @param aFolderQuotaMaxKB   Size, in KB, of this folder's quota root.
    **/
   void setFolderQuotaData(in ACString aFolderQuotaRoot, in unsigned long aFolderQuotaUsedKB, 
                           in unsigned long aFolderQuotaMaxKB);
 
   /// Should we download all the rfc822 headers of messages, instead of subset.
   readonly attribute boolean shouldDownloadAllHeaders;
-  string GetOnlineDelimiter();
+  readonly attribute char onlineDelimiter;
   void OnNewIdleMessages();
   // Tell mail master about the newly selected mailbox
   void UpdateImapMailboxInfo(in nsIImapProtocol aProtocol,
                              in nsIMailboxSpec aSpec);
   void UpdateImapMailboxStatus(in nsIImapProtocol aProtocol,
                                in nsIMailboxSpec aSpec);
   /**
    * Used when downloading headers in chunks.
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -1138,23 +1138,19 @@ NS_IMETHODIMP nsImapMailFolder::SetVerif
         }
       }
     }
     while (parent);
   }
   return NS_OK;
 }
 
-NS_IMETHODIMP nsImapMailFolder::GetOnlineDelimiter(char** onlineDelimiter)
-{
-  NS_ENSURE_ARG_POINTER(onlineDelimiter);
-  char delimiter[2] = {0, 0};
-  GetHierarchyDelimiter(delimiter);
-  *onlineDelimiter = NS_strdup(delimiter);
-  return NS_OK;
+NS_IMETHODIMP nsImapMailFolder::GetOnlineDelimiter(char* onlineDelimiter)
+{
+  return GetHierarchyDelimiter(onlineDelimiter);
 }
 
 NS_IMETHODIMP nsImapMailFolder::SetHierarchyDelimiter(char aHierarchyDelimiter)
 {
   m_hierarchyDelimiter = aHierarchyDelimiter;
   return NS_OK;
 }
 
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -6107,25 +6107,24 @@ done:
     fileInputStream->Close();
 }
 
 //caller must free using PR_Free
 char * nsImapProtocol::OnCreateServerSourceFolderPathString()
 {
   char *sourceMailbox = nsnull;
   char hierarchyDelimiter = 0;
-  char *onlineDelimiter = nsnull;
+  char onlineDelimiter = 0;
   m_runningUrl->GetOnlineSubDirSeparator(&hierarchyDelimiter);
   if (m_imapMailFolderSink)
-      m_imapMailFolderSink->GetOnlineDelimiter(&onlineDelimiter);
-  if (onlineDelimiter && *onlineDelimiter != kOnlineHierarchySeparatorUnknown
-      && *onlineDelimiter != hierarchyDelimiter)
-      m_runningUrl->SetOnlineSubDirSeparator (*onlineDelimiter);
-  if (onlineDelimiter)
-    NS_Free(onlineDelimiter);
+    m_imapMailFolderSink->GetOnlineDelimiter(&onlineDelimiter);
+
+  if (onlineDelimiter != kOnlineHierarchySeparatorUnknown &&
+      onlineDelimiter != hierarchyDelimiter)
+    m_runningUrl->SetOnlineSubDirSeparator(onlineDelimiter);
 
   m_runningUrl->CreateServerSourceFolderPathString(&sourceMailbox);
 
   return sourceMailbox;
 }
 
 //caller must free using PR_Free, safe to call from ui thread
 char * nsImapProtocol::GetFolderPathString()
@@ -6141,17 +6140,17 @@ char * nsImapProtocol::GetFolderPathStri
   if (msgFolder)
   {
     nsCOMPtr <nsIMsgImapMailFolder> imapFolder = do_QueryInterface(msgFolder);
     if (imapFolder)
     {
       imapFolder->GetHierarchyDelimiter(&hierarchyDelimiter);
       if (hierarchyDelimiter != kOnlineHierarchySeparatorUnknown &&
           onlineSubDirDelimiter != hierarchyDelimiter)
-          m_runningUrl->SetOnlineSubDirSeparator(hierarchyDelimiter);
+        m_runningUrl->SetOnlineSubDirSeparator(hierarchyDelimiter);
     }
   }
   m_runningUrl->CreateServerSourceFolderPathString(&sourceMailbox);
 
   return sourceMailbox;
 }
 
 nsresult nsImapProtocol::CreateServerSourceFolderPathString(char **result)
@@ -6161,38 +6160,38 @@ nsresult nsImapProtocol::CreateServerSou
   return (*result) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 //caller must free using PR_Free
 char * nsImapProtocol::OnCreateServerDestinationFolderPathString()
 {
   char *destinationMailbox = nsnull;
   char hierarchyDelimiter = 0;
-  char *onlineDelimiter = nsnull;
+  char onlineDelimiter = 0;
   m_runningUrl->GetOnlineSubDirSeparator(&hierarchyDelimiter);
   if (m_imapMailFolderSink)
-      m_imapMailFolderSink->GetOnlineDelimiter(&onlineDelimiter);
-  if (onlineDelimiter && *onlineDelimiter != kOnlineHierarchySeparatorUnknown
-      && *onlineDelimiter != hierarchyDelimiter)
-      m_runningUrl->SetOnlineSubDirSeparator (*onlineDelimiter);
-  if (onlineDelimiter)
-      NS_Free(onlineDelimiter);
+    m_imapMailFolderSink->GetOnlineDelimiter(&onlineDelimiter);
+  if (onlineDelimiter != kOnlineHierarchySeparatorUnknown &&
+      onlineDelimiter != hierarchyDelimiter)
+    m_runningUrl->SetOnlineSubDirSeparator(onlineDelimiter);
 
   m_runningUrl->CreateServerDestinationFolderPathString(&destinationMailbox);
 
   return destinationMailbox;
 }
 
 void nsImapProtocol::OnCreateFolder(const char * aSourceMailbox)
 {
   bool created = CreateMailboxRespectingSubscriptions(aSourceMailbox);
   if (created)
   {
     m_hierarchyNameState = kListingForCreate;
-    List(aSourceMailbox, false);
+    nsCString mailboxWODelim(aSourceMailbox);
+    RemoveHierarchyDelimiter(mailboxWODelim);
+    List(mailboxWODelim.get(), false);
     m_hierarchyNameState = kNoOperationInProgress;
   }
   else
     FolderNotCreated(aSourceMailbox);
 }
 
 void nsImapProtocol::OnEnsureExistsFolder(const char * aSourceMailbox)
 {
@@ -7411,33 +7410,43 @@ void nsImapProtocol::MailboxDiscoveryFin
     m_hostSessionList->SetHaveWeEverDiscoveredFoldersForHost(GetImapServerKey(), true);
 
     // notify front end that folder discovery is complete....
     if (m_imapServerSink)
       m_imapServerSink->DiscoveryDone();
   }
 }
 
+// returns the mailboxName with the IMAP delimiter removed from the tail end
+void nsImapProtocol::RemoveHierarchyDelimiter(nsCString &mailboxName)
+{
+  char onlineDelimiter[2] = {0, 0};
+  if (m_imapMailFolderSink)
+    m_imapMailFolderSink->GetOnlineDelimiter(&onlineDelimiter[0]);
+  // take the hierarchy delimiter off the end, if any.
+  if (onlineDelimiter[0])
+    mailboxName.Trim(onlineDelimiter, false, true);
+}
+
 // returns true is the create succeeded (regardless of subscription changes)
 bool nsImapProtocol::CreateMailboxRespectingSubscriptions(const char *mailboxName)
 {
   CreateMailbox(mailboxName);
   bool rv = GetServerStateParser().LastCommandSuccessful();
-  if (rv)
-  {
-    if (m_autoSubscribe) // auto-subscribe is on
-    {
-      // create succeeded - let's subscribe to it
-      bool reportingErrors = GetServerStateParser().GetReportingErrors();
-      GetServerStateParser().SetReportingErrors(false);
-      OnSubscribe(mailboxName);
-      GetServerStateParser().SetReportingErrors(reportingErrors);
-    }
-  }
-  return (rv);
+  if (rv && m_autoSubscribe) // auto-subscribe is on
+  {
+    // create succeeded - let's subscribe to it
+    bool reportingErrors = GetServerStateParser().GetReportingErrors();
+    GetServerStateParser().SetReportingErrors(false);
+    nsCString mailboxWODelim(mailboxName);
+    RemoveHierarchyDelimiter(mailboxWODelim);
+    OnSubscribe(mailboxWODelim.get());
+    GetServerStateParser().SetReportingErrors(reportingErrors);
+  }
+  return rv;
 }
 
 void nsImapProtocol::CreateMailbox(const char *mailboxName)
 {
   ProgressEventFunctionUsingId (IMAP_STATUS_CREATING_MAILBOX);
 
   IncrementCommandTagNumber();
 
--- a/mailnews/imap/src/nsImapProtocol.h
+++ b/mailnews/imap/src/nsImapProtocol.h
@@ -540,16 +540,17 @@ private:
   void OnRenameFolder(const char * aSourceMailbox);
   void OnMoveFolderHierarchy(const char * aSourceMailbox);
   void DeleteFolderAndMsgs(const char * aSourceMailbox);
   void RemoveMsgsAndExpunge();
   void FindMailboxesIfNecessary();
   void CreateMailbox(const char *mailboxName);
   void DeleteMailbox(const char *mailboxName);
   void RenameMailbox(const char *existingName, const char *newName);
+  void RemoveHierarchyDelimiter(nsCString &mailboxName);
   bool CreateMailboxRespectingSubscriptions(const char *mailboxName);
   bool DeleteMailboxRespectingSubscriptions(const char *mailboxName);
   bool    RenameMailboxRespectingSubscriptions(const char *existingName,
     const char *newName,
     bool reallyRename);
   // notify the fe that a folder was deleted
   void FolderDeleted(const char *mailboxName);
   // notify the fe that a folder creation failed
--- a/mailnews/imap/src/nsSyncRunnableHelpers.cpp
+++ b/mailnews/imap/src/nsSyncRunnableHelpers.cpp
@@ -405,17 +405,17 @@ NS_SYNCRUNNABLEMETHOD0(ImapProtocolSink,
 NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, FolderNeedsACLListed, bool)
 NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, FolderNeedsSubscribing, bool)
 NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, FolderNeedsAdded, bool)
 NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, AclFlags, PRUint32)
 NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, UidValidity, PRInt32)
 NS_SYNCRUNNABLEATTRIBUTE(ImapMailFolderSink, FolderQuotaCommandIssued, bool)
 NS_SYNCRUNNABLEMETHOD3(ImapMailFolderSink, SetFolderQuotaData, const nsACString &, PRUint32, PRUint32)
 NS_SYNCRUNNABLEMETHOD1(ImapMailFolderSink, GetShouldDownloadAllHeaders, bool *)
-NS_SYNCRUNNABLEMETHOD1(ImapMailFolderSink, GetOnlineDelimiter, char **)
+NS_SYNCRUNNABLEMETHOD1(ImapMailFolderSink, GetOnlineDelimiter, char *)
 NS_SYNCRUNNABLEMETHOD0(ImapMailFolderSink, OnNewIdleMessages)
 NS_SYNCRUNNABLEMETHOD2(ImapMailFolderSink, UpdateImapMailboxStatus, nsIImapProtocol *, nsIMailboxSpec *)
 NS_SYNCRUNNABLEMETHOD2(ImapMailFolderSink, UpdateImapMailboxInfo, nsIImapProtocol *, nsIMailboxSpec *)
 NS_SYNCRUNNABLEMETHOD4(ImapMailFolderSink, GetMsgHdrsToDownload, bool *, PRInt32 *, PRUint32 *, nsMsgKey **)
 NS_SYNCRUNNABLEMETHOD2(ImapMailFolderSink, ParseMsgHdrs, nsIImapProtocol *, nsIImapHeaderXferInfo *)
 NS_SYNCRUNNABLEMETHOD1(ImapMailFolderSink, AbortHeaderParseStream, nsIImapProtocol *)
 NS_SYNCRUNNABLEMETHOD2(ImapMailFolderSink, OnlineCopyCompleted, nsIImapProtocol *, ImapOnlineCopyState)
 NS_SYNCRUNNABLEMETHOD1(ImapMailFolderSink, StartMessage, nsIMsgMailNewsUrl *)