fix quoting in reply to format=flowed message
[claws.git] / src / procmime.c
index 7823ccf80526c881843d5b9328e01067a0739c68..76ee3170244f32d89a1f31a6d8f39ba4c9bd5d92 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto & The Claws Mail Team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2016 Hiroyuki Yamamoto & The Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -294,7 +293,8 @@ static int procmime_fclose(FILE *fp)
                gint llen = 0;                                                  \
                strretchomp(lastline);                                          \
                llen = strlen(lastline);                                        \
-               if (lastline[llen-1] == ' ' && strcmp(lastline,"-- ")) {        \
+               if (lastline[llen-1] == ' ' && strcmp(lastline,"-- ") &&        \
+                   strcmp(lastline,"> ")) {                                    \
                        /* this is flowed */                                    \
                        if (delsp)                                              \
                                lastline[llen-1] = '\0';                        \
@@ -324,14 +324,14 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
        gint state = 0;
        guint save = 0;
 
+       cm_return_val_if_fail(mimeinfo != NULL, FALSE);
+
        EncodingType encoding = forced_encoding 
                                ? forced_encoding
                                : mimeinfo->encoding_type;
        gchar lastline[BUFFSIZE];
        memset(lastline, 0, BUFFSIZE);
 
-       cm_return_val_if_fail(mimeinfo != NULL, FALSE);
-
        if (prefs_common.respect_flowed_format &&
            mimeinfo->type == MIMETYPE_TEXT && 
            !strcasecmp(mimeinfo->subtype, "plain")) {
@@ -360,11 +360,11 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
 
        infp = procmime_fopen(mimeinfo->data.filename, "rb");
        if (!infp) {
-               perror("fopen");
+               FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                return FALSE;
        }
        if (fseek(infp, mimeinfo->offset, SEEK_SET) < 0) {
-               perror("fseek");
+               FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                procmime_fclose(infp);
                return FALSE;
        }
@@ -381,11 +381,12 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
        tmp_file = TRUE;
        readend = mimeinfo->offset + mimeinfo->length;
 
+       *buf = '\0';
        if (encoding == ENC_QUOTED_PRINTABLE) {
                while ((ftell(infp) < readend) && (SC_FGETS(buf, sizeof(buf), infp) != NULL)) {
                        gint len;
                        len = qp_decode_line(buf);
-                       buf[len]='\0';
+                       buf[len] = '\0';
                        if (!flowed) {
                                if (SC_FWRITE(buf, 1, len, outfp) < len)
                                        err = TRUE;
@@ -409,7 +410,7 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                        uncanonicalize = TRUE;
                        tmpfp = my_tmpfile();
                        if (!tmpfp) {
-                               perror("tmpfile");
+                               perror("my_tmpfile");
                                if (tmp_file) 
                                        procmime_fclose(outfp);
                                procmime_fclose(infp);
@@ -460,8 +461,9 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                                if (SC_FPUTS(buf, outfp) == EOF)
                                        err = TRUE;
                        }
-                       procmime_fclose(tmpfp);
                }
+               if (tmpfp != outfp)
+                       procmime_fclose(tmpfp);
        } else if (encoding == ENC_X_UUENCODE) {
                gchar outbuf[BUFFSIZE];
                gint len;
@@ -862,7 +864,7 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo)
        gboolean err;
 
        if ((outfp = my_tmpfile()) == NULL) {
-               perror("tmpfile");
+               perror("my_tmpfile");
                return NULL;
        }
 #ifdef HAVE_FGETS_UNLOCKED
@@ -1120,7 +1122,8 @@ gchar *procmime_get_mime_type(const gchar *filename)
                debug_print("got type %s for %s\n", str, ext);
                g_free(ext);
                return str;
-       } 
+       }
+       g_free(ext);
        return NULL;
 #else
        gchar *str = get_content_type_from_registry_with_ext(ext);
@@ -2351,7 +2354,7 @@ static void write_parameters(gpointer key, gpointer value, gpointer user_data)
                break;
 #else
        case ENC_AS_EXTENDED:
-               debug_print("Unhandled ENC_AS_EXTENDED.");
+               debug_print("Unhandled ENC_AS_EXTENDED.\n");
                break;
 #endif
        case ENC_AS_ENCWORD: