Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit ad79c591 authored by Rob Swindell's avatar Rob Swindell 💬

Improved parsing of "charset" parameter in MIME Content-Type header.

In Issue #177, the reported problem message header was "Content-Type: text/plain; charset=utf-8; format=flowed"
The fact that the "charset" value was not quoted and not space delimited means the charset would have been parsed as "utf-8;", which would not provide an exact match (against "utf-8") in smb_msg_is_utf8() and thus the message body would not be considered to be utf-8 encoded.

The solution is to terminate the "charset" parameter value at the semicolon, if it exists, and the value was not quoted.

Also, for good measure, only search for " charset" or ";charset" to avoid false-positive parameter matches,  like "notcharset".
parent 24531cb1
......@@ -367,15 +367,22 @@ void SMBCALL smb_parse_content_type(const char* content_type, char** subtype, ch
*tp = 0;
}
}
if(charset != NULL && (p = strcasestr(p, "charset=")) != NULL) {
p += 8;
if(*p == '"')
if(charset != NULL && ((p = strcasestr(p, " charset=")) != NULL || (p = strcasestr(p, ";charset=")) != NULL)) {
BOOL quoted = FALSE;
p += 9;
if(*p == '"') {
quoted = TRUE;
p++;
}
char* tp = p;
FIND_WHITESPACE(tp);
*tp = 0;
tp = p;
FIND_CHAR(tp, '"');
if(quoted) {
FIND_CHAR(tp, '"');
} else {
FIND_CHAR(tp, ';');
}
*tp = 0;
*charset = strdup(p);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment