Bug 1498097 - never delete template when sending. r=aceman DONTBUILD
authorJorg K <jorgk@jorgk.com>
Sun, 14 Oct 2018 11:05:34 +0200
changeset 33366 33c8749ebc80aeb154c6718bea9692516e4b0ba8
parent 33365 d3153e99afae5c8ec62f70bf6b5184fffea35c8a
child 33367 9e7fc0d137ce573eb9d11818dde9d1e3adade04f
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersaceman
bugs1498097
Bug 1498097 - never delete template when sending. r=aceman DONTBUILD
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCompose.h
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -3723,17 +3723,17 @@ nsresult nsMsgComposeSendListener::OnSto
           msgCompose->CloseWindow();  // if we fail on the simple GetFcc call, close the window to be safe and avoid
                                       // windows hanging around to prevent the app from exiting.
       }
 
       // Remove the current draft msg when sending draft is done.
       bool deleteDraft;
       msgCompose->GetDeleteDraft(&deleteDraft);
       if (deleteDraft)
-        RemoveCurrentDraftMessage(msgCompose, false);
+        RemoveCurrentDraftMessage(msgCompose, false, true);
     }
     else
     {
       msgCompose->NotifyStateListeners(nsIMsgComposeNotificationType::ComposeProcessDone, aStatus);
       if (progress)
       {
         progress->CloseProgressDialog(true);
         progress->UnregisterListener(this);
@@ -3807,26 +3807,26 @@ nsMsgComposeSendListener::OnStopCopy(nsr
       // We should only close the window if we are done. Things like templates
       // and drafts aren't done so their windows should stay open
       if (mDeliverMode == nsIMsgSend::nsMsgSaveAsDraft ||
           mDeliverMode == nsIMsgSend::nsMsgSaveAsTemplate)
       {
         msgCompose->NotifyStateListeners(nsIMsgComposeNotificationType::SaveInFolderDone, aStatus);
         // Remove the current draft msg when saving as draft/template is done.
         msgCompose->SetDeleteDraft(true);
-        RemoveCurrentDraftMessage(msgCompose, true);
+        RemoveCurrentDraftMessage(msgCompose, true, false);
       }
       else
       {
         // Remove (possible) draft if we're in send later mode
         if (mDeliverMode == nsIMsgSend::nsMsgQueueForLater ||
             mDeliverMode == nsIMsgSend::nsMsgDeliverBackground)
         {
           msgCompose->SetDeleteDraft(true);
-          RemoveCurrentDraftMessage(msgCompose, true);
+          RemoveCurrentDraftMessage(msgCompose, true, true);
         }
         msgCompose->CloseWindow();
       }
     }
     msgCompose->ClearMessageSend();
   }
 
   return rv;
@@ -3850,17 +3850,17 @@ nsMsgComposeSendListener::GetMsgFolder(n
 
   nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(resource, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   folder.forget(msgFolder);
   return rv;
 }
 
 nsresult
-nsMsgComposeSendListener::RemoveCurrentDraftMessage(nsIMsgCompose *compObj, bool calledByCopy)
+nsMsgComposeSendListener::RemoveCurrentDraftMessage(nsIMsgCompose *compObj, bool calledByCopy, bool isSend)
 {
   nsresult rv;
   nsCOMPtr <nsIMsgCompFields> compFields = nullptr;
 
   rv = compObj->GetCompFields(getter_AddRefs(compFields));
   NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveCurrentDraftMessage can't get compose fields");
   if (NS_FAILED(rv) || !compFields)
     return rv;
@@ -3888,16 +3888,19 @@ nsMsgComposeSendListener::RemoveCurrentD
         if (NS_FAILED(rv) || !msgFolder)
           break;
 
         // Only do this if it's a drafts or templates folder.
         uint32_t flags;
         msgFolder->GetFlags(&flags);
         if (!(flags & (nsMsgFolderFlags::Drafts | nsMsgFolderFlags::Templates)))
           break;
+        // Never delete a template when sending.
+        if (isSend && (flags & nsMsgFolderFlags::Templates))
+          break;
 
         // Only remove if the message is actually in the db. It might have only
         // been in the use cache.
         nsMsgKey key;
         rv = msgDBHdr->GetMessageKey(&key);
         if (NS_FAILED(rv))
           break;
         nsCOMPtr<nsIMsgDatabase> db;
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -214,17 +214,17 @@ public:
   NS_DECL_NSIMSGSENDLISTENER
 
   // nsIMsgCopyServiceListener interface
   NS_DECL_NSIMSGCOPYSERVICELISTENER
 
   // nsIWebProgressListener interface
   NS_DECL_NSIWEBPROGRESSLISTENER
 
-  nsresult    RemoveCurrentDraftMessage(nsIMsgCompose *compObj, bool calledByCopy);
+  nsresult    RemoveCurrentDraftMessage(nsIMsgCompose *compObj, bool calledByCopy, bool isSend);
   nsresult    GetMsgFolder(nsIMsgCompose *compObj, nsIMsgFolder **msgFolder);
 
 private:
   virtual ~nsMsgComposeSendListener();
   nsWeakPtr               mWeakComposeObj;
   MSG_DeliverMode         mDeliverMode;
 };