From fc49175b05b13d851688e5d30551933e83274c3c Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 13 Feb 2001 22:06:14 +0000 Subject: Change charset-hook's behaviour. --- charset.c | 14 +++++++------- charset.h | 9 ++++++--- gettext.c | 3 ++- gnupgparse.c | 2 +- handler.c | 2 +- imap/utf7.c | 4 ++-- rfc2047.c | 8 ++++---- rfc2231.c | 4 ++-- sendlib.c | 10 ++++++---- 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/charset.c b/charset.c index 6d36e79e..e6529be7 100644 --- a/charset.c +++ b/charset.c @@ -278,18 +278,18 @@ int iconv_close (iconv_t cd) * Like iconv_open, but canonicalises the charsets */ -iconv_t mutt_iconv_open (const char *tocode, const char *fromcode) +iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) { char tocode1[SHORT_STRING]; char fromcode1[SHORT_STRING]; char *tmp; mutt_canonical_charset (tocode1, sizeof (tocode1), tocode); - if ((tmp = mutt_charset_hook (tocode1))) + if ((flags & M_ICONV_HOOK_TO) && (tmp = mutt_charset_hook (tocode1))) mutt_canonical_charset (tocode1, sizeof (tocode1), tmp); mutt_canonical_charset (fromcode1, sizeof (fromcode1), fromcode); - if ((tmp = mutt_charset_hook (fromcode1))) + if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook (fromcode1))) mutt_canonical_charset (fromcode1, sizeof (fromcode1), tmp); return iconv_open (tocode1, fromcode1); @@ -367,7 +367,7 @@ size_t mutt_iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, * Used in rfc2047.c and rfc2231.c */ -int mutt_convert_string (char **ps, const char *from, const char *to) +int mutt_convert_string (char **ps, const char *from, const char *to, int flags) { iconv_t cd; const char *repls[] = { "\357\277\275", "?", 0 }; @@ -376,7 +376,7 @@ int mutt_convert_string (char **ps, const char *from, const char *to) if (!s || !*s) return 0; - if (to && from && (cd = mutt_iconv_open (to, from)) != (iconv_t)-1) + if (to && from && (cd = mutt_iconv_open (to, from, flags)) != (iconv_t)-1) { int len; const char *ib; @@ -437,14 +437,14 @@ struct fgetconv_not iconv_t cd; }; -FGETCONV *fgetconv_open (FILE *file, const char *from, const char *to) +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 }; if (from && to) - cd = mutt_iconv_open (to, from); + cd = mutt_iconv_open (to, from, flags); if (cd != (iconv_t)-1) { diff --git a/charset.h b/charset.h index 2d281008..ca2efbab 100644 --- a/charset.h +++ b/charset.h @@ -21,17 +21,20 @@ #include -int mutt_convert_string (char **, const char *, const char *); +int mutt_convert_string (char **, const char *, const char *, int); -iconv_t mutt_iconv_open (const char *, const char *); +iconv_t mutt_iconv_open (const char *, const char *, int); size_t mutt_iconv (iconv_t, const char **, size_t *, char **, size_t *, const char **, const char *); typedef void * FGETCONV; -FGETCONV *fgetconv_open (FILE *, const char *, const char *); +FGETCONV *fgetconv_open (FILE *, const char *, const char *, int); int fgetconv (FGETCONV *); void fgetconv_close (FGETCONV **); void mutt_set_langinfo_charset (void); +#define M_ICONV_HOOK_FROM 1 +#define M_ICONV_HOOK_TO 2 + #endif /* _CHARSET_H */ diff --git a/gettext.c b/gettext.c index bd178ef5..7b5f3018 100644 --- a/gettext.c +++ b/gettext.c @@ -131,7 +131,8 @@ char *mutt_gettext (const char *message) mp = safe_malloc (sizeof (struct msg)); mp->key = safe_strdup (orig); mp->data = safe_strdup (orig); - mutt_convert_string (&mp->data, PoCharset ? PoCharset : "utf-8", MessageCharset); + mutt_convert_string (&mp->data, PoCharset ? PoCharset : "utf-8", + MessageCharset, 0); # ifdef DEBUG if (debugfile) diff --git a/gnupgparse.c b/gnupgparse.c index 88b1716e..407ace65 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -87,7 +87,7 @@ static void fix_uid (char *uid) } *d = '\0'; - if (_chs && (cd = mutt_iconv_open (_chs, "utf-8")) != (iconv_t)-1) + if (_chs && (cd = mutt_iconv_open (_chs, "utf-8", 0)) != (iconv_t)-1) { int n = s - uid + 1; /* chars available in original buffer */ char *buf; diff --git a/handler.c b/handler.c index 39172aeb..cc390d5e 100644 --- a/handler.c +++ b/handler.c @@ -1366,7 +1366,7 @@ void mutt_decode_attachment (BODY *b, STATE *s) { char *charset = mutt_get_parameter ("charset", b->parameter); if (charset && Charset) - cd = mutt_iconv_open (Charset, charset); + cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM); } fseek (s->fpin, b->offset, 0); diff --git a/imap/utf7.c b/imap/utf7.c index 93031503..fc68203b 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -248,7 +248,7 @@ void imap_utf7_encode (char **s) if (Charset) { char *t = safe_strdup (*s); - if (!mutt_convert_string (&t, Charset, "UTF-8")) + if (!mutt_convert_string (&t, Charset, "UTF-8", 0)) utf8_to_utf7 (t, strlen (t), s, 0); safe_free ((void **) &t); } @@ -259,7 +259,7 @@ void imap_utf7_decode (char **s) if (Charset) { char *t = utf7_to_utf8 (*s, strlen (*s), 0, 0); - if (t && !mutt_convert_string (&t, "UTF-8", Charset)) + if (t && !mutt_convert_string (&t, "UTF-8", Charset, 0)) { safe_free ((void **) s); *s = t; diff --git a/rfc2047.c b/rfc2047.c index a28c8db4..69159bf5 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -59,7 +59,7 @@ static size_t convert_string (const char *f, size_t flen, size_t obl, n; int e; - cd = mutt_iconv_open (to, from); + cd = mutt_iconv_open (to, from, 0); if (cd == (iconv_t)(-1)) return (size_t)(-1); obl = 4 * flen + 1; @@ -236,7 +236,7 @@ static size_t try_block (const char *d, size_t dlen, if (fromcode) { - cd = mutt_iconv_open (tocode, fromcode); + cd = mutt_iconv_open (tocode, fromcode, 0); assert (cd != (iconv_t)(-1)); ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode); if (iconv (cd, &ib, &ibl, &ob, &obl) == (size_t)(-1) || @@ -307,7 +307,7 @@ static size_t encode_block (char *s, char *d, size_t dlen, if (fromcode) { - cd = mutt_iconv_open (tocode, fromcode); + cd = mutt_iconv_open (tocode, fromcode, 0); assert (cd != (iconv_t)(-1)); ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - strlen (tocode); n1 = iconv (cd, &ib, &ibl, &ob, &obl); @@ -671,7 +671,7 @@ static int rfc2047_decode_word (char *d, const char *s, size_t len) } if (charset) - mutt_convert_string (&d0, charset, Charset); + mutt_convert_string (&d0, charset, Charset, M_ICONV_HOOK_FROM); strfcpy (d, d0, len); safe_free ((void **) &charset); safe_free ((void **) &d0); diff --git a/rfc2231.c b/rfc2231.c index fe22c218..3c39658f 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -124,7 +124,7 @@ void rfc2231_decode_parameters (PARAMETER **headp) s = rfc2231_get_charset (p->value, charset, sizeof (charset)); rfc2231_decode_one (p->value, s); - mutt_convert_string (&p->value, charset, Charset); + mutt_convert_string (&p->value, charset, Charset, M_ICONV_HOOK_FROM); *last = p; last = &p->next; @@ -293,7 +293,7 @@ static void rfc2231_join_continuations (PARAMETER **head, if (value) { if (encoded) - mutt_convert_string (&value, charset, Charset); + mutt_convert_string (&value, charset, Charset, M_ICONV_HOOK_FROM); *head = mutt_new_parameter (); (*head)->attribute = safe_strdup (attribute); (*head)->value = value; diff --git a/sendlib.c b/sendlib.c index 013eab0f..25764017 100644 --- a/sendlib.c +++ b/sendlib.c @@ -493,9 +493,11 @@ int mutt_write_mime_body (BODY *a, FILE *f) } if (a->type == TYPETEXT && (!a->noconv)) - fc = fgetconv_open (fpin, Charset, mutt_get_body_charset (send_charset, sizeof (send_charset), a)); + fc = fgetconv_open (fpin, Charset, + mutt_get_body_charset (send_charset, sizeof (send_charset), a), + M_ICONV_HOOK_TO); else - fc = fgetconv_open (fpin, 0, 0); + fc = fgetconv_open (fpin, 0, 0, 0); if (a->encoding == ENCQUOTEDPRINTABLE) encode_quoted (fc, f, mutt_is_text_type (a->type, a->subtype)); @@ -674,7 +676,7 @@ static size_t convert_file_to (FILE *file, const char *fromcode, CONTENT_STATE *states; size_t *score; - cd1 = mutt_iconv_open ("UTF-8", fromcode); + cd1 = mutt_iconv_open ("UTF-8", fromcode, M_ICONV_HOOK_FROM); if (cd1 == (iconv_t)(-1)) return -1; @@ -688,7 +690,7 @@ static size_t convert_file_to (FILE *file, const char *fromcode, memset (infos, 0, ncodes * sizeof (CONTENT)); for (i = 0; i < ncodes; i++) if (strcasecmp (tocodes[i], "UTF-8")) - cd[i] = mutt_iconv_open (tocodes[i], "UTF-8"); + 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] = (size_t)(-1); -- cgit v1.2.3