Fixed decoding of '&-' in IMAP modified UTF-7 encoding.

This commit is contained in:
Vincent Richard 2014-06-08 19:12:26 +02:00
parent a46e520902
commit c8c5aa065f

View File

@ -306,6 +306,7 @@ const folder::path::component IMAPUtils::fromModifiedUTF7(const string& text)
out.reserve(text.length()); out.reserve(text.length());
bool inB64sequence = false; bool inB64sequence = false;
bool plusOutput = false;
unsigned char prev = 0; unsigned char prev = 0;
for (string::const_iterator it = text.begin() ; it != text.end() ; ++it) for (string::const_iterator it = text.begin() ; it != text.end() ; ++it)
@ -320,7 +321,7 @@ const folder::path::component IMAPUtils::fromModifiedUTF7(const string& text)
if (!inB64sequence) if (!inB64sequence)
{ {
inB64sequence = true; inB64sequence = true;
out += '+'; plusOutput = false;
} }
else else
{ {
@ -332,7 +333,7 @@ const folder::path::component IMAPUtils::fromModifiedUTF7(const string& text)
// End of Base64 sequence (or "&-" --> "&") // End of Base64 sequence (or "&-" --> "&")
case '-': case '-':
{ {
if (inB64sequence && prev == '&') if (inB64sequence && prev == '&') // special case "&-" --> "&"
out += '&'; out += '&';
else else
out += '-'; out += '-';
@ -343,11 +344,23 @@ const folder::path::component IMAPUtils::fromModifiedUTF7(const string& text)
// ',' is used instead of '/' in modified Base64 // ',' is used instead of '/' in modified Base64
case ',': case ',':
{ {
if (inB64sequence && !plusOutput)
{
out += '+';
plusOutput = true;
}
out += (inB64sequence ? '/' : ','); out += (inB64sequence ? '/' : ',');
break; break;
} }
default: default:
{ {
if (inB64sequence && !plusOutput)
{
out += '+';
plusOutput = true;
}
out += c; out += c;
break; break;
} }