Merge branch 'master' of ssh+git://git.claws-mail.org/home/git/claws
authorMichael Rasmussen <mir@datanom.net>
Fri, 14 Nov 2014 23:41:21 +0000 (00:41 +0100)
committerMichael Rasmussen <mir@datanom.net>
Fri, 14 Nov 2014 23:41:21 +0000 (00:41 +0100)
src/plugins/bogofilter/bogofilter.c
src/plugins/bogofilter/bogofilter.h
src/plugins/bogofilter/bogofilter_gtk.c
src/prefs_matcher.c

index d5e6076d0067291db4cd53446c84cc9fad8e78d6..66bd311e3cdf3640f1890fc235d105f27f082155 100644 (file)
@@ -88,7 +88,7 @@ static BogofilterConfig config;
 static PrefParam param[] = {
        {"process_emails", "TRUE", &config.process_emails, P_BOOL,
         NULL, NULL, NULL},
-       {"receive_spam", "TRUE", &config.receive_spam, P_BOOL,
+       {"receive_spam", "1", &config.receive_spam, P_INT,
         NULL, NULL, NULL},
        {"save_folder", NULL, &config.save_folder, P_STRING,
         NULL, NULL, NULL},
@@ -319,9 +319,16 @@ static void bogofilter_do_filter(BogoFilterData *data)
                                        if (!whitelisted && parts && parts[0] && parts[1] && *parts[1] == 'S') {
 
                                                debug_print("message %d is spam\n", msginfo->msgnum);
-                                               /* Spam will be filtered away */
-                                               data->mail_filtering_data->filtered = g_slist_prepend(
-                                                       data->mail_filtering_data->filtered, msginfo);
+                                               /* Spam will be filtered away, unless we want "mark only".
+                                                * In that case, we want it among unfiltered messages, so
+                                                * it gets processed further. */
+                                               if (config.receive_spam == SPAM_MARK_ONLY) {
+                                                       data->mail_filtering_data->unfiltered = g_slist_prepend(
+                                                               data->mail_filtering_data->unfiltered, msginfo);
+                                               } else {
+                                                       data->mail_filtering_data->filtered = g_slist_prepend(
+                                                               data->mail_filtering_data->filtered, msginfo);
+                                               }
                                                data->new_spams = g_slist_prepend(data->new_spams, msginfo);
 
                                        } else if (whitelisted && parts && parts[0] && parts[1] && 
@@ -584,11 +591,12 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                }
        }
 
-       /* flag spams and delete them if !config.receive_spam 
-        * (if config.receive_spam is set, we'll move them later) */
+       /* flag spams and delete them if config.receive_spam == 0
+        * (if config.receive_spam is set to 1, we'll move them later,
+        * mark as spam only if set to 2) */
        for (cur = new_spams; cur; cur = cur->next) {
                MsgInfo *msginfo = (MsgInfo *)cur->data;
-               if (config.receive_spam) {
+               if (config.receive_spam != SPAM_DELETE) {
                        if (config.mark_as_read)
                                procmsg_msginfo_unset_flags(msginfo, ~0, 0);
                        procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0);
@@ -627,7 +635,7 @@ static gboolean mail_filtering_hook(gpointer source, gpointer data)
                mail_filtering_data->filtered = NULL;
                mail_filtering_data->unfiltered = NULL;
        } else {
-               if (config.receive_spam && new_spams) {
+               if (config.receive_spam == SPAM_MARK_AND_SAVE && new_spams) {
                        FolderItem *save_folder = NULL;
 
                        if ((!config.save_folder) ||
index 9d92698c19a386fd43c84346a5f211040f34e3e9..ce49b575287731497b364ce921ccb7aa2321a463 100644 (file)
@@ -31,7 +31,7 @@ typedef void (*MessageCallback) (gchar *, gint total, gint done, gboolean thread
 struct _BogofilterConfig
 {
        gboolean                 process_emails;
-       gboolean                 receive_spam;
+       guint                            receive_spam;
        gchar                   *save_folder;
        guint                    max_size;
        gchar                   *bogopath;
@@ -44,6 +44,13 @@ struct _BogofilterConfig
        gboolean                 mark_as_read;
 };
 
+/* Used for values of receive_spam preference. */
+enum {
+       SPAM_DELETE,
+       SPAM_MARK_AND_SAVE,
+       SPAM_MARK_ONLY
+};
+
 BogofilterConfig *bogofilter_get_config              (void);
 void               bogofilter_save_config            (void);
 void               bogofilter_set_message_callback (MessageCallback callback);
index 82a7fc67d3687a7f755ac2280ff7a96534b3d194..6be16d2653a91c3c24d0adeb80f492dccb47b98e 100644 (file)
@@ -79,6 +79,17 @@ static void foldersel_cb(GtkWidget *widget, gpointer data)
        }
 }
 
+static void spam_handle_combobox_callback(GtkWidget *widget, gpointer user_data)
+{
+       GtkWidget *hbox = GTK_WIDGET(user_data);
+
+       if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) == 1) {
+               gtk_widget_set_sensitive(hbox, TRUE);
+       } else {
+               gtk_widget_set_sensitive(hbox, FALSE);
+       }
+}
+
 #ifndef USE_NEW_ADDRBOOK
 static void bogofilter_whitelist_ab_select_cb(GtkWidget *widget, gpointer data)
 {
@@ -115,7 +126,8 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
 
        GtkWidget *process_emails_checkbtn;
 
-       GtkWidget *save_spam_checkbtn;
+       GtkWidget *spam_handle_label;
+       GtkWidget *spam_handle_combobox;
        GtkWidget *save_spam_folder_entry;
        GtkWidget *save_spam_folder_select;
 
@@ -175,22 +187,55 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        gtk_widget_show(hbox_save_spam);
        gtk_box_pack_start (GTK_BOX (vbox2), hbox_save_spam, TRUE, TRUE, 0);
 
-       save_spam_checkbtn = gtk_check_button_new_with_label(_("Save spam in"));
-       gtk_widget_show(save_spam_checkbtn);
-       gtk_box_pack_start(GTK_BOX(hbox_save_spam), save_spam_checkbtn, FALSE, FALSE, 0);
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       spam_handle_combobox = gtk_combo_box_new_text();
+#else
+       spam_handle_combobox = gtk_combo_box_text_new();
+#endif
+
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       gtk_combo_box_append_text(GTK_COMBO_BOX(spam_handle_combobox),
+#else
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(spam_handle_combobox),
+#endif
+                       _("Delete spam"));
+
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       gtk_combo_box_append_text(GTK_COMBO_BOX(spam_handle_combobox),
+#else
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(spam_handle_combobox),
+#endif
+                       _("Save spam in..."));
+
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       gtk_combo_box_append_text(GTK_COMBO_BOX(spam_handle_combobox),
+#else
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(spam_handle_combobox),
+#endif
+                       _("Only mark as spam"));
+
+       gtk_widget_show(spam_handle_combobox);
+       gtk_box_pack_start(GTK_BOX(hbox_save_spam), spam_handle_combobox, FALSE, FALSE, 0);
+
+       GtkWidget *hbox = gtk_hbox_new(FALSE, 8);
+       gtk_widget_show(hbox);
+       gtk_box_pack_start (GTK_BOX (hbox_save_spam), hbox, TRUE, TRUE, 0);
 
        save_spam_folder_entry = gtk_entry_new();
        gtk_widget_show (save_spam_folder_entry);
-       gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_entry, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox), save_spam_folder_entry, TRUE, TRUE, 0);
        CLAWS_SET_TIP(save_spam_folder_entry,
                        _("Folder for storing identified spam. Leave empty to use the trash folder."));
 
        save_spam_folder_select = gtkut_get_browse_directory_btn(_("_Browse"));
        gtk_widget_show (save_spam_folder_select);
-       gtk_box_pack_start (GTK_BOX (hbox_save_spam), save_spam_folder_select, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox), save_spam_folder_select, FALSE, FALSE, 0);
        CLAWS_SET_TIP(save_spam_folder_select,
                        _("Click this button to select a folder for storing spam"));
 
+       g_signal_connect(G_OBJECT(spam_handle_combobox), "changed",
+                       G_CALLBACK(spam_handle_combobox_callback), (gpointer)hbox);
+
        hbox_save_unsure = gtk_hbox_new(FALSE, 8);
        gtk_widget_show(hbox_save_unsure);
        gtk_box_pack_start (GTK_BOX (vbox2), hbox_save_unsure, TRUE, TRUE, 0);
@@ -266,8 +311,6 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        gtk_widget_show(mark_as_read_checkbtn);
        gtk_box_pack_start(GTK_BOX(hbox_mark_as_read), mark_as_read_checkbtn, FALSE, FALSE, 0);
 
-       SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_entry);
-       SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, save_spam_folder_select);
        SET_TOGGLE_SENSITIVITY(save_unsure_checkbtn, save_unsure_folder_entry);
        SET_TOGGLE_SENSITIVITY(save_unsure_checkbtn, save_unsure_folder_select);
        SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_folder_combo);
@@ -275,7 +318,6 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, whitelist_ab_select_btn);
 #endif
        SET_TOGGLE_SENSITIVITY(whitelist_ab_checkbtn, learn_from_whitelist_chkbtn);
-       SET_TOGGLE_SENSITIVITY(save_spam_checkbtn, mark_as_read_checkbtn);
 
        config = bogofilter_get_config();
 
@@ -291,7 +333,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
 #endif
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(max_size_spinbtn), (float) config->max_size);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(process_emails_checkbtn), config->process_emails);
-       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_spam_checkbtn), config->receive_spam);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(spam_handle_combobox), config->receive_spam);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_unsure_checkbtn), config->save_unsure);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(insert_header_checkbtn), config->insert_header);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(whitelist_ab_checkbtn), config->whitelist_ab);
@@ -321,7 +363,7 @@ static void bogofilter_create_widget_func(PrefsPage * _page,
        page->max_size = max_size_spinbtn;
        page->process_emails = process_emails_checkbtn;
 
-       page->receive_spam = save_spam_checkbtn;
+       page->receive_spam = spam_handle_combobox;
        page->save_folder = save_spam_folder_entry;
        page->save_folder_select = save_spam_folder_select;
 
@@ -358,7 +400,7 @@ static void bogofilter_save_func(PrefsPage *_page)
        config->process_emails = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->process_emails));
 
        /* receive_spam */
-       config->receive_spam = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->receive_spam));
+       config->receive_spam = gtk_combo_box_get_active(GTK_COMBO_BOX(page->receive_spam));
 
        /* save_folder */
        g_free(config->save_folder);
index bb9c723349c1bcd7a0c2a3db3f2be3a6b60361ca..cff16458896cdb3fd79556fdbef5757b48deacce 100644 (file)
@@ -1978,7 +1978,7 @@ static void prefs_matcher_criteria_select(GtkWidget *widget,
                prefs_matcher_set_model(matcher.match_combo, matcher.model_age);
                prefs_matcher_set_model(matcher.match_combo2, matcher.model_age_units);
                gtk_spin_button_set_range(GTK_SPIN_BUTTON(
-                                 matcher.numeric_entry), 0, 1000);
+                                 matcher.numeric_entry), 0, 10000);
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(matcher.numeric_entry), 0);
                gtk_combo_box_set_active(GTK_COMBO_BOX(matcher.match_combo2), AGE_DAYS);
                gtk_label_set_text(GTK_LABEL(matcher.match_label), _("Age is"));