X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=charset.c;h=29aa77662b3e9d208e7af623fddefb83529c340e;hp=8a1804f8d511ef17e4f0679e0fedd1fd4b4aa386;hb=e6c3d6c782080832a49192a8bd88599ef230678e;hpb=2293e9bc5a94ef33dc596b064c607d6bed5ad1fd diff --git a/charset.c b/charset.c index 8a1804f..29aa776 100644 --- a/charset.c +++ b/charset.c @@ -25,29 +25,12 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include - -#include +#include -#include -#include -#include -#include #ifdef HAVE_LANGINFO_CODESET # include #endif -#include -#include -#include -#include - #include "mutt.h" #include "charset.h" @@ -98,6 +81,11 @@ void charset_canonicalize(char *dest, ssize_t dlen, const char *name) const char *p; int i = 0; + if (!name) { + m_strcpy(dest, dlen, "us-ascii"); + return; + } + // canonize name: only keep a-z0-9 and dots, put into lowercase for (p = name; *p && *p != ':' && i < ssizeof(scratch) - 1; p++) { if (isalnum(*p) || *p== '.') { @@ -129,25 +117,18 @@ const char *charset_getfirst(const char *charset) return fcharset; } -static int mutt_chscmp(const char *s, const char *chs) -{ - char buffer[SHORT_STRING]; - - if (!s) - return 0; - - charset_canonicalize(buffer, sizeof(buffer), s); - return !strcmp(buffer, chs); -} - int charset_is_utf8(const char *s) { - return mutt_chscmp(s, "utf-8"); + char buf[SHORT_STRING]; + charset_canonicalize(buf, sizeof(buf), s); + return !strcmp(buf, "utf-8"); } int charset_is_us_ascii(const char *s) { - return mutt_chscmp(s, "us-ascii"); + char buf[SHORT_STRING]; + charset_canonicalize(buf, sizeof(buf), s); + return !strcmp(buf, "us-ascii"); } @@ -391,6 +372,7 @@ fgetconv_open(FILE *file, const char *from, const char *to, int flags) struct fgetconv_t *fc = p_new(struct fgetconv_t, 1); fc->file = file; + fc->cd = MUTT_ICONV_ERROR; if (from && to) fc->cd = mutt_iconv_open(to, from, flags);