2007-04-03 [colin] 2.8.1cvs85
authorColin Leroy <colin@colino.net>
Tue, 3 Apr 2007 16:52:42 +0000 (16:52 +0000)
committerColin Leroy <colin@colino.net>
Tue, 3 Apr 2007 16:52:42 +0000 (16:52 +0000)
* src/inc.c
Fix double-ask of offline override in
certain cases
* src/imap.c
* src/imap.h
* src/imap_gtk.c
Much more efficient way to synchronise
for offline use
* src/etpan/imap-thread.c
Fix possible segs
* src/folder.c
* src/gtk/quicksearch.c
Fix some GUI lags

ChangeLog
PATCHSETS
configure.ac
src/etpan/imap-thread.c
src/folder.c
src/gtk/quicksearch.c
src/imap.c
src/imap.h
src/imap_gtk.c
src/inc.c

index 9bc4af3..9446fc0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2007-04-03 [colin]     2.8.1cvs85
+
+       * src/inc.c
+               Fix double-ask of offline override in
+               certain cases
+       * src/imap.c
+       * src/imap.h
+       * src/imap_gtk.c
+               Much more efficient way to synchronise
+               for offline use
+       * src/etpan/imap-thread.c
+               Fix possible segs
+       * src/folder.c
+       * src/gtk/quicksearch.c
+               Fix some GUI lags
+
 2007-04-03 [paul]      2.8.1cvs84
 
        * src/filtering.c
index 78a0efb..b0a0add 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.22 -r 1.1.2.23 src/plugins/bogofilter/bogofilter_gtk.c;  ) > 2.8.1cvs82.patchset
 ( cvs diff -u -r 1.395.2.294 -r 1.395.2.295 src/summaryview.c;  cvs diff -u -r 1.1.2.28 -r 1.1.2.29 src/plugins/bogofilter/bogofilter.c;  cvs diff -u -r 1.18.2.50 -r 1.18.2.51 src/plugins/spamassassin/spamassassin.c;  ) > 2.8.1cvs83.patchset
 ( cvs diff -u -r 1.60.2.30 -r 1.60.2.31 src/filtering.c;  cvs diff -u -r 1.213.2.138 -r 1.213.2.139 src/folder.c;  cvs diff -u -r 1.87.2.39 -r 1.87.2.40 src/folder.h;  cvs diff -u -r 1.204.2.129 -r 1.204.2.130 src/prefs_common.c;  cvs diff -u -r 1.103.2.79 -r 1.103.2.80 src/prefs_common.h;  cvs diff -u -r 1.1.2.22 -r 1.1.2.23 src/prefs_other.c;  ) > 2.8.1cvs84.patchset
+( cvs diff -u -r 1.213.2.139 -r 1.213.2.140 src/folder.c;  cvs diff -u -r 1.179.2.163 -r 1.179.2.164 src/imap.c;  cvs diff -u -r 1.34.2.13 -r 1.34.2.14 src/imap.h;  cvs diff -u -r 1.1.2.44 -r 1.1.2.45 src/imap_gtk.c;  cvs diff -u -r 1.149.2.71 -r 1.149.2.72 src/inc.c;  cvs diff -u -r 1.1.4.76 -r 1.1.4.77 src/etpan/imap-thread.c;  cvs diff -u -r 1.1.2.64 -r 1.1.2.65 src/gtk/quicksearch.c;  ) > 2.8.1cvs85.patchset
index 61a0063..faff486 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=84
+EXTRA_VERSION=85
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 5b7c356..e16f275 100644 (file)
@@ -65,7 +65,7 @@ static void delete_imap(Folder *folder, mailimap *imap)
        key.data = &imap;
        key.len = sizeof(imap);
        chash_delete(courier_workaround_hash, &key, NULL);
-       if (imap->imap_stream) {
+       if (imap && imap->imap_stream) {
                /* we don't want libetpan to logout */
                mailstream_close(imap->imap_stream);
                imap->imap_stream = NULL;
@@ -1008,10 +1008,10 @@ int imap_threaded_noop(Folder * folder, unsigned int * p_exists)
        
        imap = get_imap(folder);
        param.imap = imap;
-       
+
        threaded_run(folder, &param, &result, noop_run);
        
-       if (imap->imap_selection_info != NULL) {
+       if (imap && imap->imap_selection_info != NULL) {
                * p_exists = imap->imap_selection_info->sel_exists;
        }
        else {
@@ -1086,7 +1086,7 @@ int imap_threaded_starttls(Folder * folder, const gchar *host, int port)
        
        debug_print("imap starttls - end\n");
 
-       if (result.error == 0 && !etpan_skip_ssl_cert_check) {
+       if (result.error == 0 && param.imap && !etpan_skip_ssl_cert_check) {
                cert_len = (int)mailstream_ssl_get_certificate(param.imap->imap_stream, &certificate);
                if (etpan_certificate_check(certificate, cert_len, &param) < 0)
                        result.error = MAILIMAP_ERROR_STREAM;
@@ -1283,7 +1283,7 @@ int imap_threaded_select(Folder * folder, const char * mb,
        if (result.error != MAILIMAP_NO_ERROR)
                return result.error;
        
-       if (imap->imap_selection_info == NULL)
+       if (!imap || imap->imap_selection_info == NULL)
                return MAILIMAP_ERROR_PARSE;
        
        * exists = imap->imap_selection_info->sel_exists;
@@ -1343,7 +1343,7 @@ int imap_threaded_examine(Folder * folder, const char * mb,
        if (result.error != MAILIMAP_NO_ERROR)
                return result.error;
        
-       if (imap->imap_selection_info == NULL)
+       if (!imap || imap->imap_selection_info == NULL)
                return MAILIMAP_ERROR_PARSE;
        
        * exists = imap->imap_selection_info->sel_exists;
@@ -2799,7 +2799,8 @@ static int socket_connect_cmd(mailimap * imap, const char * command,
        if (r != MAILIMAP_NO_ERROR_AUTHENTICATED
        &&  r != MAILIMAP_NO_ERROR_NON_AUTHENTICATED) {
                mailstream_close(s);
-               imap->imap_stream = NULL;
+               if (imap)
+                       imap->imap_stream = NULL;
                return r;
        }
        
index 47d87d8..bcc1f30 100644 (file)
@@ -2590,6 +2590,8 @@ gint folder_item_fetch_all_msg(FolderItem *item)
                                        folder->ui_func_data ?
                                        folder->ui_func_data :
                                        GINT_TO_POINTER(num));
+               if (num % 50 == 0)
+                       GTK_EVENTS_FLUSH();
 
                msg = folder_item_fetch_msg(item, msginfo->msgnum);
                if (!msg) {
index 7e32421..072da80 100644 (file)
@@ -1081,14 +1081,17 @@ void quicksearch_pass_key(QuickSearch *quicksearch, guint val, GdkModifierType m
 static gboolean quicksearch_match_subfolder(QuickSearch *quicksearch,
                                 FolderItem *src)
 {
-       GSList *msglist = folder_item_get_msg_list(src);
+       GSList *msglist = NULL;
        GSList *cur;
        gboolean result = FALSE;
-       gint num = 0, total = src->total_msgs;
+       gint num = 0, total = 0;
        gint interval = quicksearch_is_fast(quicksearch) ? 5000:100;
 
        statusbar_print_all(_("Searching in %s... \n"),
                src->path ? src->path : "(null)");
+               
+       msglist = folder_item_get_msg_list(src);
+       total = src->total_msgs;
        folder_item_update_freeze();
        for (cur = msglist; cur != NULL; cur = cur->next) {
                MsgInfo *msg = (MsgInfo *)cur->data;
index 69c3d58..b51447b 100644 (file)
@@ -959,22 +959,22 @@ static gchar *imap_fetch_msg(Folder *folder, FolderItem *item, gint uid)
        return imap_fetch_msg_full(folder, item, uid, TRUE, TRUE);
 }
 
-static guint get_size_with_crs(MsgInfo *info
+static guint get_file_size_with_crs(const gchar *filename
 {
        FILE *fp = NULL;
        guint cnt = 0;
        gchar buf[4096];
        
-       if (info == NULL)
+       if (filename == NULL)
                return -1;
        
-       fp = procmsg_open_message(info);
+       fp = fopen(filename, "rb");
        if (!fp)
                return -1;
        
        while (fgets(buf, sizeof (buf), fp) != NULL) {
                cnt += strlen(buf);
-               if (!strstr(buf, "\r") && strstr(buf, "\n"))
+               if (!strstr(buf, "\r\n") && strstr(buf, "\n"))
                        cnt++;
        }
        
@@ -1005,9 +1005,8 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                /* see whether the local file represents the whole message
                 * or not. As the IMAP server reports size with \r chars,
                 * we have to update the local file (UNIX \n only) size */
-               MsgInfo *msginfo = imap_parse_msg(filename, item);
                MsgInfo *cached = msgcache_get_msg(item->cache,uid);
-               guint have_size = get_size_with_crs(msginfo);
+               guint have_size = get_file_size_with_crs(filename);
 
                if (cached)
                        debug_print("message %d has been already %scached (%d/%d).\n", uid,
@@ -1016,17 +1015,14 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                
                if (cached && (cached->size <= have_size || !body)) {
                        procmsg_msginfo_free(cached);
-                       procmsg_msginfo_free(msginfo);
                        file_strip_crs(filename);
                        return filename;
                } else if (!cached && time(NULL) - get_file_mtime(filename) < 60) {
                        debug_print("message not cached and file recent, considering file complete\n");
-                       procmsg_msginfo_free(msginfo);
                        file_strip_crs(filename);
                        return filename;
                } else {
                        procmsg_msginfo_free(cached);
-                       procmsg_msginfo_free(msginfo);
                }
        }
 
@@ -1063,6 +1059,55 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
        return filename;
 }
 
+static gboolean imap_is_msg_fully_cached(Folder *folder, FolderItem *item, gint uid)
+{
+       gchar *path, *filename;
+       guint size = 0;
+       MsgInfo *cached = msgcache_get_msg(item->cache,uid);
+       
+       if (!cached)
+               return FALSE;
+
+       path = folder_item_get_path(item);
+       if (!is_dir_exist(path))
+               return FALSE;
+
+       filename = g_strconcat(path, G_DIR_SEPARATOR_S, itos(uid), NULL);
+       g_free(path);
+       if (is_file_exist(filename)) {
+               if (cached && cached->total_size == cached->size) {
+                       /* fast path */
+                       g_free(filename);
+                       return TRUE;
+               }
+               size = get_file_size_with_crs(filename);
+               g_free(filename);
+       }
+       if (cached && size >= cached->size) {
+               cached->total_size = cached->size;
+               procmsg_msginfo_free(cached);
+               return TRUE;
+       }
+       if (cached)
+               procmsg_msginfo_free(cached);
+       return FALSE;   
+}
+
+void imap_cache_msg(FolderItem *item, gint msgnum)
+{
+       Folder *folder = NULL;
+       
+       if (!item)
+               return;
+       folder = item->folder;
+       
+       if (!imap_is_msg_fully_cached(folder, item, msgnum)) {
+               gchar *tmp = imap_fetch_msg_full(folder, item, msgnum, TRUE, TRUE);
+               debug_print("fetched %s\n", tmp);
+               g_free(tmp);
+       }
+}
+
 static gint imap_add_msg(Folder *folder, FolderItem *dest, 
                         const gchar *file, MsgFlags *flags)
 {
index d329fce..52a117e 100644 (file)
@@ -39,4 +39,5 @@ void imap_disconnect_all(void);
 gint imap_scan_tree_real(Folder *folder, gboolean subs_only);
 gint imap_subscribe(Folder *folder, FolderItem *item, gchar *rpath, gboolean sub);
 GList *imap_scan_subtree(Folder *folder, FolderItem *item, gboolean unsubs_only, gboolean recursive);
+void imap_cache_msg(FolderItem *item, gint msgnum);
 #endif /* __IMAP_H__ */
index bb701be..42df6a8 100644 (file)
@@ -40,6 +40,7 @@
 #include "imap.h"
 #include "inc.h"
 #include "prefs_common.h"
+#include "statusbar.h"
 #include "summaryview.h"
 
 static void new_folder_cb(FolderView *folderview, guint action, GtkWidget *widget);
@@ -373,13 +374,25 @@ void imap_gtk_synchronise(FolderItem *item)
        gtk_widget_set_sensitive(folderview->ctree, FALSE);
        main_window_progress_on(mainwin);
        GTK_EVENTS_FLUSH();
-       if (item->no_select == FALSE && folder_item_fetch_all_msg(item) < 0) {
-               gchar *name;
+       if (item->no_select == FALSE) {
+               GSList *mlist;
+               GSList *cur;
+               gint num = 0;
+               gint total = item->total_msgs;
+
+               mlist = folder_item_get_msg_list(item);
+               for (cur = mlist; cur != NULL; cur = cur->next) {
+                       MsgInfo *msginfo = (MsgInfo *)cur->data;
+                       imap_cache_msg(msginfo->folder, msginfo->msgnum);
+                       statusbar_progress_all(num++,total, 100);
+                       if (num % 100 == 0)
+                               GTK_EVENTS_FLUSH();
+               }
 
-               name = trim_string(item->name, 32);
-               alertpanel_error(_("Error occurred while downloading messages in '%s'."), name);
-               g_free(name);
+               statusbar_progress_all(0,0,0);
+               procmsg_msg_list_free(mlist);
        }
+
        folder_set_ui_func(item->folder, NULL, NULL);
        main_window_progress_off(mainwin);
        gtk_widget_set_sensitive(folderview->ctree, TRUE);
index abb043b..9ec2c36 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -1481,8 +1481,7 @@ gboolean inc_offline_should_override(gboolean force_ask, const gchar *msg)
                                !force_ask? _("On_ly once"):NULL);
                g_free(tmp);
                if (answer == G_ALERTALTERNATE) {
-                       if (!force_ask)
-                               overridden_yes = time(NULL);
+                       overridden_yes = time(NULL);
                        return TRUE;
                } else if (answer == G_ALERTDEFAULT) {
                        if (!force_ask)