From: Pierre Habouzit Date: Wed, 15 Nov 2006 00:46:31 +0000 (+0100) Subject: finish the "read" of charset.c X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=2293e9bc5a94ef33dc596b064c607d6bed5ad1fd finish the "read" of charset.c Signed-off-by: Pierre Habouzit --- diff --git a/charset.c b/charset.c index 9a80d31..8a1804f 100644 --- a/charset.c +++ b/charset.c @@ -59,11 +59,16 @@ char *Charset; int Charset_is_utf8 = 0; wchar_t CharsetReplacement = '?'; + +/****************************************************************************/ +/* charset functions */ +/****************************************************************************/ + void charset_initialize(void) { #ifdef HAVE_LANGINFO_CODESET - char buff[LONG_STRING]; - char buff2[LONG_STRING]; + char buff[SHORT_STRING]; + char buff2[SHORT_STRING]; m_strcpy(buff, sizeof(buff), nl_langinfo(CODESET)); charset_canonicalize(buff2, sizeof(buff2), buff); @@ -89,7 +94,7 @@ void charset_initialize(void) void charset_canonicalize(char *dest, ssize_t dlen, const char *name) { const struct cset_pair *cp; - char scratch[LONG_STRING]; + char scratch[SHORT_STRING]; const char *p; int i = 0; @@ -110,9 +115,23 @@ void charset_canonicalize(char *dest, ssize_t dlen, const char *name) } } +/* XXX: MC: UGLY return of local static */ +const char *charset_getfirst(const char *charset) +{ + static char fcharset[SHORT_STRING]; + const char *p; + + if (m_strisempty(charset)) + return "us-ascii"; + + p = m_strchrnul(charset, ':'); + m_strncpy(fcharset, sizeof(fcharset), charset, p - charset); + return fcharset; +} + static int mutt_chscmp(const char *s, const char *chs) { - char buffer[STRING]; + char buffer[SHORT_STRING]; if (!s) return 0; @@ -132,361 +151,338 @@ int charset_is_us_ascii(const char *s) } -/* - * Like iconv_open, but canonicalises the charsets - */ +/****************************************************************************/ +/* iconv-line functions */ +/****************************************************************************/ -iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) +/* Like iconv_open, but canonicalises the charsets */ +iconv_t mutt_iconv_open(const char *tocode, const char *fromcode, int flags) { - char tocode1[SHORT_STRING]; - char fromcode1[SHORT_STRING]; - char *tocode2, *fromcode2; - char *tmp; + char tocode1[SHORT_STRING]; + char fromcode1[SHORT_STRING]; + const char *tmp; - iconv_t cd; + iconv_t cd; - charset_canonicalize (tocode1, sizeof (tocode1), tocode); + if ((flags & M_ICONV_HOOK_TO) && (tmp = mutt_charset_hook(tocode1))) { + charset_canonicalize(tocode1, sizeof(tocode1), tmp); + } else { + charset_canonicalize(tocode1, sizeof(tocode1), tocode); + } -#ifdef M_ICONV_HOOK_TO - /* Not used. */ - if ((flags & M_ICONV_HOOK_TO) && (tmp = mutt_charset_hook (tocode1))) - charset_canonicalize (tocode1, sizeof (tocode1), tmp); -#endif + if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook(fromcode1))) { + charset_canonicalize(fromcode1, sizeof(fromcode1), tmp); + } else { + charset_canonicalize(fromcode1, sizeof(fromcode1), fromcode); + } - charset_canonicalize (fromcode1, sizeof (fromcode1), fromcode); - if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook (fromcode1))) - charset_canonicalize (fromcode1, sizeof (fromcode1), tmp); + cd = iconv_open(tocode1, fromcode1); + if (cd != MUTT_ICONV_ERROR) + return cd; - if ((cd = iconv_open (tocode1, fromcode1)) != (iconv_t) - 1) - return cd; - if ((tocode2 = mutt_iconv_hook (tocode1)) - && (fromcode2 = mutt_iconv_hook (fromcode1))) - return iconv_open (tocode2, fromcode2); + { + const char *to = mutt_iconv_hook(tocode1); + const char *from = mutt_iconv_hook(fromcode1); - return (iconv_t) - 1; + return to && from ? iconv_open(to, from) : MUTT_ICONV_ERROR; + } } -/* - * Like iconv, but keeps going even when the input is invalid - * If you're supplying inrepls, the source charset should be stateless; - * if you're supplying an outrepl, the target charset should be. - */ - -ssize_t mutt_iconv(iconv_t cd, const char **inbuf, ssize_t *inbytesleft, +/* Like iconv, but keeps going even when the input is invalid + If you're supplying inrepls, the source charset should be stateless; + if you're supplying an outrepl, the target charset should be. */ +/* XXX: MC: I do not understand what it does yet */ +ssize_t mutt_iconv(iconv_t cd, + const char **inbuf, ssize_t *inbytesleft, char **outbuf, ssize_t *outbytesleft, const char **inrepls, const char *outrepl) { - ssize_t ret = 0, ret1; - const char *ib = *inbuf; - ssize_t ibl = *inbytesleft; - char *ob = *outbuf; - ssize_t obl = *outbytesleft; - - for (;;) { - ret1 = my_iconv(cd, &ib, &ibl, &ob, &obl); - if (ret1 != -1) - ret += ret1; - if (ibl && obl && errno == EILSEQ) { - if (inrepls) { - /* Try replacing the input */ - const char **t; - - for (t = inrepls; *t; t++) { - const char *ib1 = *t; - ssize_t ibl1 = m_strlen(*t); - char *ob1 = ob; - ssize_t obl1 = obl; - - my_iconv(cd, &ib1, &ibl1, &ob1, &obl1); - if (!ibl1) { - ++ib, --ibl; - ob = ob1, obl = obl1; - ++ret; - break; - } - } - if (*t) - continue; - } - /* Replace the output */ - if (!outrepl) - outrepl = "?"; - my_iconv(cd, 0, 0, &ob, &obl); - if (obl) { - ssize_t n = m_strlen(outrepl); - - if (n > obl) { - outrepl = "?"; - n = 1; + ssize_t ret = 0, ret1; + const char *ib = *inbuf; + ssize_t ibl = *inbytesleft; + char *ob = *outbuf; + ssize_t obl = *outbytesleft; + + for (;;) { + ret1 = my_iconv(cd, &ib, &ibl, &ob, &obl); + if (ret1 != -1) + ret += ret1; + + if (ibl && obl && errno == EILSEQ) { + if (inrepls) { + /* Try replacing the input */ + const char **t; + + for (t = inrepls; *t; t++) { + const char *ib1 = *t; + ssize_t ibl1 = m_strlen(*t); + char *ob1 = ob; + ssize_t obl1 = obl; + + my_iconv(cd, &ib1, &ibl1, &ob1, &obl1); + if (!ibl1) { + ++ib, --ibl; + ob = ob1, obl = obl1; + ++ret; + break; + } + } + if (*t) + continue; + } + /* Replace the output */ + if (!outrepl) + outrepl = "?"; + my_iconv(cd, 0, 0, &ob, &obl); + if (obl) { + ssize_t n = m_strlen(outrepl); + + if (n > obl) { + outrepl = "?"; + n = 1; + } + memcpy(ob, outrepl, n); + ++ib, --ibl; + ob += n, obl -= n; + ++ret; + my_iconv(cd, 0, 0, 0, 0); /* for good measure */ + continue; + } } - memcpy (ob, outrepl, n); - ++ib, --ibl; - ob += n, obl -= n; - ++ret; - my_iconv(cd, 0, 0, 0, 0); /* for good measure */ - continue; - } + *inbuf = ib, *inbytesleft = ibl; + *outbuf = ob, *outbytesleft = obl; + return ret; } - *inbuf = ib, *inbytesleft = ibl; - *outbuf = ob, *outbytesleft = obl; - return ret; - } } - -/* - * Convert a string - * Used in rfc2047.c and rfc2231.c - */ - -int mutt_convert_string (char **ps, const char *from, const char *to, - int flags) +/* Convert a string */ +int +mutt_convert_string(char **ps, const char *from, const char *to, int flags) { - iconv_t cd; - const char *repls[] = { "\357\277\275", "?", 0 }; - char *s = *ps; + iconv_t cd; + const char *repls[] = { "\357\277\275", "?", 0 }; - if (!s || !*s) - return 0; + if (m_strisempty(*ps)) + return 0; - if (to && from && (cd = mutt_iconv_open (to, from, flags)) != (iconv_t) - 1) { - int len; - const char *ib; - char *buf, *ob; - ssize_t ibl, obl; - const char **inrepls = NULL; - const char *outrepl = NULL; - - if (charset_is_utf8 (to)) - outrepl = "\357\277\275"; - else if (charset_is_utf8 (from)) - inrepls = repls; - else - outrepl = "?"; - - len = m_strlen(s); - ib = s, ibl = len + 1; - obl = MB_LEN_MAX * ibl; - ob = buf = xmalloc(obl + 1); - - mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); - iconv_close (cd); - - *ob = '\0'; - - p_delete(ps); - *ps = buf; - return 0; - } - else - return -1; -} + cd = mutt_iconv_open(to, from, flags); + if (cd != MUTT_ICONV_ERROR) { + const char **inrepls = NULL; + const char *outrepl = NULL; + const char *ib; + char *buf, *ob; + ssize_t ibl, obl; + if (charset_is_utf8(to)) + outrepl = "\357\277\275"; + else + if (charset_is_utf8(from)) + inrepls = repls; + else + outrepl = "?"; -/* - * FGETCONV stuff for converting a file while reading it - * Used in sendlib.c for converting from mutt's Charset - */ + ibl = m_strlen(*ps) + 1; + ib = *ps; -struct fgetconv_s { - FILE *file; - iconv_t cd; - char bufi[512]; - char bufo[512]; - char *p; - char *ob; - char *ib; - ssize_t ibl; - const char **inrepls; -}; + obl = MB_LEN_MAX * ibl; + ob = buf = p_new(char, obl + 1); -struct fgetconv_not { - FILE *file; - iconv_t cd; -}; + mutt_iconv(cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); + iconv_close(cd); -FGETCONV *fgetconv_open (FILE * file, const char *from, const char *to, - int flags) -{ - struct fgetconv_s *fc; - iconv_t cd = (iconv_t) - 1; - static const char *repls[] = { "\357\277\275", "?", 0 }; + *ob = '\0'; - if (from && to) - cd = mutt_iconv_open (to, from, flags); + p_delete(ps); + *ps = buf; + return 0; + } - if (cd != (iconv_t) - 1) { - fc = p_new(struct fgetconv_s, 1); - fc->p = fc->ob = fc->bufo; - fc->ib = fc->bufi; - fc->ibl = 0; - fc->inrepls = charset_is_utf8 (to) ? repls : repls + 1; - } - else - fc = p_new(struct fgetconv_s, 1); - fc->file = file; - fc->cd = cd; - return (FGETCONV *) fc; + return -1; } -char *fgetconvs (char *buf, ssize_t l, FGETCONV * _fc) +static ssize_t convert_string(const char *f, ssize_t flen, + const char *from, const char *to, + char **t, ssize_t * tlen) { - int c; - ssize_t r; - - for (r = 0; r + 1 < l;) { - if ((c = fgetconv (_fc)) == EOF) - break; - buf[r++] = (char) c; - if (c == '\n') - break; - } - buf[r] = '\0'; - - if (r) - return buf; - else - return NULL; + iconv_t cd; + char *buf, *ob; + ssize_t obl; + ssize_t n; + int e; + + if ((cd = mutt_iconv_open(to, from, 0)) == MUTT_ICONV_ERROR) + return -1; + + obl = 4 * flen + 1; + ob = buf = p_new(char, obl); + n = my_iconv(cd, &f, &flen, &ob, &obl); + + if (n < 0 || my_iconv(cd, 0, 0, &ob, &obl) < 0) { + e = errno; + p_delete(&buf); + iconv_close(cd); + errno = e; + return -1; + } + + *ob = '\0'; + *tlen = ob - buf; + *t = buf; + iconv_close(cd); + return n; } -int fgetconv (FGETCONV * _fc) +int mutt_convert_nonmime_string(char **ps) { - struct fgetconv_s *fc = (struct fgetconv_s *) _fc; + const char *p = AssumedCharset; + ssize_t ulen = m_strlen(*ps); + char *u = *ps; - if (!fc) - return EOF; - if (fc->cd == (iconv_t) - 1) - return fgetc (fc->file); - if (!fc->p) - return EOF; - if (fc->p < fc->ob) - return (unsigned char) *(fc->p)++; + while (*p) { + const char *q; + char fromcode[LONG_STRING], *s = NULL; + ssize_t slen; - /* Try to convert some more */ - fc->p = fc->ob = fc->bufo; - if (fc->ibl) { - ssize_t obl = ssizeof(fc->bufo); + if (!ulen) + return 0; - my_iconv(fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl); - if (fc->p < fc->ob) - return (unsigned char) *(fc->p)++; - } + while (*p == ':') + *p++; - /* If we trusted iconv a bit more, we would at this point - * ask why it had stopped converting ... */ + q = m_strchrnul(p, ':'); + m_strncpy(fromcode, sizeof(fromcode), p, q - p); + p = q; - /* Try to read some more */ - if (fc->ibl == sizeof (fc->bufi) || - (fc->ibl && fc->ib + fc->ibl < fc->bufi + sizeof (fc->bufi))) { - fc->p = 0; - return EOF; - } - if (fc->ibl) - memcpy (fc->bufi, fc->ib, fc->ibl); - fc->ib = fc->bufi; - fc->ibl += - fread (fc->ib + fc->ibl, 1, sizeof (fc->bufi) - fc->ibl, fc->file); - - /* Try harder this time to convert some */ - if (fc->ibl) { - ssize_t obl = ssizeof(fc->bufo); - - mutt_iconv (fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, - &obl, fc->inrepls, 0); - if (fc->p < fc->ob) - return (unsigned char) *(fc->p)++; - } + if (convert_string(u, ulen, fromcode, Charset, &s, &slen) >= 0) { + p_delete(ps); + *ps = s; + return 0; + } + } - /* Either the file has finished or one of the buffers is too small */ - fc->p = 0; - return EOF; + return -1; } -void fgetconv_close (FGETCONV ** _fc) +/****************************************************************************/ +/* fgetconv functions */ +/****************************************************************************/ + +/* fgetconv_t stuff for converting a file while reading it + Used in sendlib.c for converting from mutt's Charset */ + +struct fgetconv_t { + FILE *file; + iconv_t cd; + char bufi[BUFSIZ]; + char bufo[BUFSIZ]; + char *p; + char *ob; + char *ib; + ssize_t ibl; + const char **inrepls; +}; + +fgetconv_t * +fgetconv_open(FILE *file, const char *from, const char *to, int flags) { - struct fgetconv_s *fc = (struct fgetconv_s *) *_fc; + static const char *repls[] = { "\357\277\275", "?", 0 }; + + struct fgetconv_t *fc = p_new(struct fgetconv_t, 1); - if (fc->cd != (iconv_t) - 1) - iconv_close (fc->cd); - p_delete(_fc); + fc->file = file; + if (from && to) + fc->cd = mutt_iconv_open(to, from, flags); + + if (fc->cd != MUTT_ICONV_ERROR) { + fc->p = fc->ob = fc->bufo; + fc->ib = fc->bufi; + fc->ibl = 0; + fc->inrepls = repls + charset_is_utf8(to); + } + return fc; } -const char *mutt_get_first_charset (const char *charset) +void fgetconv_close(fgetconv_t **fcp) { - static char fcharset[SHORT_STRING]; - const char *c, *c1; - - c = charset; - if (!m_strlen(c)) - return "us-ascii"; - if (!(c1 = strchr (c, ':'))) - return ((char*) charset); - m_strcpy(fcharset, c1 - c + 1, c); - return fcharset; + struct fgetconv_t *fc = *fcp; + + if (fc->cd != MUTT_ICONV_ERROR) + iconv_close (fc->cd); + p_delete(fcp); } -static ssize_t convert_string (const char *f, ssize_t flen, - const char *from, const char *to, - char **t, ssize_t * tlen) + +int fgetconv(fgetconv_t *fc) { - iconv_t cd; - char *buf, *ob; - ssize_t obl; - ssize_t n; - int e; - - cd = mutt_iconv_open (to, from, 0); - if (cd == (iconv_t) (-1)) - return -1; - obl = 4 * flen + 1; - ob = buf = xmalloc(obl); - n = my_iconv(cd, &f, &flen, &ob, &obl); - if (n < 0 || my_iconv(cd, 0, 0, &ob, &obl) < 0) { - e = errno; - p_delete(&buf); - iconv_close (cd); - errno = e; - return -1; - } - *ob = '\0'; + if (!fc) + return EOF; - *tlen = ob - buf; + if (fc->cd == MUTT_ICONV_ERROR) + return fgetc(fc->file); - p_realloc(&buf, ob - buf + 1); - *t = buf; - iconv_close (cd); + if (!fc->p) + return EOF; + if (fc->p < fc->ob) + return (unsigned char)*(fc->p)++; + + /* Try to convert some more */ + fc->p = fc->ob = fc->bufo; + if (fc->ibl) { + ssize_t obl = ssizeof(fc->bufo); + + my_iconv(fc->cd, (const char **)&fc->ib, &fc->ibl, &fc->ob, &obl); + if (fc->p < fc->ob) + return (unsigned char)*(fc->p)++; + } + + /* If we trusted iconv a bit more, we would at this point + * ask why it had stopped converting ... */ + + /* Try to read some more */ + if (fc->ibl == sizeof(fc->bufi) + || (fc->ibl && fc->ib + fc->ibl < fc->bufi + sizeof(fc->bufi))) { + fc->p = NULL; + return EOF; + } + + if (fc->ibl) { + memcpy(fc->bufi, fc->ib, fc->ibl); + } + fc->ib = fc->bufi; + fc->ibl += fread(fc->ib + fc->ibl, 1, sizeof(fc->bufi) - fc->ibl, + fc->file); - return n; + /* Try harder this time to convert some */ + if (fc->ibl) { + ssize_t obl = ssizeof(fc->bufo); + + mutt_iconv(fc->cd, (const char **)&fc->ib, &fc->ibl, &fc->ob, &obl, + fc->inrepls, 0); + if (fc->p < fc->ob) { + return (unsigned char)*(fc->p)++; + } + } + + /* Either the file has finished or one of the buffers is too small */ + fc->p = NULL; + return EOF; } -int mutt_convert_nonmime_string (char **ps) +char *fgetconvs(char *buf, ssize_t len, fgetconv_t *fc) { - const char *c, *c1; + ssize_t pos = 0; - for (c = AssumedCharset; c; c = c1 ? c1 + 1 : 0) { - char *u = *ps; - char *s = NULL; - char *fromcode; - ssize_t m, n; - ssize_t ulen = m_strlen(*ps); - ssize_t slen; - - if (!u || !*u) - return 0; - - c1 = strchr (c, ':'); - n = c1 ? c1 - c : m_strlen(c); - if (!n) - continue; - fromcode = p_dupstr(c, n); - m = convert_string (u, ulen, fromcode, Charset, &s, &slen); - p_delete(&fromcode); - if (m != -1) { - p_delete(ps); - *ps = s; - return 0; + while (pos < len - 1) { + int c = fgetconv(fc); + if (c == EOF) + break; + + buf[pos++] = c; + if (c == '\n') + break; } - } - return -1; + buf[pos] = '\0'; + + return pos ? buf : NULL; } diff --git a/charset.h b/charset.h index dd44047..2f03c24 100644 --- a/charset.h +++ b/charset.h @@ -45,11 +45,15 @@ void charset_canonicalize(char *, ssize_t, const char *); int charset_is_utf8(const char *s); int charset_is_us_ascii(const char *s); +const char *charset_getfirst(const char *); + /****************************************************************************/ /* iconv-line functions */ /****************************************************************************/ +#define MUTT_ICONV_ERROR ((iconv_t)(-1)) + #ifdef HAVE_ICONV_H # include @@ -60,7 +64,7 @@ my_iconv(iconv_t ict, const char **in, ssize_t *il, char **out, ssize_t *ol) { #else # define iconv_t void* -# define iconv_open(a, b) ((iconv_t)(-1)) +# define iconv_open(a, b) MUTT_ICONV_ERROR # define my_iconv(a,b,c,d,e) 0 # define iconv_close(a) 0 #endif @@ -68,24 +72,24 @@ my_iconv(iconv_t ict, const char **in, ssize_t *il, char **out, ssize_t *ol) { #define M_ICONV_HOOK_FROM 1 #define M_ICONV_HOOK_TO 2 -int mutt_convert_string (char **, const char *, const char *, int); -const char *mutt_get_first_charset (const char *); -int mutt_convert_nonmime_string (char **); +iconv_t mutt_iconv_open(const char *, const char *, int); +ssize_t mutt_iconv(iconv_t, const char **, ssize_t *, char **, ssize_t *, + const char **, const char *); -iconv_t mutt_iconv_open (const char *, const char *, int); -ssize_t mutt_iconv (iconv_t, const char **, ssize_t *, char **, ssize_t *, - const char **, const char *); +int mutt_convert_string(char **, const char *, const char *, int); +int mutt_convert_nonmime_string (char **); /****************************************************************************/ /* fgetconv functions */ /****************************************************************************/ -typedef void *FGETCONV; +typedef struct fgetconv_t fgetconv_t; + +fgetconv_t *fgetconv_open(FILE *, const char *, const char *, int); +void fgetconv_close(fgetconv_t **); -FGETCONV *fgetconv_open (FILE *, const char *, const char *, int); -int fgetconv (FGETCONV *); -char *fgetconvs (char *, ssize_t, FGETCONV *); -void fgetconv_close (FGETCONV **); +int fgetconv(fgetconv_t *); +char *fgetconvs(char *, ssize_t, fgetconv_t *); #endif /* _CHARSET_H */ diff --git a/handler.c b/handler.c index fe2a0f7..e7ca176 100644 --- a/handler.c +++ b/handler.c @@ -1259,7 +1259,7 @@ static int external_body_handler (BODY * b, STATE * s) void mutt_decode_attachment (BODY * b, STATE * s) { int istext = mutt_is_text_part (b); - iconv_t cd = (iconv_t) (-1); + iconv_t cd = MUTT_ICONV_ERROR; Quotebuf[0] = '\0'; @@ -1268,7 +1268,7 @@ void mutt_decode_attachment (BODY * b, STATE * s) const char *charset = mutt_get_parameter ("charset", b->parameter); if (!option (OPTSTRICTMIME) && !charset) - charset = mutt_get_first_charset (AssumedCharset); + charset = charset_getfirst(AssumedCharset); if (charset && Charset) cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM); } @@ -1298,7 +1298,7 @@ void mutt_decode_attachment (BODY * b, STATE * s) break; } - if (cd != (iconv_t) (-1)) + if (cd != MUTT_ICONV_ERROR) iconv_close (cd); } diff --git a/hook.c b/hook.c index aaf1c7c..aa0d478 100644 --- a/hook.c +++ b/hook.c @@ -412,30 +412,29 @@ void mutt_select_fcc (char *path, ssize_t pathlen, HEADER * hdr) mutt_pretty_mailbox (path); } -static char *_mutt_string_hook (const char *match, int hook) +static const char *_mutt_string_hook (const char *match, int hook) { HOOK *tmp = Hooks; for (; tmp; tmp = tmp->next) { - if ((tmp->type & hook) && ((match && - regexec (tmp->rx.rx, match, 0, NULL, - 0) == 0) ^ tmp->rx.not)) + if ((tmp->type & hook) + && ((match && regexec(tmp->rx.rx, match, 0, NULL, 0) == 0) ^ tmp->rx.not)) return (tmp->command); } return (NULL); } -char *mutt_charset_hook (const char *chs) +const char *mutt_charset_hook (const char *chs) { return _mutt_string_hook (chs, M_CHARSETHOOK); } -char *mutt_iconv_hook (const char *chs) +const char *mutt_iconv_hook (const char *chs) { return _mutt_string_hook (chs, M_ICONVHOOK); } -char *mutt_crypt_hook (address_t * adr) +const char *mutt_crypt_hook (address_t * adr) { return _mutt_string_hook (adr->mailbox, M_CRYPTHOOK); } diff --git a/imap/utf7.c b/imap/utf7.c index e9ae15d..08bc14b 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -215,7 +215,7 @@ void imap_utf7_encode (char **s) if (Charset) { char *t = m_strdup(*s); - if (!mutt_convert_string (&t, Charset, "UTF-8", 0)) { + if (!mutt_convert_string (&t, Charset, "utf-8", 0)) { char *u7 = utf8_to_utf7 (t, strlen (t), NULL, 0); p_delete(s); *s = u7; @@ -229,7 +229,7 @@ void imap_utf7_decode (char **s) if (Charset) { char *t = utf7_to_utf8 (*s, m_strlen(*s), 0, 0); - if (t && !mutt_convert_string (&t, "UTF-8", Charset, 0)) { + if (t && !mutt_convert_string (&t, "utf-8", Charset, 0)) { p_delete(s); *s = t; } diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index 8311f5a..339b97c 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -1718,7 +1718,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE * s, char *charset) { char buf[HUGE_STRING]; short complete, armor_header; - FGETCONV *fc; + fgetconv_t *fc; char *fname; FILE *fp; @@ -1942,7 +1942,7 @@ int pgp_gpgme_application_handler (BODY * m, STATE * s) copy_clearsigned (armored_data, s, body_charset); } else if (pgpout) { - FGETCONV *fc; + fgetconv_t *fc; int c; rewind (pgpout); diff --git a/lib-crypt/gnupgparse.c b/lib-crypt/gnupgparse.c index f2a105c..c0c944b 100644 --- a/lib-crypt/gnupgparse.c +++ b/lib-crypt/gnupgparse.c @@ -81,7 +81,7 @@ static void fix_uid (char *uid) } *d = '\0'; - if (_chs && (cd = mutt_iconv_open (_chs, "utf-8", 0)) != (iconv_t) - 1) { + if (_chs && (cd = mutt_iconv_open (_chs, "utf-8", 0)) != MUTT_ICONV_ERROR) { int n = s - uid + 1; /* chars available in original buffer */ char *buf; const char *ib; diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index dcc905c..bb55885 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -187,7 +187,7 @@ static void pgp_copy_clearsigned (FILE * fpin, STATE * s, char *charset) char buf[HUGE_STRING]; short complete, armor_header; - FGETCONV *fc; + fgetconv_t *fc; rewind (fpin); @@ -414,7 +414,7 @@ int pgp_application_pgp_handler (BODY * m, STATE * s) pgp_copy_clearsigned (tmpfp, s, body_charset); } else if (pgpout) { - FGETCONV *fc; + fgetconv_t *fc; rewind (pgpout); state_set_prefix (s); @@ -1350,7 +1350,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) if (!charset_is_us_ascii (body_charset)) { int c; - FGETCONV *fc; + fgetconv_t *fc; if (flags & ENCRYPT) send_charset = "us-ascii"; diff --git a/lib-crypt/pgpmicalg.c b/lib-crypt/pgpmicalg.c index 8fe6a5e..f750e19 100644 --- a/lib-crypt/pgpmicalg.c +++ b/lib-crypt/pgpmicalg.c @@ -112,7 +112,7 @@ static void pgp_dearmor (FILE * in, FILE * out) return; } - mutt_decode_base64 (&state, end - start, 0, (iconv_t) - 1); + mutt_decode_base64 (&state, end - start, 0, MUTT_ICONV_ERROR); } static short pgp_mic_from_packet (unsigned char *p, size_t len) diff --git a/lib-mime/rfc2047.c b/lib-mime/rfc2047.c index 7162b47..71bf5c7 100644 --- a/lib-mime/rfc2047.c +++ b/lib-mime/rfc2047.c @@ -73,7 +73,7 @@ convert_string(const char *from, const char *f, ssize_t flen, cd = mutt_iconv_open(to, from, 0); - if (cd == (iconv_t)(-1)) + if (cd == MUTT_ICONV_ERROR) return -1; obl = 4 * flen + 1; @@ -271,7 +271,7 @@ static size_t try_block(const char *d, ssize_t dlen, ssize_t ibl = dlen; iconv_t cd = mutt_iconv_open(tocode, fromcode, 0); - assert (cd != (iconv_t)(-1)); + assert (cd != MUTT_ICONV_ERROR); ob = buf1; @@ -338,7 +338,7 @@ encode_block(char *s, char *d, ssize_t dlen, if (fromcode) { cd = mutt_iconv_open(tocode, fromcode, 0); - assert (cd != (iconv_t) (-1)); + assert (cd != MUTT_ICONV_ERROR); ib = d, ibl = dlen, ob = buf1, obl = sizeof(buf1) - m_strlen(tocode); n1 = my_iconv(cd, &ib, &ibl, &ob, &obl); n2 = my_iconv(cd, 0, 0, &ob, &obl); diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index 40da94d..3eafd9e 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -347,7 +347,7 @@ void mutt_parse_content_type(char *s, BODY *ct) if (!pc) { mutt_set_parameter("charset", option(OPTSTRICTMIME) ? "us-ascii" : - mutt_get_first_charset(AssumedCharset), + charset_getfirst(AssumedCharset), &ct->parameter); } } diff --git a/protos.h b/protos.h index ef5baf1..59d18f6 100644 --- a/protos.h +++ b/protos.h @@ -75,8 +75,8 @@ void mutt_set_mtime (const char*, const char*); time_t mutt_parse_date (const char *, HEADER *); int is_from (const char *, char *, ssize_t, time_t *); -char *mutt_charset_hook (const char *); -char *mutt_iconv_hook (const char *); +const char *mutt_charset_hook (const char *); +const char *mutt_iconv_hook (const char *); char *mutt_expand_path (char *, ssize_t); char *_mutt_expand_path (char *, ssize_t, int); char *mutt_find_hook (int, const char *); @@ -84,7 +84,7 @@ char *mutt_gen_msgid (void); char *mutt_get_body_charset (char *, ssize_t, BODY *); const char *mutt_get_name (address_t *); char *mutt_get_parameter (const char *, PARAMETER *); -char *mutt_crypt_hook (address_t *); +const char *mutt_crypt_hook (address_t *); char *mutt_make_date (char *, ssize_t); const char *mutt_make_version (int full); diff --git a/sendlib.c b/sendlib.c index 3551aaf..e8a89a6 100644 --- a/sendlib.c +++ b/sendlib.c @@ -76,7 +76,7 @@ static char MsgIdPfx = 'A'; static void transform_to_7bit (BODY * a, FILE * fpin); -static void encode_quoted (FGETCONV * fc, FILE * fout, int istext) +static void encode_quoted (fgetconv_t * fc, FILE * fout, int istext) { int c, linelen = 0; char line[77], savechar; @@ -247,7 +247,7 @@ static void b64_putc (char c, FILE * fout) } -static void encode_base64 (FGETCONV * fc, FILE * fout, int istext) +static void encode_base64 (fgetconv_t * fc, FILE * fout, int istext) { int ch, ch1 = EOF; @@ -263,7 +263,7 @@ static void encode_base64 (FGETCONV * fc, FILE * fout, int istext) fputc ('\n', fout); } -static void encode_8bit (FGETCONV * fc, FILE * fout, int istext) +static void encode_8bit (fgetconv_t * fc, FILE * fout, int istext) { int ch; @@ -373,7 +373,7 @@ int mutt_write_mime_body (BODY * a, FILE * f) char send_charset[SHORT_STRING]; FILE *fpin; BODY *t; - FGETCONV *fc; + fgetconv_t *fc; if (a->type == TYPEMULTIPART) { /* First, find the boundary to use */ @@ -598,7 +598,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode, ssize_t *score; cd1 = mutt_iconv_open ("UTF-8", fromcode, 0); - if (cd1 == (iconv_t) (-1)) + if (cd1 == MUTT_ICONV_ERROR) return -1; cd = p_new(iconv_t, ncodes); @@ -611,7 +611,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode, cd[i] = mutt_iconv_open (tocodes[i], "UTF-8", 0); else /* Special case for conversion to UTF-8 */ - cd[i] = (iconv_t) (-1), score[i] = -1; + cd[i] = MUTT_ICONV_ERROR, score[i] = -1; rewind (file); ibl = 0; @@ -637,7 +637,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode, /* Convert from UTF-8 */ for (i = 0; i < ncodes; i++) - if (cd[i] != (iconv_t) (-1) && score[i] != -1) { + if (cd[i] != MUTT_ICONV_ERROR && score[i] != -1) { ub = bufu, ubl = ubl1; ob = bufo, obl = sizeof (bufo); n = my_iconv(cd[i], (ibl || ubl) ? &ub : 0, &ubl, &ob, &obl); @@ -651,7 +651,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode, update_content_info (&infos[i], &states[i], bufo, ob - bufo); } } - else if (cd[i] == (iconv_t) (-1) && score[i] == -1) + else if (cd[i] == MUTT_ICONV_ERROR && score[i] == -1) /* Special case for conversion to UTF-8 */ update_content_info (&infos[i], &states[i], bufu, ubl1); @@ -668,13 +668,13 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode, /* Find best score */ ret = -1; for (i = 0; i < ncodes; i++) { - if (cd[i] == (iconv_t) (-1) && score[i] == -1) { + if (cd[i] == MUTT_ICONV_ERROR && score[i] == -1) { /* Special case for conversion to UTF-8 */ *tocode = i; ret = 0; break; } - else if (cd[i] == (iconv_t) (-1) || score[i] == -1) + else if (cd[i] == MUTT_ICONV_ERROR || score[i] == -1) continue; else if (ret == -1 || score[i] < ret) { *tocode = i; @@ -690,7 +690,7 @@ static ssize_t convert_file_to (FILE * file, const char *fromcode, } for (i = 0; i < ncodes; i++) - if (cd[i] != (iconv_t) (-1)) + if (cd[i] != MUTT_ICONV_ERROR) iconv_close (cd[i]); iconv_close (cd1); diff --git a/state.c b/state.c index 86a75f5..2f0c8f7 100644 --- a/state.c +++ b/state.c @@ -36,7 +36,7 @@ void mutt_convert_to_state (iconv_t cd, char *bufi, ssize_t * l, STATE * s) ssize_t ibl, obl; if (!bufi) { - if (cd != (iconv_t) (-1)) { + if (cd != MUTT_ICONV_ERROR) { ob = bufo, obl = sizeof (bufo); my_iconv(cd, 0, 0, &ob, &obl); if (ob != bufo) @@ -47,7 +47,7 @@ void mutt_convert_to_state (iconv_t cd, char *bufi, ssize_t * l, STATE * s) return; } - if (cd == (iconv_t) (-1)) { + if (cd == MUTT_ICONV_ERROR) { state_prefix_put (bufi, *l, s); *l = 0; return;