Bug 1293770 - Update popstate.dat for maildir delete. r=rkent
authorJorg K <jorgk@jorgk.com>
Wed, 19 Jul 2017 23:30:43 +0200
changeset 21789 c4c7c0e2a1c64291692fff85f81f41a22ffdc1ce
parent 21788 7a2ed081a9cb7e8fbb653d8c051951a34afa2649
child 21790 2501146ba1d4b835df72dff6c15efe6a7d18dcdb
push id13297
push usermozilla@jorgk.com
push dateWed, 19 Jul 2017 21:33:03 +0000
treeherdercomm-central@c4c7c0e2a1c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent
bugs1293770
Bug 1293770 - Update popstate.dat for maildir delete. r=rkent
mailnews/base/public/nsIMsgPluggableStore.idl
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsMsgBrkMBoxStore.cpp
mailnews/local/src/nsMsgMaildirStore.cpp
--- a/mailnews/base/public/nsIMsgPluggableStore.idl
+++ b/mailnews/base/public/nsIMsgPluggableStore.idl
@@ -209,25 +209,27 @@ interface nsIMsgPluggableStore : nsISupp
    * If the store does the copy, it must return the appropriate undo action,
    * which can be store dependent. And it must send the appropriate
    * nsIMsgFolderNotificationService notifications.
    *
    * @param isMove true if this is a move, false if it is a copy.
    * @param aHdrArray array of nsIMsgDBHdr's, all in the same folder
    * @param aDstFolder folder to move/copy the messages to.
    * @param aListener listener to notify of copy status.
+   * @param aDstHdrs array of nsIMsgDBHdr's in the destination folder.
    * @param[out,optional] aUndoAction transaction to provide undo, if
    * the store does the copy itself.
    * @return true if messages were copied, false if the core code should
    *         do the copy.
    */
   boolean copyMessages(in boolean isMove,
                        in nsIArray aHdrArray,
                        in nsIMsgFolder aDstFolder,
                        in nsIMsgCopyServiceListener aListener,
+                       out nsIArray aDstHdrs,
                        out nsITransaction aUndoAction);
 
   /**
    * Does this store require compaction? For example, maildir doesn't require
    * compaction at all. Berkeley mailbox does. A sqlite store probably doesn't.
    * This is a static property of the store. It doesn't mean that any particular
    * folder has space that can be reclaimed via compaction. Right now, the core
    * code keeps track of the size of messages deleted, which it can use in
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -1565,32 +1565,53 @@ nsMsgLocalMailFolder::CopyMessages(nsIMs
     return NS_OK;
 
   NS_ENSURE_SUCCESS(rv, rv);
   bool storeDidCopy = false;
   nsCOMPtr<nsIMsgPluggableStore> msgStore;
   rv = GetMsgStore(getter_AddRefs(msgStore));
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsITransaction> undoTxn;
+  nsCOMPtr<nsIArray> dstHdrs;
   rv = msgStore->CopyMessages(isMove, messages, this, listener,
-                              getter_AddRefs(undoTxn), &storeDidCopy);
+                              getter_AddRefs(dstHdrs), getter_AddRefs(undoTxn),
+                              &storeDidCopy);
   if (storeDidCopy)
   {
     NS_ASSERTION(undoTxn, "if store does copy, it needs to add undo action");
     if (msgWindow && undoTxn)
     {
       nsCOMPtr<nsITransactionManager> txnMgr;
       msgWindow->GetTransactionManager(getter_AddRefs(txnMgr));
       if (txnMgr)
         txnMgr->DoTransaction(undoTxn);
     }
     if (isMove)
       srcFolder->NotifyFolderEvent(NS_SUCCEEDED(rv) ? mDeleteOrMoveMsgCompletedAtom :
                                                       mDeleteOrMoveMsgFailedAtom);
 
+    if (NS_SUCCEEDED(rv)) {
+      // If the store did the copy, like maildir, we need to mark messages on the server.
+      // Otherwise that's done in EndMove().
+      nsCOMPtr <nsIMsgLocalMailFolder> localDstFolder;
+      QueryInterface(NS_GET_IID(nsIMsgLocalMailFolder), getter_AddRefs(localDstFolder));
+      if (localDstFolder)
+      {
+        // If we are the trash and a local msg is being moved to us, mark the source
+        // for delete from server, if so configured.
+        if (mFlags & nsMsgFolderFlags::Trash)
+        {
+          // If we're deleting on all moves, we'll mark this message for deletion when
+          // we call DeleteMessages on the source folder. So don't mark it for deletion
+          // here, in that case.
+          if (!GetDeleteFromServerOnMove())
+            localDstFolder->MarkMsgsOnPop3Server(dstHdrs, POP3_DELETE);
+        }
+      }
+    }
     return rv;
   }
   // If the store doesn't do the copy, we'll stream the source messages into
   // the target folder, using getMsgInputStream and getNewMsgOutputStream.
 
   // don't update the counts in the dest folder until it is all over
   EnableNotifications(allMessageCountNotifications, false);
 
--- a/mailnews/local/src/nsMsgBrkMBoxStore.cpp
+++ b/mailnews/local/src/nsMsgBrkMBoxStore.cpp
@@ -763,22 +763,25 @@ NS_IMETHODIMP nsMsgBrkMBoxStore::DeleteM
 {
   return ChangeFlags(aHdrArray, nsMsgMessageFlags::Expunged, true);
 }
 
 NS_IMETHODIMP
 nsMsgBrkMBoxStore::CopyMessages(bool isMove, nsIArray *aHdrArray,
                                nsIMsgFolder *aDstFolder,
                                nsIMsgCopyServiceListener *aListener,
+                               nsIArray **aDstHdrs,
                                nsITransaction **aUndoAction,
                                bool *aCopyDone)
 {
   NS_ENSURE_ARG_POINTER(aHdrArray);
   NS_ENSURE_ARG_POINTER(aDstFolder);
+  NS_ENSURE_ARG_POINTER(aDstHdrs);
   NS_ENSURE_ARG_POINTER(aCopyDone);
+  *aDstHdrs = nullptr;
   *aUndoAction = nullptr;
   *aCopyDone = false;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgBrkMBoxStore::GetSupportsCompaction(bool *aSupportsCompaction)
 {
--- a/mailnews/local/src/nsMsgMaildirStore.cpp
+++ b/mailnews/local/src/nsMsgMaildirStore.cpp
@@ -960,16 +960,17 @@ NS_IMETHODIMP nsMsgMaildirStore::DeleteM
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgMaildirStore::CopyMessages(bool aIsMove, nsIArray *aHdrArray,
                                nsIMsgFolder *aDstFolder,
                                nsIMsgCopyServiceListener *aListener,
+                               nsIArray **aDstHdrs,
                                nsITransaction **aUndoAction,
                                bool *aCopyDone)
 {
   NS_ENSURE_ARG_POINTER(aHdrArray);
   NS_ENSURE_ARG_POINTER(aDstFolder);
   NS_ENSURE_ARG_POINTER(aCopyDone);
   NS_ENSURE_ARG_POINTER(aUndoAction);
 
@@ -1118,16 +1119,17 @@ nsMsgMaildirStore::CopyMessages(bool aIs
 
   *aCopyDone = true;
   nsCOMPtr<nsISupports> srcSupports(do_QueryInterface(srcFolder));
   if (destLocalFolder)
     destLocalFolder->OnCopyCompleted(srcSupports, true);
   if (aListener)
     aListener->OnStopCopy(NS_OK);
   msgTxn.forget(aUndoAction);
+  dstHdrs.forget(aDstHdrs);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgMaildirStore::GetSupportsCompaction(bool *aSupportsCompaction)
 {
   NS_ENSURE_ARG_POINTER(aSupportsCompaction);
   *aSupportsCompaction = false;