sync with 0.8.1cvs2
authorPaul Mangan <paul@claws-mail.org>
Sat, 27 Jul 2002 09:58:16 +0000 (09:58 +0000)
committerPaul Mangan <paul@claws-mail.org>
Sat, 27 Jul 2002 09:58:16 +0000 (09:58 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.in
src/imap.c
src/news.c
src/procmsg.c
src/procmsg.h
src/utils.c
src/utils.h

index 2c41a71..e98a52a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2002-07-26
+
+       * src/news.c: implement automatic cache expiration.
+         news_delete_expired_caches(): new.
+         news_get_article_list(): fixed a bug that nonexistent messages
+         were not removed from list.
+       * src/procmsg.[ch]: procmsg_get_last_num_in_msg_list(): renamed
+         procmsg_get_last_num_in_cache().
+       * src/utils.[ch]: remove_expired_files(): new.
+
 2002-07-26
 
        * src/inc.c:
index b8fe61f..3287b1d 100644 (file)
@@ -1,3 +1,8 @@
+2002-07-27 [paul]      0.8.0claws22
+
+       * sync with 0.8.1cvs2
+               see ChangeLog 2002-07-26
+
 2002-07-27 [christoph] 0.8.0claws21
 
        * src/imap.c
index 45a9739..a065463 100644 (file)
@@ -1,3 +1,13 @@
+2002-07-26
+
+       * src/news.c: ¼«Æ°¥­¥ã¥Ã¥·¥åºï½ü¤ò¼ÂÁõ¡£
+         news_delete_expired_caches(): ¿·µ¬¡£
+         news_get_article_list(): Â¸ºß¤·¤Ê¤¤¥á¥Ã¥»¡¼¥¸¤¬¥ê¥¹¥È¤«¤éºï½ü
+         ¤µ¤ì¤Ê¤¤¥Ð¥°¤ò½¤Àµ¡£
+       * src/procmsg.[ch]: procmsg_get_last_num_in_msg_list():
+         procmsg_get_last_num_in_cache() ¤ò̾¾ÎÊѹ¹¡£
+       * src/utils.[ch]: remove_expired_files(): ¿·µ¬¡£
+
 2002-07-26
 
        * src/inc.c
index 58fdc32..5125631 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=8
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws21
+EXTRA_VERSION=claws22
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 834135f..6973b26 100644 (file)
@@ -563,7 +563,7 @@ GSList *imap_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
 
        if (!session) {
                mlist = procmsg_read_cache(item, FALSE);
-               item->last_num = procmsg_get_last_num_in_cache(mlist);
+               item->last_num = procmsg_get_last_num_in_msg_list(mlist);
                procmsg_set_flags(mlist, item);
                statusbar_pop_all();
                return mlist;
@@ -591,7 +591,7 @@ GSList *imap_get_msg_list(Folder *folder, FolderItem *item, gboolean use_cache)
 
                mlist = procmsg_read_cache(item, FALSE);
                procmsg_set_flags(mlist, item);
-               cache_last = procmsg_get_last_num_in_cache(mlist);
+               cache_last = procmsg_get_last_num_in_msg_list(mlist);
 
                /* calculating the range of envelope to get */
                if (item->mtime != uid_validity) {
index 56c8a03..095c12f 100644 (file)
@@ -98,6 +98,8 @@ static GSList *news_delete_old_articles        (GSList        *alist,
                                          FolderItem    *item,
                                          gint           first);
 static void news_delete_all_articles    (FolderItem    *item);
+static void news_delete_expired_caches  (GSList        *alist,
+                                         FolderItem    *item);
 
 static gint news_remove_msg             (Folder        *folder, 
                                          FolderItem    *item, 
@@ -289,7 +291,7 @@ GSList *news_get_article_list(Folder *folder, FolderItem *item,
 
        if (!session) {
                alist = procmsg_read_cache(item, FALSE);
-               item->last_num = procmsg_get_last_num_in_cache(alist);
+               item->last_num = procmsg_get_last_num_in_msg_list(alist);
        } else if (use_cache) {
                GSList *newlist;
                gint cache_last;
@@ -297,12 +299,20 @@ GSList *news_get_article_list(Folder *folder, FolderItem *item,
 
                alist = procmsg_read_cache(item, FALSE);
 
-               cache_last = procmsg_get_last_num_in_cache(alist);
+               cache_last = procmsg_get_last_num_in_msg_list(alist);
                newlist = news_get_uncached_articles
                        (session, item, cache_last, &first, &last);
-               alist = news_delete_old_articles(alist, item, first);
+               if (first == 0 && last == 0) {
+                       news_delete_all_articles(item);
+                       procmsg_msg_list_free(alist);
+                       alist = NULL;
+               } else {
+                       alist = news_delete_old_articles(alist, item, first);
+                       news_delete_expired_caches(alist, item);
+               }
 
                alist = g_slist_concat(alist, newlist);
+
                item->last_num = last;
        } else {
                gint last;
@@ -692,8 +702,8 @@ static GSList *news_get_uncached_articles(NNTPSession *session,
        GSList *llast = NULL;
        MsgInfo *msginfo;
 
-       if (rfirst) *rfirst = 0;
-       if (rlast)  *rlast  = 0;
+       if (rfirst) *rfirst = -1;
+       if (rlast)  *rlast  = -1;
 
        g_return_val_if_fail(session != NULL, NULL);
        g_return_val_if_fail(item != NULL, NULL);
@@ -712,6 +722,10 @@ static GSList *news_get_uncached_articles(NNTPSession *session,
                            first, last);
                return NULL;
        }
+
+       if (rfirst) *rfirst = first;
+       if (rlast)  *rlast  = last;
+
        if (cache_last < first)
                begin = first;
        else if (last < cache_last)
@@ -723,9 +737,6 @@ static GSList *news_get_uncached_articles(NNTPSession *session,
                begin = cache_last + 1;
        end = last;
 
-       if (rfirst) *rfirst = first;
-       if (rlast)  *rlast  = last;
-
        if (prefs_common.max_articles > 0 &&
            end - begin + 1 > prefs_common.max_articles)
                begin = end - prefs_common.max_articles + 1;
@@ -930,7 +941,7 @@ static GSList *news_delete_old_articles(GSList *alist, FolderItem *item,
 
        if (first < 2) return alist;
 
-       debug_print(_("Deleting cached articles 1 - %d ... "), first - 1);
+       debug_print("Deleting cached articles 1 - %d ...\n", first - 1);
 
        dir = folder_item_get_path(item);
        remove_numbered_files(dir, 1, first - 1);
@@ -947,7 +958,6 @@ static GSList *news_delete_old_articles(GSList *alist, FolderItem *item,
 
                cur = next;
        }
-       debug_print(_("done.\n"));
 
        return alist;
 }
@@ -960,13 +970,26 @@ static void news_delete_all_articles(FolderItem *item)
        g_return_if_fail(item->folder != NULL);
        g_return_if_fail(item->folder->type == F_NEWS);
 
-       debug_print(_("\tDeleting all cached articles... "));
+       debug_print("Deleting all cached articles...\n");
 
        dir = folder_item_get_path(item);
        remove_all_numbered_files(dir);
        g_free(dir);
+}
 
-       debug_print(_("done.\n"));
+static void news_delete_expired_caches(GSList *alist, FolderItem *item)
+{
+       gchar *dir;
+
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+       g_return_if_fail(item->folder->type == F_NEWS);
+
+       debug_print("Deleting expired cached articles...\n");
+
+       dir = folder_item_get_path(item);
+       remove_expired_files(dir, 24 * 7);
+       g_free(dir);
 }
 
 gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
index 00d8e05..64a501e 100644 (file)
@@ -334,14 +334,12 @@ void procmsg_set_flags(GSList *mlist, FolderItem *item)
        g_hash_table_destroy(mark_table);
 }
 
-gint procmsg_get_last_num_in_cache(GSList *mlist)
+gint procmsg_get_last_num_in_msg_list(GSList *mlist)
 {
        GSList *cur;
        MsgInfo *msginfo;
        gint last = 0;
 
-       if (mlist == NULL) return 0;
-
        for (cur = mlist; cur != NULL; cur = cur->next) {
                msginfo = (MsgInfo *)cur->data;
                if (msginfo && msginfo->msgnum > last)
index a7d8b2b..da94523 100644 (file)
@@ -218,7 +218,7 @@ GSList *procmsg_read_cache          (FolderItem     *item,
                                         gboolean        scan_file);
 void   procmsg_set_flags               (GSList         *mlist,
                                         FolderItem     *item);
-gint   procmsg_get_last_num_in_cache   (GSList         *mlist);
+gint   procmsg_get_last_num_in_msg_list(GSList         *mlist);
 void   procmsg_msg_list_free           (GSList         *mlist);
 void   procmsg_write_cache             (MsgInfo        *msginfo,
                                         FILE           *fp);
index 4d33b92..498faa8 100644 (file)
@@ -1752,6 +1752,60 @@ gint remove_all_numbered_files(const gchar *dir)
        return remove_numbered_files(dir, 0, UINT_MAX);
 }
 
+gint remove_expired_files(const gchar *dir, guint hours)
+{
+       DIR *dp;
+       struct dirent *d;
+       struct stat s;
+       gchar *prev_dir;
+       gint fileno;
+       time_t mtime, now, expire_time;
+
+       prev_dir = g_get_current_dir();
+
+       if (chdir(dir) < 0) {
+               FILE_OP_ERROR(dir, "chdir");
+               return -1;
+       }
+
+       if ((dp = opendir(".")) == NULL) {
+               FILE_OP_ERROR(dir, "opendir");
+               return -1;
+       }
+
+       now = time(NULL);
+       expire_time = hours * 60 * 60;
+
+       while ((d = readdir(dp)) != NULL) {
+               fileno = to_number(d->d_name);
+               if (fileno >= 0) {
+                       if (stat(d->d_name, &s) < 0) {
+                               FILE_OP_ERROR(d->d_name, "stat");
+                               continue;
+                       }
+                       if (S_ISDIR(s.st_mode))
+                               continue;
+                       mtime = MAX(s.st_mtime, s.st_atime);
+                       if (now - mtime > expire_time) {
+                               if (unlink(d->d_name) < 0)
+                                       FILE_OP_ERROR(d->d_name, "unlink");
+                       }
+               }
+       }
+
+       closedir(dp);
+
+       if (chdir(prev_dir) < 0) {
+               FILE_OP_ERROR(prev_dir, "chdir");
+               g_free(prev_dir);
+               return -1;
+       }
+
+       g_free(prev_dir);
+
+       return 0;
+}
+
 gint remove_dir_recursive(const gchar *dir)
 {
        struct stat s;
index bc4e796..b99fd96 100644 (file)
@@ -326,6 +326,8 @@ gint remove_numbered_files  (const gchar    *dir,
                                 guint           first,
                                 guint           last);
 gint remove_all_numbered_files (const gchar    *dir);
+gint remove_expired_files      (const gchar    *dir,
+                                guint           hours);
 gint remove_dir_recursive      (const gchar    *dir);
 gint copy_file                 (const gchar    *src,
                                 const gchar    *dest);