summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-09-10 15:08:21 +0200
committerStephan Bergmann <sbergman@redhat.com>2015-09-10 23:04:34 +0200
commit4464e5dbca7cab6ec91d19914eddd934cb354aa7 (patch)
tree5777fd95f29f299f6c0f41e038017d6038969cf9 /tools
parent8cb1f9ac1ce90b324307711f752591a1acc9a6df (diff)
No need for INetMIMEMessageStream encoding
...in the only use case in ODatabaseForm Change-Id: I0282a9f60b05f279a11dcf1990e68b7e017ea3aa
Diffstat (limited to 'tools')
-rw-r--r--tools/source/inet/inetstrm.cxx535
1 files changed, 4 insertions, 531 deletions
diff --git a/tools/source/inet/inetstrm.cxx b/tools/source/inet/inetstrm.cxx
index 053b649c576e..a3c76e754559 100644
--- a/tools/source/inet/inetstrm.cxx
+++ b/tools/source/inet/inetstrm.cxx
@@ -26,55 +26,6 @@
#include <ctype.h>
-/** Quoted-Printable Encoding */
-class INetMessageEncodeQPStream_Impl : public INetMessageIStream
-{
- SvStream* pMsgStrm;
-
- sal_uIntPtr nMsgBufSiz;
- sal_Char* pMsgBuffer;
- sal_Char* pMsgRead;
- sal_Char* pMsgWrite;
-
- sal_uIntPtr nTokBufSiz;
- sal_Char* pTokBuffer;
- sal_Char* pTokRead;
- sal_Char* pTokWrite;
-
- INetMessageStreamState eState;
- bool bDone;
-
- virtual int GetMsgLine(sal_Char* pData, sal_uIntPtr nSize) SAL_OVERRIDE;
-
-public:
- explicit INetMessageEncodeQPStream_Impl(sal_uIntPtr nMsgBufferSize = 1024);
- virtual ~INetMessageEncodeQPStream_Impl();
-};
-
-/** Base64 Encoding */
-class INetMessageEncode64Stream_Impl : public INetMessageIStream
-{
- SvStream* pMsgStrm;
-
- sal_uIntPtr nMsgBufSiz;
- sal_uInt8* pMsgBuffer;
- sal_uInt8* pMsgRead;
- sal_uInt8* pMsgWrite;
-
- sal_uIntPtr nTokBufSiz;
- sal_Char* pTokBuffer;
- sal_Char* pTokRead;
- sal_Char* pTokWrite;
-
- bool bDone;
-
- virtual int GetMsgLine(sal_Char* pData, sal_uIntPtr nSize) SAL_OVERRIDE;
-
-public:
- explicit INetMessageEncode64Stream_Impl(sal_uIntPtr nMsgBufferSize = 2048);
- virtual ~INetMessageEncode64Stream_Impl();
-};
-
// INetMessageIStream
INetMessageIStream::INetMessageIStream(sal_uIntPtr nBufferSize)
@@ -207,364 +158,6 @@ int INetMessageIStream::GetMsgLine(sal_Char* pData, sal_uIntPtr nSize)
return (pWBuf - pData);
}
-// INetMessageEncodeQPStream_Impl
-
-static const sal_Char hex2pr[16] = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'A', 'B', 'C', 'D', 'E', 'F'
-};
-
-INetMessageEncodeQPStream_Impl::INetMessageEncodeQPStream_Impl( sal_uIntPtr nMsgBufferSize)
- : INetMessageIStream (),
- pMsgStrm (NULL),
- nMsgBufSiz (nMsgBufferSize),
- nTokBufSiz (80),
- eState (INETMSG_EOL_SCR),
- bDone (false)
-{
- SetHeaderGenerated();
-
- pMsgBuffer = new sal_Char[nMsgBufSiz];
- pMsgRead = pMsgWrite = pMsgBuffer;
-
- pTokBuffer = new sal_Char[nTokBufSiz];
- pTokRead = pTokWrite = pTokBuffer;
-}
-
-INetMessageEncodeQPStream_Impl::~INetMessageEncodeQPStream_Impl()
-{
- delete pMsgStrm;
- delete [] pMsgBuffer;
- delete [] pTokBuffer;
-}
-
-int INetMessageEncodeQPStream_Impl::GetMsgLine(sal_Char* pData, sal_uIntPtr nSize)
-{
- INetMIMEMessage* pMsg = GetSourceMessage();
- if (pMsg == NULL) return INETSTREAM_STATUS_ERROR;
-
- if (pMsg->GetDocumentLB() == NULL) return 0;
- if (pMsgStrm == NULL) pMsgStrm = new SvStream(pMsg->GetDocumentLB());
-
- sal_Char* pWBuf = pData;
- while (pWBuf < (pData + nSize))
- {
- // Caller's buffer not yet filled.
- if ((pMsgRead - pMsgWrite) > 0)
- {
- // Bytes still in message buffer.
- if ((eState != INETMSG_EOL_BEGIN) &&
- ((pTokRead - pTokBuffer) < 72))
- {
- // Token buffer not yet filled.
- if (eState == INETMSG_EOL_FCR)
- {
- eState = INETMSG_EOL_BEGIN;
- if (*pMsgWrite != '\n')
- {
- // Convert orphant <CR> into <CR><LF> sequence.
- *pTokRead++ = '\n';
- }
- *pTokRead++ = *pMsgWrite++;
- }
- else if ((*pMsgWrite == ' ') || (*pMsgWrite == '\t'))
- {
- eState = INETMSG_EOL_FSP;
- *pTokRead++ = *pMsgWrite++;
- }
- else if (*pMsgWrite == '\r')
- {
- // Found <CR>.
- if (eState == INETMSG_EOL_FSP)
- {
- // Encode last (trailing space) character.
- sal_uInt8 c = (sal_uInt8)(*(--pTokRead));
- *pTokRead++ = '=';
- *pTokRead++ = hex2pr[((c & 0xf0) >> 4)];
- *pTokRead++ = hex2pr[((c & 0x0f) )];
- }
- eState = INETMSG_EOL_FCR;
- *pTokRead++ = *pMsgWrite++;
- }
- else if (*pMsgWrite == '\n')
- {
- // Found <LF> only.
- if (eState == INETMSG_EOL_FSP)
- {
- // Encode last (trailing space) character.
- sal_uInt8 c = (sal_uInt8)(*(--pTokRead));
- *pTokRead++ = '=';
- *pTokRead++ = hex2pr[((c & 0xf0) >> 4)];
- *pTokRead++ = hex2pr[((c & 0x0f) )];
- }
- eState = INETMSG_EOL_BEGIN;
-
- // Convert orphant <LF> into <CR><LF> sequence.
- *pTokRead++ = '\r';
- *pTokRead++ = *pMsgWrite++;
- }
- else if (*pMsgWrite == '=')
- {
- // Escape character itself MUST be encoded, of course.
- sal_uInt8 c = (sal_uInt8)(*pMsgWrite++);
- *pTokRead++ = '=';
- *pTokRead++ = hex2pr[((c & 0xf0) >> 4)];
- *pTokRead++ = hex2pr[((c & 0x0f) )];
-
- eState = INETMSG_EOL_SCR;
- }
- else if (((sal_uInt8)(*pMsgWrite) > 0x20) &&
- ((sal_uInt8)(*pMsgWrite) < 0x7f) )
- {
- /*
- * Some printable ASCII character.
- * (Encode EBCDIC special characters (NYI)).
- */
- *pTokRead++ = *pMsgWrite++;
- eState = INETMSG_EOL_SCR;
- }
- else
- {
- // Encode any other character.
- sal_uInt8 c = (sal_uInt8)(*pMsgWrite++);
- *pTokRead++ = '=';
- *pTokRead++ = hex2pr[((c & 0xf0) >> 4)];
- *pTokRead++ = hex2pr[((c & 0x0f) )];
-
- eState = INETMSG_EOL_SCR;
- }
- }
- else
- {
- // Check for maximum line length.
- if (eState != INETMSG_EOL_BEGIN)
- {
- // Insert soft line break.
- *pTokRead++ = '=';
- *pTokRead++ = '\r';
- *pTokRead++ = '\n';
-
- eState = INETMSG_EOL_BEGIN;
- }
-
- // Copy to caller's buffer.
- if ((pTokRead - pTokWrite) > 0)
- {
- // Bytes still in token buffer.
- *pWBuf++ = *pTokWrite++;
- }
- else
- {
- // Token buffer empty. Reset to <Begin-of-Buffer>.
- pTokRead = pTokWrite = pTokBuffer;
- eState = INETMSG_EOL_SCR;
- }
- }
- }
- else
- {
- // Message buffer empty. Reset to <Begin-of-Buffer>.
- pMsgRead = pMsgWrite = pMsgBuffer;
-
- // Read next message block.
- sal_uIntPtr nRead = pMsgStrm->Read(pMsgBuffer, nMsgBufSiz);
- if (nRead > 0)
- {
- // Set read pointer.
- pMsgRead = (pMsgBuffer + nRead);
- }
- else
- {
- // Nothing more ro read.
- if (!bDone)
- {
- // Append final <CR><LF> and mark we're done.
- *pTokRead++ = '\r';
- *pTokRead++ = '\n';
-
- bDone = true;
- }
- else
- {
- // Already done all encoding.
- if ((pTokRead - pTokWrite) > 0)
- {
- // Bytes still in token buffer.
- *pWBuf++ = *pTokWrite++;
- }
- else
- {
- // Token buffer empty. Reset to <Begin-of-Buffer>.
- pTokRead = pTokWrite = pTokBuffer;
-
- // Return.
- return (pWBuf - pData);
- }
- }
- }
- }
- }
- return (pWBuf - pData);
-}
-
-// INetMessageEncode64Stream_Impl
-
-static const sal_Char six2pr[64] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
-};
-
-INetMessageEncode64Stream_Impl::INetMessageEncode64Stream_Impl(
- sal_uIntPtr nMsgBufferSize)
- : INetMessageIStream(),
- pMsgStrm (NULL),
- nMsgBufSiz (nMsgBufferSize),
- nTokBufSiz (80),
- bDone (false)
-{
- SetHeaderGenerated();
-
- pMsgBuffer = new sal_uInt8[nMsgBufSiz];
- pMsgRead = pMsgWrite = pMsgBuffer;
-
- pTokBuffer = new sal_Char[nTokBufSiz];
- pTokRead = pTokWrite = pTokBuffer;
-}
-
-INetMessageEncode64Stream_Impl::~INetMessageEncode64Stream_Impl()
-{
- delete pMsgStrm;
- delete [] pMsgBuffer;
- delete [] pTokBuffer;
-}
-
-int INetMessageEncode64Stream_Impl::GetMsgLine(sal_Char* pData, sal_uIntPtr nSize)
-{
- INetMIMEMessage* pMsg = GetSourceMessage();
- if (pMsg == NULL) return INETSTREAM_STATUS_ERROR;
-
- if (pMsg->GetDocumentLB() == NULL) return 0;
- if (pMsgStrm == NULL) pMsgStrm = new SvStream(pMsg->GetDocumentLB());
-
- sal_Char* pWBuf = pData;
- while (pWBuf < (pData + nSize))
- {
- // Caller's buffer not yet filled.
- if ((pMsgRead - pMsgWrite) > 0)
- {
- // Bytes still in message buffer.
- if ((pTokRead - pTokBuffer) < 72)
- {
- // Token buffer not yet filled.
- switch ((pTokRead - pTokBuffer) % 4)
- {
- case 0:
- *pTokRead++ = six2pr[(int)(*pMsgWrite >> 2)];
- break;
-
- case 1:
- *pTokRead++ = six2pr[ (int)(((*pMsgWrite << 4) & 060) |
- (((*(pMsgWrite + 1)) >> 4) & 017))];
- pMsgWrite++;
- break;
-
- case 2:
- *pTokRead++ = six2pr[ (int)(((*pMsgWrite << 2) & 074) |
- (((*(pMsgWrite + 1)) >> 6) & 003))];
- pMsgWrite++;
- break;
-
- default: // == case 3
- *pTokRead++ = six2pr[(int)(*pMsgWrite & 077)];
- pMsgWrite++;
- break;
- }
- }
- else if ((pTokRead - pTokBuffer) == 72)
- {
- // Maximum line length. Append <CR><LF>.
- *pTokRead++ = '\r';
- *pTokRead++ = '\n';
- }
- else
- {
- if ((pTokRead - pTokWrite) > 0)
- {
- // Bytes still in token buffer.
- *pWBuf++ = *pTokWrite++;
- }
- else
- {
- // Token buffer empty. Reset to <Begin-of-Buffer>.
- pTokRead = pTokWrite = pTokBuffer;
- }
- }
- }
- else
- {
- // Message buffer empty. Reset to <Begin-of-Buffer>.
- pMsgRead = pMsgWrite = pMsgBuffer;
-
- // Read next message block.
- sal_uIntPtr nRead = pMsgStrm->Read(pMsgBuffer, nMsgBufSiz);
- if (nRead > 0)
- {
- // Set read pointer.
- pMsgRead = (pMsgBuffer + nRead);
- }
- else
- {
- // Nothing more to read.
- if (!bDone)
- {
- // Append pad character(s) and final <CR><LF>.
- switch ((pTokRead - pTokBuffer) % 4)
- {
- case 2:
- *pTokRead++ = '=';
- // Fall through for 2nd pad character.
- case 3:
- *pTokRead++ = '=';
- break;
-
- default:
- break;
- }
- *pTokRead++ = '\r';
- *pTokRead++ = '\n';
-
- // Mark we're done.
- bDone = true;
- }
- else
- {
- // Already done all encoding.
- if ((pTokRead - pTokWrite) > 0)
- {
- // Bytes still in token buffer.
- *pWBuf++ = *pTokWrite++;
- }
- else
- {
- // Token buffer empty. Reset to <Begin-of-Buffer>.
- pTokRead = pTokWrite = pTokBuffer;
-
- // Reset done flag, if everything has been done.
- // if (pWBuf == pData) bDone = false;
-
- // Return.
- return (pWBuf - pData);
- }
- }
- }
- }
- } // while (pWBuf < (pData + nSize))
- return (pWBuf - pData);
-}
-
// INetMIMEMessageStream
INetMIMEMessageStream::INetMIMEMessageStream(sal_uIntPtr nBufferSize)
@@ -572,8 +165,6 @@ INetMIMEMessageStream::INetMIMEMessageStream(sal_uIntPtr nBufferSize)
eState (INETMSG_EOL_BEGIN),
nChildIndex (0),
pChildStrm (NULL),
- eEncoding (INETMSG_ENCODING_BINARY),
- pEncodeStrm (NULL),
pMsgBuffer (NULL)
{
}
@@ -581,43 +172,9 @@ INetMIMEMessageStream::INetMIMEMessageStream(sal_uIntPtr nBufferSize)
INetMIMEMessageStream::~INetMIMEMessageStream()
{
delete pChildStrm;
- delete pEncodeStrm;
delete pMsgBuffer;
}
-INetMessageEncoding
-INetMIMEMessageStream::GetMsgEncoding(const OUString& rContentType)
-{
- if (rContentType.startsWithIgnoreAsciiCase("message") ||
- rContentType.startsWithIgnoreAsciiCase("multipart"))
- {
- return INETMSG_ENCODING_7BIT;
- }
- if (rContentType.startsWithIgnoreAsciiCase("text"))
- {
- if (rContentType.startsWithIgnoreAsciiCase("text/plain"))
- {
- if (comphelper::string::getTokenCount(rContentType, '=') > 1)
- {
- OUString aCharset(rContentType.getToken(1, '='));
- aCharset = comphelper::string::stripStart(aCharset, ' ');
- aCharset = comphelper::string::stripStart(aCharset, '"');
-
- if (aCharset.startsWithIgnoreAsciiCase("us-ascii"))
- return INETMSG_ENCODING_7BIT;
- else
- return INETMSG_ENCODING_QUOTED;
- }
- else
- return INETMSG_ENCODING_7BIT;
- }
- else
- return INETMSG_ENCODING_QUOTED;
- }
-
- return INETMSG_ENCODING_BASE64;
-}
-
/// Message Generator
int INetMIMEMessageStream::GetMsgLine(sal_Char* pData, sal_uIntPtr nSize)
{
@@ -658,51 +215,8 @@ int INetMIMEMessageStream::GetMsgLine(sal_Char* pData, sal_uIntPtr nSize)
}
}
- // Check Encoding.
- OUString aEncoding(pMsg->GetContentTransferEncoding());
- if (!aEncoding.isEmpty())
- {
- // Use given Encoding.
- if (aEncoding.startsWithIgnoreAsciiCase("base64"))
- {
- eEncoding = INETMSG_ENCODING_BASE64;
- }
- else if (aEncoding.startsWithIgnoreAsciiCase("quoted-printable"))
- {
- eEncoding = INETMSG_ENCODING_QUOTED;
- }
- else
- {
- eEncoding = INETMSG_ENCODING_7BIT;
- }
- }
- else
- {
- // Use default Encoding for (given|default) Content-Type.
- if (aContentType.isEmpty())
- {
- // Determine default Content-Type.
- aContentType = pMsg->GetDefaultContentType();
- }
- eEncoding = GetMsgEncoding(aContentType);
- }
-
- // Set Content-Transfer-Encoding header.
- if (eEncoding == INETMSG_ENCODING_BASE64)
- {
- // Base64.
- pMsg->SetContentTransferEncoding("base64");
- }
- else if (eEncoding == INETMSG_ENCODING_QUOTED)
- {
- // Quoted-Printable.
- pMsg->SetContentTransferEncoding("quoted-printable");
- }
- else
- {
- // No need to specify default.
- pMsg->SetContentTransferEncoding(OUString());
- }
+ // No need to specify default.
+ pMsg->SetContentTransferEncoding(OUString());
// Mark we're done.
eState = INETMSG_EOL_DONE;
@@ -795,49 +309,8 @@ int INetMIMEMessageStream::GetMsgLine(sal_Char* pData, sal_uIntPtr nSize)
return 0;
}
- // Check whether message body needs to be encoded.
- if (eEncoding == INETMSG_ENCODING_7BIT)
- {
- // No Encoding.
- return INetMessageIStream::GetMsgLine(pData, nSize);
- }
-
- // Apply appropriate Encoding.
- while (eState == INETMSG_EOL_BEGIN)
- {
- if (pEncodeStrm == NULL)
- {
- // Create encoder stream.
- if (eEncoding == INETMSG_ENCODING_QUOTED)
- {
- // Quoted-Printable Encoding.
- pEncodeStrm = new INetMessageEncodeQPStream_Impl;
- }
- else
- {
- // Base64 Encoding.
- pEncodeStrm = new INetMessageEncode64Stream_Impl;
- }
- pEncodeStrm->SetSourceMessage(pMsg);
- }
-
- // Read encoded message.
- int nRead = pEncodeStrm->Read(pData, nSize);
- if (nRead > 0)
- {
- return nRead;
- }
- else
- {
- // Cleanup exhausted encoder stream.
- delete pEncodeStrm;
- pEncodeStrm = NULL;
-
- // Mark we're done.
- eState = INETMSG_EOL_DONE;
- }
- }
- return 0;
+ // No Encoding.
+ return INetMessageIStream::GetMsgLine(pData, nSize);
}
}
}