diff options
-rw-r--r-- | include/tools/inetmime.hxx | 99 | ||||
-rw-r--r-- | include/tools/inetmsg.hxx | 8 | ||||
-rw-r--r-- | tools/qa/cppunit/test_inetmime.cxx | 3 | ||||
-rw-r--r-- | tools/source/inet/inetmime.cxx | 743 | ||||
-rw-r--r-- | tools/source/inet/inetmsg.cxx | 7 |
5 files changed, 18 insertions, 842 deletions
diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx index a61956b0fe26..6746962b85a0 100644 --- a/include/tools/inetmime.hxx +++ b/include/tools/inetmime.hxx @@ -88,101 +88,6 @@ typedef std::unordered_map<OString, INetContentTypeParameter, OStringHash> class TOOLS_DLLPUBLIC INetMIME { public: - /** The various types of message header field bodies, with respect to - encoding and decoding them. - - @descr At the moment, five different types of header fields suffice - to describe how to encoded and decode any known message header field - body, but need for more types may arise in the future as new header - fields are introduced. - - @descr The following is an exhaustive list of all the header fields - currently known to our implementation. For every header field, it - includes a 'canonic' (with regard to capitalization) name, a grammar - rule for the body (using RFC 822 and RFC 2234 conventions), a list of - relevant sources of information, and the HeaderFieldType value to use - with that header field. The list is based on RFC 2076 and draft- - palme-mailext-headers-02.txt (see also <http://www.dsv.su.se/~jpalme/ - ietf/jp-ietf-home.html#anchor1003783>). - - Approved: address ;RFC 1036; HEADER_FIELD_ADDRESS - bcc: #address ;RFCs 822, 2047; HEADER_FIELD_ADDRESS - cc: 1#address ;RFCs 822, 2047; HEADER_FIELD_ADDRESS - Comments: *text ;RFCs 822, RFC 2047; HEADER_FIELD_TEXT - Content-Base: absoluteURI ;RFC 2110; HEADER_FIELD_TEXT - Content-Description: *text ;RFC 2045, RFC 2047; HEADER_FIELD_TEXT - Content-Disposition: disposition-type *(";" disposition-parm) - ;RFC 1806; HEADER_FIELD_STRUCTURED - Content-ID: msg-id ;RFC 2045, RFC 2047; HEADER_FIELD_MESSAGE_ID - Content-Location: absoluteURI / relativeURI ;RFC 2110; - HEADER_FIELD_TEXT - Content-Transfer-Encoding: mechanism ;RFC 2045, RFC 2047; - HEADER_FIELD_STRUCTURED - Content-Type: type "/" subtype *(";" parameter) ;RFC 2045, RFC 2047; - HEADER_FIELD_STRUCTURED - Control: *text ;RFC 1036; HEADER_FIELD_TEXT - Date: date-time ;RFC 822, RFC 1123, RFC 2047; HEADER_FIELD_STRUCTURED - Distribution: 1#atom ;RFC 1036; HEADER_FIELD_STRUCTURED - Encrypted: 1#2word ;RFC 822, RFC 2047; HEADER_FIELD_STRUCTURED - Expires: date-time ;RFC 1036; HEADER_FIELD_STRUCTURED - Followup-To: 1#(atom *("." atom)) ;RFC 1036; HEADER_FIELD_STRUCTURED - From: mailbox / 1#mailbox ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - In-Reply-To: *(phrase / msg-id) ;RFC 822, RFC 2047; - HEADER_FIELD_ADDRESS - Keywords: #phrase ;RFC 822, RFC 2047; HEADER_FIELD_PHRASE - MIME-Version: 1*DIGIT "." 1*DIGIT ;RFC 2045, RFC 2047; - HEADER_FIELD_STRUCTURED - Message-ID: msg-id ;RFC 822, RFC 2047; HEADER_FIELD_MESSAGE_ID - Newsgroups: 1#(atom *("." atom)) ;RFC 1036, RFC 2047; - HEADER_FIELD_STRUCTURED - Organization: *text ;RFC 1036; HEADER_FIELD_TEXT - Received: ["from" domain] ["by" domain] ["via" atom] *("with" atom) - ["id" msg-id] ["for" addr-spec] ";" date-time ;RFC 822, RFC 1123, - RFC 2047; HEADER_FIELD_STRUCTURED - References: *(phrase / msg-id) ;RFC 822, RFC 2047; - HEADER_FIELD_ADDRESS - Reply-To: 1#address ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - Resent-Date: date-time ;RFC 822, RFC 1123, RFC 2047; - HEADER_FIELD_STRUCTURED - Resent-From: mailbox / 1#mailbox ;RFC 822, RFC 2047; - HEADER_FIELD_ADDRESS - Resent-Message-ID: msg-id ;RFC 822, RFC 2047; HEADER_FIELD_MESSAGE_ID - Resent-Reply-To: 1#address ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - Resent-Sender: mailbox ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - Resent-To: 1#address ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - Resent-bcc: #address ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - Resent-cc: 1#address ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - Return-path: route-addr / ("<" ">") ;RFC 822, RFC 1123, RFC 2047; - HEADER_FIELD_STRUCTURED - Return-Receipt-To: address ;Not Internet standard; - HEADER_FIELD_ADDRES - Sender: mailbox ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - Subject: *text ;RFC 822, RFC 2047; HEADER_FIELD_TEXT - Summary: *text ;RFC 1036; HEADER_FIELD_TEXT - To: 1#address ;RFC 822, RFC 2047; HEADER_FIELD_ADDRESS - X-CHAOS-Marked: "YES" / "NO" ;local; HEADER_FIELD_STRUCTURED - X-CHAOS-Read: "YES" / "NO" ;local; HEADER_FIELD_STRUCTURED - X-CHAOS-Recipients: #*("<" atom word ">") ;local; - HEADER_FIELD_STRUCTURED - X-CHAOS-Size: 1*DIGIT ;local; HEADER_FIELD_STRUCTURED - X-Mailer: *text ;Not Internet standard; HEADER_FIELD_TEXT - X-Mozilla-Status: 4HEXDIG ;Mozilla; HEADER_FIELD_STRUCTURED - X-Newsreader: *text ;Not Internet standard; HEADER_FIELD_TEXT - X-Priority: "1" / "2" / "3" / "4" / "5" ;Not Internet standard; - HEADER_FIELD_STRUCTURED - Xref: sub-domain - 1*((atom / string) *("." (atom / string)) ":" msg-number) - ;RFCs 1036, 2047, local; HEADER_FIELD_STRUCTURED - */ - enum HeaderFieldType - { - HEADER_FIELD_TEXT, - HEADER_FIELD_STRUCTURED, - HEADER_FIELD_PHRASE, - HEADER_FIELD_MESSAGE_ID, - HEADER_FIELD_ADDRESS - }; - /** Check for US-ASCII white space character. @param nChar Some UCS-4 character. @@ -436,7 +341,6 @@ public: static void writeUTF8(INetMIMEOutputSink & rSink, sal_uInt32 nChar); static void writeHeaderFieldBody(INetMIMEOutputSink & rSink, - HeaderFieldType eType, const OUString& rBody, rtl_TextEncoding ePreferredEncoding, bool bInitialSpace = true); @@ -446,8 +350,7 @@ public: rtl_TextEncoding eEncoding, sal_uInt32 & rCharacter); - static OUString decodeHeaderFieldBody(HeaderFieldType eType, - const OString& rBody); + static OUString decodeHeaderFieldBody(const OString& rBody); /** Get the UTF-32 character at the head of a UTF-16 encoded string. diff --git a/include/tools/inetmsg.hxx b/include/tools/inetmsg.hxx index fa4d159dd147..2d83469d71d2 100644 --- a/include/tools/inetmsg.hxx +++ b/include/tools/inetmsg.hxx @@ -83,10 +83,10 @@ class TOOLS_DLLPUBLIC INetMIMEMessage OString m_aBoundary; OUString GetHeaderValue_Impl ( - sal_uIntPtr nIndex, INetMIME::HeaderFieldType eType) const + sal_uIntPtr nIndex) const { if ( nIndex < m_aHeaderList.size() ) { - return INetMIME::decodeHeaderFieldBody(eType, m_aHeaderList[ nIndex ]->GetValue()); + return INetMIME::decodeHeaderFieldBody(m_aHeaderList[ nIndex ]->GetValue()); } else { return OUString(); } @@ -109,7 +109,6 @@ class TOOLS_DLLPUBLIC INetMIMEMessage } void SetHeaderField_Impl ( - INetMIME::HeaderFieldType eType, const OString &rName, const OUString &rValue, sal_uIntPtr &rnIndex); @@ -150,8 +149,7 @@ public: OUString GetContentType() const { return GetHeaderValue_Impl( - m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE), - INetMIME::HEADER_FIELD_TEXT); + m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE)); } void SetContentTransferEncoding (const OUString& rEncoding); diff --git a/tools/qa/cppunit/test_inetmime.cxx b/tools/qa/cppunit/test_inetmime.cxx index ee165750ca5a..50973dff8649 100644 --- a/tools/qa/cppunit/test_inetmime.cxx +++ b/tools/qa/cppunit/test_inetmime.cxx @@ -42,8 +42,7 @@ namespace bool Test::testDecode(char const * input, char const * expected) { - OUString result = INetMIME::decodeHeaderFieldBody( - INetMIME::HEADER_FIELD_TEXT, input); + OUString result = INetMIME::decodeHeaderFieldBody(input); return result.equalsAscii(expected); } diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx index 02b8ec233619..47529674245c 100644 --- a/tools/source/inet/inetmime.cxx +++ b/tools/source/inet/inetmime.cxx @@ -1619,692 +1619,18 @@ void INetMIME::writeUTF8(INetMIMEOutputSink & rSink, sal_uInt32 nChar) // static void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink, - HeaderFieldType eType, const OUString& rBody, rtl_TextEncoding ePreferredEncoding, bool bInitialSpace) { - if (eType == HEADER_FIELD_TEXT) - { - INetMIMEEncodedWordOutputSink - aOutput(rSink, INetMIMEEncodedWordOutputSink::CONTEXT_TEXT, - bInitialSpace ? - INetMIMEEncodedWordOutputSink::SPACE_ALWAYS : - INetMIMEEncodedWordOutputSink::SPACE_NO, - ePreferredEncoding); - aOutput.write(rBody.getStr(), rBody.getStr() + rBody.getLength()); - aOutput.flush(); - } - else - { - enum Brackets { BRACKETS_OUTSIDE, BRACKETS_OPENING, BRACKETS_INSIDE }; - Brackets eBrackets = BRACKETS_OUTSIDE; - - const sal_Unicode * pBodyPtr = rBody.getStr(); - const sal_Unicode * pBodyEnd = pBodyPtr + rBody.getLength(); - while (pBodyPtr != pBodyEnd) - switch (*pBodyPtr) - { - case '\t': - case ' ': - // A WSP adds to accumulated space: - bInitialSpace = true; - ++pBodyPtr; - break; - - case '(': - { - // Write a pending '<' if necessary: - if (eBrackets == BRACKETS_OPENING) - { - if (bInitialSpace) - rSink << ' '; - rSink << '<'; - bInitialSpace = false; - eBrackets = BRACKETS_INSIDE; - } - - // Write the comment, introducing encoded-words where - // necessary: - int nLevel = 0; - INetMIMEEncodedWordOutputSink - aOutput( - rSink, - INetMIMEEncodedWordOutputSink::CONTEXT_COMMENT, - INetMIMEEncodedWordOutputSink::SPACE_NO, - ePreferredEncoding); - while (pBodyPtr != pBodyEnd) - switch (*pBodyPtr) - { - case '(': - aOutput.flush(); - if (bInitialSpace) - rSink << ' '; - rSink << '('; - bInitialSpace = false; - ++nLevel; - ++pBodyPtr; - break; - - case ')': - aOutput.flush(); - rSink << ')'; - ++pBodyPtr; - if (--nLevel == 0) - goto comment_done; - break; - - case '\\': - if (++pBodyPtr == pBodyEnd) - break; - default: - aOutput.WriteUInt32( *pBodyPtr++ ); - break; - } - comment_done: - break; - } - - case '<': - // Write an already pending '<' if necessary: - if (eBrackets == BRACKETS_OPENING) - { - if (bInitialSpace) - rSink << ' '; - rSink << '<'; - bInitialSpace = false; - } - - // Remember this '<' as pending, and open a bracketed - // block: - eBrackets = BRACKETS_OPENING; - ++pBodyPtr; - break; - - case '>': - // Write a pending '<' if necessary: - if (eBrackets == BRACKETS_OPENING) - { - if (bInitialSpace) - rSink << ' '; - rSink << '<'; - bInitialSpace = false; - } - - // Write this '>', and close any bracketed block: - if (bInitialSpace) - rSink << ' '; - rSink << '>'; - bInitialSpace = false; - eBrackets = BRACKETS_OUTSIDE; - ++pBodyPtr; - break; - - case ',': - case ':': - case ';': - case '\\': - case ']': - // Write a pending '<' if necessary: - if (eBrackets == BRACKETS_OPENING) - { - if (bInitialSpace) - rSink << ' '; - rSink << '<'; - bInitialSpace = false; - eBrackets = BRACKETS_INSIDE; - } - - // Write this specials: - if (bInitialSpace) - rSink << ' '; - rSink << sal_Char(*pBodyPtr++); - bInitialSpace = false; - break; - - case '\x0D': // CR - // A <CRLF WSP> adds to accumulated space, a <CR> not - // followed by <LF WSP> starts 'junk': - if (startsWithLineFolding(pBodyPtr, pBodyEnd)) - { - bInitialSpace = true; - pBodyPtr += 3; - break; - } - default: - { - // The next token is either one of <"." / "@" / atom / - // quoted-string / domain-literal>, or it's 'junk'; if it - // is not 'junk', it is either a 'phrase' (i.e., it may - // contain encoded-words) or a 'non-phrase' (i.e., it may - // not contain encoded-words): - enum Entity { ENTITY_JUNK, ENTITY_NON_PHRASE, - ENTITY_PHRASE }; - Entity eEntity = ENTITY_JUNK; - switch (*pBodyPtr) - { - case '.': - case '@': - case '[': - // A token of <"." / "@" / domain-literal> always - // starts a 'non-phrase': - eEntity = ENTITY_NON_PHRASE; - break; - - default: - if (rtl::isAscii(*pBodyPtr) - && !isAtomChar(*pBodyPtr)) - { - eEntity = ENTITY_JUNK; - break; - } - case '"': - // A token of <atom / quoted-string> can either be - // a 'phrase' or a 'non-phrase': - switch (eType) - { - case HEADER_FIELD_STRUCTURED: - eEntity = ENTITY_NON_PHRASE; - break; - - case HEADER_FIELD_PHRASE: - eEntity = ENTITY_PHRASE; - break; - - case HEADER_FIELD_MESSAGE_ID: - // A 'phrase' if and only if outside any - // bracketed block: - eEntity - = eBrackets == BRACKETS_OUTSIDE ? - ENTITY_PHRASE : - ENTITY_NON_PHRASE; - break; - - case HEADER_FIELD_ADDRESS: - { - // A 'non-phrase' if and only if, after - // skipping this token and any following - // <linear-white-space> and <comment>s, - // there is no token left, or the next - // token is any of <"." / "@" / ">" / "," - // / ";">, or the next token is <":"> and - // is within a bracketed block: - const sal_Unicode * pLookAhead = pBodyPtr; - if (*pLookAhead == '"') - { - pLookAhead - = skipQuotedString(pLookAhead, - pBodyEnd); - if (pLookAhead == pBodyPtr) - pLookAhead = pBodyEnd; - } - else - while (pLookAhead != pBodyEnd - && (isAtomChar(*pLookAhead) - || !rtl::isAscii( - *pLookAhead))) - ++pLookAhead; - while (pLookAhead != pBodyEnd) - switch (*pLookAhead) - { - case '\t': - case ' ': - ++pLookAhead; - break; - - case '(': - { - const sal_Unicode * pPast - = skipComment(pLookAhead, - pBodyEnd); - pLookAhead - = pPast == pLookAhead ? - pBodyEnd : pPast; - break; - } - - case ',': - case '.': - case ';': - case '>': - case '@': - eEntity = ENTITY_NON_PHRASE; - goto entity_determined; - - case ':': - eEntity - = eBrackets - == BRACKETS_OUTSIDE ? - ENTITY_PHRASE : - ENTITY_NON_PHRASE; - goto entity_determined; - - case '\x0D': // CR - if (startsWithLineFolding( - pLookAhead, pBodyEnd)) - { - pLookAhead += 3; - break; - } - default: - eEntity = ENTITY_PHRASE; - goto entity_determined; - } - eEntity = ENTITY_NON_PHRASE; - entity_determined: - break; - } - - case HEADER_FIELD_TEXT: - OSL_ASSERT(false); - break; - } - - // In a 'non-phrase', a non-US-ASCII character - // cannot be part of an <atom>, but instead the - // whole entity is 'junk' rather than 'non- - // phrase': - if (eEntity == ENTITY_NON_PHRASE - && !rtl::isAscii(*pBodyPtr)) - eEntity = ENTITY_JUNK; - break; - } - - switch (eEntity) - { - case ENTITY_JUNK: - { - // Write a pending '<' if necessary: - if (eBrackets == BRACKETS_OPENING) - { - if (bInitialSpace) - rSink << ' '; - rSink << '<'; - bInitialSpace = false; - eBrackets = BRACKETS_INSIDE; - } - - // Calculate the length of in- and output: - const sal_Unicode * pStart = pBodyPtr; - sal_Size nLength = 0; - bool bModify = false; - bool bEnd = false; - while (pBodyPtr != pBodyEnd && !bEnd) - switch (*pBodyPtr) - { - case '\x0D': // CR - if (startsWithLineFolding(pBodyPtr, - pBodyEnd)) - bEnd = true; - else if (startsWithLineBreak( - pBodyPtr, pBodyEnd)) - { - nLength += 3; - bModify = true; - pBodyPtr += 2; - } - else - { - ++nLength; - ++pBodyPtr; - } - break; - - case '\t': - case ' ': - bEnd = true; - break; - - default: - if (isVisible(*pBodyPtr)) - bEnd = true; - else if (rtl::isAscii(*pBodyPtr)) - { - ++nLength; - ++pBodyPtr; - } - else - { - nLength += getUTF8OctetCount( - *pBodyPtr++); - bModify = true; - } - break; - } - - // Write the output: - if (bInitialSpace) - rSink << ' '; - bInitialSpace = false; - if (bModify) - while (pStart != pBodyPtr) - if (startsWithLineBreak(pStart, pBodyPtr)) - { - rSink << "\x0D\\\x0A"; // CR, '\', LF - pStart += 2; - } - else - writeUTF8(rSink, *pStart++); - else - rSink.write(pStart, pBodyPtr); - break; - } - - case ENTITY_NON_PHRASE: - { - // Calculate the length of in- and output: - const sal_Unicode * pStart = pBodyPtr; - sal_Size nLength = 0; - bool bBracketedBlock = false; - bool bSymbol = *pStart != '.' && *pStart != '@'; - bool bModify = false; - bool bEnd = false; - while (pBodyPtr != pBodyEnd && !bEnd) - switch (*pBodyPtr) - { - case '\t': - case ' ': - case '\x0D': // CR - { - const sal_Unicode * pLookAhead - = skipLinearWhiteSpace(pBodyPtr, - pBodyEnd); - if (pLookAhead < pBodyEnd - && (bSymbol ? - isAtomChar(*pLookAhead) - || *pLookAhead == '"' - || *pLookAhead == '[' : - *pLookAhead == '.' - || *pLookAhead == '@' - || (*pLookAhead == '>' - && eType - >= HEADER_FIELD_MESSAGE_ID - && eBrackets - == BRACKETS_OPENING))) - { - bModify = true; - pBodyPtr = pLookAhead; - } - else - bEnd = true; - break; - } - - case '"': - if (bSymbol) - { - pBodyPtr - = scanQuotedBlock(pBodyPtr, - pBodyEnd, - '"', '"', - nLength, - bModify); - bSymbol = false; - } - else - bEnd = true; - break; - - case '[': - if (bSymbol) - { - pBodyPtr - = scanQuotedBlock(pBodyPtr, - pBodyEnd, - '[', ']', - nLength, - bModify); - bSymbol = false; - } - else - bEnd = true; - break; - - case '.': - case '@': - if (bSymbol) - bEnd = true; - else - { - ++nLength; - bSymbol = true; - ++pBodyPtr; - } - break; - - case '>': - if (eBrackets == BRACKETS_OPENING - && eType - >= HEADER_FIELD_MESSAGE_ID) - { - ++nLength; - bBracketedBlock = true; - ++pBodyPtr; - } - bEnd = true; - break; - - default: - if (isAtomChar(*pBodyPtr) && bSymbol) - { - while (pBodyPtr != pBodyEnd - && isAtomChar(*pBodyPtr)) - { - ++nLength; - ++pBodyPtr; - } - bSymbol = false; - } - else - { - if (!rtl::isAscii(*pBodyPtr)) - bModify = true; - bEnd = true; - } - break; - } - - // Write a pending '<' if necessary: - if (eBrackets == BRACKETS_OPENING - && !bBracketedBlock) - { - if (bInitialSpace) - rSink << ' '; - rSink << '<'; - bInitialSpace = false; - eBrackets = BRACKETS_INSIDE; - } - - // Write the output: - if (bInitialSpace) - rSink << ' '; - bInitialSpace = false; - if (bBracketedBlock) - { - rSink << '<'; - eBrackets = BRACKETS_OUTSIDE; - } - if (bModify) - { - enum Mode { MODE_PLAIN, MODE_QUOTED_STRING, - MODE_DOMAIN_LITERAL }; - Mode eMode = MODE_PLAIN; - while (pStart != pBodyPtr) - switch (*pStart) - { - case '\x0D': // CR - if (startsWithLineFolding( - pStart, pBodyPtr)) - { - if (eMode != MODE_PLAIN) - rSink << sal_Char( - pStart[2]); - pStart += 3; - } - else if (startsWithLineBreak( - pStart, pBodyPtr)) - { - rSink << "\x0D\\\x0A"; - // CR, '\', LF - pStart += 2; - } - else - { - rSink << '\x0D'; // CR - ++pStart; - } - break; - - case '\t': - case ' ': - if (eMode != MODE_PLAIN) - rSink << sal_Char(*pStart); - ++pStart; - break; - - case '"': - if (eMode == MODE_PLAIN) - eMode = MODE_QUOTED_STRING; - else if (eMode - == MODE_QUOTED_STRING) - eMode = MODE_PLAIN; - rSink << '"'; - ++pStart; - break; - - case '[': - if (eMode == MODE_PLAIN) - eMode = MODE_DOMAIN_LITERAL; - rSink << '['; - ++pStart; - break; - - case ']': - if (eMode == MODE_DOMAIN_LITERAL) - eMode = MODE_PLAIN; - rSink << ']'; - ++pStart; - break; - - case '\\': - rSink << '\\'; - if (++pStart < pBodyPtr) - writeUTF8(rSink, *pStart++); - break; - - default: - writeUTF8(rSink, *pStart++); - break; - } - } - else - rSink.write(pStart, pBodyPtr); - break; - } - - case ENTITY_PHRASE: - { - // Write a pending '<' if necessary: - if (eBrackets == BRACKETS_OPENING) - { - if (bInitialSpace) - rSink << ' '; - rSink << '<'; - bInitialSpace = false; - eBrackets = BRACKETS_INSIDE; - } - - // Calculate the length of in- and output: - const sal_Unicode * pStart = pBodyPtr; - bool bQuotedString = false; - bool bEnd = false; - while (pBodyPtr != pBodyEnd && !bEnd) - switch (*pBodyPtr) - { - case '\t': - case ' ': - case '\x0D': // CR - if (bQuotedString) - ++pBodyPtr; - else - { - const sal_Unicode * pLookAhead - = skipLinearWhiteSpace( - pBodyPtr, pBodyEnd); - if (pLookAhead != pBodyEnd - && (isAtomChar(*pLookAhead) - || !rtl::isAscii(*pLookAhead) - || *pLookAhead == '"')) - pBodyPtr = pLookAhead; - else - bEnd = true; - } - break; - - case '"': - bQuotedString = !bQuotedString; - ++pBodyPtr; - break; - - case '\\': - if (bQuotedString) - { - if (++pBodyPtr != pBodyEnd) - ++pBodyPtr; - } - else - bEnd = true; - break; - - default: - if (bQuotedString - || isAtomChar(*pBodyPtr) - || !rtl::isAscii(*pBodyPtr)) - ++pBodyPtr; - else - bEnd = true; - break; - } - - // Write the phrase, introducing encoded-words - // where necessary: - INetMIMEEncodedWordOutputSink - aOutput( - rSink, - INetMIMEEncodedWordOutputSink::CONTEXT_PHRASE, - bInitialSpace ? - INetMIMEEncodedWordOutputSink::SPACE_ALWAYS : - INetMIMEEncodedWordOutputSink::SPACE_ENCODED, - ePreferredEncoding); - while (pStart != pBodyPtr) - switch (*pStart) - { - case '"': - ++pStart; - break; - - case '\\': - if (++pStart != pBodyPtr) - aOutput.WriteUInt32( *pStart++ ); - break; - - case '\x0D': // CR - pStart += 2; - aOutput.WriteUInt32( *pStart++ ); - break; - - default: - aOutput.WriteUInt32( *pStart++ ); - break; - } - bInitialSpace = aOutput.flush(); - break; - } - } - break; - } - } - } + INetMIMEEncodedWordOutputSink + aOutput(rSink, INetMIMEEncodedWordOutputSink::CONTEXT_TEXT, + bInitialSpace ? + INetMIMEEncodedWordOutputSink::SPACE_ALWAYS : + INetMIMEEncodedWordOutputSink::SPACE_NO, + ePreferredEncoding); + aOutput.write(rBody.getStr(), rBody.getStr() + rBody.getLength()); + aOutput.flush(); } // static @@ -2383,8 +1709,7 @@ bool INetMIME::translateUTF8Char(const sal_Char *& rBegin, } // static -OUString INetMIME::decodeHeaderFieldBody(HeaderFieldType eType, - const OString& rBody) +OUString INetMIME::decodeHeaderFieldBody(const OString& rBody) { // Due to a bug in INetCoreRFC822MessageStream::ConvertTo7Bit(), old // versions of StarOffice send mails with header fields where encoded @@ -2661,45 +1986,9 @@ OUString INetMIME::decodeHeaderFieldBody(HeaderFieldType eType, if (bEncodedWord) { appendISO88591(sDecoded, pCopyBegin, pWSPBegin); - if (eType == HEADER_FIELD_TEXT) - sDecoded += OUString( - pUnicodeBuffer, - static_cast< sal_Int32 >(nUnicodeSize)); - else if (nCommentLevel == 0) - { - sEncodedText = OUString(pUnicodeBuffer, nUnicodeSize); - if (!bQuotedEncodedText) - { - const sal_Unicode * pTextPtr = pUnicodeBuffer; - const sal_Unicode * pTextEnd = pTextPtr - + nUnicodeSize; - for (; pTextPtr != pTextEnd; ++pTextPtr) - if (!isEncodedWordTokenChar(*pTextPtr)) - { - bQuotedEncodedText = true; - break; - } - } - } - else - { - const sal_Unicode * pTextPtr = pUnicodeBuffer; - const sal_Unicode * pTextEnd = pTextPtr + nUnicodeSize; - for (; pTextPtr != pTextEnd; ++pTextPtr) - { - switch (*pTextPtr) - { - case '(': - case ')': - case '\\': - case '\x0D': - case '=': - sDecoded += "\\"; - break; - } - sDecoded += OUString(*pTextPtr); - } - } + sDecoded += OUString( + pUnicodeBuffer, + static_cast< sal_Int32 >(nUnicodeSize)); delete[] pUnicodeBuffer; p = q; pCopyBegin = p; @@ -2744,18 +2033,10 @@ OUString INetMIME::decodeHeaderFieldBody(HeaderFieldType eType, switch (*p++) { case '"': - if (eType != HEADER_FIELD_TEXT && nCommentLevel == 0) - { - const sal_Char * pQuotedStringEnd - = skipQuotedString(p - 1, pEnd); - p = pQuotedStringEnd == p - 1 ? pEnd : pQuotedStringEnd; - } /* bStartEncodedWord = true; */ break; case '(': - if (eType != HEADER_FIELD_TEXT) - ++nCommentLevel; /* bStartEncodedWord = true; */ break; diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx index 188dd1a3bc6c..d6ae40b2e14a 100644 --- a/tools/source/inet/inetmsg.cxx +++ b/tools/source/inet/inetmsg.cxx @@ -41,14 +41,13 @@ inline bool ascii_isLetter( sal_Unicode ch ) } void INetMIMEMessage::SetHeaderField_Impl ( - INetMIME::HeaderFieldType eType, const OString &rName, const OUString &rValue, sal_uIntPtr &rnIndex) { INetMIMEOutputSink aSink; INetMIME::writeHeaderFieldBody ( - aSink, eType, rValue, osl_getThreadTextEncoding(), false); + aSink, rValue, osl_getThreadTextEncoding(), false); SetHeaderField_Impl ( INetMessageHeader (rName, aSink.takeBuffer()), rnIndex); } @@ -233,7 +232,6 @@ INetMIMEMessage::~INetMIMEMessage() void INetMIMEMessage::SetMIMEVersion (const OUString& rVersion) { SetHeaderField_Impl ( - INetMIME::HEADER_FIELD_TEXT, ImplINetMIMEMessageHeaderData.at(InetMessageMime::VERSION), rVersion, m_nMIMEIndex[InetMessageMime::VERSION]); } @@ -241,7 +239,6 @@ void INetMIMEMessage::SetMIMEVersion (const OUString& rVersion) void INetMIMEMessage::SetContentDisposition (const OUString& rDisposition) { SetHeaderField_Impl ( - INetMIME::HEADER_FIELD_TEXT, ImplINetMIMEMessageHeaderData.at(InetMessageMime::CONTENT_DISPOSITION), rDisposition, m_nMIMEIndex[InetMessageMime::CONTENT_DISPOSITION]); } @@ -249,7 +246,6 @@ void INetMIMEMessage::SetContentDisposition (const OUString& rDisposition) void INetMIMEMessage::SetContentType (const OUString& rType) { SetHeaderField_Impl ( - INetMIME::HEADER_FIELD_TEXT, ImplINetMIMEMessageHeaderData.at(InetMessageMime::CONTENT_TYPE), rType, m_nMIMEIndex[InetMessageMime::CONTENT_TYPE]); } @@ -258,7 +254,6 @@ void INetMIMEMessage::SetContentTransferEncoding ( const OUString& rEncoding) { SetHeaderField_Impl ( - INetMIME::HEADER_FIELD_TEXT, ImplINetMIMEMessageHeaderData.at(InetMessageMime::CONTENT_TRANSFER_ENCODING), rEncoding, m_nMIMEIndex[InetMessageMime::CONTENT_TRANSFER_ENCODING]); } |