Improve how message body is quoted for reply/forward/etc.
[claws.git] / src / textview.c
index b2a0985a8284cae517d8e4aa341f98ef67668375..0a39b7a9db1245c67289c7ba5b5419df73a23dac 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto and 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,7 @@
  *
  * 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
@@ -63,7 +63,6 @@
 #include "menu.h"
 #include "image_viewer.h"
 #include "filesel.h"
-#include "base64.h"
 #include "inputdialog.h"
 #include "timing.h"
 #include "tags.h"
@@ -664,6 +663,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
        const gchar *name;
        gchar *content_type;
        gint charcount;
+
        START_TIMING("");
 
        cm_return_if_fail(mimeinfo != NULL);
@@ -747,7 +747,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        filename = procmime_get_tmp_file_name(mimeinfo);
 
                        if ((err = procmime_get_part(filename, mimeinfo)) < 0) {
-                               g_warning("Can't get the image file.(%s)", strerror(-err));
+                               g_warning("Can't get the image file.(%s)", g_strerror(-err));
                                g_free(filename);
                                END_TIMING();
                                return;
@@ -814,7 +814,17 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                if (prefs_common.display_header && (charcount > 0))
                        gtk_text_buffer_insert(buffer, &iter, "\n", 1);
 
+               if (!gtk_text_buffer_get_mark(buffer, "body_start")) {
+                       gtk_text_buffer_get_end_iter(buffer, &iter);
+                       gtk_text_buffer_create_mark(buffer, "body_start", &iter, TRUE);
+               }
+
                textview_write_body(textview, mimeinfo);
+
+               if (!gtk_text_buffer_get_mark(buffer, "body_end")) {
+                       gtk_text_buffer_get_end_iter(buffer, &iter);
+                       gtk_text_buffer_create_mark(buffer, "body_end", &iter, TRUE);
+               }
        }
        END_TIMING();
 }
@@ -1103,14 +1113,14 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
 
                if (pipe(pfd) < 0) {
                        g_snprintf(buf, sizeof(buf),
-                               "pipe failed for textview\n\n%s\n", strerror(errno));
+                               "pipe failed for textview\n\n%s\n", g_strerror(errno));
                        textview_write_line(textview, buf, conv, TRUE);
                        goto textview_default;
                }
                pid = fork();
                if (pid < 0) {
                        g_snprintf(buf, sizeof(buf),
-                               "fork failed for textview\n\n%s\n", strerror(errno));
+                               "fork failed for textview\n\n%s\n", g_strerror(errno));
                        textview_write_line(textview, buf, conv, TRUE);
                        close(pfd[0]);
                        close(pfd[1]);
@@ -1748,6 +1758,10 @@ void textview_clear(TextView *textview)
 
        buffer = gtk_text_view_get_buffer(text);
        gtk_text_buffer_set_text(buffer, "", -1);
+       if (gtk_text_buffer_get_mark(buffer, "body_start"))
+               gtk_text_buffer_delete_mark_by_name(buffer, "body_start");
+       if (gtk_text_buffer_get_mark(buffer, "body_end"))
+               gtk_text_buffer_delete_mark_by_name(buffer, "body_end");
 
        TEXTVIEW_STATUSBAR_POP(textview);
        textview_uri_list_remove_all(textview->uri_list);
@@ -2943,7 +2957,7 @@ static void open_image_cb (GtkAction *action, TextView *textview)
        gchar *cmd = NULL;
        gchar buf[1024];
        const gchar *p;
-       gchar *filename = NULL;
+       gchar *filename = NULL, *filepath = NULL;
        gchar *tmp_filename = NULL;
 
        if (uri == NULL)
@@ -2962,8 +2976,11 @@ static void open_image_cb (GtkAction *action, TextView *textview)
 
        subst_for_filename(filename);
 
+       filepath = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
+                              filename, NULL);
+
        tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
-       copy_file(tmp_filename, filename, FALSE);
+       copy_file(tmp_filename, filepath, FALSE);
        g_free(tmp_filename);
 
        cmd = mailcap_get_command_for_type("image/jpeg", filename);
@@ -2982,14 +2999,17 @@ static void open_image_cb (GtkAction *action, TextView *textview)
        }
        if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
            !strchr(p + 2, '%'))
-               g_snprintf(buf, sizeof(buf), cmd, filename);
+               g_snprintf(buf, sizeof(buf), cmd, filepath);
        else {
                g_warning("Image viewer command-line is invalid: '%s'", cmd);
+               g_free(filepath);
+               g_free(filename);
                return;
        }
 
        execute_command_line(buf, TRUE);
 
+       g_free(filepath);
        g_free(filename);
        g_free(cmd);
 
@@ -3027,7 +3047,8 @@ static void save_file_cb (GtkAction *action, TextView *textview)
                filepath = g_strconcat(prefs_common.attach_save_dir,
                                       G_DIR_SEPARATOR_S, filename, NULL);
        else
-               filepath = g_strdup(filename);
+               filepath = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
+                                      filename, NULL);
 
        g_free(filename);