summaryrefslogtreecommitdiffstats
path: root/charset.c
diff options
context:
space:
mode:
authorRocco Rutte <pdmef@gmx.net>2008-08-18 10:20:40 +0200
committerRocco Rutte <pdmef@gmx.net>2008-08-18 10:20:40 +0200
commitc69de21086cd552d88be90cd6e626129168efaa3 (patch)
tree43822820193d08052fab3e86235c60a6e714edf1 /charset.c
parent06ba5e75095170b9d640b704841f905edf463399 (diff)
Validate charset names for all charset options.
Validation is either done against mutt's table of IANA assigned names or local iconv implementation (based on the assumption that iconv_open(charset,charset) fails if charset is unknown to the implementation). Closes #1668.
Diffstat (limited to 'charset.c')
-rw-r--r--charset.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/charset.c b/charset.c
index 30d157e2..69c0e9bb 100644
--- a/charset.c
+++ b/charset.c
@@ -629,3 +629,28 @@ void fgetconv_close (FGETCONV **_fc)
iconv_close (fc->cd);
FREE (_fc); /* __FREE_CHECKED__ */
}
+
+int mutt_check_charset (const char *s, int strict)
+{
+ int i;
+ iconv_t cd;
+
+ if (mutt_is_utf8 (s))
+ return 0;
+
+ if (!strict)
+ for (i = 0; PreferredMIMENames[i].key; i++)
+ {
+ if (ascii_strcasecmp (PreferredMIMENames[i].key, s) == 0 ||
+ ascii_strcasecmp (PreferredMIMENames[i].pref, s) == 0)
+ return 0;
+ }
+
+ if ((cd = mutt_iconv_open (s, s, 0)) != (iconv_t)(-1))
+ {
+ iconv_close (cd);
+ return 0;
+ }
+
+ return -1;
+}