From: Masayuki Moriyama Date: Wed, 7 Mar 2007 01:45:49 +0000 (-0800) Subject: Allow iconv-hook to use virtual charsets as targets. (closes: #1269) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a30e5e448c9dd9f162ddf3ce0585e6c5b06d1a2;p=neomutt Allow iconv-hook to use virtual charsets as targets. (closes: #1269) --- diff --git a/ChangeLog b/ChangeLog index 6dc031c37..fa556d18c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-03-04 19:26 +0100 Alain Bench (4dc1d87f4c25) + + * doc/manual.xml.head, init.h: Doc fixes and updates concerning hooks + + - Add reply-hooks and send2-hooks in lists they miss. + - Fix that they all take full patterns, not only regexps. + - Note interaction with $default_hook. + - Enumerate them in execution order/increasing priority. + - Add iconv-hook, remove a duplicate charset-hook. + +2007-03-06 15:45 -0800 Brendan Cully (607688bd77b1) + + * ChangeLog, hg-commit: Add check_sec.sh call + 2007-03-06 15:43 -0800 Brendan Cully (52c24a8a42a8) * hg-commit: Make hg commit less clever diff --git a/charset.c b/charset.c index b52911ab9..570654ef8 100644 --- a/charset.c +++ b/charset.c @@ -318,7 +318,10 @@ int iconv_close (iconv_t cd) /* - * Like iconv_open, but canonicalises the charsets + * Like iconv_open, but canonicalises the charsets, applies + * charset-hooks, recanonicalises, and finally applies iconv-hooks. + * Parameter flags=0 skips charset-hooks, while M_ICONV_HOOK_FROM + * applies them to fromcode. */ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) @@ -329,7 +332,8 @@ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) char *tmp; iconv_t cd; - + + /* transform to MIME preferred charset names */ mutt_canonical_charset (tocode1, sizeof (tocode1), tocode); #ifdef M_ICONV_HOOK_TO @@ -339,13 +343,22 @@ iconv_t mutt_iconv_open (const char *tocode, const char *fromcode, int flags) #endif mutt_canonical_charset (fromcode1, sizeof (fromcode1), fromcode); + + /* maybe apply charset-hooks and recanonicalise fromcode, + * but only when caller asked us to sanitize a potentialy wrong + * charset name incoming from the wild exterior. */ if ((flags & M_ICONV_HOOK_FROM) && (tmp = mutt_charset_hook (fromcode1))) mutt_canonical_charset (fromcode1, sizeof (fromcode1), tmp); - if ((cd = iconv_open (tocode1, fromcode1)) != (iconv_t) -1) + /* always apply iconv-hooks to suit system's iconv tastes */ + tocode2 = mutt_iconv_hook (tocode1); + tocode2 = (tocode2) ? tocode2 : tocode1; + fromcode2 = mutt_iconv_hook (fromcode1); + fromcode2 = (fromcode2) ? fromcode2 : fromcode1; + + /* call system iconv with names it appreciates */ + if ((cd = iconv_open (tocode2, fromcode2)) != (iconv_t) -1) return cd; - if ((tocode2 = mutt_iconv_hook (tocode1)) && (fromcode2 = mutt_iconv_hook (fromcode1))) - return iconv_open (tocode2, fromcode2); return (iconv_t) -1; } diff --git a/hook.c b/hook.c index 064910e78..f0f98f7e8 100644 --- a/hook.c +++ b/hook.c @@ -92,12 +92,16 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) memset (&pattern, 0, sizeof (pattern)); pattern.data = safe_strdup (path); } - else if (DefaultHook && !(data & (M_CHARSETHOOK | M_ACCOUNTHOOK)) + else if (DefaultHook && !(data & (M_CHARSETHOOK | M_ICONVHOOK | M_ACCOUNTHOOK)) && (!WithCrypto || !(data & M_CRYPTHOOK)) ) { char tmp[HUGE_STRING]; + /* At this stage remain only message-hooks, reply-hooks, send-hooks, + * send2-hooks, save-hooks, and fcc-hooks: All those allowing full + * patterns. If given a simple regexp, we expand $default_hook. + */ strfcpy (tmp, pattern.data, sizeof (tmp)); mutt_check_simple (tmp, sizeof (tmp), DefaultHook); FREE (&pattern.data); @@ -159,9 +163,10 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) } else { + /* Hooks not allowing full patterns: Check syntax of regexp */ rx = safe_malloc (sizeof (regex_t)); #ifdef M_CRYPTHOOK - if ((rc = REGCOMP (rx, NONULL(pattern.data), ((data & (M_CRYPTHOOK|M_CHARSETHOOK)) ? REG_ICASE : 0))) != 0) + if ((rc = REGCOMP (rx, NONULL(pattern.data), ((data & (M_CRYPTHOOK|M_CHARSETHOOK|M_ICONVHOOK)) ? REG_ICASE : 0))) != 0) #else if ((rc = REGCOMP (rx, NONULL(pattern.data), (data & (M_CHARSETHOOK|M_ICONVHOOK)) ? REG_ICASE : 0)) != 0) #endif /* M_CRYPTHOOK */ diff --git a/mbyte.c b/mbyte.c index 726b0b41c..cd60dbed9 100644 --- a/mbyte.c +++ b/mbyte.c @@ -71,8 +71,15 @@ void mutt_set_charset (char *charset) || !ascii_strcasecmp(buffer, "cp932") || !ascii_strcasecmp(buffer, "eucJP-ms")) { charset_is_ja = 1; - charset_to_utf8 = iconv_open ("UTF-8", charset); - charset_from_utf8 = iconv_open (charset, "UTF-8"); + + /* Note flags=0 to skip charset-hooks: User masters the $charset + * name, and we are sure of our "UTF-8" constant. So there is no + * possibility of wrong name that we would want to try to correct + * with a charset-hook. Or rather: If $charset was wrong, we would + * want to try to correct... $charset directly. + */ + charset_to_utf8 = mutt_iconv_open ("UTF-8", charset, 0); + charset_from_utf8 = mutt_iconv_open (charset, "UTF-8", 0); } #endif