make filtering action 'mark_as_unread' set the unread flag AND remove the new flag
[claws.git] / src / filtering.c
index ff6eece6294047b85965a7de83c2d22ec29d0ed1..1b565a5d583a16f58fc0eab718a0a185fedc4448 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto & The Claws Mail Team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2015 Hiroyuki Yamamoto & The Claws Mail Team
  *
  * 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #include "defs.h"
@@ -57,19 +56,6 @@ gboolean debug_filtering_session = FALSE;
 
 static gboolean filtering_is_final_action(FilteringAction *filtering_action);
 
-#define STRLEN_WITH_CHECK(expr) \
-        strlen_with_check(#expr, __LINE__, expr)
-               
-static inline gint strlen_with_check(const gchar *expr, gint fline, const gchar *str)
-{
-        if (str) 
-               return strlen(str);
-       else {
-               debug_print("%s(%d) - invalid string %s\n", __FILE__, fline, expr?expr:"(null)");
-               return 0;
-       }
-}
-
 FilteringAction * filteringaction_new(int type, int account_id,
                                      gchar * destination,
                                      gint labelcolor, gint score, gchar * header)
@@ -392,17 +378,13 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
 
        case MATCHACTION_MARK_AS_UNREAD:
                FLUSH_COPY_IF_NEEDED(info);
-               procmsg_msginfo_set_flags(info, MSG_UNREAD, 0);
+               procmsg_msginfo_change_flags(info, MSG_UNREAD, 0, MSG_NEW, 0);
                return TRUE;
        
        case MATCHACTION_MARK_AS_SPAM:
                FLUSH_COPY_IF_NEEDED(info);
                procmsg_spam_learner_learn(info, NULL, TRUE);
                procmsg_msginfo_change_flags(info, MSG_SPAM, 0, MSG_NEW|MSG_UNREAD, 0);
-               if (procmsg_spam_get_folder(info)) {
-                       info->filter_op = IS_MOVE;
-                       info->to_filter_folder = procmsg_spam_get_folder(info);
-               }
                return TRUE;
 
        case MATCHACTION_MARK_AS_HAM:
@@ -534,16 +516,18 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
                                        extract_address(stripped_addr);
 
                                        if (complete_matches_found(walk->data) == 0) {
+                                               gchar *name = procheader_get_fromname(walk->data);
                                                debug_print("adding address '%s' to addressbook '%s'\n",
                                                                stripped_addr, action->destination);
 #ifndef USE_NEW_ADDRBOOK
-                                               if (!addrbook_add_contact(abf, folder, stripped_addr, stripped_addr, NULL)) {
+                                               if (!addrbook_add_contact(abf, folder, name, stripped_addr, NULL)) {
 #else
-                                               if (!addressadd_selection(NULL, stripped_addr, NULL, NULL)) {
+                                               if (!addressadd_selection(name, stripped_addr, NULL, NULL)) {
 #endif
-                                                       g_warning("contact could not been added\n");
+                                                       g_warning("contact could not be added\n");
                                                        errors++;
                                                }
+                                               g_free(name);
                                        } else {
                                                debug_print("address '%s' already found in addressbook '%s', skipping\n",
                                                                stripped_addr, action->destination);