Do not generate 7-bit value for parameter if RFC-2231 extended value is generated (thanks to Eugene A. Shatokhin).

This commit is contained in:
Vincent Richard 2010-06-23 20:42:25 +00:00
parent 2f8026dc5b
commit 1930316f36

View File

@ -257,11 +257,23 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
// For compatibility with implementations that do not understand RFC-2231,
// also generate a normal "7bit/us-ascii" parameter
// [By Eugene A. Shatokhin]
// Note that if both the normal "7bit/us-ascii" value and the extended
// value are present, the latter can be ignored by mail processing systems.
// This may lead to annoying problems, for example, with strange names of
// attachments with all but 7-bit ascii characters removed, etc. To avoid
// this, I would suggest not to create "7bit/us-ascii" value if the extended
// value is to be generated.
// A stream for a temporary storage
std::ostringstream sevenBitBuffer;
string::size_type pos = curLinePos;
if (pos + name.length() + 10 + value.length() > maxLineLength)
{
os << NEW_LINE_SEQUENCE;
sevenBitBuffer << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH;
}
@ -301,12 +313,12 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
if (needQuoting)
{
os << name << "=\"";
sevenBitBuffer << name << "=\"";
pos += name.length() + 2;
}
else
{
os << name << "=";
sevenBitBuffer << name << "=";
pos += name.length() + 1;
}
@ -318,12 +330,12 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
if (/* needQuoting && */ (c == '"' || c == '\\')) // 'needQuoting' is implicit
{
os << '\\' << value[i]; // escape 'x' with '\x'
sevenBitBuffer << '\\' << value[i]; // escape 'x' with '\x'
pos += 2;
}
else if (parserHelpers::isAscii(c))
{
os << value[i];
sevenBitBuffer << value[i];
++pos;
}
else
@ -334,17 +346,31 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
if (needQuoting)
{
os << '"';
sevenBitBuffer << '"';
++pos;
}
#if VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
os << sevenBitBuffer;
#endif // !VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
// Also generate an extended parameter if the value contains 8-bit characters
// or is too long for a single line
if (extended || cutValue)
{
#if VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
os << ';';
++pos;
#else // !VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
// The data output to 'sevenBitBuffer' will be discarded in this case
pos = curLinePos;
#endif // VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
/* RFC-2231
* ========
*
@ -477,6 +503,17 @@ void parameter::generate(utility::outputStream& os, const string::size_type maxL
}
}
}
#if !VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
else
{
// The value does not contain 8-bit characters and
// is short enough for a single line.
// "7bit/us-ascii" will suffice in this case.
// Output what has been stored in temporary buffer so far
os << sevenBitBuffer.str();
}
#endif // !VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
if (newLinePos)
*newLinePos = pos;