Do not try to handle quotes in text attachments.
[claws.git] / src / textview.c
index c35dbf9d3769c07c80faa5a122eb4de463fdbc18..c9be5d8ad058810c328b1defdd202d3690ee9716 100644 (file)
@@ -123,6 +123,20 @@ static GdkColor diff_hunk_color = {
        (gushort)0
 };
 
+static GdkColor tags_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor tags_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GdkCursor *hand_cursor = NULL;
 static GdkCursor *text_cursor = NULL;
 static GdkCursor *watch_cursor= NULL;
@@ -401,26 +415,8 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
 {
        GtkTextBuffer *buffer;
        GtkTextTag *tag, *qtag;
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow, black;
-       static gboolean color_init = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint16)0xf5, (guint16)0xf6, (guint16)0xbe };
-       static GdkColor black = { (guint32)0, (guint16)0x0, (guint16)0x0, (guint16)0x0 };
-#endif
        static PangoFontDescription *font_desc, *bold_font_desc;
        
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       if (!color_init) {
-               gdk_color_parse("#f5f6be", &yellow);
-               gdk_color_parse("#000000", &black);
-               color_init = gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &yellow, FALSE, TRUE);
-               color_init &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &black, FALSE, TRUE);
-       }
-#endif
-
        if (!font_desc)
                font_desc = pango_font_description_from_string
                        (NORMAL_FONT);
@@ -488,8 +484,8 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
                                NULL);
        }
        gtk_text_buffer_create_tag(buffer, "tags",
-                       "foreground-gdk", &black,
-                       "paragraph-background-gdk", &yellow,
+                       "foreground-gdk", &tags_color,
+                       "paragraph-background-gdk", &tags_bgcolor,
                        NULL);
        gtk_text_buffer_create_tag(buffer, "emphasis",
                        "foreground-gdk", &emphasis_color,
@@ -565,6 +561,7 @@ static void textview_update_message_colors(TextView *textview)
        quote_colors[0] = quote_colors[1] = quote_colors[2] = black;
        uri_color = emphasis_color = signature_color = diff_added_color =
                diff_deleted_color = diff_hunk_color = black;
+       tags_bgcolor = tags_color = black;
 
        if (prefs_common.enable_color) {
                /* grab the quote colors, converting from an int to a GdkColor */
@@ -612,6 +609,11 @@ static void textview_update_message_colors(TextView *textview)
        CHANGE_TAG_COLOR("diff-add-file", &diff_added_color, NULL);
        CHANGE_TAG_COLOR("diff-del-file", &diff_deleted_color, NULL);
        CHANGE_TAG_COLOR("diff-hunk", &diff_hunk_color, NULL);
+
+       gtkut_convert_int_to_gdk_color(prefs_common.tags_bgcolor,
+                                          &tags_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.tags_color,
+                                          &tags_color);
 }
 #undef CHANGE_TAG_COLOR
 
@@ -1041,7 +1043,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        FILE *tmpfp;
        gchar buf[BUFFSIZE];
        CodeConverter *conv;
-       const gchar *charset, *p, *cmd;
+       const gchar *charset;
+#ifndef G_OS_WIN32
+       const gchar *p, *cmd;
+#endif
        GSList *cur;
        gboolean continue_write = TRUE;
        size_t wrote = 0, i = 0;
@@ -1069,6 +1074,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        
        textview->is_in_signature = FALSE;
        textview->is_diff = FALSE;
+       textview->is_attachment = FALSE;;
 
        procmime_decode_content(mimeinfo);
 
@@ -1136,6 +1142,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        close(pfd[0]);
                        rc = dup(pfd[1]);
                        rc = execvp(argv[0], argv);
+                       perror("execvp");
                        close(pfd[1]);
                        g_print(_("The command to view attachment "
                                "as text failed:\n"
@@ -1161,11 +1168,20 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                g_unlink(fname);
 #endif
        } else {
+#ifndef G_OS_WIN32
 textview_default:
+#endif
                if (!g_ascii_strcasecmp(mimeinfo->subtype, "x-patch")
                                || !g_ascii_strcasecmp(mimeinfo->subtype, "x-diff"))
                        textview->is_diff = TRUE;
 
+               /* Displayed part is an attachment, but not an attached
+                * e-mail. Set a flag, so that elsewhere in the code we
+                * know not to try making collapsible quotes in it. */
+               if (mimeinfo->disposition == DISPOSITIONTYPE_ATTACHMENT &&
+                               mimeinfo->type != MIMETYPE_MESSAGE)
+                       textview->is_attachment = TRUE;
+
                if (mimeinfo->content == MIMECONTENT_MEM)
                        tmpfp = str_open_as_stream(mimeinfo->data.mem);
                else
@@ -1589,7 +1605,8 @@ static void textview_write_line(TextView *textview, const gchar *str,
           >, foo>, _> ... ok, <foo>, foo bar>, foo-> ... ng
           Up to 3 levels of quotations are detected, and each
           level is colored using a different color. */
-       if (prefs_common.enable_color 
+       if (prefs_common.enable_color
+           && !textview->is_attachment
            && line_has_quote_char(buf, prefs_common.quote_chars)) {
                real_quotelevel = get_quote_level(buf, prefs_common.quote_chars);
                quotelevel = real_quotelevel;
@@ -1632,7 +1649,7 @@ static void textview_write_line(TextView *textview, const gchar *str,
                }
        }
 
-       if (real_quotelevel > -1 && do_quote_folding) {
+       if (!textview->is_attachment && real_quotelevel > -1 && do_quote_folding) {
                if (!g_utf8_validate(buf, -1, NULL)) {
                        gchar *utf8buf = NULL;
                        utf8buf = g_malloc(BUFFSIZE);
@@ -2774,9 +2791,11 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                        } 
                        return TRUE;
                } else if (qlink && bevent->button == 1) {
-                       if (prefs_common.hide_quoted)
+                       if (prefs_common.hide_quoted) {
                                textview_toggle_quote(textview, NULL, uri, FALSE);
-                       return TRUE;
+                               return TRUE;
+                       } else
+                               return FALSE;
                } else if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
                        if (bevent->button == 3) {
                                g_object_set_data(