Transcode mh_execm text/plain output like we do for mh_exec. Adjust handling of transcoding errors. These changes should fix most cases of non-utf8 text making it to unac/index
This commit is contained in:
@@ -153,17 +153,24 @@ void MimeHandlerExec::finaldetails()
|
||||
// cfgFilterOutputCharset comes from the mimeconf filter definition line
|
||||
string charset = cfgFilterOutputCharset.empty() ? "utf-8" :
|
||||
cfgFilterOutputCharset;
|
||||
bool trustcharset = true;
|
||||
if (!stringlowercmp("default", charset)) {
|
||||
charset = m_dfltInputCharset;
|
||||
trustcharset = false;
|
||||
}
|
||||
string mt = cfgFilterOutputMtype.empty() ? "text/html" :
|
||||
cfgFilterOutputMtype;
|
||||
if (!mt.compare(cstr_textplain) && stringlowercmp("utf-8", charset)) {
|
||||
|
||||
// If this is text/plain and not utf-8 or untrusted, transcode to utf-8.
|
||||
if (!mt.compare(cstr_textplain) &&
|
||||
(!trustcharset || stringlowercmp("utf-8", charset))) {
|
||||
string transcoded;
|
||||
int ecnt;
|
||||
if (!transcode(output, transcoded, charset, "UTF-8", &ecnt)) {
|
||||
LOGERR(("mh_exec: transcode failed from [%s] to UTF-8\n",
|
||||
charset.c_str()));
|
||||
// Erase text in this case: it's garbage
|
||||
output.clear();
|
||||
} else {
|
||||
if (ecnt) {
|
||||
LOGDEB(("mh_exec: %d transcoding errors from [%s] to UTF-8\n",
|
||||
|
||||
@@ -284,15 +284,37 @@ bool MimeHandlerExecMultiple::next_document()
|
||||
|
||||
// Charset. For many document types it doesn't matter. For text
|
||||
// and html it does. We supply a default from the
|
||||
// configuration. We should do the text transcoding to utf-8 here
|
||||
// like exec::finaldetails does.
|
||||
// configuration.
|
||||
bool trustcharset = true;
|
||||
if (charset.empty()) {
|
||||
charset = cfgFilterOutputCharset.empty() ? "utf-8" :
|
||||
cfgFilterOutputCharset;
|
||||
if (!stringlowercmp("default", charset)) {
|
||||
trustcharset = false;
|
||||
charset = m_dfltInputCharset;
|
||||
}
|
||||
}
|
||||
|
||||
string& output = m_metaData[cstr_content];
|
||||
if (!m_metaData[cstr_mimetype].compare(cstr_textplain) &&
|
||||
(!trustcharset || stringlowercmp("utf-8", charset))) {
|
||||
string transcoded;
|
||||
int ecnt;
|
||||
if (!transcode(output, transcoded, charset, "UTF-8", &ecnt)) {
|
||||
LOGERR(("mh_execm: transcode failed from [%s] to UTF-8\n",
|
||||
charset.c_str()));
|
||||
// Erase text in this case: it's garbage
|
||||
output.clear();
|
||||
} else {
|
||||
if (ecnt) {
|
||||
LOGDEB(("mh_exec: %d transcoding errors from [%s] to UTF-8\n",
|
||||
ecnt, charset.c_str()));
|
||||
}
|
||||
output = transcoded;
|
||||
charset = "utf-8";
|
||||
}
|
||||
}
|
||||
|
||||
m_metaData[cstr_charset] = charset;
|
||||
|
||||
if (eofnext_received)
|
||||
|
||||
@@ -259,13 +259,13 @@ bool MimeHandlerMail::processAttach()
|
||||
// Special case for text/plain content. Internfile should deal
|
||||
// with this but it expects text/plain to be utf-8 already, so we
|
||||
// handle the transcoding if needed
|
||||
if (m_metaData[cstr_mimetype] == cstr_textplain &&
|
||||
stringicmp(m_metaData[cstr_charset], "UTF-8")) {
|
||||
if (m_metaData[cstr_mimetype] == cstr_textplain) {
|
||||
string utf8;
|
||||
if (!transcode(body, utf8, m_metaData[cstr_charset], "UTF-8")) {
|
||||
LOGERR((" processAttach: transcode to utf-8 failed "
|
||||
"for charset [%s]\n", m_metaData[cstr_charset].c_str()));
|
||||
// Just let it through and hope for the best...
|
||||
// can't transcode at all -> data is garbage just erase it
|
||||
body.clear();
|
||||
} else {
|
||||
body = utf8;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user