mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-25 17:43:44 +00:00
Make EscapeFromSpaceLine use an outputstream instead of filespec (#323211).
r+sr=bienvenu
This commit is contained in:
parent
d807f17350
commit
1b4ea33146
@ -76,6 +76,7 @@
|
||||
#include "nsIRssIncomingServer.h"
|
||||
#include "nsIMsgFolder.h"
|
||||
#include "nsIMsgMessageService.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
|
||||
static NS_DEFINE_CID(kCMailboxUrl, NS_MAILBOXURL_CID);
|
||||
@ -667,11 +668,11 @@ PRBool IsAFromSpaceLine(char *start, const char *end)
|
||||
// with one or more '>' (ie, ">From", ">>From", etc) in the input buffer
|
||||
// (between 'start' and 'end') and prefix them with a ">" .
|
||||
//
|
||||
nsresult EscapeFromSpaceLine(nsIFileSpec *pDst, char *start, const char *end)
|
||||
nsresult EscapeFromSpaceLine(nsIOutputStream *outputStream, char *start, const char *end)
|
||||
{
|
||||
nsresult rv;
|
||||
char *pChar;
|
||||
PRInt32 written;
|
||||
PRUint32 written;
|
||||
|
||||
pChar = start;
|
||||
while (start < end)
|
||||
@ -683,9 +684,9 @@ nsresult EscapeFromSpaceLine(nsIFileSpec *pDst, char *start, const char *end)
|
||||
{
|
||||
// Found a line so check if it's a qualified "From " line.
|
||||
if (IsAFromSpaceLine(start, pChar))
|
||||
rv = pDst->Write(">", 1, &written);
|
||||
rv = outputStream->Write(">", 1, &written);
|
||||
PRInt32 lineTerminatorCount = (*(pChar + 1) == nsCRT::LF) ? 2 : 1;
|
||||
rv = pDst->Write(start, pChar - start + lineTerminatorCount, &written);
|
||||
rv = outputStream->Write(start, pChar - start + lineTerminatorCount, &written);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
pChar += lineTerminatorCount;
|
||||
start = pChar;
|
||||
@ -694,8 +695,8 @@ nsresult EscapeFromSpaceLine(nsIFileSpec *pDst, char *start, const char *end)
|
||||
{
|
||||
// Check and flush out the remaining data and we're done.
|
||||
if (IsAFromSpaceLine(start, end))
|
||||
rv = pDst->Write(">", 1, &written);
|
||||
rv = pDst->Write(start, end-start, &written);
|
||||
rv = outputStream->Write(">", 1, &written);
|
||||
rv = outputStream->Write(start, end-start, &written);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
break;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ class nsIPrefBranch;
|
||||
class nsIMsgFolder;
|
||||
class nsIMsgMessageService;
|
||||
class nsIUrlListener;
|
||||
class nsIOutputStream;
|
||||
|
||||
//These are utility functions that can used throughout the mailnews code
|
||||
|
||||
@ -92,7 +93,7 @@ NS_MSG_BASE PRBool WeAreOffline();
|
||||
NS_MSG_BASE nsresult GetExistingFolder(const char *aFolderURI, nsIMsgFolder **aFolder);
|
||||
|
||||
// Escape lines starting with "From ", ">From ", etc. in a buffer.
|
||||
NS_MSG_BASE nsresult EscapeFromSpaceLine(nsIFileSpec *pDst, char *start, const char *end);
|
||||
NS_MSG_BASE nsresult EscapeFromSpaceLine(nsIOutputStream *ouputStream, char *start, const char *end);
|
||||
NS_MSG_BASE PRBool IsAFromSpaceLine(char *start, const char *end);
|
||||
|
||||
NS_MSG_BASE nsresult NS_GetPersistentFile(const char *relPrefName,
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "nsIURI.h"
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
@ -968,8 +969,10 @@ nsresult nsEudoraCompose::CopyComposedMessage( nsCString& fromLine, nsIFileSpec
|
||||
// so that the following will properly copy the rest of the body
|
||||
char lastChar = 0;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outStream;
|
||||
pDst->GetOutputStream (getter_AddRefs (outStream));
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
rv = EscapeFromSpaceLine(pDst, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
rv = EscapeFromSpaceLine(outStream, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
if (copy.m_bytesInBuf)
|
||||
lastChar = copy.m_pBuffer[copy.m_bytesInBuf - 1];
|
||||
if (NS_SUCCEEDED(rv))
|
||||
@ -979,7 +982,7 @@ nsresult nsEudoraCompose::CopyComposedMessage( nsCString& fromLine, nsIFileSpec
|
||||
while ((state.offset < state.size) && NS_SUCCEEDED( rv)) {
|
||||
rv = FillMailBuffer( &state, copy);
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
rv = EscapeFromSpaceLine(pDst, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
rv = EscapeFromSpaceLine(outStream, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
lastChar = copy.m_pBuffer[copy.m_bytesInBuf - 1];
|
||||
if (NS_SUCCEEDED( rv))
|
||||
copy.m_writeOffset = copy.m_bytesInBuf;
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "msgCore.h"
|
||||
#include "prprf.h"
|
||||
#include "nsMsgLocalFolderHdrs.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
|
||||
#define kIndexGrowBy 100
|
||||
@ -361,7 +362,9 @@ nsresult nsOE5File::ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsStrin
|
||||
}
|
||||
|
||||
// Now process the block of data which ends with CRLF.
|
||||
rv = EscapeFromSpaceLine(pDestination, pStart, partialLineStart);
|
||||
nsCOMPtr<nsIOutputStream> outStream;
|
||||
pDestination->GetOutputStream (getter_AddRefs (outStream));
|
||||
rv = EscapeFromSpaceLine(outStream, pStart, partialLineStart);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
@ -372,7 +375,7 @@ nsresult nsOE5File::ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsStrin
|
||||
{
|
||||
// OK, we're done so flush out the partial line if it's not empty.
|
||||
if (partialLine.Length())
|
||||
rv = EscapeFromSpaceLine(pDestination, (char *)partialLine.get(), (partialLine.get()+partialLine.Length()));
|
||||
rv = EscapeFromSpaceLine(outStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length()));
|
||||
}
|
||||
else
|
||||
if (ReadBytes(inFile, block, next, 16) && (block[0] == next) &&
|
||||
@ -392,7 +395,7 @@ nsresult nsOE5File::ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsStrin
|
||||
pStart += 2; // .. then copy that too.
|
||||
tempLine.Assign(pBuffer, pStart - pBuffer);
|
||||
partialLine.Append(tempLine);
|
||||
rv = EscapeFromSpaceLine(pDestination, (char *)partialLine.get(), (partialLine.get()+partialLine.Length()));
|
||||
rv = EscapeFromSpaceLine(outStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length()));
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsMsgI18N.h"
|
||||
#include "nsNativeCharsetUtils.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
@ -910,8 +911,10 @@ nsresult nsOutlookCompose::CopyComposedMessage( nsCString& fromLine, nsIFileSpec
|
||||
// so that the following will properly copy the rest of the body
|
||||
char lastChar = 0;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outStream;
|
||||
pDst->GetOutputStream (getter_AddRefs (outStream));
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
rv = EscapeFromSpaceLine(pDst, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
rv = EscapeFromSpaceLine(outStream, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
if (copy.m_bytesInBuf)
|
||||
lastChar = copy.m_pBuffer[copy.m_bytesInBuf - 1];
|
||||
if (NS_SUCCEEDED(rv))
|
||||
@ -921,7 +924,7 @@ nsresult nsOutlookCompose::CopyComposedMessage( nsCString& fromLine, nsIFileSpec
|
||||
while ((state.offset < state.size) && NS_SUCCEEDED( rv)) {
|
||||
rv = FillMailBuffer( &state, copy);
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
rv = EscapeFromSpaceLine(pDst, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
rv = EscapeFromSpaceLine(outStream, copy.m_pBuffer + copy.m_writeOffset, copy.m_pBuffer+copy.m_bytesInBuf);
|
||||
lastChar = copy.m_pBuffer[copy.m_bytesInBuf - 1];
|
||||
if (NS_SUCCEEDED( rv))
|
||||
copy.m_writeOffset = copy.m_bytesInBuf;
|
||||
|
@ -59,6 +59,7 @@
|
||||
#include "nsOutlookMail.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsMsgUtils.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
static NS_DEFINE_CID(kImportMimeEncodeCID, NS_IMPORTMIMEENCODE_CID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
@ -585,12 +586,15 @@ BOOL nsOutlookMail::WriteMessage( nsIFileSpec *pDest, CMapiMessage *pMsg, int& a
|
||||
checkStart = TRUE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outStream;
|
||||
pDest->GetOutputStream (getter_AddRefs (outStream));
|
||||
|
||||
pData = pMsg->GetHeaders( len);
|
||||
if (pData && len) {
|
||||
if (checkStart)
|
||||
bResult = (EscapeFromSpaceLine(pDest, (char *)pData, pData+len) == NS_OK);
|
||||
bResult = (EscapeFromSpaceLine(outStream, (char *)pData, pData+len) == NS_OK);
|
||||
else
|
||||
bResult = (EscapeFromSpaceLine(pDest, (char *)(pData+1), pData+len-1) == NS_OK);
|
||||
bResult = (EscapeFromSpaceLine(outStream, (char *)(pData+1), pData+len-1) == NS_OK);
|
||||
}
|
||||
|
||||
// Do we need to add any mime headers???
|
||||
@ -642,7 +646,7 @@ BOOL nsOutlookMail::WriteMessage( nsIFileSpec *pDest, CMapiMessage *pMsg, int& a
|
||||
pData = pMsg->GetBody( len);
|
||||
if (pData && len) {
|
||||
if (bResult)
|
||||
bResult = (EscapeFromSpaceLine(pDest, (char *)pData, pData+len) == NS_OK);
|
||||
bResult = (EscapeFromSpaceLine(outStream, (char *)pData, pData+len) == NS_OK);
|
||||
if ((len < 2) || (pData[len - 1] != 0x0A) || (pData[len - 2] != 0x0D))
|
||||
bResult = WriteStr( pDest, "\x0D\x0A");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user