2007-08-08 [colin] 2.10.0cvs99
authorColin Leroy <colin@colino.net>
Wed, 8 Aug 2007 06:57:41 +0000 (06:57 +0000)
committerColin Leroy <colin@colino.net>
Wed, 8 Aug 2007 06:57:41 +0000 (06:57 +0000)
* src/imap.c
Better way to fetch UIDs on non-UIDPLUS servers

ChangeLog
PATCHSETS
configure.ac
src/imap.c

index f3c4ec83ab1af5ce0c7565458569f67a9f0f6b2c..5216910b0493a83641b345f7f7481eca4e7d46f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-08-08 [colin]     2.10.0cvs99
+
+       * src/imap.c
+               Better way to fetch UIDs on non-UIDPLUS servers
+
 2007-08-07 [colin]     2.10.0cvs98
 
        * src/imap.c
index cc946cc6167e87d19221fe5511888b86bc53f6ac..9e6a6836aed5f1de80cad408ccee07e85d236590 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.204.2.144 -r 1.204.2.145 src/prefs_common.c;  cvs diff -u -r 1.103.2.90 -r 1.103.2.91 src/prefs_common.h;  cvs diff -u -r 1.96.2.180 -r 1.96.2.181 src/textview.c;  ) > 2.10.0cvs96.patchset
 ( cvs diff -u -r 1.1.2.9 -r 1.1.2.10 manual/account.xml;  cvs diff -u -r 1.1.2.39 -r 1.1.2.40 manual/advanced.xml;  cvs diff -u -r 1.1.2.8 -r 1.1.2.9 manual/fr/account.xml;  cvs diff -u -r 1.1.2.15 -r 1.1.2.16 manual/fr/advanced.xml;  ) > 2.10.0cvs97.patchset
 ( cvs diff -u -r 1.179.2.177 -r 1.179.2.178 src/imap.c;  cvs diff -u -r 1.94.2.143 -r 1.94.2.144 src/messageview.c;  cvs diff -u -r 1.16.2.53 -r 1.16.2.54 src/msgcache.c;  ) > 2.10.0cvs98.patchset
+( cvs diff -u -r 1.179.2.178 -r 1.179.2.179 src/imap.c;  ) > 2.10.0cvs99.patchset
index 724a8a44cfe5c5a48f958850d63cb642f3ced1db..0076fdca0d69da06182814515e390f2e5ab00294 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=10
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=98
+EXTRA_VERSION=99
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index ae40420c2f9610d5affc37c7457b5cced6c58d62..ce86d94e6beafd55b42fbfc1950dce4a65e3369f 100644 (file)
@@ -1178,22 +1178,33 @@ static gint imap_add_msg(Folder *folder, FolderItem *dest,
 static gint imap_get_msg_from_local(Folder *folder, FolderItem *dest, const gchar *real_file)
 {
        /* don't get session, already done. */
-       MsgInfo *msginfo, *r_msginfo;
+       MsgInfo *msginfo;
        MsgFlags flags = {0, 0};
        gint msgnum = 0;
        msginfo = procheader_parse_file(real_file, flags, FALSE, FALSE);
-       unlock_session(IMAP_SESSION(REMOTE_FOLDER(folder)->session));
-       folder_item_scan_full(dest, FALSE);
-       lock_session(IMAP_SESSION(REMOTE_FOLDER(folder)->session));
+
        if (msginfo && msginfo->msgid) {
-               r_msginfo = folder_item_get_msginfo_by_msgid(dest, msginfo->msgid);
-               if (r_msginfo) {
-                       msgnum = r_msginfo->msgnum;
-                       debug_print("get msgnum from msgid %s: %d\n", msginfo->msgid, msgnum);
+               GSList *msglist = folder_item_get_msg_list(dest);
+               GSList *cur;
+               gint found_num = 0;
+
+               /* gets last matching mail with msgid. Slower than by msgid but gets the
+                * most recent one */
+               for (cur = msglist ; cur != NULL ; cur = cur->next) {
+                       MsgInfo * r_msginfo;
+
+                       r_msginfo = (MsgInfo *) cur->data;
+                       
+                       if (r_msginfo->msgid && !strcmp(r_msginfo->msgid,msginfo->msgid)) {
+                               if (found_num < r_msginfo->msgnum) {
+                                       found_num = r_msginfo->msgnum;
+                               }
+                       }
                        procmsg_msginfo_free(r_msginfo);
-               } else {
-                       debug_print("no msgnum\n");
                }
+               msgnum = found_num;
+               g_slist_free(msglist);
+
        }
        procmsg_msginfo_free(msginfo);
        return msgnum;
@@ -1209,6 +1220,7 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
        MsgFileInfo *fileinfo;
        gint ok;
        gint curnum = 0, total = 0;
+       gboolean missing_uids = FALSE;
 
        g_return_val_if_fail(folder != NULL, -1);
        g_return_val_if_fail(dest != NULL, -1);
@@ -1265,9 +1277,10 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                        debug_print("appended new message as %d\n", new_uid);
                        /* put the local file in the imapcache, so that we don't
                         * have to fetch it back later. */
-                       if (new_uid == 0 && !(cur->next)) {
-                               debug_print("didn't get uid, last in list: scanning\n");
-                               new_uid = imap_get_msg_from_local(folder, dest, real_file);
+                       
+                       if (new_uid == 0) {
+                               missing_uids = TRUE;
+                               debug_print("Missing UID (0)\n");
                        }
                        if (new_uid > 0) {
                                gchar *cache_path = folder_item_get_path(dest);
@@ -1278,7 +1291,7 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                                                cache_path, G_DIR_SEPARATOR_S, 
                                                itos(new_uid), NULL);
                                        copy_file(real_file, cache_file, TRUE);
-                                       debug_print("copied to cache: %s\n", cache_file);
+                                       debug_print("got UID %d, copied to cache: %s\n", new_uid, cache_file);
                                        g_free(cache_file);
                                }
                                g_free(cache_path);
@@ -1295,6 +1308,46 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
 
                g_free(real_file);
        }
+       
+       if (missing_uids) {
+               unlock_session(IMAP_SESSION(REMOTE_FOLDER(folder)->session));
+               folder_item_scan_full(dest, FALSE);
+               lock_session(IMAP_SESSION(REMOTE_FOLDER(folder)->session));
+               for (cur = file_list; cur != NULL; cur = cur->next) {
+                       guint32 new_uid = 0;
+                       fileinfo = (MsgFileInfo *)cur->data;
+                       
+                       if (!fileinfo->file)
+                               continue;
+
+                       new_uid = imap_get_msg_from_local(folder, dest, fileinfo->file);
+                       debug_print("new uid %d from scanning\n", new_uid);
+                       if (new_uid > 0) {
+                               gchar *cache_path = folder_item_get_path(dest);
+                               if (!is_dir_exist(cache_path))
+                                       make_dir_hier(cache_path);
+                               if (is_dir_exist(cache_path)) {
+                                       gchar *cache_file = g_strconcat(
+                                               cache_path, G_DIR_SEPARATOR_S, 
+                                               itos(new_uid), NULL);
+                                       copy_file(fileinfo->file, cache_file, TRUE);
+                                       debug_print("copied to cache: %s\n", cache_file);
+                                       g_free(cache_file);
+                               }
+                               g_free(cache_path);
+                               g_relation_delete(relation, fileinfo->msginfo != NULL ? 
+                                                 (gpointer) fileinfo->msginfo : (gpointer) fileinfo,
+                                                 0);
+
+                               g_relation_insert(relation, fileinfo->msginfo != NULL ? 
+                                                 (gpointer) fileinfo->msginfo : (gpointer) fileinfo,
+                                                 GINT_TO_POINTER(new_uid));
+                       }
+                       if (last_uid < new_uid) {
+                               last_uid = new_uid;
+                       }
+               }
+       }
        statusbar_progress_all(0,0,0);
        statusbar_pop_all();