diff --git a/mailnews/db/msgdb/src/nsMailDatabase.cpp b/mailnews/db/msgdb/src/nsMailDatabase.cpp index 5472cc6565c7..8a9ec5dcfde5 100644 --- a/mailnews/db/msgdb/src/nsMailDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMailDatabase.cpp @@ -70,6 +70,7 @@ nsMailDatabase::~nsMailDatabase() NS_IMETHODIMP nsMailDatabase::SetFolderStream(nsIOFileStream *aFileStream) { + NS_ASSERTION(!m_folderStream || !aFileStream, "m_folderStream is not null and we are assigning a non null stream to it"); m_folderStream = aFileStream; //m_folderStream is set externally, so m_ownFolderStream is false m_ownFolderStream = PR_FALSE; return NS_OK; @@ -331,6 +332,7 @@ void nsMailDatabase::UpdateFolderFlag(nsIMsgDBHdr *mailHdr, PRBool bSet, MsgFlags flag, nsIOFileStream **ppFileStream) { static char buf[50]; + PRInt32 folderStreamPos; //saves the folderStream pos in case we are sharing the stream with other code nsIOFileStream *fileStream = (m_folderStream) ? m_folderStream : *ppFileStream; //#ifdef GET_FILE_STUFF_TOGETHER #ifdef XP_MAC @@ -356,6 +358,11 @@ void nsMailDatabase::UpdateFolderFlag(nsIMsgDBHdr *mailHdr, PRBool bSet, { fileStream = new nsIOFileStream(nsFileSpec(*m_folderSpec)); } + else if (!m_ownFolderStream) + { + m_folderStream->flush(); + folderStreamPos = m_folderStream->tell(); + } if (fileStream) { PRUint32 msgOffset; @@ -454,6 +461,8 @@ void nsMailDatabase::UpdateFolderFlag(nsIMsgDBHdr *mailHdr, PRBool bSet, //#endif // GET_FILE_STUFF_TOGETHER if (!m_folderStream) *ppFileStream = fileStream; // This tells the caller that we opened the file, and please to close it. + else if (!m_ownFolderStream) + m_folderStream->seek(PR_SEEK_SET, folderStreamPos); } NS_IMETHODIMP nsMailDatabase::GetSummaryValid(PRBool *aResult) diff --git a/mailnews/local/src/nsPop3Sink.cpp b/mailnews/local/src/nsPop3Sink.cpp index 8645d5ea62ec..3e2acabc0870 100644 --- a/mailnews/local/src/nsPop3Sink.cpp +++ b/mailnews/local/src/nsPop3Sink.cpp @@ -447,11 +447,9 @@ nsresult nsPop3Sink::WriteLineToMailbox(char *buffer) // See bug 62480 if (!m_outFileStream) return NS_ERROR_OUT_OF_MEMORY; + + NS_ASSERTION(m_outFileStream->eof(), "we are not writing to end-of-file"); - /*This file stream is also used by db so file pos could have changed - set it to the end of the file before writing anything */ - - m_outFileStream->seek(PR_SEEK_END, 0); PRInt32 bytes = m_outFileStream->write(buffer,bufferLen); if (bytes != bufferLen) return NS_ERROR_FAILURE; } @@ -475,13 +473,8 @@ nsPop3Sink::IncorporateComplete(nsIMsgWindow *msgWindow) if (NS_FAILED(rv)) return rv; NS_ASSERTION(m_newMailParser, "could not get m_newMailParser"); if (m_newMailParser) - { m_newMailParser->PublishMsgHeader(msgWindow); - //PublishMsgHeader might have changed the postion of file stream pointer, reset it back. - m_outFileStream->seek(PR_SEEK_END, 0); - } - #ifdef DEBUG printf("Incorporate message complete.\n"); #endif