2007-09-29 [colin] 3.0.1cvs46
authorColin Leroy <colin@colino.net>
Sat, 29 Sep 2007 17:02:25 +0000 (17:02 +0000)
committerColin Leroy <colin@colino.net>
Sat, 29 Sep 2007 17:02:25 +0000 (17:02 +0000)
* src/imap.c
Notice disconnections faster

ChangeLog
PATCHSETS
configure.ac
src/imap.c

index 8949e6e381950c760abff88b161ec3b5832de2b8..4176691733379af4797557f426d0d34d0c8456a6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-09-29 [colin]     3.0.1cvs46
+
+       * src/imap.c
+               Notice disconnections faster
+
 2007-09-28 [colin]     3.0.1cvs45
 
        * src/addressbook.c
index 64a61855e261ba033ca82526dff66cdb04c763c1..2718f08a2c110b70ae9ab8b6b04c2da6c68cbb2d 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.61.2.69 -r 1.61.2.70 src/account.c;  ) > 3.0.1cvs43.patchset
 ( cvs diff -u -r 1.83.2.116 -r 1.83.2.117 src/mimeview.c;  ) > 3.0.1cvs44.patchset
 ( cvs diff -u -r 1.60.2.97 -r 1.60.2.98 src/addressbook.c;  cvs diff -u -r 1.28.2.30 -r 1.28.2.31 src/addrindex.c;  ) > 3.0.1cvs45.patchset
+( cvs diff -u -r 1.179.2.188 -r 1.179.2.189 src/imap.c;  ) > 3.0.1cvs46.patchset
index fec920f97d2bd52346ef2f29bd5105d658a273d1..0cebbb420c628e35cb1d375c5e92f9cff5d76013 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=0
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=45
+EXTRA_VERSION=46
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 6a7cbf969d8f06c5c7a32522d85997379f2a05df..692ce2657d8696dc763c2791d79c1d56f55162bd 100644 (file)
@@ -727,7 +727,6 @@ static void lock_session(IMAPSession *session)
 static void unlock_session(IMAPSession *session)
 {
        if (session) {
-               
                debug_print("unlocking session %p\n", session);
                session->busy = FALSE;
                imap_refresh_sensitivity(session);
@@ -736,6 +735,23 @@ static void unlock_session(IMAPSession *session)
        }
 }
 
+static void imap_disc_session_destroy(Folder *folder)
+{
+       RemoteFolder *rfolder = REMOTE_FOLDER(folder);
+       IMAPSession *session = NULL;
+       
+       if (!rfolder)
+               return;
+       session = IMAP_SESSION(rfolder->session);
+       if (!session)
+               return;
+
+       log_warning(LOG_PROTOCOL, _("IMAP4 connection broken\n"));
+       SESSION(session)->state = SESSION_DISCONNECTED;
+       session_destroy(SESSION(session));
+       rfolder->session = NULL;
+}
+
 static IMAPSession *imap_session_get(Folder *folder)
 {
        RemoteFolder *rfolder = REMOTE_FOLDER(folder);
@@ -1116,6 +1132,10 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                g_warning("can't select mailbox %s\n", item->path);
                g_free(filename);
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return NULL;
        }
 
@@ -1126,6 +1146,10 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                g_warning("can't fetch message %d\n", uid);
                g_free(filename);
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return NULL;
        }
 
@@ -1284,6 +1308,10 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                        unlock_session(session);
                        statusbar_progress_all(0,0,0);
                        statusbar_pop_all();
+                       if (ok == MAILIMAP_ERROR_STREAM) {
+                               imap_disc_session_destroy(folder);
+                               session = NULL;
+                       }
                        return -1;
                } else {
                        debug_print("appended new message as %d\n", new_uid);
@@ -1334,6 +1362,10 @@ static gint imap_add_msgs(Folder *folder, FolderItem *dest, GSList *file_list,
                gint a;
                ok = imap_select(session, IMAP_FOLDER(folder), dest->path,
                         &a, NULL, NULL, NULL, FALSE);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
        }
        return last_uid;
 }
@@ -1424,6 +1456,10 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
                         NULL, NULL, NULL, NULL, FALSE);
        if (ok != IMAP_SUCCESS) {
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return ok;
        }
 
@@ -1445,6 +1481,10 @@ static gint imap_do_copy_msgs(Folder *folder, FolderItem *dest,
                ok = imap_cmd_copy(session, seq_set, destdir, uid_mapping,
                        &source, &dest);
                
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                if (ok == IMAP_SUCCESS) {
                        if (relation && source && dest) {
                                GSList *s_list = flatten_mailimap_set(source);
@@ -1599,6 +1639,10 @@ static gint imap_do_remove_msgs(Folder *folder, FolderItem *dest,
                         NULL, NULL, NULL, NULL, FALSE);
        if (ok != IMAP_SUCCESS) {
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return ok;
        }
 
@@ -1618,12 +1662,20 @@ static gint imap_do_remove_msgs(Folder *folder, FolderItem *dest,
        if (ok != IMAP_SUCCESS) {
                log_warning(LOG_PROTOCOL, _("can't set deleted flags\n"));
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return ok;
        }
        ok = imap_cmd_expunge(session);
        if (ok != IMAP_SUCCESS) {
                log_warning(LOG_PROTOCOL, _("can't expunge\n"));
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return ok;
        }
        
@@ -2208,6 +2260,10 @@ static FolderItem *imap_create_folder(Folder *folder, FolderItem *parent,
                                g_free(imap_path);
                                g_free(dirpath);
                                unlock_session(session);
+                               if (ok == MAILIMAP_ERROR_STREAM) {
+                                       imap_disc_session_destroy(folder);
+                                       session = NULL;
+                               }
                                return NULL;
                        }
                        r = imap_threaded_list(folder, "", imap_path, &lep_list);
@@ -2310,6 +2366,10 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item,
        if (ok != IMAP_SUCCESS) {
                g_free(real_oldpath);
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return -1;
        }
 
@@ -2332,6 +2392,10 @@ static gint imap_rename_folder(Folder *folder, FolderItem *item,
                g_free(newpath);
                g_free(real_newpath);
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return -1;
        }
        g_free(item->name);
@@ -2415,6 +2479,10 @@ static gint imap_remove_folder_real(Folder *folder, FolderItem *item)
                ok = imap_cmd_close(session);
                if (ok != MAILIMAP_NO_ERROR) {
                        debug_print("close err %d\n", ok);
+                       if (ok == MAILIMAP_ERROR_STREAM) {
+                               imap_disc_session_destroy(folder);
+                               session = NULL;
+                       }
                        return IMAP_ERROR;
                }
        }
@@ -2431,6 +2499,10 @@ static gint imap_remove_folder_real(Folder *folder, FolderItem *item)
                log_warning(LOG_PROTOCOL, _("can't delete mailbox\n"));
                g_free(path);
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return -1;
        }
 
@@ -2796,9 +2868,13 @@ static gint imap_select(IMAPSession *session, IMAPFolder *folder,
 
        ok = imap_cmd_select(session, real_path,
                             exists, recent, unseen, uid_validity, block);
-       if (ok != IMAP_SUCCESS)
+       if (ok != IMAP_SUCCESS) {
                log_warning(LOG_PROTOCOL, _("can't select folder: %s\n"), real_path);
-       else {
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(FOLDER(folder));
+                       session = NULL;
+               }
+       } else {
                session->mbox = g_strdup(path);
                session->folder_content_changed = FALSE;
                session->exists = *exists;
@@ -2862,7 +2938,7 @@ static gint imap_status(IMAPSession *session, IMAPFolder *folder,
        g_free(real_path);
        if (r != MAILIMAP_NO_ERROR) {
                debug_print("status err %d\n", r);
-               return IMAP_ERROR;
+               return r;
        }
        
        if (data_status->st_info_list == NULL) {
@@ -3042,7 +3118,7 @@ static gint imap_cmd_select(IMAPSession *session, const gchar *folder,
                                 exists, recent, unseen, uid_validity);
        if (r != MAILIMAP_NO_ERROR) {
                debug_print("select err %d\n", r);
-               return IMAP_ERROR;
+               return r;
        }
        return IMAP_SUCCESS;
 }
@@ -3534,6 +3610,10 @@ static void *get_list_of_uids_thread(void *data)
                         NULL, NULL, NULL, NULL, TRUE);
        if (ok != IMAP_SUCCESS) {
                stuff->done = TRUE;
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return GINT_TO_POINTER(-1);
        }
 
@@ -3741,6 +3821,10 @@ GSList *imap_get_msginfos(Folder *folder, FolderItem *item,
                         NULL, NULL, NULL, NULL, FALSE);
        if (ok != IMAP_SUCCESS) {
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return NULL;
        }
        if (!(folder_has_parent_of_type(item, F_DRAFT) || 
@@ -3880,6 +3964,10 @@ gboolean imap_scan_required(Folder *folder, FolderItem *_item)
                                 &exists, &uid_next, &uid_val, &unseen, FALSE);
                if (ok != IMAP_SUCCESS) {
                        unlock_session(session);
+                       if (ok == MAILIMAP_ERROR_STREAM) {
+                               imap_disc_session_destroy(folder);
+                               session = NULL;
+                       }
                        return FALSE;
                }
 
@@ -3957,6 +4045,10 @@ void imap_change_flags(Folder *folder, FolderItem *item, MsgInfo *msginfo, MsgPe
        if ((ok = imap_select(session, IMAP_FOLDER(folder), msginfo->folder->path,
            NULL, NULL, NULL, NULL, FALSE)) != IMAP_SUCCESS) {
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return;
        }
        numlist.next = NULL;
@@ -4000,6 +4092,10 @@ void imap_change_flags(Folder *folder, FolderItem *item, MsgInfo *msginfo, MsgPe
                        ok = imap_set_message_flags(session, &numlist, flags_set, TRUE);
                        if (ok != IMAP_SUCCESS) {
                                unlock_session(session);
+                               if (ok == MAILIMAP_ERROR_STREAM) {
+                                       imap_disc_session_destroy(folder);
+                                       session = NULL;
+                               }
                                return;
                        }
                }
@@ -4008,6 +4104,10 @@ void imap_change_flags(Folder *folder, FolderItem *item, MsgInfo *msginfo, MsgPe
                        ok = imap_set_message_flags(session, &numlist, flags_unset, FALSE);
                        if (ok != IMAP_SUCCESS) {
                                unlock_session(session);
+                               if (ok == MAILIMAP_ERROR_STREAM) {
+                                       imap_disc_session_destroy(folder);
+                                       session = NULL;
+                               }
                                return;
                        }
                }
@@ -4036,6 +4136,10 @@ static gint imap_remove_msg(Folder *folder, FolderItem *item, gint uid)
                         NULL, NULL, NULL, NULL, FALSE);
        if (ok != IMAP_SUCCESS) {
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return ok;
        }
        numlist.next = NULL;
@@ -4046,6 +4150,10 @@ static gint imap_remove_msg(Folder *folder, FolderItem *item, gint uid)
        if (ok != IMAP_SUCCESS) {
                log_warning(LOG_PROTOCOL, _("can't set deleted flags: %d\n"), uid);
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return ok;
        }
 
@@ -4061,6 +4169,10 @@ static gint imap_remove_msg(Folder *folder, FolderItem *item, gint uid)
        if (ok != IMAP_SUCCESS) {
                log_warning(LOG_PROTOCOL, _("can't expunge\n"));
                unlock_session(session);
+               if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(folder);
+                       session = NULL;
+               }
                return ok;
        }
 
@@ -4146,6 +4258,10 @@ static /*gint*/ void *imap_get_flags_thread(void *data)
                if (ok != IMAP_SUCCESS) {
                        stuff->done = TRUE;
                        unlock_session(session);
+                       if (ok == MAILIMAP_ERROR_STREAM) {
+                               imap_disc_session_destroy(folder);
+                               session = NULL;
+                       }
                        return GINT_TO_POINTER(-1);
                }
 
@@ -4386,6 +4502,10 @@ static gboolean process_flags(gpointer key, gpointer value, gpointer user_data)
        }
 
        unlock_session(session);
+       if (ok == MAILIMAP_ERROR_STREAM) {
+                       imap_disc_session_destroy(item->folder);
+                       session = NULL;
+       }
        g_slist_free(data->msglist);    
        g_free(data);
        return TRUE;