2004-07-13 [colin] 0.9.12cvs18.3
authorColin Leroy <colin@colino.net>
Tue, 13 Jul 2004 11:55:36 +0000 (11:55 +0000)
committerColin Leroy <colin@colino.net>
Tue, 13 Jul 2004 11:55:36 +0000 (11:55 +0000)
* src/pop.c
* src/pop.h
* src/messageview.c
Refactor API (to avoid passing 5+ params and code
duplication)
* src/folder.c
* src/msgcache.c
* src/procheader.c
* src/common/defs.h
Add planned_download to cache
Don't mess uidl file when moving partially downloaded
mails (they change folder, we should change it in the
uidl list too or we'll remove an incorrect message)
(this also helps removing hacks when changing
 planned_download in messageview.c)

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/common/defs.h
src/folder.c
src/messageview.c
src/msgcache.c
src/pop.c
src/pop.h
src/procheader.c

index 0116bb43dd6a2129d4a9d20dc7f7a0dc113ee30c..530eb0d2409a41125d2ec782d2f8e39a3a2eaa15 100644 (file)
@@ -1,3 +1,21 @@
+2004-07-13 [colin]     0.9.12cvs18.3
+
+       * src/pop.c
+       * src/pop.h
+       * src/messageview.c
+               Refactor API (to avoid passing 5+ params and code
+               duplication)
+       * src/folder.c
+       * src/msgcache.c
+       * src/procheader.c
+       * src/common/defs.h
+               Add planned_download to cache
+               Don't mess uidl file when moving partially downloaded
+               mails (they change folder, we should change it in the
+               uidl list too or we'll remove an incorrect message)
+               (this also helps removing hacks when changing 
+               planned_download in messageview.c)
+
 2004-07-12 [colin]     0.9.12cvs18.2
 
        * src/gtk/quicksearch.c
index e7c063fe2f253a077d6d877cf25b696188116706..982fa01a9ae92d5a17aff710e73f2e7a8ae1b0d4 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
@@ -20,3 +20,4 @@
 ( cvs diff -u -r 1.149.2.10 -r 1.149.2.11 src/inc.c; cvs diff -u -r 1.94.2.17 -r 1.94.2.18 src/messageview.c; cvs diff -u -r 1.56.2.11 -r 1.56.2.12 src/pop.c; cvs diff -u -r 1.17.2.8 -r 1.17.2.9 src/pop.h; ) > 0.9.11cvs17.24.patchset
 ( cvs diff -u -r 1.213.2.6 -r 1.213.2.7 src/folder.c; cvs diff -u -r 1.87.2.6 -r 1.87.2.7 src/folder.h; ) > 0.9.11cvs17.25.patchset
 ( cvs diff -u -r 1.1.2.5 -r 1.1.2.6 src/gtk/quicksearch.c; ) > 0.9.12cvs18.2.patchset
+( cvs diff -u -r 1.213.2.7 -r 1.213.2.8 src/folder.c; cvs diff -u -r 1.94.2.18 -r 1.94.2.19 src/messageview.c; cvs diff -u -r 1.16.2.5 -r 1.16.2.6 src/msgcache.c; cvs diff -u -r 1.56.2.12 -r 1.56.2.13 src/pop.c; cvs diff -u -r 1.17.2.9 -r 1.17.2.10 src/pop.h; cvs diff -u -r 1.47.2.6 -r 1.47.2.7 src/procheader.c; cvs diff -u -r 1.9.2.4 -r 1.9.2.5 src/common/defs.h; ) > 0.9.12cvs18.3.patchset
index 026e8a7519399f4645dcc48674330d9fd39b502a..362d0814538705399a77b269b48612fab70ee7a1 100644 (file)
@@ -13,7 +13,7 @@ INTERFACE_AGE=0
 BINARY_AGE=0
 EXTRA_VERSION=18
 EXTRA_RELEASE=
-EXTRA_GTK2_VERSION=.2
+EXTRA_GTK2_VERSION=.3
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}${EXTRA_RELEASE}${EXTRA_GTK2_VERSION}
index 730591c6b6f68d20dee9e4a306b2de0133346177..8acd15a9eaf602b617ad79c3db16dfd36561e2bc 100644 (file)
@@ -78,7 +78,7 @@
 #define CACHE_FILE             ".sylpheed_cache"
 #define MARK_FILE              ".sylpheed_mark"
 /* #warning FIXME_GTK2 */
-#define CACHE_VERSION          2020
+#define CACHE_VERSION          2021
 #define MARK_VERSION           2
 
 #define DEFAULT_SIGNATURE      ".signature"
index 94f0d1fa3daf2414ebf41b18e1a36c29d5fde3ae..80d7d9a6d565eea6e6ceef5805d6899dd3cc3c44 100644 (file)
@@ -48,6 +48,7 @@
 #include "log.h"
 #include "folder_item_prefs.h"
 #include "remotefolder.h"
+#include "pop.h"
 
 /* Dependecies to be removed ?! */
 #include "prefs_common.h"
@@ -2523,6 +2524,17 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
        g_relation_index(relation, 0, g_direct_hash, g_direct_equal);
        g_relation_index(relation, 1, g_direct_hash, g_direct_equal);
 
+       for (l = msglist ; l != NULL ; l = g_slist_next(l)) {
+               MsgInfo * msginfo = (MsgInfo *) l->data;
+
+               if (msginfo->planned_download != 0) {
+                       int old_planned = msginfo->planned_download;
+                       pop3_unmark(msginfo);
+                       /* little hack to reenable after */
+                       msginfo->planned_download = old_planned;
+               }
+       }
+
        /* 
         * Copy messages to destination folder and 
         * store new message numbers in newmsgnums
@@ -2570,17 +2582,26 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
                                        if (newmsginfo != NULL) {
                                                copy_msginfo_flags(msginfo, newmsginfo);
                                                num = newmsginfo->msgnum;
-                                               procmsg_msginfo_free(newmsginfo);
                                        }
                                }
                        } else {
                                newmsginfo = get_msginfo(dest, num);
                                if (newmsginfo != NULL) {
                                        add_msginfo_to_cache(dest, newmsginfo, msginfo);
-                                       procmsg_msginfo_free(newmsginfo);
                                }
                        }
 
+                       if (msginfo->planned_download 
+                           == POP3_PARTIAL_DLOAD_DELE) {
+                               pop3_mark_for_delete(newmsginfo);
+                       }
+                       if (msginfo->planned_download 
+                           == POP3_PARTIAL_DLOAD_DLOAD) {
+                               pop3_mark_for_download(newmsginfo);
+                       }
+                       procmsg_msginfo_free(newmsginfo);
+
+
                        if (num > lastnum)
                                lastnum = num;
                }
index 6591be71e672585df64c1e24399622320680c1a5..693d64a87a231cc3cd91d80999fcabd5ba83f66e 100644 (file)
@@ -1125,88 +1125,25 @@ static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
 static void partial_recv_dload_clicked(NoticeView *noticeview, 
                                       MsgInfo *msginfo)
 {
-       MsgInfo *tmpmsginfo;
-       gchar *file;
-
-       file = procmsg_get_message_file_path(msginfo);
-       if (!file) {
-               g_warning("can't get message file path.\n");
-               return;
-       }
-
-       tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
-       tmpmsginfo->folder = msginfo->folder;
-       tmpmsginfo->msgnum = msginfo->msgnum;
-
-       if (pop3_mark_for_download(tmpmsginfo->account_server, 
-                                  tmpmsginfo->account_login, 
-                                  tmpmsginfo->partial_recv, file,
-                                  folder_item_get_identifier(msginfo->folder), 
-                                  msginfo->msgnum) == 0) {
-               msginfo->planned_download = POP3_PARTIAL_DLOAD_DLOAD;
+       if (pop3_mark_for_download(msginfo) == 0) {
                partial_recv_show(noticeview, msginfo);
        }
-
-       procmsg_msginfo_free(tmpmsginfo);
-       g_free(file);
 }
 
 static void partial_recv_del_clicked(NoticeView *noticeview, 
                                       MsgInfo *msginfo)
 {
-       MsgInfo *tmpmsginfo;
-       gchar *file;
-
-       file = procmsg_get_message_file_path(msginfo);
-       if (!file) {
-               g_warning("can't get message file path.\n");
-               return;
-       }
-
-       tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
-       tmpmsginfo->folder = msginfo->folder;
-       tmpmsginfo->msgnum = msginfo->msgnum;
-
-       if (pop3_mark_for_delete(tmpmsginfo->account_server, 
-                                  tmpmsginfo->account_login, 
-                                  tmpmsginfo->partial_recv, file,
-                                  folder_item_get_identifier(msginfo->folder), 
-                                  msginfo->msgnum) == 0) {
-               msginfo->planned_download = POP3_PARTIAL_DLOAD_DELE;
+       if (pop3_mark_for_delete(msginfo) == 0) {
                partial_recv_show(noticeview, msginfo);
        }
-
-       procmsg_msginfo_free(tmpmsginfo);
-       g_free(file);
 }
 
 static void partial_recv_unmark_clicked(NoticeView *noticeview, 
                                       MsgInfo *msginfo)
 {
-       MsgInfo *tmpmsginfo;
-       gchar *file;
-
-       file = procmsg_get_message_file_path(msginfo);
-       if (!file) {
-               g_warning("can't get message file path.\n");
-               return;
-       }
-
-       tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
-       tmpmsginfo->folder = msginfo->folder;
-       tmpmsginfo->msgnum = msginfo->msgnum;
-
-       if (pop3_unmark(tmpmsginfo->account_server, 
-                       tmpmsginfo->account_login, 
-                       tmpmsginfo->partial_recv, file,
-                       folder_item_get_identifier(msginfo->folder), 
-                       msginfo->msgnum) == 0) {
-               msginfo->planned_download = POP3_PARTIAL_DLOAD_UNKN;
+       if (pop3_unmark(msginfo) == 0) {
                partial_recv_show(noticeview, msginfo);
        }
-
-       procmsg_msginfo_free(tmpmsginfo);
-       g_free(file);
 }
 
 static void select_account_cb(GtkWidget *w, gpointer data)
index b9651dcd66fcbf75570e1c9cebd75aed0fd485dd..cfc1d095b16a664c94077551789776c2e2b3d116 100644 (file)
@@ -392,6 +392,7 @@ MsgCache *msgcache_read_cache(FolderItem *item, const gchar *cache_file)
                READ_CACHE_DATA(msginfo->inreplyto, fp);
                READ_CACHE_DATA(msginfo->references, fp);
                READ_CACHE_DATA(msginfo->xref, fp);
+               READ_CACHE_DATA_INT(msginfo->planned_download, fp);
 
                msginfo->folder = item;
                msginfo->flags.tmp_flags |= tmp_flags;
@@ -462,6 +463,7 @@ void msgcache_write_cache(MsgInfo *msginfo, FILE *fp)
        WRITE_CACHE_DATA(msginfo->inreplyto, fp);
        WRITE_CACHE_DATA(msginfo->references, fp);
        WRITE_CACHE_DATA(msginfo->xref, fp);
+       WRITE_CACHE_DATA_INT(msginfo->planned_download, fp);
 }
 
 static void msgcache_write_flags(MsgInfo *msginfo, FILE *fp)
index 631d4cf2dab04dffdd49423553a9d2275748140d..a7ab021a393a1438b3a2911dcb69057269949e11 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -37,6 +37,9 @@
 #include "utils.h"
 #include "recv.h"
 #include "folder.h"
+#include "procmsg.h"
+#include "procheader.h"
+#include "msgcache.h"
 
 #include "log.h"
 #include "hooks.h"
@@ -408,7 +411,8 @@ static gint pop3_top_recv(Pop3Session *session, const gchar *data, guint len)
        mail_receive_data.data = g_strndup(data, len);
        hooks_invoke(MAIL_RECEIVE_HOOKLIST, &mail_receive_data);
 
-       partial_notice = g_strdup_printf("SC-Partially-Retrieved: %s\n"
+       partial_notice = g_strdup_printf("SC-Marked-For-Download: 0\n"
+                                        "SC-Partially-Retrieved: %s\n"
                                         "SC-Account-Server: %s\n"
                                         "SC-Account-Login: %s\n"
                                         "SC-Message-Size: %d",
@@ -719,10 +723,7 @@ static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session,
        return result;
 }
 
-static int pop3_uidl_mark_mail(const gchar *server, const gchar *login, 
-                         const gchar *muidl, const gchar *filename, 
-                         const gchar *folder_item_id, guint msgnum, 
-                         int download)
+static int pop3_uidl_mark_mail(MsgInfo *msginfo, int download)
 {
        gchar *path;
        gchar *pathnew;
@@ -735,32 +736,42 @@ static int pop3_uidl_mark_mail(const gchar *server, const gchar *login,
        int len;
        int start = TRUE;
        gchar partial_recv[POPBUFSIZE];
-       
+       int err = -1;
+
+       gchar *filename;
+       MsgInfo *tinfo;
+       filename = procmsg_get_message_file_path(msginfo);
+       if (!filename) {
+               g_warning("can't get message file path.\n");
+               return err;
+       }
+       tinfo = procheader_parse_file(filename, msginfo->flags, TRUE, TRUE);
+
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
-                          "uidl", G_DIR_SEPARATOR_S, server,
-                          "-", login, NULL);
+                          "uidl", G_DIR_SEPARATOR_S, tinfo->account_server,
+                          "-", tinfo->account_login, NULL);
        if ((fp = fopen(path, "rb")) == NULL) {
                perror("fopen1");
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
                path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
-                                  "uidl-", server,
-                                  "-", login, NULL);
+                                  "uidl-", tinfo->account_server,
+                                  "-", tinfo->account_login, NULL);
                if ((fp = fopen(path, "rb")) == NULL) {
                        if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                        g_free(path);
                }
-               return -1;
+               goto bail;
        }
 
        pathnew = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
-                          "uidl", G_DIR_SEPARATOR_S, server,
-                          "-", login, ".new", NULL);
+                          "uidl", G_DIR_SEPARATOR_S, tinfo->account_server,
+                          "-", tinfo->account_login, ".new", NULL);
        if ((fpnew = fopen(pathnew, "wb")) == NULL) {
                perror("fopen2");
                fclose(fp);
                g_free(pathnew);
-               return -1;      
+               goto bail;
        }
        
        now = time(NULL);
@@ -778,14 +789,17 @@ static int pop3_uidl_mark_mail(const gchar *server, const gchar *login,
                                recv_time = now;
                        }
                }
-               if (strcmp(muidl, uidl)) {
+               if (strcmp(tinfo->partial_recv, uidl)) {
                        fprintf(fpnew, "%s\t%ld\t%s\n", 
                                uidl, recv_time, partial_recv);
                } else {
                        gchar *stat = NULL;
                        if (download == POP3_PARTIAL_DLOAD_DLOAD) {
+                               gchar *folder_id = folder_item_get_identifier(
+                                                       msginfo->folder);
                                stat = g_strdup_printf("%s:%d",
-                                       folder_item_id, msgnum);
+                                       folder_id, msginfo->msgnum);
+                               g_free(folder_id);
                        }
                        else if (download == POP3_PARTIAL_DLOAD_UNKN)
                                stat = strdup("1");
@@ -807,22 +821,21 @@ static int pop3_uidl_mark_mail(const gchar *server, const gchar *login,
        
        if ((fp = fopen(filename,"rb")) == NULL) {
                perror("fopen3");
-               return -1;
+               goto bail;
        }
        pathnew = g_strdup_printf("%s.new", filename);
        if ((fpnew = fopen(pathnew, "wb")) == NULL) {
                perror("fopen4");
                fclose(fp);
                g_free(pathnew);
-               return -1;
+               goto bail;
        }
        
        while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
                buf[len]='\0';
                if (start) {
                        start = FALSE;
-                       if (download != POP3_PARTIAL_DLOAD_UNKN)
-                               fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
+                       fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
                                        download);
                        
                        if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
@@ -839,9 +852,15 @@ static int pop3_uidl_mark_mail(const gchar *server, const gchar *login,
        fclose(fp);
        unlink(filename);
        rename(pathnew, filename);
-       
        g_free(pathnew);
-       return 0;
+       err = 0;
+bail:
+       g_free(filename);
+       procmsg_msginfo_free(tinfo);
+       
+       msginfo->planned_download = download;
+       msgcache_update_msg(msginfo->folder->cache, msginfo);
+       return err;
 }
 
 /* Partial download:
@@ -868,28 +887,19 @@ static int pop3_uidl_mark_mail(const gchar *server, const gchar *login,
  * this mail from the server as soon as the leave_time preference specifies.
  */
  
-int pop3_mark_for_delete(const gchar *server, const gchar *login, 
-                        const gchar *muidl, const gchar *file, 
-                        const gchar *folder_item_id, guint msgnum)
+int pop3_mark_for_delete(MsgInfo *msginfo)
 {
-       return pop3_uidl_mark_mail(server, login, muidl, file, folder_item_id, 
-               msgnum, POP3_PARTIAL_DLOAD_DELE);
+       return pop3_uidl_mark_mail(msginfo, POP3_PARTIAL_DLOAD_DELE);
 }
 
-int pop3_mark_for_download(const gchar *server, const gchar *login, 
-                          const gchar *muidl, const gchar *file, 
-                          const gchar *folder_item_id, guint msgnum)
+int pop3_mark_for_download(MsgInfo *msginfo)
 {
-       return pop3_uidl_mark_mail(server, login, muidl, file, folder_item_id, 
-               msgnum, POP3_PARTIAL_DLOAD_DLOAD);
+       return pop3_uidl_mark_mail(msginfo, POP3_PARTIAL_DLOAD_DLOAD);
 }
 
-int pop3_unmark(const gchar *server, const gchar *login, 
-               const gchar *muidl, const gchar *file, 
-               const gchar *folder_item_id, guint msgnum)
+int pop3_unmark(MsgInfo *msginfo)
 {
-       return pop3_uidl_mark_mail(server, login, muidl, file, folder_item_id, 
-               msgnum, POP3_PARTIAL_DLOAD_UNKN);
+       return pop3_uidl_mark_mail(msginfo, POP3_PARTIAL_DLOAD_UNKN);
 }
 
 static void pop3_delete_old_partial(const gchar *file) 
index bbed958eeb05a021d56ca9030922f0480c2b8700..3efc55d0a1c67aaf8f06337ab847a8612b38fbbb 100644 (file)
--- a/src/pop.h
+++ b/src/pop.h
@@ -27,6 +27,7 @@
 #include <glib.h>
 #include <time.h>
 
+#include "procmsg.h"
 #include "session.h"
 #include "prefs_account.h"
 
@@ -170,23 +171,8 @@ gint pop3_write_uidl_list  (Pop3Session    *session);
 gint pop3_msg_in_uidl_list     (const gchar    *server, 
                                 const gchar    *login, 
                                 const gchar    *uidl);
-int pop3_mark_for_download     (const gchar    *server, 
-                                const gchar    *login, 
-                                const gchar    *uidl, 
-                                const gchar    *filename, 
-                                const gchar    *folder_item_id,
-                                guint           msgnum);
-int pop3_mark_for_delete       (const gchar    *server, 
-                                const gchar    *login, 
-                                const gchar    *uidl, 
-                                const gchar    *filename, 
-                                const gchar    *folder_item_id,
-                                guint           msgnum);
-int pop3_unmark                        (const gchar    *server, 
-                                const gchar    *login, 
-                                const gchar    *uidl, 
-                                const gchar    *filename, 
-                                const gchar    *folder_item_id,
-                                guint           msgnum);
+int pop3_mark_for_download     (MsgInfo        *msginfo);
+int pop3_mark_for_delete       (MsgInfo        *msginfo);
+int pop3_unmark                        (MsgInfo        *msginfo);
 
 #endif /* __POP_H__ */
index e65350c66e55507d8f062769b7bda9d2802b44cf..c6377caaa71b61482fb26f40ada071f3048eaa31 100644 (file)
@@ -500,14 +500,14 @@ enum
        H_STATUS        = 11,
        H_X_STATUS      = 12,
        H_FROM_SPACE    = 13,
-       H_X_FACE        = 14,
-       H_DISPOSITION_NOTIFICATION_TO = 15,
-       H_RETURN_RECEIPT_TO = 16,
-       H_SC_PARTIALLY_RETRIEVED = 17,
-       H_SC_ACCOUNT_SERVER = 18,
-       H_SC_ACCOUNT_LOGIN = 19,
-       H_SC_MESSAGE_SIZE = 20,
-       H_SC_PLANNED_DOWNLOAD = 21
+       H_SC_PLANNED_DOWNLOAD = 14,
+       H_X_FACE        = 15,
+       H_DISPOSITION_NOTIFICATION_TO = 16,
+       H_RETURN_RECEIPT_TO = 17,
+       H_SC_PARTIALLY_RETRIEVED = 18,
+       H_SC_ACCOUNT_SERVER = 19,
+       H_SC_ACCOUNT_LOGIN = 20,
+       H_SC_MESSAGE_SIZE = 21
 };
 
 static HeaderEntry hentry_full[] = {{"Date:",          NULL, FALSE},
@@ -524,6 +524,7 @@ static HeaderEntry hentry_full[] = {{"Date:",               NULL, FALSE},
                                   {"Status:",          NULL, FALSE},
                                   {"X-Status:",        NULL, FALSE},
                                   {"From ",            NULL, FALSE},
+                                  {"SC-Marked-For-Download:", NULL, FALSE},
                                   {"X-Face:",          NULL, FALSE},
                                   {"Disposition-Notification-To:", NULL, FALSE},
                                   {"Return-Receipt-To:", NULL, FALSE},
@@ -531,7 +532,6 @@ static HeaderEntry hentry_full[] = {{"Date:",               NULL, FALSE},
                                   {"SC-Account-Server:", NULL, FALSE},
                                   {"SC-Account-Login:",NULL, FALSE},
                                   {"SC-Message-Size:", NULL, FALSE},
-                                  {"SC-Marked-For-Download:", NULL, FALSE},
                                   {NULL,               NULL, FALSE}};
 
 static HeaderEntry hentry_short[] = {{"Date:",         NULL, FALSE},
@@ -548,6 +548,7 @@ static HeaderEntry hentry_short[] = {{"Date:",              NULL, FALSE},
                                    {"Status:",         NULL, FALSE},
                                    {"X-Status:",       NULL, FALSE},
                                    {"From ",           NULL, FALSE},
+                                   {"SC-Marked-For-Download:", NULL, FALSE},
                                    {NULL,              NULL, FALSE}};
 
 HeaderEntry* procheader_get_headernames(gboolean full)
@@ -703,7 +704,6 @@ static MsgInfo *parse_stream(void *data, gboolean isstring, MsgFlags flags,
                        msginfo->total_size = atoi(hp);
                        break;
                case H_SC_PLANNED_DOWNLOAD:
-                       if (msginfo->planned_download) break;
                        msginfo->planned_download = atoi(hp);
                        break;
 #ifdef ALLOW_HEADER_HINT