[Libreoffice-commits] core.git: 7 commits - include/tools tools/source

Stephan Bergmann sbergman at redhat.com
Thu Sep 17 07:58:02 PDT 2015


 include/tools/inetmime.hxx     |  115 +-----------
 tools/source/inet/inetmime.cxx |  367 +++++++----------------------------------
 tools/source/inet/inetmsg.cxx  |    2 
 3 files changed, 77 insertions(+), 407 deletions(-)

New commits:
commit 50ea351929e9d3ba7b9b88d772a11286c59a1f66
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Sep 17 16:56:49 2015 +0200

    INetMIMEOutputSink line length limit is unused
    
    Change-Id: Ib9da396d0669bfd89dbbff17821b8303f20d61aa

diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index e0c37c7..a61956b 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -624,12 +624,7 @@ inline sal_Unicode * INetMIME::putUTF32Character(sal_Unicode * pBuffer,
 
 class INetMIMEOutputSink
 {
-public:
-    static sal_uInt32 const NO_LINE_LENGTH_LIMIT = SAL_MAX_UINT32;
-
 private:
-    sal_uInt32 m_nColumn;
-    sal_uInt32 m_nLineLengthLimit;
     OStringBuffer m_aBuffer;
 
     /** Write a sequence of octets.
@@ -664,17 +659,6 @@ private:
                                const sal_Unicode * pEnd);
 
 public:
-    INetMIMEOutputSink():
-        m_nColumn(0), m_nLineLengthLimit(NO_LINE_LENGTH_LIMIT) {}
-
-    /** Get the current column.
-
-        @return  The current column (starting from zero).
-     */
-    sal_uInt32 getColumn() const { return m_nColumn; }
-
-    sal_uInt32 getLineLengthLimit() const { return m_nLineLengthLimit; }
-
     /** Write a sequence of octets.
 
         @descr  The supplied sequence of Unicode characters is interpreted as
@@ -714,7 +698,6 @@ public:
     INetMIMEOutputSink & operator <<(const OString& rOctets)
     {
         writeSequence(rOctets.getStr(), rOctets.getStr() + rOctets.getLength());
-        m_nColumn += rOctets.getLength();
         return *this;
     }
 
@@ -728,22 +711,10 @@ public:
     operator <<(INetMIMEOutputSink & (* pManipulator)(INetMIMEOutputSink &))
     { return pManipulator(*this); }
 
-    /** Write a line end (CR LF).
-     */
-    void writeLineEnd();
-
     OString takeBuffer()
     {
         return m_aBuffer.makeStringAndClear();
     }
-
-    /** A manipulator function that writes a line end (CR LF).
-
-        @param rSink  Some sink.
-
-        @return  The sink rSink.
-     */
-    static inline INetMIMEOutputSink & endl(INetMIMEOutputSink & rSink);
 };
 
 
@@ -751,32 +722,22 @@ inline void INetMIMEOutputSink::write(const sal_Unicode * pBegin,
                                       const sal_Unicode * pEnd)
 {
     writeSequence(pBegin, pEnd);
-    m_nColumn += pEnd - pBegin;
 }
 
 inline INetMIMEOutputSink & INetMIMEOutputSink::operator <<(sal_Char nOctet)
 {
     writeSequence(&nOctet, &nOctet + 1);
-    ++m_nColumn;
     return *this;
 }
 
 inline INetMIMEOutputSink & INetMIMEOutputSink::operator <<(const sal_Char *
                                                                 pOctets)
 {
-    m_nColumn += writeSequence(pOctets);
+    writeSequence(pOctets);
     return *this;
 }
 
 // static
-inline INetMIMEOutputSink & INetMIMEOutputSink::endl(INetMIMEOutputSink &
-                                                         rSink)
-{
-    rSink.writeLineEnd();
-    return rSink;
-}
-
-// static
 inline void INetMIME::writeEscapeSequence(INetMIMEOutputSink & rSink,
                                           sal_uInt32 nChar)
 {
@@ -818,7 +779,6 @@ private:
     Coding m_ePrevCoding;
     rtl_TextEncoding m_ePrevMIMEEncoding;
     Coding m_eCoding;
-    sal_uInt32 m_nQuotedEscaped;
     EncodedWordState m_eEncodedWordState;
 
     inline bool needsEncodedWordEscape(sal_uInt32 nChar) const;
@@ -851,7 +811,6 @@ inline INetMIMEEncodedWordOutputSink::INetMIMEEncodedWordOutputSink(
     m_ePrevCoding(CODING_NONE),
     m_ePrevMIMEEncoding(RTL_TEXTENCODING_DONTKNOW),
     m_eCoding(CODING_NONE),
-    m_nQuotedEscaped(0),
     m_eEncodedWordState(STATE_INITIAL)
 {
     m_nBufferSize = BUFFER_SIZE;
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index dbc693a..a434735 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -1657,10 +1657,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                     // Write a pending '<' if necessary:
                     if (eBrackets == BRACKETS_OPENING)
                     {
-                        if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                                >= rSink.getLineLengthLimit())
-                            rSink << INetMIMEOutputSink::endl << ' ';
-                        else if (bInitialSpace)
+                        if (bInitialSpace)
                             rSink << ' ';
                         rSink << '<';
                         bInitialSpace = false;
@@ -1681,11 +1678,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                         {
                             case '(':
                                 aOutput.flush();
-                                if (rSink.getColumn()
-                                            + (bInitialSpace ? 1 : 0)
-                                        >= rSink.getLineLengthLimit())
-                                    rSink << INetMIMEOutputSink::endl << ' ';
-                                else if (bInitialSpace)
+                                if (bInitialSpace)
                                     rSink << ' ';
                                 rSink << '(';
                                 bInitialSpace = false;
@@ -1695,9 +1688,6 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
 
                             case ')':
                                 aOutput.flush();
-                                if (rSink.getColumn()
-                                        >= rSink.getLineLengthLimit())
-                                    rSink << INetMIMEOutputSink::endl << ' ';
                                 rSink << ')';
                                 ++pBodyPtr;
                                 if (--nLevel == 0)
@@ -1719,10 +1709,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                     // Write an already pending '<' if necessary:
                     if (eBrackets == BRACKETS_OPENING)
                     {
-                        if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                                >= rSink.getLineLengthLimit())
-                            rSink << INetMIMEOutputSink::endl << ' ';
-                        else if (bInitialSpace)
+                        if (bInitialSpace)
                             rSink << ' ';
                         rSink << '<';
                         bInitialSpace = false;
@@ -1738,20 +1725,14 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                     // Write a pending '<' if necessary:
                     if (eBrackets == BRACKETS_OPENING)
                     {
-                        if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                                >= rSink.getLineLengthLimit())
-                            rSink << INetMIMEOutputSink::endl << ' ';
-                        else if (bInitialSpace)
+                        if (bInitialSpace)
                             rSink << ' ';
                         rSink << '<';
                         bInitialSpace = false;
                     }
 
                     // Write this '>', and close any bracketed block:
-                    if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                            >= rSink.getLineLengthLimit())
-                        rSink << INetMIMEOutputSink::endl << ' ';
-                    else if (bInitialSpace)
+                    if (bInitialSpace)
                         rSink << ' ';
                     rSink << '>';
                     bInitialSpace = false;
@@ -1767,10 +1748,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                     // Write a pending '<' if necessary:
                     if (eBrackets == BRACKETS_OPENING)
                     {
-                        if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                                >= rSink.getLineLengthLimit())
-                            rSink << INetMIMEOutputSink::endl << ' ';
-                        else if (bInitialSpace)
+                        if (bInitialSpace)
                             rSink << ' ';
                         rSink << '<';
                         bInitialSpace = false;
@@ -1778,10 +1756,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                     }
 
                     // Write this specials:
-                    if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                            >= rSink.getLineLengthLimit())
-                        rSink << INetMIMEOutputSink::endl << ' ';
-                    else if (bInitialSpace)
+                    if (bInitialSpace)
                         rSink << ' ';
                     rSink << sal_Char(*pBodyPtr++);
                     bInitialSpace = false;
@@ -1942,11 +1917,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                             // Write a pending '<' if necessary:
                             if (eBrackets == BRACKETS_OPENING)
                             {
-                                if (rSink.getColumn()
-                                            + (bInitialSpace ? 1 : 0)
-                                        >= rSink.getLineLengthLimit())
-                                    rSink << INetMIMEOutputSink::endl << ' ';
-                                else if (bInitialSpace)
+                                if (bInitialSpace)
                                     rSink << ' ';
                                 rSink << '<';
                                 bInitialSpace = false;
@@ -2002,11 +1973,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                                 }
 
                             // Write the output:
-                            if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                                        + nLength
-                                    > rSink.getLineLengthLimit())
-                                rSink << INetMIMEOutputSink::endl << ' ';
-                            else if (bInitialSpace)
+                            if (bInitialSpace)
                                 rSink << ' ';
                             bInitialSpace = false;
                             if (bModify)
@@ -2141,11 +2108,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                             if (eBrackets == BRACKETS_OPENING
                                 && !bBracketedBlock)
                             {
-                                if (rSink.getColumn()
-                                            + (bInitialSpace ? 1 : 0)
-                                        >= rSink.getLineLengthLimit())
-                                    rSink << INetMIMEOutputSink::endl << ' ';
-                                else if (bInitialSpace)
+                                if (bInitialSpace)
                                     rSink << ' ';
                                 rSink << '<';
                                 bInitialSpace = false;
@@ -2153,11 +2116,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                             }
 
                             // Write the output:
-                            if (rSink.getColumn() + (bInitialSpace ? 1 : 0)
-                                        + nLength
-                                    > rSink.getLineLengthLimit())
-                                rSink << INetMIMEOutputSink::endl << ' ';
-                            else if (bInitialSpace)
+                            if (bInitialSpace)
                                 rSink << ' ';
                             bInitialSpace = false;
                             if (bBracketedBlock)
@@ -2248,11 +2207,7 @@ void INetMIME::writeHeaderFieldBody(INetMIMEOutputSink & rSink,
                             // Write a pending '<' if necessary:
                             if (eBrackets == BRACKETS_OPENING)
                             {
-                                if (rSink.getColumn()
-                                            + (bInitialSpace ? 1 : 0)
-                                        >= rSink.getLineLengthLimit())
-                                    rSink << INetMIMEOutputSink::endl << ' ';
-                                else if (bInitialSpace)
+                                if (bInitialSpace)
                                     rSink << ' ';
                                 rSink << '<';
                                 bInitialSpace = false;
@@ -2870,13 +2825,6 @@ void INetMIMEOutputSink::writeSequence(const sal_Unicode * pBegin,
     delete[] pBufferBegin;
 }
 
-void INetMIMEOutputSink::writeLineEnd()
-{
-    static const sal_Char aCRLF[2] = { 0x0D, 0x0A };
-    writeSequence(aCRLF, aCRLF + 2);
-    m_nColumn = 0;
-}
-
 //  INetMIMEEncodedWordOutputSink
 
 static const sal_Char aEscape[128]
@@ -3023,7 +2971,6 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
     if (m_eEncodedWordState == STATE_SECOND_EQUALS)
     {
         // If the text is already an encoded word, copy it verbatim:
-        sal_uInt32 nSize = m_pBufferEnd - m_pBuffer;
         switch (m_ePrevCoding)
         {
             case CODING_QUOTED:
@@ -3031,40 +2978,22 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
             case CODING_NONE:
                 if (m_eInitialSpace == SPACE_ENCODED && m_nExtraSpaces == 0)
                     m_nExtraSpaces = 1;
-                for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
-                {
-                    if (m_rSink.getColumn() >= m_rSink.getLineLengthLimit())
-                        m_rSink << INetMIMEOutputSink::endl;
-                    m_rSink << ' ';
-                }
-                if (m_nExtraSpaces == 1)
+                while (m_nExtraSpaces-- > 0)
                 {
-                    if (m_rSink.getColumn() + nSize
-                            >= m_rSink.getLineLengthLimit())
-                        m_rSink << INetMIMEOutputSink::endl;
                     m_rSink << ' ';
                 }
                 break;
 
             case CODING_ENCODED:
             {
-                const sal_Char * pCharsetName
-                 = INetMIME::getCharsetName(m_ePrevMIMEEncoding);
                 while (m_nExtraSpaces-- > 0)
                 {
-                    if (m_rSink.getColumn()
-                            > m_rSink.getLineLengthLimit() - 3)
-                        m_rSink << "?=" << INetMIMEOutputSink::endl << " =?"
-                                << pCharsetName << "?Q?";
                     m_rSink << '_';
                 }
                 m_rSink << "?=";
             }
             //fall-through
             case CODING_ENCODED_TERMINATED:
-                if (m_rSink.getColumn() + nSize
-                        > m_rSink.getLineLengthLimit() - 1)
-                    m_rSink << INetMIMEOutputSink::endl;
                 m_rSink << ' ';
                 break;
         }
@@ -3073,64 +3002,13 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
     }
     else
     {
-        // If the text itself is too long to fit into a single line, make it
-        // into multiple encoded words:
-        switch (m_eCoding)
-        {
-            case CODING_NONE:
-                if (m_nExtraSpaces == 0)
-                {
-                    DBG_ASSERT(m_ePrevCoding == CODING_NONE
-                               || m_pBuffer == m_pBufferEnd,
-                               "INetMIMEEncodedWordOutputSink::finish():"
-                                   " Bad state");
-                    if (m_rSink.getColumn() + (m_pBufferEnd - m_pBuffer)
-                            > m_rSink.getLineLengthLimit())
-                        m_eCoding = CODING_ENCODED;
-                }
-                else
-                {
-                    OSL_ASSERT(m_pBufferEnd >= m_pBuffer);
-                    if (static_cast< std::size_t >(m_pBufferEnd - m_pBuffer)
-                        > m_rSink.getLineLengthLimit() - 1)
-                    {
-                        m_eCoding = CODING_ENCODED;
-                    }
-                }
-                break;
-
-            case CODING_QUOTED:
-                if (m_nExtraSpaces == 0)
-                {
-                    DBG_ASSERT(m_ePrevCoding == CODING_NONE,
-                               "INetMIMEEncodedWordOutputSink::finish():"
-                                   " Bad state");
-                    if (m_rSink.getColumn() + (m_pBufferEnd - m_pBuffer)
-                                + m_nQuotedEscaped
-                            > m_rSink.getLineLengthLimit() - 2)
-                        m_eCoding = CODING_ENCODED;
-                }
-                else if ((m_pBufferEnd - m_pBuffer) + m_nQuotedEscaped
-                             > m_rSink.getLineLengthLimit() - 3)
-                    m_eCoding = CODING_ENCODED;
-                break;
-
-            default:
-                break;
-        }
-
         switch (m_eCoding)
         {
             case CODING_NONE:
                 switch (m_ePrevCoding)
                 {
                     case CODING_QUOTED:
-                        if (m_rSink.getColumn() + m_nExtraSpaces
-                                    + (m_pBufferEnd - m_pBuffer)
-                                < m_rSink.getLineLengthLimit())
-                            m_eCoding = CODING_QUOTED;
-                        else
-                            m_rSink << '"';
+                        m_eCoding = CODING_QUOTED;
                         break;
 
                     case CODING_ENCODED:
@@ -3140,17 +3018,8 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
                     default:
                         break;
                 }
-                for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
-                {
-                    if (m_rSink.getColumn() >= m_rSink.getLineLengthLimit())
-                        m_rSink << INetMIMEOutputSink::endl;
-                    m_rSink << ' ';
-                }
-                if (m_nExtraSpaces == 1)
+                while (m_nExtraSpaces-- > 0)
                 {
-                    if (m_rSink.getColumn() + (m_pBufferEnd - m_pBuffer)
-                            >= m_rSink.getLineLengthLimit())
-                        m_rSink << INetMIMEOutputSink::endl;
                     m_rSink << ' ';
                 }
                 m_rSink.write(m_pBuffer, m_pBufferEnd);
@@ -3164,19 +3033,10 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
             case CODING_QUOTED:
             {
                 bool bInsertLeadingQuote = true;
-                sal_uInt32 nSize = (m_pBufferEnd - m_pBuffer)
-                                       + m_nQuotedEscaped + 2;
                 switch (m_ePrevCoding)
                 {
                     case CODING_QUOTED:
-                        if (m_rSink.getColumn() + m_nExtraSpaces + nSize - 1
-                                < m_rSink.getLineLengthLimit())
-                        {
-                            bInsertLeadingQuote = false;
-                            --nSize;
-                        }
-                        else
-                            m_rSink << '"';
+                        bInsertLeadingQuote = false;
                         break;
 
                     case CODING_ENCODED:
@@ -3186,17 +3046,8 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
                     default:
                         break;
                 }
-                for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
-                {
-                    if (m_rSink.getColumn() >= m_rSink.getLineLengthLimit())
-                        m_rSink << INetMIMEOutputSink::endl;
-                    m_rSink << ' ';
-                }
-                if (m_nExtraSpaces == 1)
+                while (m_nExtraSpaces-- > 0)
                 {
-                    if (m_rSink.getColumn() + nSize
-                            >= m_rSink.getLineLengthLimit())
-                        m_rSink << INetMIMEOutputSink::endl;
                     m_rSink << ' ';
                 }
                 if (bInsertLeadingQuote)
@@ -3224,68 +3075,8 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
                 rtl_TextEncoding eMIMEEncoding
                     = INetMIME::translateToMIME(eCharsetEncoding);
 
-                // The non UTF-8 code will only work for stateless single byte
-                // character encodings (see also below):
-                sal_Char * pTargetBuffer = NULL;
-                sal_Size nTargetSize = 0;
-                sal_uInt32 nSize;
-                if (eMIMEEncoding == RTL_TEXTENCODING_UTF8)
-                {
-                    nSize = 0;
-                    for (sal_Unicode const * p = m_pBuffer;
-                         p != m_pBufferEnd;)
-                    {
-                        sal_uInt32 nUTF32
-                            = INetMIME::getUTF32Character(p, m_pBufferEnd);
-                        nSize += needsEncodedWordEscape(nUTF32) ?
-                                     3 * INetMIME::getUTF8OctetCount(nUTF32) :
-                                     1;
-                            // only US-ASCII characters (that are converted to
-                            // a single byte by UTF-8) need no encoded word
-                            // escapes...
-                    }
-                }
-                else
-                {
-                    rtl_UnicodeToTextConverter hConverter
-                        = rtl_createUnicodeToTextConverter(eCharsetEncoding);
-                    rtl_UnicodeToTextContext hContext
-                        = rtl_createUnicodeToTextContext(hConverter);
-                    for (sal_Size nBufferSize = m_pBufferEnd - m_pBuffer;;
-                         nBufferSize += nBufferSize / 3 + 1)
-                    {
-                        pTargetBuffer = new sal_Char[nBufferSize];
-                        sal_uInt32 nInfo;
-                        sal_Size nSrcCvtBytes;
-                        nTargetSize
-                            = rtl_convertUnicodeToText(
-                                  hConverter, hContext, m_pBuffer,
-                                  m_pBufferEnd - m_pBuffer, pTargetBuffer,
-                                  nBufferSize,
-                                  RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
-                                     | RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE,
-                                  &nInfo, &nSrcCvtBytes);
-                        if (!(nInfo
-                                  & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL))
-                            break;
-                        delete[] pTargetBuffer;
-                        pTargetBuffer = NULL;
-                        rtl_resetUnicodeToTextContext(hConverter, hContext);
-                    }
-                    rtl_destroyUnicodeToTextContext(hConverter, hContext);
-                    rtl_destroyUnicodeToTextConverter(hConverter);
-
-                    nSize = nTargetSize;
-                    for (sal_Size k = 0; k < nTargetSize; ++k)
-                        if (needsEncodedWordEscape(static_cast<unsigned char>(
-                                                       pTargetBuffer[k])))
-                            nSize += 2;
-                }
-
                 const sal_Char * pCharsetName
                     = INetMIME::getCharsetName(eMIMEEncoding);
-                sal_uInt32 nWrapperSize = rtl_str_getLength(pCharsetName) + 7;
-                    // '=?', '?Q?', '?='
 
                 switch (m_ePrevCoding)
                 {
@@ -3295,63 +3086,35 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
                         if (m_eInitialSpace == SPACE_ENCODED
                             && m_nExtraSpaces == 0)
                             m_nExtraSpaces = 1;
-                        nSize += nWrapperSize;
-                        for (; m_nExtraSpaces > 1; --m_nExtraSpaces)
-                        {
-                            if (m_rSink.getColumn() >= m_rSink.getLineLengthLimit())
-                                m_rSink << INetMIMEOutputSink::endl;
-                            m_rSink << ' ';
-                        }
-                        if (m_nExtraSpaces == 1)
+                        while (m_nExtraSpaces-- > 0)
                         {
-                            if (m_rSink.getColumn() + nSize >= m_rSink.getLineLengthLimit())
-                                m_rSink << INetMIMEOutputSink::endl;
                             m_rSink << ' ';
                         }
                         m_rSink << "=?" << pCharsetName << "?Q?";
                         break;
 
                     case CODING_ENCODED:
-                        if (m_ePrevMIMEEncoding != eMIMEEncoding
-                            || m_rSink.getColumn() + m_nExtraSpaces + nSize
-                                   > m_rSink.getLineLengthLimit() - 2)
+                        if (m_ePrevMIMEEncoding != eMIMEEncoding)
                         {
-                            m_rSink << "?=";
-                            if (m_rSink.getColumn() + nWrapperSize
-                                        + m_nExtraSpaces + nSize
-                                    > m_rSink.getLineLengthLimit() - 1)
-                                m_rSink << INetMIMEOutputSink::endl;
-                            m_rSink << " =?" << pCharsetName << "?Q?";
+                            m_rSink << "?= =?" << pCharsetName << "?Q?";
                         }
                         while (m_nExtraSpaces-- > 0)
                         {
-                            if (m_rSink.getColumn()
-                                    > m_rSink.getLineLengthLimit() - 3)
-                                m_rSink << "?=" << INetMIMEOutputSink::endl
-                                        << " =?" << pCharsetName << "?Q?";
                             m_rSink << '_';
                         }
                         break;
 
                     case CODING_ENCODED_TERMINATED:
-                        if (m_rSink.getColumn() + nWrapperSize
-                                    + m_nExtraSpaces + nSize
-                                > m_rSink.getLineLengthLimit() - 1)
-                            m_rSink << INetMIMEOutputSink::endl;
                         m_rSink << " =?" << pCharsetName << "?Q?";
                         while (m_nExtraSpaces-- > 0)
                         {
-                            if (m_rSink.getColumn()
-                                    > m_rSink.getLineLengthLimit() - 3)
-                                m_rSink << "?=" << INetMIMEOutputSink::endl
-                                        << " =?" << pCharsetName << "?Q?";
                             m_rSink << '_';
                         }
                         break;
                 }
 
                 // The non UTF-8 code will only work for stateless single byte
-                // character encodings (see also above):
+                // character encodings:
                 if (eMIMEEncoding == RTL_TEXTENCODING_UTF8)
                 {
                     bool bInitial = true;
@@ -3361,17 +3124,6 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
                         sal_uInt32 nUTF32
                             = INetMIME::getUTF32Character(p, m_pBufferEnd);
                         bool bEscape = needsEncodedWordEscape(nUTF32);
-                        sal_uInt32 nWidth
-                            = bEscape ?
-                                  3 * INetMIME::getUTF8OctetCount(nUTF32) : 1;
-                            // only US-ASCII characters (that are converted to
-                            // a single byte by UTF-8) need no encoded word
-                            // escapes...
-                        if (!bInitial
-                            && m_rSink.getColumn() + nWidth + 2
-                                   > m_rSink.getLineLengthLimit())
-                            m_rSink << "?=" << INetMIMEOutputSink::endl
-                                    << " =?" << pCharsetName << "?Q?";
                         if (bEscape)
                         {
                             DBG_ASSERT(
@@ -3428,15 +3180,39 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
                 }
                 else
                 {
+                    sal_Char * pTargetBuffer = NULL;
+                    sal_Size nTargetSize = 0;
+                    rtl_UnicodeToTextConverter hConverter
+                        = rtl_createUnicodeToTextConverter(eCharsetEncoding);
+                    rtl_UnicodeToTextContext hContext
+                        = rtl_createUnicodeToTextContext(hConverter);
+                    for (sal_Size nBufferSize = m_pBufferEnd - m_pBuffer;;
+                         nBufferSize += nBufferSize / 3 + 1)
+                    {
+                        pTargetBuffer = new sal_Char[nBufferSize];
+                        sal_uInt32 nInfo;
+                        sal_Size nSrcCvtBytes;
+                        nTargetSize
+                            = rtl_convertUnicodeToText(
+                                  hConverter, hContext, m_pBuffer,
+                                  m_pBufferEnd - m_pBuffer, pTargetBuffer,
+                                  nBufferSize,
+                                  RTL_UNICODETOTEXT_FLAGS_UNDEFINED_IGNORE
+                                     | RTL_UNICODETOTEXT_FLAGS_INVALID_IGNORE,
+                                  &nInfo, &nSrcCvtBytes);
+                        if (!(nInfo
+                                  & RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL))
+                            break;
+                        delete[] pTargetBuffer;
+                        pTargetBuffer = NULL;
+                        rtl_resetUnicodeToTextContext(hConverter, hContext);
+                    }
+                    rtl_destroyUnicodeToTextContext(hConverter, hContext);
+                    rtl_destroyUnicodeToTextConverter(hConverter);
                     for (sal_Size k = 0; k < nTargetSize; ++k)
                     {
                         sal_uInt32 nUCS4 = static_cast<unsigned char>(pTargetBuffer[k]);
                         bool bEscape = needsEncodedWordEscape(nUCS4);
-                        if (k > 0
-                            && m_rSink.getColumn() + (bEscape ? 5 : 3)
-                                   > m_rSink.getLineLengthLimit())
-                            m_rSink << "?=" << INetMIMEOutputSink::endl
-                                    << " =?" << pCharsetName << "?Q?";
                         if (bEscape)
                             INetMIME::writeEscapeSequence(m_rSink, nUCS4);
                         else
@@ -3467,7 +3243,6 @@ void INetMIMEEncodedWordOutputSink::finish(bool bWriteTrailer)
     m_pBufferEnd = m_pBuffer;
     m_ePrevCoding = m_eCoding;
     m_eCoding = CODING_NONE;
-    m_nQuotedEscaped = 0;
     m_eEncodedWordState = STATE_INITIAL;
 }
 
@@ -3707,9 +3482,6 @@ INetMIMEEncodedWordOutputSink::WriteUInt32(sal_uInt32 nChar)
                                                            CODING_NONE;
         if (eNewCoding > m_eCoding)
             m_eCoding = eNewCoding;
-        if (m_eCoding == CODING_QUOTED
-            && INetMIME::needsQuotedStringEscape(nChar))
-            ++m_nQuotedEscaped;
 
         // Append to buffer:
         if (sal_uInt32(m_pBufferEnd - m_pBuffer) == m_nBufferSize)
commit ade5624f31233ce2369660f44d8f62bb4e8a6aea
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Sep 17 15:30:26 2015 +0200

    All INetMIMEOutputSink instances use same fixed ctor arg values
    
    Change-Id: I49126732be307b80270843c147d9cce4b3fdd2a3

diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index 657fc49..e0c37c7 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -88,8 +88,6 @@ typedef std::unordered_map<OString, INetContentTypeParameter, OStringHash>
 class TOOLS_DLLPUBLIC INetMIME
 {
 public:
-    enum { SOFT_LINE_LENGTH_LIMIT = 76 };
-
     /** The various types of message header field bodies, with respect to
         encoding and decoding them.
 
@@ -666,10 +664,8 @@ private:
                                const sal_Unicode * pEnd);
 
 public:
-    INetMIMEOutputSink(
-        sal_uInt32 nTheColumn = 0,
-        sal_uInt32 nTheLineLengthLimit= INetMIME::SOFT_LINE_LENGTH_LIMIT):
-        m_nColumn(nTheColumn), m_nLineLengthLimit(nTheLineLengthLimit) {}
+    INetMIMEOutputSink():
+        m_nColumn(0), m_nLineLengthLimit(NO_LINE_LENGTH_LIMIT) {}
 
     /** Get the current column.
 
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index bf22a52..dbc693a 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -861,8 +861,7 @@ sal_Unicode const * INetMIME::scanParameters(sal_Unicode const * pBegin,
             }
             if (pParameters)
             {
-                INetMIMEOutputSink
-                    aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
+                INetMIMEOutputSink aSink;
                 while (p != pEnd)
                 {
                     sal_uInt32 nChar = INetMIME::getUTF32Character(p, pEnd);
@@ -890,8 +889,7 @@ sal_Unicode const * INetMIME::scanParameters(sal_Unicode const * pBegin,
         else if (p != pEnd && *p == '"')
             if (pParameters)
             {
-                INetMIMEOutputSink
-                    aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
+                INetMIMEOutputSink aSink;
                 bool bInvalid = false;
                 for (++p;;)
                 {
diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx
index 3bb9333..188dd1a 100644
--- a/tools/source/inet/inetmsg.cxx
+++ b/tools/source/inet/inetmsg.cxx
@@ -46,7 +46,7 @@ void INetMIMEMessage::SetHeaderField_Impl (
     const OUString &rValue,
     sal_uIntPtr &rnIndex)
 {
-    INetMIMEOutputSink aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
+    INetMIMEOutputSink aSink;
     INetMIME::writeHeaderFieldBody (
         aSink, eType, rValue, osl_getThreadTextEncoding(), false);
     SetHeaderField_Impl (
commit bfff96fec8735d62c6655f1f423a3eefb2306ef9
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Sep 17 15:23:26 2015 +0200

    Odd that this started out as STRING_MAXLEN
    
    ...rather than as NO_LINE_LENGTH_LIMIT, in
    8ab086b6cc054501bfbf7ef6fa509c393691e860 "initial import"
    
    Change-Id: I8772236e4ce1576f2d0d4d6c02800c4d569520a4

diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx
index 5debdf9..3bb9333 100644
--- a/tools/source/inet/inetmsg.cxx
+++ b/tools/source/inet/inetmsg.cxx
@@ -46,7 +46,7 @@ void INetMIMEMessage::SetHeaderField_Impl (
     const OUString &rValue,
     sal_uIntPtr &rnIndex)
 {
-    INetMIMEOutputSink aSink (0, 32767); /* weird the mime standard says that aline MUST not be longeur that 998 */
+    INetMIMEOutputSink aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
     INetMIME::writeHeaderFieldBody (
         aSink, eType, rValue, osl_getThreadTextEncoding(), false);
     SetHeaderField_Impl (
commit 54ddc13bd2cffea7e8be9cc32083acda3fde9ddd
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Sep 17 15:18:38 2015 +0200

    Fold INetMIMEStringOutputSink into INetMIMEOutputSink base
    
    Change-Id: I675e656b57fca90e42be2d924c102a995168984d

diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index 8d4b01a..657fc49 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -632,16 +632,15 @@ public:
 private:
     sal_uInt32 m_nColumn;
     sal_uInt32 m_nLineLengthLimit;
+    OStringBuffer m_aBuffer;
 
-protected:
     /** Write a sequence of octets.
 
         @param pBegin  Points to the start of the sequence, must not be null.
 
         @param pEnd  Points past the end of the sequence, must be >= pBegin.
      */
-    virtual void writeSequence(const sal_Char * pBegin,
-                               const sal_Char * pEnd) = 0;
+    void writeSequence(const sal_Char * pBegin, const sal_Char * pEnd);
 
     /** Write a null terminated sequence of octets (without the terminating
         null).
@@ -667,11 +666,11 @@ protected:
                                const sal_Unicode * pEnd);
 
 public:
-    INetMIMEOutputSink(sal_uInt32 nTheColumn, sal_uInt32 nTheLineLengthLimit):
+    INetMIMEOutputSink(
+        sal_uInt32 nTheColumn = 0,
+        sal_uInt32 nTheLineLengthLimit= INetMIME::SOFT_LINE_LENGTH_LIMIT):
         m_nColumn(nTheColumn), m_nLineLengthLimit(nTheLineLengthLimit) {}
 
-    virtual ~INetMIMEOutputSink() {}
-
     /** Get the current column.
 
         @return  The current column (starting from zero).
@@ -737,6 +736,11 @@ public:
      */
     void writeLineEnd();
 
+    OString takeBuffer()
+    {
+        return m_aBuffer.makeStringAndClear();
+    }
+
     /** A manipulator function that writes a line end (CR LF).
 
         @param rSink  Some sink.
@@ -785,27 +789,6 @@ inline void INetMIME::writeEscapeSequence(INetMIMEOutputSink & rSink,
           << sal_uInt8(getHexDigit(nChar & 15));
 }
 
-class INetMIMEStringOutputSink: public INetMIMEOutputSink
-{
-    OStringBuffer m_aBuffer;
-
-    using INetMIMEOutputSink::writeSequence;
-
-    virtual void writeSequence(const sal_Char * pBegin,
-                               const sal_Char * pEnd) SAL_OVERRIDE;
-
-public:
-    inline INetMIMEStringOutputSink(sal_uInt32 nColumn = 0,
-                                    sal_uInt32 nLineLengthLimit
-                                        = INetMIME::SOFT_LINE_LENGTH_LIMIT):
-        INetMIMEOutputSink(nColumn, nLineLengthLimit) {}
-
-    OString takeBuffer()
-    {
-        return m_aBuffer.makeStringAndClear();
-    }
-};
-
 class INetMIMEEncodedWordOutputSink
 {
 public:
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index faf3502..bf22a52 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -861,7 +861,7 @@ sal_Unicode const * INetMIME::scanParameters(sal_Unicode const * pBegin,
             }
             if (pParameters)
             {
-                INetMIMEStringOutputSink
+                INetMIMEOutputSink
                     aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
                 while (p != pEnd)
                 {
@@ -890,7 +890,7 @@ sal_Unicode const * INetMIME::scanParameters(sal_Unicode const * pBegin,
         else if (p != pEnd && *p == '"')
             if (pParameters)
             {
-                INetMIMEStringOutputSink
+                INetMIMEOutputSink
                     aSink(0, INetMIMEOutputSink::NO_LINE_LENGTH_LIMIT);
                 bool bInvalid = false;
                 for (++p;;)
@@ -2838,9 +2838,15 @@ OUString INetMIME::decodeHeaderFieldBody(HeaderFieldType eType,
     return sDecoded;
 }
 
-//  INetMIMEOutputSink
+void INetMIMEOutputSink::writeSequence(const sal_Char * pBegin,
+                                       const sal_Char * pEnd)
+{
+    OSL_ENSURE(pBegin && pBegin <= pEnd,
+               "INetMIMEOutputSink::writeSequence(): Bad sequence");
+
+    m_aBuffer.append(pBegin, pEnd - pBegin);
+}
 
-// virtual
 sal_Size INetMIMEOutputSink::writeSequence(const sal_Char * pSequence)
 {
     sal_Size nLength = rtl_str_getLength(pSequence);
@@ -2848,7 +2854,6 @@ sal_Size INetMIMEOutputSink::writeSequence(const sal_Char * pSequence)
     return nLength;
 }
 
-// virtual
 void INetMIMEOutputSink::writeSequence(const sal_Unicode * pBegin,
                                        const sal_Unicode * pEnd)
 {
@@ -2874,18 +2879,6 @@ void INetMIMEOutputSink::writeLineEnd()
     m_nColumn = 0;
 }
 
-//  INetMIMEStringOutputSink
-
-// virtual
-void INetMIMEStringOutputSink::writeSequence(const sal_Char * pBegin,
-                                             const sal_Char * pEnd)
-{
-    OSL_ENSURE(pBegin && pBegin <= pEnd,
-               "INetMIMEStringOutputSink::writeSequence(): Bad sequence");
-
-    m_aBuffer.append(pBegin, pEnd - pBegin);
-}
-
 //  INetMIMEEncodedWordOutputSink
 
 static const sal_Char aEscape[128]
diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx
index 099e6bf..5debdf9 100644
--- a/tools/source/inet/inetmsg.cxx
+++ b/tools/source/inet/inetmsg.cxx
@@ -46,7 +46,7 @@ void INetMIMEMessage::SetHeaderField_Impl (
     const OUString &rValue,
     sal_uIntPtr &rnIndex)
 {
-    INetMIMEStringOutputSink aSink (0, 32767); /* weird the mime standard says that aline MUST not be longeur that 998 */
+    INetMIMEOutputSink aSink (0, 32767); /* weird the mime standard says that aline MUST not be longeur that 998 */
     INetMIME::writeHeaderFieldBody (
         aSink, eType, rValue, osl_getThreadTextEncoding(), false);
     SetHeaderField_Impl (
commit 717de02367f842a49431b0003eab4f99afec8ab1
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Sep 17 15:08:23 2015 +0200

    INetMIMEOutputSink ctor args are always given explicitly
    
    Change-Id: Iacb01ac77ef4419f7428ecb397e91ab8d666a8f3

diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index 2308380..8d4b01a 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -667,9 +667,7 @@ protected:
                                const sal_Unicode * pEnd);
 
 public:
-    INetMIMEOutputSink(sal_uInt32 nTheColumn = 0,
-                       sal_uInt32 nTheLineLengthLimit
-                           = INetMIME::SOFT_LINE_LENGTH_LIMIT):
+    INetMIMEOutputSink(sal_uInt32 nTheColumn, sal_uInt32 nTheLineLengthLimit):
         m_nColumn(nTheColumn), m_nLineLengthLimit(nTheLineLengthLimit) {}
 
     virtual ~INetMIMEOutputSink() {}
commit f7dc03f666954b741b90c5021704249a4f76ed7b
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Sep 17 15:07:04 2015 +0200

    Remove unused HARD_LINE_LENGTH_LIMIT
    
    Change-Id: Iae65de5a71f8a0b8ad80138ae310db9a84736878

diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index dc64319..2308380 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -88,8 +88,7 @@ typedef std::unordered_map<OString, INetContentTypeParameter, OStringHash>
 class TOOLS_DLLPUBLIC INetMIME
 {
 public:
-    enum { SOFT_LINE_LENGTH_LIMIT = 76,
-           HARD_LINE_LENGTH_LIMIT = 998 };
+    enum { SOFT_LINE_LENGTH_LIMIT = 76 };
 
     /** The various types of message header field bodies, with respect to
         encoding and decoding them.
commit 149384846be910c6aa966185bce2038d6e31a565
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Sep 17 15:06:11 2015 +0200

    No need for user-prov. INetContentTypeParameter ctor, use list-initialization
    
    Change-Id: Ie116def9e5e90a59a82c3e8a4821eecd68eee64c

diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index b5d4786..dc64319 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -42,26 +42,17 @@ struct INetContentTypeParameter
         will only be one item for the complete parameter, with the attribute
         name lacking any section suffix.
      */
-#ifndef _LIBCPP_VERSION
-    const
-#endif
-          OString m_sAttribute;
+    OString m_sAttribute;
 
     /** The optional character set specification (see RFC 2231), in US-ASCII
         encoding and converted to lower case.
      */
-#ifndef _LIBCPP_VERSION
-    const
-#endif
-          OString m_sCharset;
+    OString m_sCharset;
 
     /** The optional language specification (see RFC 2231), in US-ASCII
         encoding and converted to lower case.
      */
-#ifndef _LIBCPP_VERSION
-    const
-#endif
-          OString m_sLanguage;
+    OString m_sLanguage;
 
     /** The attribute value.  If the value is a quoted-string, it is
         'unpacked.'  If a character set is specified, and the value can be
@@ -80,30 +71,13 @@ struct INetContentTypeParameter
         within Unicode's Private Use Area (effectively adding 0xF800 to the
         character's numeric value).
      */
-#ifndef _LIBCPP_VERSION
-    const
-#endif
-          OUString m_sValue;
+    OUString m_sValue;
 
     /** This is true if the value is successfully converted to Unicode, and
         false if the value is a special mixture of ISO-LATIN-1 characters and
         characters from Unicode's Private Use Area.
      */
-#ifndef _LIBCPP_VERSION
-    const
-#endif
-          bool m_bConverted;
-
-    INetContentTypeParameter(const OString& rTheAttribute,
-        const OString& rTheCharset, const OString& rTheLanguage,
-        const OUString& rTheValue, bool bTheConverted)
-    : m_sAttribute(rTheAttribute)
-    , m_sCharset(rTheCharset)
-    , m_sLanguage(rTheLanguage)
-    , m_sValue(rTheValue)
-    , m_bConverted(bTheConverted)
-    {
-    }
+    bool m_bConverted;
 };
 
 // the key is the m_sAttribute again; all keys are lower case:
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index 44c0fdf..faf3502 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -332,12 +332,10 @@ bool parseParameters(ParameterList const & rInput,
                         break;
                 };
             }
-            auto const ret = pOutput->insert(std::make_pair(p->m_aAttribute,
-                                    INetContentTypeParameter(p->m_aAttribute,
-                                                             p->m_aCharset,
-                                                             p->m_aLanguage,
-                                                             aValue,
-                                                             !bBadEncoding)));
+            auto const ret = pOutput->insert(
+                {p->m_aAttribute,
+                 {p->m_aAttribute, p->m_aCharset, p->m_aLanguage, aValue,
+                  !bBadEncoding}});
             SAL_INFO_IF(!ret.second, "tools",
                 "INetMIME: dropping duplicate parameter: " << p->m_aAttribute);
             p = pNext;


More information about the Libreoffice-commits mailing list