must add CHARSET=UTF-8 if non-ASCII character is found because default charset is not well-defined

git-svn-id: https://zeitsenke.de/svn/SyncEvolution/trunk@181 15ad00c4-1369-45f4-8270-35d70d36bdcd
This commit is contained in:
Patrick Ohly 2006-07-14 21:19:41 +00:00
parent 46cd60c556
commit 6f6c575290

View file

@ -385,6 +385,10 @@ void VObject::fromNativeEncoding()
// if necessary do quoted-printable encoding
bool doquoted = !is_30 &&
wcsstr(native, SYNC4J_LINEBREAK) != NULL;
// non-ASCII character encountered
bool utf8 = false;
while ((curr = native[in]) != 0) {
in++;
switch (curr) {
@ -408,8 +412,14 @@ void VObject::fromNativeEncoding()
out++;
break;
default:
bool currIsUTF8 = (unsigned char)curr >= 128;
if (currIsUTF8) {
utf8 = true;
}
if (doquoted &&
(curr == '=' || (unsigned char)curr >= 128)) {
(curr == '=' || currIsUTF8)) {
// escape = and non-ASCII characters
wsprintf(foreign + out, TEXT("=%02X"), (unsigned int)(unsigned char)curr);
out += 3;
@ -441,6 +451,9 @@ void VObject::fromNativeEncoding()
// we have used quoted-printable encoding
vprop->addParameter(TEXT("ENCODING"), TEXT("QUOTED-PRINTABLE"));
}
if (utf8 && !vprop->getParameterValue("CHARSET")) {
vprop->addParameter("CHARSET", "UTF-8");
}
}
}