2008-11-21 [colin] 3.6.1cvs40
authorColin Leroy <colin@colino.net>
Fri, 21 Nov 2008 17:33:04 +0000 (17:33 +0000)
committerColin Leroy <colin@colino.net>
Fri, 21 Nov 2008 17:33:04 +0000 (17:33 +0000)
* src/compose.c
* src/procmime.c
Fix bug 1776, 'use encoded name parameters
for attachments instead of ascii'.
Break the RFC 2047 by using B-encoded
filename parameter, like everyone does,
following advice from the RFC author.

ChangeLog
PATCHSETS
configure.ac
src/compose.c
src/procmime.c

index 8be3ec7..147d4b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-11-21 [colin]     3.6.1cvs40
+
+       * src/compose.c
+       * src/procmime.c
+               Fix bug 1776, 'use encoded name parameters 
+               for attachments instead of ascii'.
+               Break the RFC 2047 by using B-encoded 
+               filename parameter, like everyone does,
+               following advice from the RFC author.
+
 2008-11-21 [colin]     3.6.1cvs39
 
        * src/common/socket.c
index 249755a..f021f77 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.60.2.65 -r 1.60.2.66 src/prefs_actions.c;  ) > 3.6.1cvs37.patchset
 ( cvs diff -u -r 1.20.2.27 -r 1.20.2.28 src/mimeview.h;  cvs diff -u -r 1.19.2.29 -r 1.19.2.30 src/toolbar.h;  cvs diff -u -r 1.8.2.14 -r 1.8.2.15 src/common/session.h;  cvs diff -u -r 1.6.2.15 -r 1.6.2.16 src/common/smtp.h;  ) > 3.6.1cvs38.patchset
 ( cvs diff -u -r 1.13.2.41 -r 1.13.2.42 src/common/socket.c;  ) > 3.6.1cvs39.patchset
+( cvs diff -u -r 1.382.2.486 -r 1.382.2.487 src/compose.c;  cvs diff -u -r 1.49.2.120 -r 1.49.2.121 src/procmime.c;  ) > 3.6.1cvs40.patchset
index 5cd2e5f..62b0caf 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=6
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=39
+EXTRA_VERSION=40
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index d20fcdb..1ce4e3e 100644 (file)
@@ -5708,8 +5708,10 @@ static void compose_add_attachments(Compose *compose, MimeInfo *parent)
                        mimepart->disposition = DISPOSITIONTYPE_INLINE;
                } else {
                        if (ainfo->name) {
-                               g_hash_table_insert(mimepart->typeparameters,
-                                           g_strdup("name"), g_strdup(ainfo->name));
+                               if (mimepart->type == MIMETYPE_APPLICATION && 
+                                  !strcmp2(mimepart->subtype, "octet-stream"))
+                                       g_hash_table_insert(mimepart->typeparameters,
+                                                   g_strdup("name"), g_strdup(ainfo->name));
                                g_hash_table_insert(mimepart->dispositionparameters,
                                            g_strdup("filename"), g_strdup(ainfo->name));
                                mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
index a472df5..e235892 100644 (file)
@@ -2111,13 +2111,12 @@ typedef enum {
     ENC_AS_TOKEN,
     ENC_AS_QUOTED_STRING,
     ENC_AS_EXTENDED,
-    ENC_TO_ASCII,
+    ENC_AS_B64
 } EncodeAs;
 
 typedef struct _ParametersData {
        FILE *fp;
        guint len;
-       guint ascii_only;
        gint error;
 } ParametersData;
 
@@ -2127,12 +2126,13 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
        gchar *val = value, *valpos, *tmp;
        ParametersData *pdata = (ParametersData *)user_data;
        GString *buf = g_string_new("");
+       gint len;
 
        EncodeAs encas = ENC_AS_TOKEN;
 
        for (valpos = val; *valpos != 0; valpos++) {
-               if (!IS_ASCII(*valpos) || *valpos == '"') {
-                       encas = ENC_AS_EXTENDED;
+               if (!IS_ASCII(*valpos)) {
+                       encas = ENC_AS_B64;
                        break;
                }
            
@@ -2154,7 +2154,7 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
                case ';':
                case ':':
                case '\\':
-               case '\'':
+               case '"':
                case '/':
                case '[':
                case ']':
@@ -2165,25 +2165,11 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
                }
        }
        
-       if (encas == ENC_AS_EXTENDED && pdata->ascii_only == TRUE) 
-               encas = ENC_TO_ASCII;
-
        switch (encas) {
        case ENC_AS_TOKEN:
                g_string_append_printf(buf, "%s=%s", param, val);
                break;
 
-       case ENC_TO_ASCII:
-               tmp = g_strdup(val);
-               g_strcanon(tmp, 
-                       " ()<>@,';:\\/[]?=.0123456789"
-                       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                       "abcdefghijklmnopqrstuvwxyz",
-                       '_');
-               g_string_append_printf(buf, "%s=\"%s\"", param, tmp);
-               g_free(tmp);
-               break;
-
        case ENC_AS_QUOTED_STRING:
                g_string_append_printf(buf, "%s=\"%s\"", param, val);
                break;
@@ -2205,6 +2191,15 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
                        }
                }
                break;          
+
+       case ENC_AS_B64:
+               len = strlen(val)*6;
+               tmp = g_malloc(len+1);
+               base64_encode(tmp, val, strlen(val));
+               g_string_append_printf(buf, "%s=\"=?UTF-8?B?%s?=\"", param, tmp);
+               g_free(tmp);
+               break;
+
        }
        
        if (buf->str && strlen(buf->str)) {
@@ -2234,7 +2229,6 @@ int procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
        debug_print("procmime_write_mime_header\n");
        
        pdata->fp = fp;
-       pdata->ascii_only = FALSE;
        pdata->error = FALSE;
        for (type_table = mime_type_table; type_table->str != NULL; type_table++)
                if (mimeinfo->type == type_table->type) {
@@ -2246,7 +2240,6 @@ int procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
                                return -1;
                        }
                        pdata->len = strlen(buf);
-                       pdata->ascii_only = TRUE;
                        g_free(buf);
                        break;
                }
@@ -2290,7 +2283,6 @@ int procmime_write_mime_header(MimeInfo *mimeinfo, FILE *fp)
                g_free(buf);
 
                pdata->fp = fp;
-               pdata->ascii_only = FALSE;
                pdata->error = FALSE;
                g_hash_table_foreach(mimeinfo->dispositionparameters, write_parameters, pdata);
                if (pdata->error == TRUE) {