2007-08-09 [wwp] 2.10.0cvs108
[claws.git] / src / folder.c
index 2221d7863b203ff404b3c4db22486cfcedfb17b5..869cdc7160d3c2bf3458c74e9f2ba903b0dc4066 100644 (file)
@@ -4,7 +4,7 @@
  *
  * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -215,6 +215,9 @@ void folder_item_change_type(FolderItem *item, SpecialFolderItemType newtype)
        Folder *folder = NULL;
        FolderUpdateData hookdata;
 
+       if (item == NULL)
+               return;
+
        folder = item->folder;
        /* unset previous root of newtype */
        switch(newtype) {
@@ -2091,6 +2094,9 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
                if (!MSG_IS_IGNORE_THREAD(msginfo->flags) && procmsg_msg_has_flagged_parent(msginfo, MSG_IGNORE_THREAD)) {
                        procmsg_msginfo_change_flags(msginfo, MSG_IGNORE_THREAD, 0, MSG_NEW | MSG_UNREAD, 0);
                }
+               if (!MSG_IS_WATCH_THREAD(msginfo->flags) && procmsg_msg_has_flagged_parent(msginfo, MSG_WATCH_THREAD)) {
+                       procmsg_msginfo_set_flags(msginfo, MSG_WATCH_THREAD, 0);
+               }
                if(prefs_common.thread_by_subject && !msginfo->inreplyto &&
                        !msginfo->references && !MSG_IS_IGNORE_THREAD(msginfo->flags) &&
                        (parent_msginfo = subject_table_lookup(subject_table, msginfo->subject)))
@@ -2295,6 +2301,38 @@ void folder_clean_cache_memory(FolderItem *protected_item)
        }
 }
 
+static void folder_item_remove_cached_msg(FolderItem *item, MsgInfo *msginfo)
+{
+       Folder *folder = item->folder;
+
+       g_return_if_fail(folder != NULL);
+
+       if (folder->klass->remove_cached_msg == NULL)
+               return;
+       
+       folder->klass->remove_cached_msg(folder, item, msginfo);
+}
+
+static void folder_item_clean_local_files(FolderItem *item, gint days)
+{
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+
+       if (FOLDER_TYPE(item->folder) == F_IMAP ||
+           FOLDER_TYPE(item->folder) == F_NEWS) {
+               GSList *msglist = folder_item_get_msg_list(item);
+               GSList *cur;
+               time_t t = time(NULL);
+               for (cur = msglist; cur; cur = cur->next) {
+                       MsgInfo *msginfo = (MsgInfo *)cur->data;
+                       gint age = (t - msginfo->date_t) / (60*60*24);
+                       if (age > days)
+                               folder_item_remove_cached_msg(item, msginfo);
+               }
+               procmsg_msg_list_free(msglist);
+       }
+}
+
 static void folder_item_read_cache(FolderItem *item)
 {
        gchar *cache_file, *mark_file, *tags_file;
@@ -2698,6 +2736,9 @@ static void copy_msginfo_flags(MsgInfo *source, MsgInfo *dest)
        if (procmsg_msg_has_flagged_parent(dest, MSG_IGNORE_THREAD))
                perm_flags |= MSG_IGNORE_THREAD;
 
+       if (procmsg_msg_has_flagged_parent(dest, MSG_WATCH_THREAD))
+               perm_flags |= MSG_WATCH_THREAD;
+
        /* Unset tmp flags that should not be copied */
        tmp_flags &= ~(MSG_MOVE | MSG_COPY | MSG_MOVE_DONE);
 
@@ -3518,7 +3559,12 @@ static gchar *folder_item_get_tags_file(FolderItem *item)
 
        identifier = folder_item_get_identifier(item);
        g_return_val_if_fail(identifier != NULL, NULL);
-       
+
+#ifdef G_OS_WIN32
+       while (strchr(identifier, '/'))
+               *strchr(identifier, '/') = '\\';
+#endif
+
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "tagsdb", G_DIR_SEPARATOR_S,
                           identifier, NULL);
@@ -3963,6 +4009,8 @@ void folder_item_apply_processing(FolderItem *item)
                 /* apply post global rules */
                filter_message_by_msginfo(post_global_processing, msginfo, NULL,
                                FILTERING_POST_PROCESSING, NULL);
+               if (curmsg % 1000 == 0)
+                       GTK_EVENTS_FLUSH();
        }
        prefs_common.apply_per_account_filtering_rules = last_apply_per_account;
 
@@ -4066,7 +4114,11 @@ void folder_item_synchronise(FolderItem *item)
                return;
        if (item->prefs->offlinesync && item->folder->klass->synchronise) {
                statusbar_print_all(_("Synchronising %s for offline use...\n"), item->path ? item->path : "(null)");
-               item->folder->klass->synchronise(item);
+               item->folder->klass->synchronise(item, 
+                       item->prefs->offlinesync_days);
+               if (item->prefs->offlinesync_days > 0 &&
+                   item->prefs->remove_old_bodies)
+                       folder_item_clean_local_files(item, item->prefs->offlinesync_days);
                statusbar_pop_all();
        }
 }