Quote mailbox name instead of encoding it whenever it's possible.

This commit is contained in:
Vincent Richard 2009-11-12 15:40:56 +00:00
parent b0fbd0edf0
commit 90f838232f
3 changed files with 18 additions and 5 deletions

View File

@ -415,7 +415,7 @@ void mailbox::generate(utility::outputStream& os, const string::size_type maxLin
bool newLine = true;
m_name.encodeAndFold(os, maxLineLength, pos, &pos,
forceEncode ? text::FORCE_ENCODING : 0);
text::QUOTE_IF_POSSIBLE | (forceEncode ? text::FORCE_ENCODING : 0));
if (pos + m_email.length() + 3 > maxLineLength)
{

View File

@ -352,10 +352,22 @@ void word::generate(utility::outputStream& os, const string::size_type maxLineLe
noEncoding = false;
}
if (noEncoding)
// If possible and requested (with flag), quote the buffer (no folding is performed).
// Quoting is possible if and only if:
// - the whole buffer is ASCII-only
// - the buffer does not contain quoting character (")
// - there is enough remaining space on the current line to hold the whole buffer
if ((flags & text::QUOTE_IF_POSSIBLE) &&
asciiCount == m_buffer.length() &&
m_buffer.find('"') == string::npos &&
(curLineLength + 2 /* 2 x " */ + m_buffer.length()) < maxLineLength)
{
os << '"' << m_buffer << '"';
curLineLength += 2 + m_buffer.length();
}
// We will fold lines without encoding them.
else if (noEncoding)
{
// We will fold lines without encoding them.
string::const_iterator lastWSpos = m_buffer.end(); // last white-space position
string::const_iterator curLineStart = m_buffer.begin(); // current line start

View File

@ -197,7 +197,8 @@ public:
FORCE_NO_ENCODING = (1 << 0), /**< Just fold lines, don't encode them. */
FORCE_ENCODING = (1 << 1), /**< Encode lines even if they are plain ASCII text. */
NO_NEW_LINE_SEQUENCE = (1 << 2) /**< Use CRLF instead of new-line sequence (CRLF + TAB). */
NO_NEW_LINE_SEQUENCE = (1 << 2), /**< Use CRLF instead of new-line sequence (CRLF + TAB). */
QUOTE_IF_POSSIBLE = (1 << 3) /**< Use quoting instead of encoding when possible (even if FORCE_ENCODING is specified). */
};
/** Encode and fold text in respect to RFC-2047.