Bug 668952 - Inbox corruption/error message occurs with "move to folder" filters, r=bienvenu,a=Standard8
authorKent James <kent@caspia.com>
Tue, 23 Aug 2011 10:39:31 -0700
changeset 8854 9d247c12a9a4d98f940b36dea7e28813f799e4b4
parent 8853 4bc1aa261198535fbcf0a8b291050fbc547fe675
child 8855 567184a444a229379883e29fb420f2eccb05d6e0
push idunknown
push userunknown
push dateunknown
reviewersbienvenu, Standard8
bugs668952
Bug 668952 - Inbox corruption/error message occurs with "move to folder" filters, r=bienvenu,a=Standard8
mailnews/local/src/nsPop3Sink.cpp
mailnews/local/src/nsPop3Sink.h
--- a/mailnews/local/src/nsPop3Sink.cpp
+++ b/mailnews/local/src/nsPop3Sink.cpp
@@ -323,20 +323,19 @@ nsPop3Sink::BeginMailDelivery(PRBool uid
     NS_ENSURE_SUCCESS(rv, rv);
 
     m_tmpDownloadFile = do_QueryInterface(tmpDownloadFile, &rv);
     if (NS_SUCCEEDED(rv))
     {
       rv = MsgGetFileStream(m_tmpDownloadFile, getter_AddRefs(m_outFileStream));
       NS_ENSURE_SUCCESS(rv, rv);
     }
-    nsCOMPtr<nsIOutputStream> inboxOutputStream;
-    rv = MsgGetFileStream(path, getter_AddRefs(inboxOutputStream));
+    rv = MsgGetFileStream(path, getter_AddRefs(m_inboxOutputStream));
     NS_ENSURE_SUCCESS(rv, rv);
-    inboxInputStream = do_QueryInterface(inboxOutputStream);
+    inboxInputStream = do_QueryInterface(m_inboxOutputStream);
   }
   else
   {
     rv = MsgGetFileStream(path, getter_AddRefs(m_outFileStream));
     NS_ENSURE_SUCCESS(rv, rv);
     inboxInputStream = do_QueryInterface(m_outFileStream);
   }
   // The following (!m_outFileStream etc) was added to make sure that we don't write somewhere
@@ -416,16 +415,21 @@ nsPop3Sink::EndMailDelivery(nsIPop3Proto
     m_newMailParser->SetDBFolderStream(nsnull); // stream is going away
     m_newMailParser->EndMsgDownload();
   }
   if (m_outFileStream)
   {
     m_outFileStream->Close();
     m_outFileStream = 0;
   }
+  if (m_inboxOutputStream)
+  {
+    m_inboxOutputStream->Close();
+    m_inboxOutputStream = nsnull;
+  }
 
   if (m_downloadingToTempFile)
     m_tmpDownloadFile->Remove(PR_FALSE);
 
   // tell the parser to mark the db valid *after* closing the mailbox.
   if (m_newMailParser)
     m_newMailParser->UpdateDBFolderInfo();
 
@@ -543,16 +547,21 @@ nsPop3Sink::AbortMailDelivery(nsIPop3Pro
   if (m_newMailParser)
     m_newMailParser->SetDBFolderStream(nsnull); //stream is going away
 
   if (m_outFileStream)
   {
     m_outFileStream->Close();
     m_outFileStream = 0;
   }
+  if (m_inboxOutputStream)
+  {
+    m_inboxOutputStream->Close();
+    m_inboxOutputStream = nsnull;
+  }
 
   if (m_downloadingToTempFile && m_tmpDownloadFile)
     m_tmpDownloadFile->Remove(PR_FALSE);
 
   /* tell the parser to mark the db valid *after* closing the mailbox.
   we have truncated the inbox, so berkeley mailbox and msf file are in sync*/
   if (m_newMailParser)
     m_newMailParser->UpdateDBFolderInfo();
--- a/mailnews/local/src/nsPop3Sink.h
+++ b/mailnews/local/src/nsPop3Sink.h
@@ -91,17 +91,19 @@ protected:
     PRInt32 m_outputBufferSize;
     nsIPop3IncomingServer *m_popServer;
     //Currently the folder we want to update about biff info
     nsCOMPtr<nsIMsgFolder> m_folder;
     nsParseNewMailState  *m_newMailParser;
 #ifdef DEBUG
     PRInt32 m_fileCounter;
 #endif
-    nsCOMPtr <nsIOutputStream> m_outFileStream;
+    nsCOMPtr <nsIOutputStream> m_outFileStream; // the file we write to, which may be temporary
+    nsCOMPtr <nsIOutputStream> m_inboxOutputStream; // the actual mailbox
+
     PRBool m_buildMessageUri;
     PRBool m_downloadingToTempFile;
     nsCOMPtr <nsILocalFile> m_tmpDownloadFile;
     nsCString m_messageUri;
     nsCString m_baseMessageUri;
     nsCString m_origMessageUri;
     nsCString m_accountKey;
     nsTArray<partialRecord*> m_partialMsgsArray;