]> granicus.if.org Git - neomutt/commitdiff
Allow iconv-hook to use virtual charsets as targets. (closes: #1269)
authorMasayuki Moriyama <unknown>
Wed, 7 Mar 2007 01:45:49 +0000 (17:45 -0800)
committerMasayuki Moriyama <unknown>
Wed, 7 Mar 2007 01:45:49 +0000 (17:45 -0800)
ChangeLog
charset.c
hook.c
mbyte.c

index 6dc031c37988bf33879aae86f3cd882fc026aacb..fa556d18c8128ed03fe93ffafd7e42951107aa00 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-03-04 19:26 +0100  Alain Bench  <veronatif@free.fr>  (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  <brendan@kublai.com>  (607688bd77b1)
+
+       * ChangeLog, hg-commit: Add check_sec.sh call
+
 2007-03-06 15:43 -0800  Brendan Cully  <brendan@kublai.com>  (52c24a8a42a8)
 
        * hg-commit: Make hg commit less clever
index b52911ab9c6c2394d991383b205c1f2a58304959..570654ef8f074b046a365b96198c9aa5e45e183d 100644 (file)
--- 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 064910e7829b3807ee41f3ccab1a5106607f10e8..f0f98f7e8bd20183b87697dce45afbcbcfc968a4 100644 (file)
--- 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 726b0b41ca07084d717e68430118eb68d8bbf7f8..cd60dbed95e86a3a3d1fe1c4e0c52bd923c00410 100644 (file)
--- 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