add Phishing warning when copying url
[claws.git] / src / textview.c
index ee3c213904c5b9f4dfeaf5af8e82bb1ead30fcd0..a76d88e2ea396af6d6e6b9d818214e6d935f6109 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
  *
  * 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
@@ -718,27 +718,17 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        GdkPixbuf *pixbuf;
                        GError *error = NULL;
                        ClickableText *uri;
-                       GInputStream *stream;
 
                        START_TIMING("inserting image");
 
-                       stream = procmime_get_part_as_inputstream(mimeinfo, &error);
-                       if (error != NULL) {
-                               g_warning("Can't get the image file: %s", error->message);
-                               g_error_free(error);
-                               END_TIMING();
-                               return;
-                       }
-
-                       pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, &error);
-                       g_object_unref(stream);
-
+                       pixbuf = procmime_get_part_as_pixbuf(mimeinfo, &error);
                        if (error != NULL) {
                                g_warning("Can't load the image: %s\n", error->message);
                                g_error_free(error);
                                END_TIMING();
                                return;
                        }
+
                        if (textview->stop_loading) {
                                END_TIMING();
                                return;
@@ -1046,10 +1036,11 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        textview->is_in_signature = FALSE;
        textview->is_diff = FALSE;
        textview->is_attachment = FALSE;;
+       textview->is_in_git_patch = FALSE;
 
        procmime_decode_content(mimeinfo);
 
-       account_signatures_matchlist_create();
+       account_sigsep_matchlist_create();
 
        if (!g_ascii_strcasecmp(mimeinfo->subtype, "html") &&
            prefs_common.render_html) {
@@ -1132,7 +1123,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                                claws_fclose(tmpfp);
                                waitpid(pid, pfd, 0);
                                g_unlink(fname);
-                               account_signatures_matchlist_delete();
+                               account_sigsep_matchlist_delete();
                                return;
                        }
                }
@@ -1162,13 +1153,13 @@ textview_default:
                        tmpfp = claws_fopen(mimeinfo->data.filename, "rb");
                if (!tmpfp) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
-                       account_signatures_matchlist_delete();
+                       account_sigsep_matchlist_delete();
                        return;
                }
                if (fseek(tmpfp, mimeinfo->offset, SEEK_SET) < 0) {
                        FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
                        claws_fclose(tmpfp);
-                       account_signatures_matchlist_delete();
+                       account_sigsep_matchlist_delete();
                        return;
                }
                debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
@@ -1178,7 +1169,7 @@ textview_default:
                        textview_write_line(textview, buf, conv, TRUE);
                        if (textview->stop_loading) {
                                claws_fclose(tmpfp);
-                               account_signatures_matchlist_delete();
+                               account_sigsep_matchlist_delete();
                                return;
                        }
                        wrote += ftell(tmpfp)-i;
@@ -1191,7 +1182,7 @@ textview_default:
                claws_fclose(tmpfp);
        }
 
-       account_signatures_matchlist_delete();
+       account_sigsep_matchlist_delete();
 
        conv_code_converter_destroy(conv);
        procmime_force_encoding(0);
@@ -1229,7 +1220,7 @@ static void textview_show_html(TextView *textview, FILE *fp,
        parser = sc_html_parser_new(fp, conv);
        cm_return_if_fail(parser != NULL);
 
-       account_signatures_matchlist_create();
+       account_sigsep_matchlist_create();
 
        while ((str = sc_html_parse(parser)) != NULL) {
                if (parser->state == SC_HTML_HREF) {
@@ -1255,13 +1246,13 @@ static void textview_show_html(TextView *textview, FILE *fp,
                if (lines % 500 == 0)
                        GTK_EVENTS_FLUSH();
                if (textview->stop_loading) {
-                       account_signatures_matchlist_delete();
+                       account_sigsep_matchlist_delete();
                        return;
                }
        }
        textview_write_line(textview, "\n", NULL, FALSE);
 
-       account_signatures_matchlist_delete();
+       account_sigsep_matchlist_delete();
 
        sc_html_parser_destroy(parser);
 }
@@ -1276,7 +1267,7 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
        parser = ertf_parser_new(fp, conv);
        cm_return_if_fail(parser != NULL);
 
-       account_signatures_matchlist_create();
+       account_sigsep_matchlist_create();
 
        while ((str = ertf_parse(parser)) != NULL) {
                textview_write_line(textview, str, NULL, FALSE);
@@ -1284,12 +1275,12 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
                if (lines % 500 == 0)
                        GTK_EVENTS_FLUSH();
                if (textview->stop_loading) {
-                       account_signatures_matchlist_delete();
+                       account_sigsep_matchlist_delete();
                        return;
                }
        }
        
-       account_signatures_matchlist_delete();
+       account_sigsep_matchlist_delete();
 
        ertf_parser_destroy(parser);
 }
@@ -1619,7 +1610,7 @@ static void textview_write_line(TextView *textview, const gchar *str,
        }
 
        if (prefs_common.enable_color) {
-               if (textview->is_diff) {
+               if (textview->is_diff || textview->is_in_git_patch) {
                        if (strncmp(buf, "+++ ", 4) == 0)
                                fg_color = "diff-add-file";
                        else if (buf[0] == '+')
@@ -1629,13 +1620,21 @@ static void textview_write_line(TextView *textview, const gchar *str,
                        else if (buf[0] == '-')
                                fg_color = "diff-del";
                        else if (strncmp(buf, "@@ ", 3) == 0 &&
-                                       strcmp(buf+strlen(buf)-4, " @@\n") == 0)
+                                strstr(&buf[3], " @@"))
                                fg_color = "diff-hunk";
-               } else if (account_signatures_matchlist_str_found(buf,"%s\n")
-                               || account_signatures_matchlist_str_found(buf, "- %s\n")
+
+                       if (account_sigsep_matchlist_nchar_found(buf, "%s\n")) {
+                               textview->is_in_git_patch = FALSE;
+                               textview->is_in_signature = TRUE;
+                               fg_color = "signature";
+                       }
+               } else if (account_sigsep_matchlist_str_found(buf, "%s\n")
+                               || account_sigsep_matchlist_str_found(buf, "- %s\n")
                                || textview->is_in_signature) {
                        fg_color = "signature";
                        textview->is_in_signature = TRUE;
+               } else if (strncmp(buf, "diff --git ", 11) == 0) {
+                       textview->is_in_git_patch = TRUE;
                }
        }
 
@@ -2977,16 +2976,16 @@ static void copy_uri_cb (GtkAction *action, TextView *textview)
        const gchar *raw_url =  g_object_get_data(G_OBJECT(textview->link_popup_menu),
                                           "raw_url");
        if (uri) {
-               gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), uri->uri, -1);
-               gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), uri->uri, -1);
-               g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
-                         NULL);
+               if (textview_uri_security_check(textview, uri) == TRUE) {
+                       gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), uri->uri, -1);
+                       gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), uri->uri, -1);
+                       g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button", NULL);
+               }
        }
        if (raw_url) {
                gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), raw_url, -1);
                gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), raw_url, -1);
-               g_object_set_data(G_OBJECT(textview->link_popup_menu), "raw_url",
-                         NULL);
+               g_object_set_data(G_OBJECT(textview->link_popup_menu), "raw_url", NULL);
        }
 }