commit c4bb4f33ce4ca8e7f040aba158d0fa807f9b5d89
parent c1cd5dd02d6645c597a81f5f1efb681af9f59095
Author: Christoph Lohmann <20h@r-36.net>
Date: Wed, 25 Jul 2012 18:01:41 +0200
Another support for malformed header encodings in buggy MUAs.
Diffstat:
4 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/mime.c b/mime.c
@@ -296,6 +296,25 @@ mime_decodeheader(char *value)
}
char *
+mime_decodeheaderdefault(char *value, char *charset)
+{
+ char *ret, *rdec;
+
+ ret = mime_decodeheader(value);
+ if (ret != NULL) {
+ if (strcasecmp(charset, "utf-8")) {
+ rdec = mime_iconv(ret, charset, "UTF-8");
+ if (rdec != NULL) {
+ free(ret);
+ ret = rdec;
+ }
+ }
+ }
+
+ return ret;
+}
+
+char *
mime_decodeparam(char *value)
{
char *work, *cret, *ret, *cs, *str, *lang;
diff --git a/mime.h b/mime.h
@@ -36,6 +36,7 @@ char *mime_iconv(char *str, char *from, char *to);
char *mime_decodeheaderext(char *value);
int mime_isextws(char *str, int len);
char *mime_decodeheader(char *value);
+char *mime_decodeheaderdefault(char *value, char *charset);
char *mime_decodeparam(char *value);
char *mime_encodestring(char *value);
char *mime_encodeheader(char *header, char *value);
diff --git a/scan.c b/scan.c
@@ -93,8 +93,9 @@ scanmain(int argc, char *argv[])
frome = llist_ciget(mime->hdrs, "from");
if (subjecte != NULL) {
- subject = mime_decodeheader(
- (char *)subjecte->data);
+ subject = mime_decodeheaderdefault(
+ (char *)subjecte->data,
+ mime->charset);
} else {
subject = "<empty>";
}
@@ -111,7 +112,9 @@ scanmain(int argc, char *argv[])
}
if (frome != NULL) {
- from = mime_decodeheader((char *)frome->data);
+ from = mime_decodeheaderdefault(
+ (char *)frome->data,
+ mime->charset);
} else {
from = "<empty>";
}
@@ -166,8 +169,9 @@ scanmain(int argc, char *argv[])
id = (char *)ide->data;
if (subjecte != NULL) {
- subject = mime_decodeheader(
- (char *)subjecte->data);
+ subject = mime_decodeheaderdefault(
+ (char *)subjecte->data,
+ mime->charset);
} else {
subject = "<empty>";
}
@@ -184,7 +188,9 @@ scanmain(int argc, char *argv[])
}
if (frome != NULL) {
- from = mime_decodeheader((char *)frome->data);
+ from = mime_decodeheaderdefault(
+ (char *)frome->data,
+ mime->charset);
} else {
from = "<empty>";
}
diff --git a/view.c b/view.c
@@ -141,7 +141,7 @@ view_printpart(char *id, mime_t *mime, llist_t *dhdrs, llist_t *partl,
didprint = 0;
if (!strcasecmp(dhdrs->first->key, "all")) {
forllist(mime->hdrs, helem) {
- hvalue = mime_decodeheader((char *)helem->data);
+ hvalue = mime_decodeheaderdefault((char *)helem->data, mime->charset);
if (hvalue == NULL)
continue;
if (options & PRINT_VALUE) {
@@ -157,8 +157,8 @@ view_printpart(char *id, mime_t *mime, llist_t *dhdrs, llist_t *partl,
hlist = llist_cifind(mime->hdrs, delem->key);
if (hlist != NULL) {
forllist(hlist, helem) {
- hvalue = mime_decodeheader(
- (char *)helem->data);
+ hvalue = mime_decodeheaderdefault(
+ (char *)helem->data, mime->charset);
if (hvalue == NULL)
continue;
if (options & PRINT_VALUE) {