summaryrefslogtreecommitdiffstats
path: root/mailnews/base
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2019-11-10 18:43:43 -0500
committerMatt A. Tobin <email@mattatobin.com>2019-11-10 18:43:43 -0500
commite60090bc9c7e14bb8253eeb64658aedaa0f863c7 (patch)
tree0d8b21f3ff848346d601c34c88bd35c76fb06d0a /mailnews/base
parent1ec388b2383aa1540961843847d3af32174a248d (diff)
downloadUXP-e60090bc9c7e14bb8253eeb64658aedaa0f863c7.tar
UXP-e60090bc9c7e14bb8253eeb64658aedaa0f863c7.tar.gz
UXP-e60090bc9c7e14bb8253eeb64658aedaa0f863c7.tar.lz
UXP-e60090bc9c7e14bb8253eeb64658aedaa0f863c7.tar.xz
UXP-e60090bc9c7e14bb8253eeb64658aedaa0f863c7.zip
Bug 1427732 - fix newline handling when copying messages and compacting folders.
Tag #1273
Diffstat (limited to 'mailnews/base')
-rw-r--r--mailnews/base/public/msgCore.h13
-rw-r--r--mailnews/base/src/nsMsgFolderCompactor.cpp23
2 files changed, 27 insertions, 9 deletions
diff --git a/mailnews/base/public/msgCore.h b/mailnews/base/public/msgCore.h
index fc18fb16f..d14ff6140 100644
--- a/mailnews/base/public/msgCore.h
+++ b/mailnews/base/public/msgCore.h
@@ -178,6 +178,19 @@ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MAILNEWS, value)
#define MSG_LINEBREAK_LEN 1
#endif
+/*
+ * On Windows, we use \r\n as the line terminator in mbox files. On
+ * other platforms, we use \n. However, we need to be able to
+ * recognize line terminators produced on any platform, because we
+ * allow profiles (including the mbox files they contain) to be shared
+ * between platforms.
+ *
+ * Returns 0 (i.e., false) if the line is not blank, or otherwise the
+ * length of the line terminator, i.e., 1 for \n or 2 for \r\n.
+ */
+#define IS_MSG_LINEBREAK(line) \
+ (line[0] == '\012' ? 1 : ((line[0] == '\015' && line[1] == '\012') ? 2 : 0))
+
#define NS_MSG_BASE
#define NS_MSG_BASE_STATIC_MEMBER_(type) type
diff --git a/mailnews/base/src/nsMsgFolderCompactor.cpp b/mailnews/base/src/nsMsgFolderCompactor.cpp
index 4b0dc3ad5..5224aef51 100644
--- a/mailnews/base/src/nsMsgFolderCompactor.cpp
+++ b/mailnews/base/src/nsMsgFolderCompactor.cpp
@@ -734,6 +734,7 @@ nsFolderCompactState::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
}
else
{
+ // XXX TODO: Error checking and handling missing here.
EndCopy(nullptr, status);
if (m_curIndex >= m_size)
{
@@ -754,6 +755,8 @@ nsFolderCompactState::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
return status;
}
+// XXX TODO: This function is sadly lacking all status checking, it always
+// returns NS_OK and moves onto the next message.
NS_IMETHODIMP
nsFolderCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
nsIInputStream *inStr,
@@ -784,7 +787,7 @@ nsFolderCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
{
(void) m_curSrcHdr->GetFlags(&msgFlags);
(void) m_curSrcHdr->GetStatusOffset(&statusOffset);
-
+
if (statusOffset == 0)
m_needStatusLine = true;
// x-mozilla-status lines should be at the start of the headers, and the code
@@ -794,7 +797,7 @@ nsFolderCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
{
checkForKeyword = false;
NS_ASSERTION(false, "status offset past end of read buffer size");
-
+
}
}
}
@@ -802,18 +805,18 @@ nsFolderCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
}
uint32_t maxReadCount, readCount, writeCount;
uint32_t bytesWritten;
-
+
while (NS_SUCCEEDED(rv) && (int32_t) count > 0)
{
maxReadCount = count > sizeof(m_dataBuffer) - 1 ? sizeof(m_dataBuffer) - 1 : count;
writeCount = 0;
rv = inStr->Read(m_dataBuffer, maxReadCount, &readCount);
-
+
// if status offset is past the number of bytes we read, it's probably bogus,
// and we shouldn't do any of the keyword stuff.
if (statusOffset + X_MOZILLA_STATUS_LEN > readCount)
checkForKeyword = false;
-
+
if (NS_SUCCEEDED(rv))
{
if (checkForKeyword)
@@ -967,7 +970,7 @@ nsFolderCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
{
NS_ASSERTION(false, "bad block offset");
// not sure what to do to handle this.
-
+
}
m_fileStream->Write(m_dataBuffer + blockOffset, readCount - blockOffset, &bytesWritten);
writeCount += bytesWritten;
@@ -1131,7 +1134,6 @@ done:
}
return rv;
}
-
nsresult
nsOfflineStoreCompactState::FinishCompact()
@@ -1226,6 +1228,10 @@ nsFolderCompactState::EndCopy(nsISupports *url, nsresult aStatus)
return NS_OK;
}
+ /* Messages need to have trailing blank lines */
+ uint32_t bytesWritten;
+ (void) m_fileStream->Write(MSG_LINEBREAK, MSG_LINEBREAK_LEN, &bytesWritten);
+
/**
* Done with the current message; copying the existing message header
* to the new database.
@@ -1255,7 +1261,7 @@ nsFolderCompactState::EndCopy(nsISupports *url, nsresult aStatus)
msgSize += m_addedHeaderSize;
newMsgHdr->SetMessageSize(msgSize);
}
- m_totalMsgSize += msgSize;
+ m_totalMsgSize += msgSize + MSG_LINEBREAK_LEN;
}
// m_db->Commit(nsMsgDBCommitType::kLargeCommit); // no sense commiting until the end
@@ -1345,4 +1351,3 @@ nsOfflineStoreCompactState::OnDataAvailable(nsIRequest *request, nsISupports *ct
}
return rv;
}
-