2006-10-04 [colin] 2.5.2cvs42
[claws.git] / src / folder.c
index 654488e0995a631d74e8099c48633ad5e821db09..ac0dc906e9b89d50e544ce2f92ec7890a9b34d36 100644 (file)
@@ -1202,7 +1202,9 @@ gchar *folder_item_get_identifier(FolderItem *item)
        gchar *folder_id = NULL;
 
        g_return_val_if_fail(item != NULL, NULL);
-       g_return_val_if_fail(item->path != NULL, NULL);
+
+       if (item->path == NULL)
+               return NULL;
 
        folder_id = folder_get_identifier(item->folder);
        id = g_strconcat(folder_id, "/", item->path, NULL);
@@ -1346,6 +1348,8 @@ FolderItem *folder_get_default_inbox(void)
                        continue;
                if (folder->inbox == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->inbox;
        }
@@ -1364,6 +1368,8 @@ FolderItem *folder_get_default_outbox(void)
                        continue;
                if (folder->outbox == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->outbox;
        }
@@ -1382,6 +1388,8 @@ FolderItem *folder_get_default_draft(void)
                        continue;
                if (folder->draft == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->draft;
        }
@@ -1400,6 +1408,8 @@ FolderItem *folder_get_default_queue(void)
                        continue;
                if (folder->queue == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->queue;
        }
@@ -1418,6 +1428,8 @@ FolderItem *folder_get_default_trash(void)
                        continue;
                if (folder->trash == NULL)
                        continue;
+               if (folder->klass->type == F_UNKNOWN)
+                       continue;
 
                return folder->trash;
        }
@@ -1559,7 +1571,6 @@ void folder_item_process_open (FolderItem *item,
        /* Processing */
        buf = g_strdup_printf(_("Processing (%s)...\n"), 
                              item->path ? item->path : item->name);
-       debug_print("%s\n", buf);
        g_free(buf);
 
        if (before_proc_func)
@@ -1570,14 +1581,13 @@ void folder_item_process_open (FolderItem *item,
        if (after_proc_func)
                after_proc_func(data);
 
-       debug_print("done.\n");
        item->processing_pending = FALSE;
        return; 
 }
 
 gint folder_item_open(FolderItem *item)
 {
-       START_TIMING("folder_item_open"); 
+       START_TIMING(""); 
        if (item->no_select)
                return -1;
 
@@ -1924,47 +1934,57 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
        folder_item_update_freeze();
        if (newmsg_list != NULL) {
                GSList *elem, *to_filter = NULL;
-               int total = g_slist_length(newmsg_list), cur = 0;
-               
-               if ((filtering == TRUE) &&
-                   (item->stype == F_INBOX) &&
-                   (item->folder->account != NULL) && 
-                   (item->folder->account->filter_on_recv)) 
-                       statusbar_print_all(_("Filtering messages...\n"));
+               gboolean do_filter = (filtering == TRUE) &&
+                                       (item->stype == F_INBOX) &&
+                                       (item->folder->account != NULL) && 
+                                       (item->folder->account->filter_on_recv);
                
                for (elem = newmsg_list; elem != NULL; elem = g_slist_next(elem)) {
                        MsgInfo *msginfo = (MsgInfo *) elem->data;
 
-                       statusbar_progress_all(cur++,total, 10);
-
                        msgcache_add_msg(item->cache, msginfo);
-                       if ((filtering == TRUE) &&
-                           (item->stype == F_INBOX) &&
-                           (item->folder->account != NULL) && 
-                           (item->folder->account->filter_on_recv) &&
-                           procmsg_msginfo_filter(msginfo))
-                               to_filter = g_slist_prepend(to_filter, msginfo);
-                       else {
+                       if (!do_filter) {
                                exists_list = g_slist_prepend(exists_list, msginfo);
-                               
+
                                if(prefs_common.thread_by_subject &&
                                        MSG_IS_IGNORE_THREAD(msginfo->flags) &&
                                        !subject_table_lookup(subject_table, msginfo->subject)) {
                                        subject_table_insert(subject_table, msginfo->subject, msginfo);
-                               }
+                               }                       
                        }
                }
-               filtering_move_and_copy_msgs(to_filter);
-               for (elem = to_filter; elem; elem = g_slist_next(elem)) {
-                       MsgInfo *msginfo = (MsgInfo *)elem->data;
-                       procmsg_msginfo_free(msginfo);
-               }
 
-               g_slist_free(to_filter);
+               if (do_filter) {
+                       GSList *unfiltered;
+                       procmsg_msglist_filter(newmsg_list, item->folder->account, 
+                                       &to_filter, &unfiltered, 
+                                       TRUE);
+                       
+                       filtering_move_and_copy_msgs(newmsg_list);
+                       if (to_filter != NULL) {
+                               for (elem = to_filter; elem; elem = g_slist_next(elem)) {
+                                       MsgInfo *msginfo = (MsgInfo *)elem->data;
+                                       procmsg_msginfo_free(msginfo);
+                               }
+                               g_slist_free(to_filter);
+                       }
+                       if (unfiltered != NULL) {
+                               for (elem = unfiltered; elem; elem = g_slist_next(elem)) {
+                                       MsgInfo *msginfo = (MsgInfo *)elem->data;
+                                       exists_list = g_slist_prepend(exists_list, msginfo);
+
+                                       if(prefs_common.thread_by_subject &&
+                                               MSG_IS_IGNORE_THREAD(msginfo->flags) &&
+                                               !subject_table_lookup(subject_table, msginfo->subject)) {
+                                               subject_table_insert(subject_table, msginfo->subject, msginfo);
+                                       }
+                               }
+                               g_slist_free(unfiltered);
+                       }
+               } 
+
                g_slist_free(newmsg_list);
 
-               statusbar_progress_all(0,0,0);
-               statusbar_pop_all();
                update_flags |= F_ITEM_UPDATE_MSGCNT | F_ITEM_UPDATE_CONTENT;
        }
 
@@ -2013,6 +2033,12 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
                g_hash_table_destroy(subject_table);
        }
        
+       if (item->new_msgs != newcnt || item->unread_msgs != unreadcnt
+       ||  item->total_msgs != totalcnt || item->marked_msgs != markedcnt
+       ||  item->unreadmarked_msgs != unreadmarkedcnt) {
+               update_flags |= F_ITEM_UPDATE_CONTENT;
+       }
+
        item->new_msgs = newcnt;
        item->unread_msgs = unreadcnt;
        item->total_msgs = totalcnt;
@@ -2194,7 +2220,7 @@ void folder_clean_cache_memory(FolderItem *protected_item)
 void folder_item_read_cache(FolderItem *item)
 {
        gchar *cache_file, *mark_file;
-       START_TIMING("folder_item_read_cache");
+       START_TIMING("");
        g_return_if_fail(item != NULL);
 
        if (item->path != NULL) {
@@ -2248,10 +2274,17 @@ void folder_item_write_cache(FolderItem *item)
        FolderItemPrefs *prefs;
        gint filemode = 0;
        gchar *id;
+       time_t last_mtime = (time_t)0;
+       gboolean need_scan = FALSE;
        
        if (!item || !item->path || !item->cache)
                return;
 
+       if (FOLDER_TYPE(item->folder) == F_MH) {
+               last_mtime = item->mtime;
+               need_scan = item->folder->klass->scan_required(item->folder, item);
+       }
+
        id = folder_item_get_identifier(item);
        debug_print("Save cache for folder %s\n", id);
        g_free(id);
@@ -2269,6 +2302,12 @@ void folder_item_write_cache(FolderItem *item)
                }
         }
 
+       if (!need_scan && FOLDER_TYPE(item->folder) == F_MH) {
+               if (item->mtime == last_mtime) {
+                       mh_set_mtime(item);
+               }
+       }
+
        g_free(cache_file);
        g_free(mark_file);
 }
@@ -2346,7 +2385,6 @@ void msginfo_set_mime_flags(GNode *node, gpointer data)
                ||  strcmp(mimeinfo->subtype, "pgp-signature"))
                        procmsg_msginfo_set_flags(msginfo, 0, MSG_HAS_ATTACHMENT);
        } else if (mimeinfo->disposition == DISPOSITIONTYPE_INLINE &&
-               (mimeinfo->type != MIMETYPE_TEXT || strcmp(mimeinfo->subtype, "plain")) &&
                strcmp(mimeinfo->subtype, "pgp-signature") && 
                (procmime_mimeinfo_get_parameter(mimeinfo, "name") != NULL ||
                 procmime_mimeinfo_get_parameter(mimeinfo, "filename") != NULL)) {
@@ -2571,7 +2609,7 @@ static void copy_msginfo_flags(MsgInfo *source, MsgInfo *dest)
                perm_flags |= MSG_IGNORE_THREAD;
 
        /* Unset tmp flags that should not be copied */
-       tmp_flags &= ~(MSG_MOVE | MSG_COPY);
+       tmp_flags &= ~(MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
 
        /* unset flags that are set but should not */
        /* and set new flags */
@@ -2985,7 +3023,7 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
                 * copying was successfull and update folder
                 * message counts
                 */
-               if (item->folder->klass->remove_msgs) {
+               if (not_moved == NULL && item->folder->klass->remove_msgs) {
                        item->folder->klass->remove_msgs(item->folder,
                                                                msginfo->folder,
                                                                msglist,
@@ -3713,6 +3751,7 @@ void folder_item_apply_processing(FolderItem *item)
        GSList *processing_list;
        GSList *mlist, *cur;
        guint total = 0, curmsg = 0;
+       gint last_apply_per_account;
 
        g_return_if_fail(item != NULL);
 
@@ -3725,11 +3764,16 @@ void folder_item_apply_processing(FolderItem *item)
        &&  !post_global_processing)
                return;
 
+       debug_print("processing %s\n", item->name);
        folder_item_update_freeze();
 
        mlist = folder_item_get_msg_list(item);
        total = g_slist_length(mlist);
        statusbar_print_all(_("Processing messages..."));
+
+       last_apply_per_account = prefs_common.apply_per_account_filtering_rules;
+       prefs_common.apply_per_account_filtering_rules = FILTERING_ACCOUNT_RULES_SKIP;
+
        for (cur = mlist ; cur != NULL ; cur = cur->next) {
                MsgInfo * msginfo;
 
@@ -3742,15 +3786,17 @@ void folder_item_apply_processing(FolderItem *item)
                statusbar_progress_all(curmsg++,total, 10);
 
                 /* apply pre global rules */
-               filter_message_by_msginfo(pre_global_processing, msginfo);
+               filter_message_by_msginfo(pre_global_processing, msginfo, NULL);
                
                 /* apply rules of the folder */
-               filter_message_by_msginfo(processing_list, msginfo);
+               filter_message_by_msginfo(processing_list, msginfo, NULL);
 
                 /* apply post global rules */
-               filter_message_by_msginfo(post_global_processing, msginfo);
+               filter_message_by_msginfo(post_global_processing, msginfo, NULL);
                 
        }
+       prefs_common.apply_per_account_filtering_rules = last_apply_per_account;
+
        if (pre_global_processing || processing_list
            || post_global_processing)
                filtering_move_and_copy_msgs(mlist);
@@ -3924,10 +3970,6 @@ gboolean folder_has_parent_of_type(FolderItem *item,
                        /* here's an exception: Inbox subfolders are normal. */
                        if (item->parent_stype == -1 && cur->stype == F_INBOX 
                        && item != cur) {
-                               debug_print("set item %s parent type to %d "
-                                       "even if %s is F_INBOX\n",
-                                       item->path ? item->path : "(null)",
-                                       0, cur->path);
                                item->parent_stype = F_NORMAL;
                                break;
                        }
@@ -3935,21 +3977,11 @@ gboolean folder_has_parent_of_type(FolderItem *item,
                         * well copy it instead of going up the full way */
                        if (cur->parent_stype != -1) {
                                item->parent_stype = cur->parent_stype;
-                               debug_print("set item %s parent type to %d "
-                                       "from %s's parent type\n",
-                                       item->path ? item->path : "(null)",
-                                       cur->parent_stype ? cur->parent_stype : 0, 
-                                       cur->path ? cur->path : "(null)");
                                break;
                        }
                        /* we found a parent that has a special type. That's 
                         * our parent type. */
                        if (cur->stype != F_NORMAL) {
-                               debug_print("set item %s parent type to %d "
-                                       "from %s's type\n",
-                                       item->path ? item->path : "(null)",
-                                       cur->stype ? cur->stype : 0, 
-                                       cur->path ? cur->path : "(null)");
                                cur->parent_stype = cur->stype;
                                item->parent_stype = cur->stype;
                                break;
@@ -3960,8 +3992,6 @@ gboolean folder_has_parent_of_type(FolderItem *item,
                /* as we still didn't find anything, our parents must all be 
                 * normal. */
                if (item->parent_stype == -1) {
-                       debug_print("set item %s to 0 from default\n", 
-                               item->path ? item->path : "(null)");
                        item->parent_stype = F_NORMAL;
                }
        }
@@ -3982,4 +4012,17 @@ gboolean folder_subscribe (const gchar *uri)
        return FALSE;
 
 }
+
+gboolean folder_get_sort_type          (Folder         *folder,
+                                        FolderSortKey  *sort_key,
+                                        FolderSortType *sort_type)
+{
+       if (!folder || !sort_key || !sort_type)
+               return FALSE;
+       if (folder->klass->get_sort_type == NULL)
+               return FALSE;
+       folder->klass->get_sort_type(folder, sort_key, sort_type); 
+       return TRUE;
+}
+
 #undef PUT_ESCAPE_STR