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

[PATCH]To make mutt can display some 8bits characters correctly



Hi!
  I am a mutt user. My native language is chinese.
  I found some rfc2047 encoded characters can not
  display correctly sometimes.

  At last I found it is perhapsly related to some bugs of some 
  broken email client.

  One bug is that some email clients will rfc2047 encode
  filenames of attachments if these names contain 8bits
  characters. Now mutt doesn't deal with it.I don't know whether
  the encoding of filename confirms to rfc.

  Anoter bug is that some email clients will use such encoding
  string like this:

  ?GB2312?Q?Re: =C7=EB=CE=CA=D3=B2=C5=CC=CB=F0=BB=B5=C1=F7=B3=CC=CA=C7??=

  1. There are space characters in the middle of encoded strings.
  2. It ends with "??=" but not "?="

  Since to fix the email clients of  others is impossile for me.
  I have to "fix" mutt .

  The following is my patch. I think the change to parse.c should be
  harmless for others. I don't know wether the change to rfc2047.c is
  harmless for others.

diff -ur mutt-1.5.5.1/parse.c mutt-1.5.5.1-new/parse.c
--- mutt-1.5.5.1/parse.c        Wed Nov  5 17:41:33 2003
+++ mutt-1.5.5.1-new/parse.c    Thu Feb 12 17:51:52 2004
@@ -318,8 +318,10 @@
     /* Some pre-RFC1521 gateways still use the "name=filename" convention,
      * but if a filename has already been set in the content-disposition,
      * let that take precedence, and don't set it here */
-    if ((pc = mutt_get_parameter( "name", ct->parameter)) != 0 && 
!ct->filename)
+    if ((pc = mutt_get_parameter( "name", ct->parameter)) != 0 && 
!ct->filename){
       ct->filename = safe_strdup(pc);
+      rfc2047_decode (&ct->filename); //fix for some "broken" mail clients
+    }
     
 #ifdef SUN_ATTACHMENT
     /* this is deep and utter perversion */
@@ -400,8 +402,10 @@
   {
     s++;
     SKIPWS (s);
-    if ((s = mutt_get_parameter ("filename", (parms = parse_parameters (s)))) 
!= 0)
+    if ((s = mutt_get_parameter ("filename", (parms = parse_parameters (s)))) 
!= 0){
       mutt_str_replace (&ct->filename, s);
+      rfc2047_decode(&ct->filename);
+    }
     if ((s = mutt_get_parameter ("name", parms)) != 0)
       ct->form_name = safe_strdup (s);
     mutt_free_parameter (&parms);
diff -ur mutt-1.5.5.1/rfc2047.c mutt-1.5.5.1-new/rfc2047.c
--- mutt-1.5.5.1/rfc2047.c      Wed Nov  5 17:41:33 2003
+++ mutt-1.5.5.1-new/rfc2047.c  Thu Feb 12 19:05:40 2004
@@ -691,9 +691,9 @@
       ;
     if (q[0] != '?' || !strchr ("BbQq", q[1]) || q[2] != '?')
       continue;
-    for (q = q + 3; 0x20 < *q && *q < 0x7f && *q != '?'; q++)
+    for (q = q + 3; 0x20 <= *q && *q < 0x7f && *q != '?'; q++)
       ;
-    if (q[0] != '?' || q[1] != '=')
+    if (q[0] != '?' || (q[1] != '=') && (q[1]!='?'||q[2]!='='))
     {
       --q;
       continue;