Fix #2927 'Optional case insensitivity for the attach-warner-plugin'
authorRicardo Mones <ricardo@mones.org>
Mon, 20 May 2013 20:59:57 +0000 (22:59 +0200)
committerRicardo Mones <ricardo@mones.org>
Mon, 20 May 2013 22:50:47 +0000 (00:50 +0200)
Based on original patch provided by Henri Bauer <henri.bauer@voila.fr>

src/matcher.c
src/matcher.h
src/plugins/address_keeper/address_keeper.c
src/plugins/attachwarner/attachwarner.c
src/plugins/attachwarner/attachwarner_prefs.c
src/plugins/attachwarner/attachwarner_prefs.h

index c95655cf49889b1e5a05b94d0ff8c7bbb3d5f4bc..93df515100e2eb2b53b66afdc04f6cfe35f25da4 100644 (file)
@@ -1188,10 +1188,12 @@ static gchar *build_complete_regexp(gchar **strings)
  *
  *\param       lines String with "\n"-separated expressions
  *\param       bool_and Operator
+ *\param       case_sensitive If the matching is case sensitive or not
  *
  *\return      MatcherList * New matcher list
  */
-MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
+MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and, 
+                                       gboolean case_sensitive)
 {
        MatcherProp *m = NULL;
        GSList *matchers = NULL;
@@ -1202,8 +1204,9 @@ MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
        expr = build_complete_regexp(strings);
        debug_print("building matcherprop for expr '%s'\n", expr?expr:"NULL");
        
-       m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_REGEXP, 
-                           expr, 0);
+       m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL,
+                       case_sensitive? MATCHTYPE_REGEXP: MATCHTYPE_REGEXPCASE,
+                       expr, 0);
        if (m == NULL) {
                /* print error message */
                debug_print("failed to allocate memory for matcherprop\n");
@@ -1215,8 +1218,9 @@ MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
 #else
        int i = 0;
        while (strings && strings[i] && *strings[i]) {
-               m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_MATCHCASE, 
-                           strings[i], 0);
+               m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL,
+                       case_sensitive? MATCHTYPE_MATCH: MATCHTYPE_MATCHCASE
+                       strings[i], 0);
                if (m == NULL) {
                        /* print error message */
                        debug_print("failed to allocate memory for matcherprop\n");
index 13542a68007714f786a3daae7d51525654551c67..9a6c89816f5eadf81461120c9edd3347075b3231 100644 (file)
@@ -163,7 +163,8 @@ MatcherProp *matcherprop_copy               (const MatcherProp *src);
 MatcherList * matcherlist_new          (GSList         *matchers, 
                                         gboolean       bool_and);
 MatcherList * matcherlist_new_from_lines(gchar         *lines,
-                                        gboolean       bool_and);
+                                        gboolean       bool_and,
+                                        gboolean       case_sensitive);
 void matcherlist_free                  (MatcherList    *cond);
 
 MatcherList *matcherlist_parse         (gchar          **str);
index be4f05338deb4d82400b51d0b93fa5aa8f9d0bce..673fe120a66aa709640d171655a2b414c4c7f2e5 100644 (file)
@@ -197,7 +197,7 @@ static gboolean addrk_before_send_hook(gpointer source, gpointer data)
 
        if (addkeeperprefs.block_matching_addrs != NULL
                        && addkeeperprefs.block_matching_addrs[0] != '\0') {
-               blocked = matcherlist_new_from_lines(addkeeperprefs.block_matching_addrs, FALSE);
+               blocked = matcherlist_new_from_lines(addkeeperprefs.block_matching_addrs, FALSE, TRUE);
                if (blocked == NULL)
                        g_warning("couldn't allocate matcher");
        }
index e4d19a9e8a0ce7ad28e9e137f85b3697f6f54a28..f5160dc4f11e0da5469d58cbd434fd7b0ca5daf2 100644 (file)
@@ -111,7 +111,7 @@ AttachWarnerMention *are_attachments_mentioned(Compose *compose)
        AttachWarnerMention *mention = NULL;
        MatcherList *matchers = NULL;
 
-       matchers = matcherlist_new_from_lines(attwarnerprefs.match_strings, FALSE);
+       matchers = matcherlist_new_from_lines(attwarnerprefs.match_strings, FALSE, attwarnerprefs.case_sensitive);
 
        if (matchers == NULL) {
                g_warning("couldn't allocate matcher");
index b1b7bf781a6bb1ee7c0bc273e62282b805a97e31..82fe167cfd9bda589a3145b1cf6c95666d6aa4cd 100644 (file)
@@ -45,6 +45,7 @@ struct AttachWarnerPrefsPage
        GtkWidget *skip_quotes_checkbox;
        GtkWidget *skip_forwards_and_redirections;
        GtkWidget *skip_signature;
+       GtkWidget *case_sensitive_checkbox;
 };
 
 struct AttachWarnerPrefsPage attwarnerprefs_page;
@@ -58,6 +59,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"skip_signature", "TRUE", &attwarnerprefs.skip_signature, P_BOOL,
         NULL, NULL, NULL},
+       {"case_sensitive", "TRUE", &attwarnerprefs.case_sensitive, P_BOOL,
+        NULL, NULL, NULL},
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
 
@@ -73,6 +76,7 @@ static void attwarner_prefs_create_widget_func(PrefsPage * _page,
        GtkWidget *skip_quotes_checkbox;
        GtkWidget *skip_fwd_redir_checkbox;
        GtkWidget *skip_signature_checkbox;
+       GtkWidget *case_sensitive_checkbox;
 
        vbox = gtk_vbox_new(FALSE, 6);
        hbox = gtk_hbox_new(FALSE, 6);
@@ -80,8 +84,18 @@ static void attwarner_prefs_create_widget_func(PrefsPage * _page,
        label = gtk_label_new(_("Warn when matching the following regular expressions:\n(one per line)"));
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 6);
+
+       case_sensitive_checkbox = gtk_check_button_new_with_label(_("Case sensitive"));
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(case_sensitive_checkbox),
+                attwarnerprefs.case_sensitive);
+       gtk_box_pack_start(GTK_BOX(vbox), case_sensitive_checkbox, FALSE, FALSE, 0);
+       gtk_widget_show(case_sensitive_checkbox);
+
+       CLAWS_SET_TIP(case_sensitive_checkbox,
+                       _("Case sensitive when matching for the regular expressions in the list"));
+       page->case_sensitive_checkbox = case_sensitive_checkbox;
+
        page->regexp_text = gtk_text_view_new();
-       
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(page->regexp_text));
        gtk_text_buffer_set_text(buffer, attwarnerprefs.match_strings, -1);
        
@@ -125,7 +139,7 @@ static void attwarner_prefs_create_widget_func(PrefsPage * _page,
        CLAWS_SET_TIP(skip_signature_checkbox,
                        _("Exclude lines from the first signature-separator onwards from checking for the regular expressions above"));
        page->skip_signature = skip_signature_checkbox;
-
+       
        gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 6);
        gtk_widget_show_all(hbox);
        
@@ -186,6 +200,8 @@ static void attwarner_prefs_save_func(PrefsPage * _page)
                        (GTK_TOGGLE_BUTTON(page->skip_forwards_and_redirections));
        attwarnerprefs.skip_signature = gtk_toggle_button_get_active
                        (GTK_TOGGLE_BUTTON(page->skip_signature));
+       attwarnerprefs.case_sensitive = gtk_toggle_button_get_active
+                       (GTK_TOGGLE_BUTTON(page->case_sensitive_checkbox));
 
        attwarner_save_config();
        g_free(attwarnerprefs.match_strings);
index 942a21c3557f6b040fce51dd2ff7745437981dd0..0d5b27e6f880f55ab39e9e3959206f09c5e7175c 100644 (file)
@@ -31,6 +31,7 @@ struct _AttachWarnerPrefs
        gboolean         skip_quotes;
        gboolean         skip_forwards_and_redirections;
        gboolean         skip_signature;
+       gboolean         case_sensitive;
 };
 
 extern AttachWarnerPrefs attwarnerprefs;