<<< Date Index >>>     <<< Thread Index >>>

For 1.5.9: assumed_charset



Here is the assumed_charset patch without file_charset.
Now it's only 8.5K.

-- 
tamo
Index: PATCHES
===================================================================
RCS file: /home/roessler/cvs/mutt/PATCHES,v
retrieving revision 3.6
diff -u -u -r3.6 PATCHES
--- PATCHES     9 Dec 2002 17:44:54 -0000       3.6
+++ PATCHES     18 Feb 2005 13:09:09 -0000
@@ -0,0 +1 @@
+patch-1.5.8.tt+tamo.assumed.4
Index: charset.c
===================================================================
RCS file: /home/roessler/cvs/mutt/charset.c,v
retrieving revision 3.9
diff -u -u -r3.9 charset.c
--- charset.c   12 Feb 2005 19:52:28 -0000      3.9
+++ charset.c   18 Feb 2005 13:09:10 -0000
@@ -591,3 +591,93 @@
     iconv_close (fc->cd);
   FREE (_fc);
 }
+
+char *mutt_get_first_charset (const char *charset)
+{
+  static char fcharset[SHORT_STRING];
+  const char *next;
+
+  if (!charset || !*charset)
+    return NONULL (charset);
+  if (!(next = strchr (charset, ':')))
+    return charset;
+  strfcpy (fcharset, charset, next - charset + 1);
+  return fcharset;
+}
+
+static size_t convert_string (ICONV_CONST char *src, size_t srclen,
+                             const char *from, const char *to,
+                             char **dst, size_t *dstlen)
+{
+  iconv_t cd;
+  char *buf, *ob;
+  size_t obl, n;
+  int e;
+
+  if (!from || !(*from))
+  {
+    *dst = safe_strdup (src);
+    *dstlen = mutt_strlen (src);
+    return 0;
+  }
+
+  cd = mutt_iconv_open (to, from, M_ICONV_HOOK_FROM);
+  if (cd == (iconv_t)(-1))
+    return (size_t)(-1);
+  obl = 4 * srclen + 1;
+  ob = buf = safe_malloc (obl);
+  n = iconv (cd, &src, &srclen, &ob, &obl);
+  if (n == (size_t)(-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t)(-1))
+  {
+    e = errno;
+    FREE (&buf);
+    iconv_close (cd);
+    errno = e;
+    return (size_t)(-1);
+  }
+  *ob = '\0';
+  
+  *dstlen = ob - buf;
+
+  safe_realloc (&buf, ob - buf + 1);
+  *dst = buf;
+  iconv_close (cd);
+
+  return n;
+}
+
+int mutt_convert_nomime_string (char **ps)
+{
+  const char *c, *c1;
+
+  for (c = NONULL (AssumedCharset); c; c = c1 ? c1 + 1 : 0)
+  {
+    char *u = *ps;
+    char *s;
+    char *fromcode;
+    size_t m, n;
+    size_t ulen = mutt_strlen (*ps);
+    size_t slen;
+
+    if (!u || !*u)
+      return 0;
+
+    c1 = strchr (c, ':');
+    n = c1 ? c1 - c : mutt_strlen (c);
+    fromcode = safe_malloc (n + 1);
+    strfcpy (fromcode, c, n + 1);
+    m = convert_string (u, ulen, fromcode, Charset, &s, &slen);
+    FREE (&fromcode);
+    if (m != (size_t)(-1))
+    {
+      FREE (ps);
+      *ps = s;
+      return 0;
+    }
+  }
+  mutt_convert_string (ps,
+    (const char *) mutt_get_first_charset (AssumedCharset),
+    Charset, M_ICONV_HOOK_FROM);
+  return -1;
+}
+
Index: charset.h
===================================================================
RCS file: /home/roessler/cvs/mutt/charset.h,v
retrieving revision 3.6
diff -u -u -r3.6 charset.h
--- charset.h   3 Mar 2003 14:01:06 -0000       3.6
+++ charset.h   18 Feb 2005 13:09:10 -0000
@@ -35,6 +35,8 @@
 #endif
 
 int mutt_convert_string (char **, const char *, const char *, int);
+char *mutt_get_first_charset (const char *);
+int mutt_convert_nomime_string (char **);
 
 iconv_t mutt_iconv_open (const char *, const char *, int);
 size_t mutt_iconv (iconv_t, ICONV_CONST char **, size_t *, char **, size_t *, 
ICONV_CONST char **, const char *);
Index: globals.h
===================================================================
RCS file: /home/roessler/cvs/mutt/globals.h,v
retrieving revision 3.16
diff -u -u -r3.16 globals.h
--- globals.h   12 Feb 2005 20:08:19 -0000      3.16
+++ globals.h   18 Feb 2005 13:09:11 -0000
@@ -32,6 +32,7 @@
 
 WHERE char *AliasFile;
 WHERE char *AliasFmt;
+WHERE char *AssumedCharset;
 WHERE char *AttachSep;
 WHERE char *Attribution;
 WHERE char *AttachFormat;
Index: handler.c
===================================================================
RCS file: /home/roessler/cvs/mutt/handler.c,v
retrieving revision 3.19
diff -u -u -r3.19 handler.c
--- handler.c   3 Feb 2005 17:01:43 -0000       3.19
+++ handler.c   18 Feb 2005 13:09:12 -0000
@@ -1725,11 +1725,16 @@
   int istext = mutt_is_text_part (b);
   iconv_t cd = (iconv_t)(-1);
 
-  if (istext && s->flags & M_CHARCONV)
+  if (istext)
   {
-    char *charset = mutt_get_parameter ("charset", b->parameter);
-    if (charset && Charset)
-      cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM);
+    if(s->flags & M_CHARCONV)
+    {
+      char *charset = mutt_get_parameter ("charset", b->parameter);
+      if (!charset && AssumedCharset && *AssumedCharset)
+        charset = mutt_get_first_charset (AssumedCharset);
+      if (charset && Charset)
+        cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM);
+    }
   }
 
   fseek (s->fpin, b->offset, 0);
Index: init.h
===================================================================
RCS file: /home/roessler/cvs/mutt/init.h,v
retrieving revision 3.66
diff -u -u -r3.66 init.h
--- init.h      12 Feb 2005 20:08:19 -0000      3.66
+++ init.h      18 Feb 2005 13:09:13 -0000
@@ -185,6 +185,22 @@
   ** If set, Mutt will prompt you for carbon-copy (Cc) recipients before
   ** editing the body of an outgoing message.
   */  
+  { "assumed_charset", DT_STR, R_NONE, UL &AssumedCharset, UL "" },
+  /*
+  ** .pp
+  ** This variable is a colon-separated list of character encoding 
+  ** schemes for messages without character encoding indication.
+  ** Header field values without character encoding indication would be 
+  ** assumed to be written in one of this list.
+  ** Message body content without character encoding indication would be
+  ** assumed to be written in the first entry of this list.
+  ** By default, any header fields and message body with no charset 
+  ** indication are assumed to be in $$charset.
+  ** .pp
+  ** For example, Japanese users might prefer this setting:
+  ** .pp
+  **   set assumed_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"
+  */
   { "attach_format",   DT_STR,  R_NONE, UL &AttachFormat, UL "%u%D%I %t%4n 
%T%.40d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] " },
   /*
   ** .pp
Index: parse.c
===================================================================
RCS file: /home/roessler/cvs/mutt/parse.c,v
retrieving revision 3.14
diff -u -u -r3.14 parse.c
--- parse.c     3 Feb 2005 17:01:43 -0000       3.14
+++ parse.c     18 Feb 2005 13:09:13 -0000
@@ -213,9 +213,21 @@
 
       if (*s == '"')
       {
+       int state_ascii = 1;
        s++;
-       for (i=0; *s && *s != '"' && i < sizeof (buffer) - 1; i++, s++)
+       for (i=0; *s && i < sizeof (buffer) - 1; i++, s++)
        {
+         if (*s == 0x1b)
+         {
+           if (s[1] == '(' && (s[2] == 'B' || s[2] == 'J'))
+             state_ascii = 1;
+           else
+             state_ascii = 0;
+         }
+         if (state_ascii)
+         {
+           if (*s == '"')
+             break;
          if (*s == '\\')
          {
            /* Quote the next character */
@@ -226,6 +238,9 @@
          else
            buffer[i] = *s;
        }
+         else
+           buffer[i] = *s;
+       }
        buffer[i] = 0;
        if (*s)
          s++; /* skip over the " */
@@ -384,7 +399,10 @@
   if (ct->type == TYPETEXT)
   {
     if (!(pc = mutt_get_parameter ("charset", ct->parameter)))
-      mutt_set_parameter ("charset", "us-ascii", &ct->parameter);
+      mutt_set_parameter ("charset", (AssumedCharset && *AssumedCharset) ?
+                         (const char *) mutt_get_first_charset 
(AssumedCharset) :
+                         "us-ascii",
+                         &ct->parameter);
   }
 
 }
Index: rfc2047.c
===================================================================
RCS file: /home/roessler/cvs/mutt/rfc2047.c,v
retrieving revision 3.8
diff -u -u -r3.8 rfc2047.c
--- rfc2047.c   3 Feb 2005 17:01:44 -0000       3.8
+++ rfc2047.c   18 Feb 2005 13:09:13 -0000
@@ -733,6 +733,21 @@
     if (!(p = find_encoded_word (s, &q)))
     {
       /* no encoded words */
+      n = mutt_strlen (s);
+      if (AssumedCharset && *AssumedCharset)
+      {
+       char *t;
+       size_t tlen;
+
+       t = safe_malloc (n + 1);
+       strfcpy (t, s, n + 1);
+       mutt_convert_nomime_string (&t);
+       tlen = mutt_strlen (t);
+       strncpy (d, t, tlen); 
+       d += tlen;
+       FREE (&t);
+       break;
+      }
       strncpy (d, s, dlen);
       d += dlen;
       break;
@@ -770,7 +785,7 @@
 {
   while (a)
   {
-    if (a->personal && strstr (a->personal, "=?") != NULL)
+    if (a->personal)
       rfc2047_decode (&a->personal);
 #ifdef EXACT_ADDRESS
     if (a->val && strstr (a->val, "=?") != NULL)
Index: rfc2231.c
===================================================================
RCS file: /home/roessler/cvs/mutt/rfc2231.c,v
retrieving revision 3.5
diff -u -u -r3.5 rfc2231.c
--- rfc2231.c   3 Feb 2005 17:01:44 -0000       3.5
+++ rfc2231.c   18 Feb 2005 13:09:14 -0000
@@ -117,6 +117,8 @@
 
       if (option (OPTRFC2047PARAMS) && p->value && strstr (p->value, "=?"))
        rfc2047_decode (&p->value);
+      else if (AssumedCharset && *AssumedCharset)
+       mutt_convert_nomime_string (&p->value);
 
       *last = p;
       last = &p->next;