Magnus Melin 2019-12-02 14:32:11 +02:00
Родитель 0762062d65
Коммит 2ef473ed7f
1 изменённых файлов: 28 добавлений и 17 удалений

Просмотреть файл

@ -1772,31 +1772,42 @@ extern "C" char *MimeGetStringByName(const char16_t *stringName) {
void ResetChannelCharset(MimeObject *obj) { void ResetChannelCharset(MimeObject *obj) {
if (obj->options && obj->options->stream_closure && if (obj->options && obj->options->stream_closure &&
obj->options->default_charset && obj->headers) { obj->options->default_charset && obj->headers) {
// The previous version of this code would have entered an infinite
// loop. But it never showed up, so it's not clear that it is ever called.
// See bug #1597891.
MOZ_DIAGNOSTIC_ASSERT(false, "Should never get here (see bug 1597891)");
mime_stream_data *msd = (mime_stream_data *)(obj->options->stream_closure); mime_stream_data *msd = (mime_stream_data *)(obj->options->stream_closure);
char *ct = MimeHeaders_get(obj->headers, HEADER_CONTENT_TYPE, false, false); char *ct = MimeHeaders_get(obj->headers, HEADER_CONTENT_TYPE, false, false);
if (ct && msd && msd->channel) { if ((ct) && (msd) && (msd->channel)) {
char *cSet = MimeHeaders_get_parameter(ct, "charset", nullptr, nullptr); char *ptr = strstr(ct, "charset=");
if (cSet) { if (ptr) {
// First, setup the channel. // First, setup the channel!
msd->channel->SetContentType(nsDependentCString(ct)); msd->channel->SetContentType(nsDependentCString(ct));
// Second, if this is a Save As operation, then we need to convert // Second, if this is a Save As operation, then we need to convert
// to override the output charset. // to override the output charset!
if (msd->format_out == nsMimeOutput::nsMimeMessageSaveAs) { mime_stream_data *msd = GetMSD(obj->options);
PR_FREEIF(obj->options->default_charset); if ((msd) && (msd->format_out == nsMimeOutput::nsMimeMessageSaveAs)) {
obj->options->default_charset = cSet; // Extract the charset alone
cSet = nullptr; // Ownership was transferred. char *cSet = nullptr;
obj->options->override_charset = true; if (*(ptr + 8) == '"')
cSet = strdup(ptr + 9);
else
cSet = strdup(ptr + 8);
if (cSet) {
char *ptr2 = cSet;
while ((*cSet) && (*cSet != ' ') && (*cSet != ';') &&
(*cSet != '\r') && (*cSet != '\n') && (*cSet != '"'))
ptr2++;
if (*cSet) {
PR_FREEIF(obj->options->default_charset);
obj->options->default_charset = strdup(cSet);
obj->options->override_charset = true;
}
PR_FREEIF(cSet);
}
} }
PR_FREEIF(cSet);
} }
PR_FREEIF(ct);
} }
PR_FREEIF(ct);
} }
} }