2005-06-11 [colin] 1.9.11cvs58
authorColin Leroy <colin@colino.net>
Sat, 11 Jun 2005 02:37:21 +0000 (02:37 +0000)
committerColin Leroy <colin@colino.net>
Sat, 11 Jun 2005 02:37:21 +0000 (02:37 +0000)
* src/imap.c
o Fix build without USE_PTHREAD
o Factorize imap_open
o Alertpanel in case of impossible connection
o Alertpanel in case of impossible login
o Fix deferred flags processing to force a
  flush before adding some more flags to process,
  but in another folder.

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/imap.c

index 667c9f95d3273ebfbae7c6f6532220d414354afb..9a82dbd8a285bb16fc7a2cb71ebdbb3b47864a7c 100644 (file)
@@ -1,3 +1,14 @@
+2005-06-11 [colin]     1.9.11cvs58
+
+       * src/imap.c
+               o Fix build without USE_PTHREAD
+               o Factorize imap_open
+               o Alertpanel in case of impossible connection
+               o Alertpanel in case of impossible login
+               o Fix deferred flags processing to force a 
+                 flush before adding some more flags to process,
+                 but in another folder.
+
 2005-06-10 [colin]     1.9.11cvs57
 
        * src/imap.c
 2005-06-10 [colin]     1.9.11cvs57
 
        * src/imap.c
index 57a931eb65fbf6f713665c088365b2ff83cd83bb..cb3e4c3ab58bcddd470ea961cba4b89a66bb2fb7 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.179.2.22 -r 1.179.2.23 src/imap.c;  ) > 1.9.11cvs55.patchset
 ( cvs diff -u -r 1.179.2.23 -r 1.179.2.24 src/imap.c;  ) > 1.9.11cvs56.patchset
 ( cvs diff -u -r 1.179.2.24 -r 1.179.2.25 src/imap.c;  cvs diff -u -r 1.49.2.46 -r 1.49.2.47 src/procmime.c;  cvs diff -u -r 1.11.2.11 -r 1.11.2.12 src/common/smtp.c;  cvs diff -u -r 1.2.2.8 -r 1.2.2.9 src/gtk/inputdialog.c;  ) > 1.9.11cvs57.patchset
 ( cvs diff -u -r 1.179.2.22 -r 1.179.2.23 src/imap.c;  ) > 1.9.11cvs55.patchset
 ( cvs diff -u -r 1.179.2.23 -r 1.179.2.24 src/imap.c;  ) > 1.9.11cvs56.patchset
 ( cvs diff -u -r 1.179.2.24 -r 1.179.2.25 src/imap.c;  cvs diff -u -r 1.49.2.46 -r 1.49.2.47 src/procmime.c;  cvs diff -u -r 1.11.2.11 -r 1.11.2.12 src/common/smtp.c;  cvs diff -u -r 1.2.2.8 -r 1.2.2.9 src/gtk/inputdialog.c;  ) > 1.9.11cvs57.patchset
+( cvs diff -u -r 1.179.2.25 -r 1.179.2.26 src/imap.c;  ) > 1.9.11cvs58.patchset
index 79761864d46ead9936329b47ee523d97fa12d465..32549bbb50bfe9c34ba7276162d866603c8cb941 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=57
+EXTRA_VERSION=58
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 8cfd4115ecc0bc0d46c7d5f3af80bf7a33167e62..87980ea5b80344998987fe44482c8dbc8538e121 100644 (file)
 #include "alertpanel.h"
 #include "sylpheed.h"
 #include "statusbar.h"
 #include "alertpanel.h"
 #include "sylpheed.h"
 #include "statusbar.h"
-#ifdef USE_PTHREAD
-#include <pthread.h>
-#endif
 
 #ifdef USE_PTHREAD
 
 #ifdef USE_PTHREAD
-typedef struct _thread_data {
-       gchar *server;
-       gushort port;
-       gboolean done;
-       SockInfo *sock;
-#ifdef USE_OPENSSL
-       SSLType ssl_type;
-#endif
-} thread_data;
+#include <pthread.h>
 #endif
 
 #endif
 
-
 typedef struct _IMAPFolder     IMAPFolder;
 typedef struct _IMAPSession    IMAPSession;
 typedef struct _IMAPNameSpace  IMAPNameSpace;
 typedef struct _IMAPFolder     IMAPFolder;
 typedef struct _IMAPSession    IMAPSession;
 typedef struct _IMAPNameSpace  IMAPNameSpace;
@@ -483,6 +471,15 @@ static gchar *imap_item_get_path           (Folder         *folder,
 
 static FolderClass imap_class;
 
 
 static FolderClass imap_class;
 
+typedef struct _thread_data {
+       gchar *server;
+       gushort port;
+       gboolean done;
+       SockInfo *sock;
+#ifdef USE_OPENSSL
+       SSLType ssl_type;
+#endif
+} thread_data;
 
 #ifdef USE_PTHREAD
 void *imap_getline_thread(void *data)
 
 #ifdef USE_PTHREAD
 void *imap_getline_thread(void *data)
@@ -917,6 +914,9 @@ static void imap_session_authenticate(IMAPSession *session,
        if (imap_auth(session, account->userid, pass, account->imap_auth_type) != IMAP_SUCCESS) {
                imap_cmd_logout(session);
                statusbar_pop_all();
        if (imap_auth(session, account->userid, pass, account->imap_auth_type) != IMAP_SUCCESS) {
                imap_cmd_logout(session);
                statusbar_pop_all();
+               alertpanel_error(_("Can't authenticate on IMAP4 server: %s"),
+                                account->recv_server);
+               
                return;
        }
        statusbar_pop_all();
                return;
        }
        statusbar_pop_all();
@@ -2062,8 +2062,6 @@ static SockInfo *imap_open_tunnel(const gchar *server,
 #endif
 }
 
 #endif
 }
 
-
-#ifdef USE_PTHREAD
 void *imap_open_thread(void *data)
 {
        SockInfo *sock = NULL;
 void *imap_open_thread(void *data)
 {
        SockInfo *sock = NULL;
@@ -2078,33 +2076,6 @@ void *imap_open_thread(void *data)
        td->done = TRUE;
        return sock;
 }
        td->done = TRUE;
        return sock;
 }
-#endif
-
-#if USE_OPENSSL
-static SockInfo *imap_open_blocking(const gchar *server, gushort port,
-                          SSLType ssl_type)
-#else
-static SockInfo *imap_open_blocking(const gchar *server, gushort port)
-#endif
-{
-       SockInfo *sock;
-       if ((sock = sock_connect(server, port)) == NULL) {
-               log_warning(_("Can't connect to IMAP4 server: %s:%d\n"),
-                           server, port);
-               return NULL;
-       }
-
-#if USE_OPENSSL
-       if (ssl_type == SSL_TUNNEL && !ssl_init_socket(sock)) {
-               log_warning(_("Can't establish IMAP4 session with: %s:%d\n"),
-                           server, port);
-               sock_close(sock);
-               sock = NULL;
-               return NULL;
-       }
-#endif
-       return sock;
-}
 
 #if USE_OPENSSL
 static SockInfo *imap_open(const gchar *server, gushort port,
 
 #if USE_OPENSSL
 static SockInfo *imap_open(const gchar *server, gushort port,
@@ -2113,12 +2084,12 @@ static SockInfo *imap_open(const gchar *server, gushort port,
 static SockInfo *imap_open(const gchar *server, gushort port)
 #endif
 {
 static SockInfo *imap_open(const gchar *server, gushort port)
 #endif
 {
-#if (defined USE_PTHREAD && defined __GLIBC__ && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)))
-       /* non blocking stuff */
        thread_data *td = g_new0(thread_data, 1);
        thread_data *td = g_new0(thread_data, 1);
+#if USE_PTHREAD
        pthread_t pt;
        pthread_t pt;
+#endif
        SockInfo *sock = NULL;
        SockInfo *sock = NULL;
-       
+
 #if USE_OPENSSL
        td->ssl_type = ssl_type;
 #endif
 #if USE_OPENSSL
        td->ssl_type = ssl_type;
 #endif
@@ -2128,26 +2099,24 @@ static SockInfo *imap_open(const gchar *server, gushort port)
 
        statusbar_print_all(_("Connecting to IMAP4 server: %s..."), server);
 
 
        statusbar_print_all(_("Connecting to IMAP4 server: %s..."), server);
 
+#if (defined USE_PTHREAD && defined __GLIBC__ && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)))
        if (pthread_create(&pt, PTHREAD_CREATE_JOINABLE,
                        imap_open_thread, td) != 0) {
                statusbar_pop_all();
        if (pthread_create(&pt, PTHREAD_CREATE_JOINABLE,
                        imap_open_thread, td) != 0) {
                statusbar_pop_all();
-               g_free(td->server);
-               g_free(td);
-#if USE_OPENSSL
-               return imap_open_blocking(server, port, ssl_type);
+               sock = imap_open_thread(td);
+       } else {        
+               debug_print("+++waiting for imap_open_thread...\n");
+               while(!td->done) {
+                       /* don't let the interface freeze while waiting */
+                       sylpheed_do_idle();
+               }
+
+               /* get the thread's return value and clean its resources */
+               pthread_join(pt, (void *)&sock);
+       }
 #else
 #else
-               return imap_open_blocking(server, port);
+       sock = imap_open_thread(td);
 #endif
 #endif
-       }
-       
-       debug_print("+++waiting for imap_open_thread...\n");
-       while(!td->done) {
-               /* don't let the interface freeze while waiting */
-               sylpheed_do_idle();
-       }
-
-       /* get the thread's return value and clean its resources */
-       pthread_join(pt, (void *)&sock);
 #if USE_OPENSSL
        if (sock && td->ssl_type == SSL_TUNNEL && !ssl_init_socket(sock)) {
                log_warning(_("Can't establish IMAP4 session with: %s:%d\n"),
 #if USE_OPENSSL
        if (sock && td->ssl_type == SSL_TUNNEL && !ssl_init_socket(sock)) {
                log_warning(_("Can't establish IMAP4 session with: %s:%d\n"),
@@ -2155,7 +2124,6 @@ static SockInfo *imap_open(const gchar *server, gushort port)
                sock_close(sock);
                sock = NULL;
                td->done = TRUE;
                sock_close(sock);
                sock = NULL;
                td->done = TRUE;
-               return NULL;
        }
 #endif
        g_free(td->server);
        }
 #endif
        g_free(td->server);
@@ -2163,14 +2131,13 @@ static SockInfo *imap_open(const gchar *server, gushort port)
 
        debug_print("---imap_open_thread returned %p\n", sock);
        statusbar_pop_all();
 
        debug_print("---imap_open_thread returned %p\n", sock);
        statusbar_pop_all();
+
+       if(!sock && !prefs_common.no_recv_err_panel) {
+               alertpanel_error(_("Can't connect to IMAP4 server: %s:%d"),
+                                server, port);
+       }
+
        return sock;
        return sock;
-#else
-#if USE_OPENSSL
-       return imap_open_blocking(server, port, ssl_type);
-#else
-       return imap_open_blocking(server, port);
-#endif
-#endif
 }
 
 #if USE_OPENSSL
 }
 
 #if USE_OPENSSL
@@ -4351,6 +4318,7 @@ static gint hashtable_process_tag = -1;
 typedef struct _hashtable_data {
        IMAPSession *session;
        GSList *msglist;
 typedef struct _hashtable_data {
        IMAPSession *session;
        GSList *msglist;
+       FolderItem *item;
 } hashtable_data;
 
 static gboolean process_flags(gpointer key, gpointer value, gpointer user_data)
 } hashtable_data;
 
 static gboolean process_flags(gpointer key, gpointer value, gpointer user_data)
@@ -4382,8 +4350,10 @@ static gboolean process_flags(gpointer key, gpointer value, gpointer user_data)
        return TRUE;
 }
 
        return TRUE;
 }
 
+static FolderItem *last_deferred_item = NULL;
 static gboolean process_hashtable(void *data)
 {
 static gboolean process_hashtable(void *data)
 {
+       FolderItem *item = (FolderItem *)data;
        debug_print("processing flags change hashtables\n");
        if (flags_set_table) {
                g_hash_table_foreach_remove(flags_set_table, process_flags, GINT_TO_POINTER(TRUE));
        debug_print("processing flags change hashtables\n");
        if (flags_set_table) {
                g_hash_table_foreach_remove(flags_set_table, process_flags, GINT_TO_POINTER(TRUE));
@@ -4396,6 +4366,8 @@ static gboolean process_hashtable(void *data)
                flags_unset_table = NULL;
        }
        
                flags_unset_table = NULL;
        }
        
+       folder_item_scan_full(item, FALSE);
+       hashtable_process_tag = -1;
        return FALSE;
 }
 
        return FALSE;
 }
 
@@ -4416,6 +4388,18 @@ void imap_change_flags(Folder *folder, FolderItem *item, MsgInfo *msginfo, MsgPe
        session = imap_session_get(folder);
        if (!session) return;
 printf("changing flags\n");
        session = imap_session_get(folder);
        if (!session) return;
 printf("changing flags\n");
+
+       if (hashtable_process_tag != -1 && item != last_deferred_item
+       &&  last_deferred_item != NULL) {
+               debug_print("forcing flush for %s (!= %s)\n",
+                               last_deferred_item->path,
+                               item->path);
+               gtk_timeout_remove(hashtable_process_tag);
+               process_hashtable(last_deferred_item);
+               hashtable_process_tag = -1;
+       }
+       last_deferred_item = item;
+       
        if ((ok = imap_select(session, IMAP_FOLDER(folder), msginfo->folder->path,
            NULL, NULL, NULL, NULL, FALSE)) != IMAP_SUCCESS)
                return;
        if ((ok = imap_select(session, IMAP_FOLDER(folder), msginfo->folder->path,
            NULL, NULL, NULL, NULL, FALSE)) != IMAP_SUCCESS)
                return;
@@ -4444,7 +4428,7 @@ printf("changing flags\n");
 
        /* instead of performing an UID STORE command for each message change,
         * as a lot of them can change "together", we just fill in hashtables
 
        /* instead of performing an UID STORE command for each message change,
         * as a lot of them can change "together", we just fill in hashtables
-        * and defer the treatment 500ms so that we're able to send only one
+        * and defer the treatment 100ms so that we're able to send only one
         * command.
         */
        if (flags_set) {
         * command.
         */
        if (flags_set) {
@@ -4474,7 +4458,7 @@ printf("changing flags\n");
        if (hashtable_process_tag != -1)
                gtk_timeout_remove(hashtable_process_tag);
                
        if (hashtable_process_tag != -1)
                gtk_timeout_remove(hashtable_process_tag);
                
-       hashtable_process_tag = gtk_timeout_add(500, process_hashtable, NULL);
+       hashtable_process_tag = gtk_timeout_add(100, process_hashtable, item);
        
        return;
 }
        
        return;
 }
@@ -4501,6 +4485,17 @@ static gint imap_remove_msg(Folder *folder, FolderItem *item, gint uid)
        session = imap_session_get(folder);
        if (!session) return -1;
 
        session = imap_session_get(folder);
        if (!session) return -1;
 
+       if (hashtable_process_tag != -1 && item != last_deferred_item
+       &&  last_deferred_item != NULL) {
+               debug_print("forcing flush for %s (!= %s)\n",
+                               last_deferred_item->path,
+                               item->path);
+               gtk_timeout_remove(hashtable_process_tag);
+               process_hashtable(last_deferred_item);
+               hashtable_process_tag = -1;
+       }
+       last_deferred_item = item;
+
 printf("removing messages\n");
        ok = imap_select(session, IMAP_FOLDER(folder), item->path,
                         NULL, NULL, NULL, NULL, FALSE);
 printf("removing messages\n");
        ok = imap_select(session, IMAP_FOLDER(folder), item->path,
                         NULL, NULL, NULL, NULL, FALSE);
@@ -4520,7 +4515,7 @@ printf("removing messages\n");
        if (hashtable_process_tag != -1)
                gtk_timeout_remove(hashtable_process_tag);
                
        if (hashtable_process_tag != -1)
                gtk_timeout_remove(hashtable_process_tag);
                
-       hashtable_process_tag = gtk_timeout_add(500, process_hashtable, NULL);
+       hashtable_process_tag = gtk_timeout_add(100, process_hashtable, item);
 
        IMAP_FOLDER_ITEM(item)->uid_list = g_slist_remove(
            IMAP_FOLDER_ITEM(item)->uid_list, numlist.data);
 
        IMAP_FOLDER_ITEM(item)->uid_list = g_slist_remove(
            IMAP_FOLDER_ITEM(item)->uid_list, numlist.data);