From 0f1a9464181978dff13728f940f98c05fcbdb859 Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 29 Jul 2010 07:56:34 +0000 Subject: use default Junk folder when prefs_common.junk_folder is not set. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2639 ee746299-78ed-0310-b773-934348b2243d --- ChangeLog | 7 +++++++ libsylph/prefs_common.c | 34 +++++++++++++++++++++++++++------- src/main.c | 2 ++ src/summaryview.c | 21 ++++++++++++++++++--- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea4ecff9..8b4e18e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-07-29 + + * libsylph/prefs_common.c + src/main.c + src/summaryview.c: use default Junk folder when + prefs_common.junk_folder is not set. + 2010-07-29 * libsylph/mh.c diff --git a/libsylph/prefs_common.c b/libsylph/prefs_common.c index 4b5759de..238c5dd5 100644 --- a/libsylph/prefs_common.c +++ b/libsylph/prefs_common.c @@ -514,8 +514,6 @@ void prefs_common_read_config(void) prefs_common.online_mode = TRUE; - prefs_common_junk_filter_list_set(); - path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMAND_HISTORY, NULL); if ((fp = g_fopen(path, "rb")) == NULL) { @@ -568,19 +566,33 @@ static FilterRule *prefs_common_junk_filter_rule_create(gboolean is_manual) FilterCond *cond; FilterAction *action; GSList *cond_list = NULL, *action_list = NULL; + gchar *junk_id; + + if (prefs_common.junk_folder) + junk_id = g_strdup(prefs_common.junk_folder); + else { + FolderItem *item; + item = folder_get_default_junk(); + if (!item) + return NULL; + junk_id = folder_item_get_identifier(item); + if (!junk_id) + return NULL; + } + + debug_print("prefs_common_junk_filter_rule_create: junk folder: %s\n", + junk_id); cond = filter_cond_new(FLT_COND_CMD_TEST, 0, 0, NULL, prefs_common.junk_classify_cmd); cond_list = g_slist_append(NULL, cond); if (prefs_common.delete_junk_on_recv && !is_manual) { - action = filter_action_new(FLT_ACTION_COPY, - prefs_common.junk_folder); + action = filter_action_new(FLT_ACTION_COPY, junk_id); action_list = g_slist_append(NULL, action); action = filter_action_new(FLT_ACTION_DELETE, NULL); action_list = g_slist_append(action_list, action); } else { - action = filter_action_new(FLT_ACTION_MOVE, - prefs_common.junk_folder); + action = filter_action_new(FLT_ACTION_MOVE, junk_id); action_list = g_slist_append(NULL, action); } @@ -596,6 +608,8 @@ static FilterRule *prefs_common_junk_filter_rule_create(gboolean is_manual) rule = filter_rule_new(_("Junk mail filter"), FLT_OR, cond_list, action_list); + g_free(junk_id); + return rule; } @@ -603,6 +617,8 @@ void prefs_common_junk_filter_list_set(void) { FilterRule *rule; + debug_print("prefs_common_junk_filter_list_set\n"); + if (prefs_common.junk_fltlist) { filter_rule_list_free(prefs_common.junk_fltlist); prefs_common.junk_fltlist = NULL; @@ -612,13 +628,17 @@ void prefs_common_junk_filter_list_set(void) prefs_common.manual_junk_fltlist = NULL; } - if (!prefs_common.junk_classify_cmd || !prefs_common.junk_folder) + if (!prefs_common.junk_classify_cmd) return; rule = prefs_common_junk_filter_rule_create(FALSE); + if (!rule) + return; prefs_common.junk_fltlist = g_slist_append(NULL, rule); rule = prefs_common_junk_filter_rule_create(TRUE); + if (!rule) + return; prefs_common.manual_junk_fltlist = g_slist_append(NULL, rule); } diff --git a/src/main.c b/src/main.c index 46e7091d..8b0a140c 100644 --- a/src/main.c +++ b/src/main.c @@ -346,6 +346,8 @@ int main(int argc, char *argv[]) new_account = setup_account(); } + prefs_common_junk_filter_list_set(); + account_set_menu(); main_window_reflect_prefs_all(); diff --git a/src/summaryview.c b/src/summaryview.c index d65b787c..ec5162d0 100644 --- a/src/summaryview.c +++ b/src/summaryview.c @@ -4787,17 +4787,21 @@ static void summary_junk_func(GtkTreeModel *model, GtkTreePath *path, MsgInfo *msginfo; FilterInfo *fltinfo; gchar *file; + gchar *junk_id = NULL; gint ret; gtk_tree_model_get(model, iter, S_COL_MSG_INFO, &msginfo, -1); file = procmsg_get_message_file(msginfo); g_return_if_fail(file != NULL); + if (summaryview->to_folder) + junk_id = folder_item_get_identifier(summaryview->to_folder); + action1.str_value = prefs_common.junk_learncmd; - action2.str_value = prefs_common.junk_folder; + action2.str_value = junk_id; rule.action_list = g_slist_append(rule.action_list, &action1); - if (prefs_common.junk_folder) + if (junk_id) rule.action_list = g_slist_append(rule.action_list, &action2); if (prefs_common.mark_junk_as_read) rule.action_list = g_slist_append(rule.action_list, &action3); @@ -4822,6 +4826,7 @@ static void summary_junk_func(GtkTreeModel *model, GtkTreePath *path, filter_info_free(fltinfo); g_slist_free(rule.action_list); + g_free(junk_id); g_free(file); } @@ -4854,6 +4859,8 @@ static void summary_not_junk_func(GtkTreeModel *model, GtkTreePath *path, void summary_junk(SummaryView *summaryview) { + FolderItem *junk; + if (!prefs_common.enable_junk) return; if (!prefs_common.junk_learncmd) @@ -4863,12 +4870,20 @@ void summary_junk(SummaryView *summaryview) debug_print("Set mail as junk\n"); + if (prefs_common.junk_folder) + junk = folder_find_item_from_identifier + (prefs_common.junk_folder); + else + junk = folder_get_default_junk(); + + summaryview->to_folder = junk; gtk_tree_selection_selected_foreach(summaryview->selection, summary_junk_func, summaryview); + summaryview->to_folder = NULL; summary_unlock(summaryview); - if (prefs_common.junk_folder && prefs_common.immediate_exec) + if (junk && prefs_common.immediate_exec) summary_execute(summaryview); else { summary_step(summaryview, GTK_SCROLL_STEP_FORWARD); -- cgit v1.2.3