2006-02-08 [colin] 2.0.0cvs34
authorColin Leroy <colin@colino.net>
Wed, 8 Feb 2006 12:56:43 +0000 (12:56 +0000)
committerColin Leroy <colin@colino.net>
Wed, 8 Feb 2006 12:56:43 +0000 (12:56 +0000)
* src/compose.c
* src/procmime.c
* src/procmime.h
Fix bug #905 (damaged attachment)
text files with raw \0's aren't really text files

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

index 5eb52e3b2271715327c29885180cbb428889f984..bee8beeb6a0f3a319d8eded34cf295c031c6c919 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-02-08 [colin]     2.0.0cvs34
+
+       * src/compose.c
+       * src/procmime.c
+       * src/procmime.h
+               Fix bug #905 (damaged attachment)
+               text files with raw \0's aren't really text files
+
 2006-02-08 [colin]     2.0.0cvs33
 
        * src/summaryview.c
index 2e08feafe02ab957eb5fdcab28571121f06b13af..e6d09596d321f1dc55d8838baf741d2b3c7cb638 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.12.2.22 -r 1.12.2.23 src/prefs_template.c;  ) > 2.0.0cvs31.patchset
 ( cvs diff -u -r 1.382.2.237 -r 1.382.2.238 src/compose.c;  cvs diff -u -r 1.50.2.19 -r 1.50.2.20 src/compose.h;  ) > 2.0.0cvs32.patchset
 ( cvs diff -u -r 1.395.2.166 -r 1.395.2.167 src/summaryview.c;  ) > 2.0.0cvs33.patchset
+( cvs diff -u -r 1.382.2.238 -r 1.382.2.239 src/compose.c;  cvs diff -u -r 1.49.2.70 -r 1.49.2.71 src/procmime.c;  cvs diff -u -r 1.17.2.13 -r 1.17.2.14 src/procmime.h;  ) > 2.0.0cvs34.patchset
index ace7c605eeaca9ba599928c4f920c635b3fd40d8..aee9b092c798211fd746e253eebbaf824f7be539 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=33
+EXTRA_VERSION=34
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index d4e3b147d9c01a67fe72b1e7da42799526b2d9b2..3dd00b0d641faa6439791ebb42f261cc7410b69b 100644 (file)
@@ -2726,6 +2726,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
        gchar *size_text;
        GtkListStore *store;
        gchar *name;
+       gboolean has_binary = FALSE;
 
        if (!is_file_exist(file)) {
                g_warning("File %s doesn't exist\n", filename);
@@ -2756,7 +2757,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                        MsgInfo *msginfo;
                        MsgFlags flags = {0, 0};
 
-                       if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
+                       if (procmime_get_encoding_for_text_file(file, &has_binary) == ENC_7BIT)
                                ainfo->encoding = ENC_7BIT;
                        else
                                ainfo->encoding = ENC_8BIT;
@@ -2772,7 +2773,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                        procmsg_msginfo_free(msginfo);
                } else {
                        if (!g_ascii_strncasecmp(content_type, "text", 4))
-                               ainfo->encoding = procmime_get_encoding_for_text_file(file);
+                               ainfo->encoding = procmime_get_encoding_for_text_file(file, &has_binary);
                        else
                                ainfo->encoding = ENC_BASE64;
                        name = g_path_get_basename(filename ? filename : file);
@@ -2787,7 +2788,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                        ainfo->encoding = ENC_BASE64;
                } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
                        ainfo->encoding =
-                               procmime_get_encoding_for_text_file(file);
+                               procmime_get_encoding_for_text_file(file, &has_binary);
                else
                        ainfo->encoding = ENC_BASE64;
                name = g_path_get_basename(filename ? filename : file);
@@ -2795,7 +2796,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
                g_free(name);
        }
 
-       if (!strcmp(ainfo->content_type, "unknown")) {
+       if (!strcmp(ainfo->content_type, "unknown") || has_binary) {
                g_free(ainfo->content_type);
                ainfo->content_type = g_strdup("application/octet-stream");
        }
index 96284a40138d375a56e9fb23e3197caeb789e66f..e153ae3ba6b3ec8138f104f47a46e6a7b3e607a2 100644 (file)
@@ -1180,7 +1180,7 @@ EncodingType procmime_get_encoding_for_charset(const gchar *charset)
                return ENC_8BIT;
 }
 
-EncodingType procmime_get_encoding_for_text_file(const gchar *file)
+EncodingType procmime_get_encoding_for_text_file(const gchar *file, gboolean *has_binary)
 {
        FILE *fp;
        guchar buf[BUFFSIZE];
@@ -1188,6 +1188,7 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file)
        size_t octet_chars = 0;
        size_t total_len = 0;
        gfloat octet_percentage;
+       gboolean force_b64 = FALSE;
 
        if ((fp = g_fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
@@ -1201,6 +1202,10 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file)
                for (p = buf, i = 0; i < len; ++p, ++i) {
                        if (*p & 0x80)
                                ++octet_chars;
+                       if (*p == '\0') {
+                               force_b64 = TRUE;
+                               *has_binary = TRUE;
+                       }
                }
                total_len += len;
        }
@@ -1216,7 +1221,7 @@ EncodingType procmime_get_encoding_for_text_file(const gchar *file)
                    "8bit chars: %d / %d (%f%%)\n", octet_chars, total_len,
                    100.0 * octet_percentage);
 
-       if (octet_percentage > 0.20) {
+       if (octet_percentage > 0.20 || force_b64) {
                debug_print("using BASE64\n");
                return ENC_BASE64;
        } else if (octet_chars > 0) {
index 0200356368c54f341ff124541a3e6338b47daf90..374b66408f7665e1638de46bb2c3a201dcc8a8df 100644 (file)
@@ -207,7 +207,8 @@ gchar *procmime_get_mime_type               (const gchar    *filename);
 GList *procmime_get_mime_type_list     (void);
 
 EncodingType procmime_get_encoding_for_charset (const gchar    *charset);
-EncodingType procmime_get_encoding_for_text_file(const gchar   *file);
+EncodingType procmime_get_encoding_for_text_file(const gchar   *file,
+                                                gboolean       *has_binary);
 const gchar *procmime_get_encoding_str         (EncodingType    encoding);
 MimeInfo *procmime_scan_file                   (const gchar    *filename);
 MimeInfo *procmime_scan_queue_file             (const gchar    *filename);