0.8.6claws60
authorChristoph Hohmann <reboot@gmx.ch>
Wed, 4 Dec 2002 19:38:21 +0000 (19:38 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Wed, 4 Dec 2002 19:38:21 +0000 (19:38 +0000)
* src/imap.[ch]
        put imap authentication code into a new function and
        remove it from imap_session_new that will allow to
        send other commands before authentication

ChangeLog.claws
configure.in
src/imap.c
src/imap.h

index 87caeb5..4873e88 100644 (file)
@@ -1,3 +1,10 @@
+2002-12-04 [christoph] 0.8.6claws60
+
+       * src/imap.[ch]
+               put imap authentication code into a new function and
+               remove it from imap_session_new that will allow to
+               send other commands before authentication
+
 2002-12-04 [christoph] 0.8.6claws59
 
        * src/imap.[ch]
index 2e6ec74..ddba5bd 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws59
+EXTRA_VERSION=claws60
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 70b5f20..534ad32 100644 (file)
@@ -415,10 +415,17 @@ static IMAPSession *imap_session_get(Folder *folder)
                rfolder->session =
                        imap_session_new(folder->account);
                if (rfolder->session) {
-                       imap_parse_namespace(IMAP_SESSION(rfolder->session),
-                                            IMAP_FOLDER(folder));
-                       rfolder->session->last_access_time = time(NULL);
-                       imap_reset_uid_lists(folder);
+                       if (!IMAP_SESSION(rfolder->session)->authenticated)
+                               imap_session_authenticate(IMAP_SESSION(rfolder->session), folder->account);
+                       if (IMAP_SESSION(rfolder->session)->authenticated) {
+                               imap_parse_namespace(IMAP_SESSION(rfolder->session),
+                                                    IMAP_FOLDER(folder));
+                               rfolder->session->last_access_time = time(NULL);
+                               imap_reset_uid_lists(folder);
+                       } else {
+                               session_destroy(rfolder->session);
+                               rfolder->session = NULL;
+                       }
                }
                statusbar_pop_all();
                return IMAP_SESSION(rfolder->session);
@@ -446,9 +453,17 @@ static IMAPSession *imap_session_get(Folder *folder)
                rfolder->session =
                        imap_session_new(folder->account);
                if (rfolder->session) {
-                       imap_parse_namespace(IMAP_SESSION(rfolder->session),
-                                            IMAP_FOLDER(folder));
-                       imap_reset_uid_lists(folder);
+                       if (!IMAP_SESSION(rfolder->session)->authenticated)
+                               imap_session_authenticate(IMAP_SESSION(rfolder->session), folder->account);
+                       if (IMAP_SESSION(rfolder->session)->authenticated) {
+                               imap_parse_namespace(IMAP_SESSION(rfolder->session),
+                                                    IMAP_FOLDER(folder));
+                               rfolder->session->last_access_time = time(NULL);
+                               imap_reset_uid_lists(folder);
+                       } else {
+                               session_destroy(rfolder->session);
+                               rfolder->session = NULL;
+                       }
                }
        }
 
@@ -463,7 +478,6 @@ Session *imap_session_new(const PrefsAccount *account)
        IMAPSession *session;
        SockInfo *imap_sock;
        gushort port;
-       gchar *pass;
        gboolean is_preauth;
 
 #ifdef USE_SSL
@@ -508,26 +522,6 @@ Session *imap_session_new(const PrefsAccount *account)
        imap_greeting(imap_sock, &is_preauth);
        log_message("IMAP connection is %s-authenticated\n",
                    (is_preauth) ? "pre" : "un");
-       if (!is_preauth) {
-               g_return_val_if_fail(account->userid != NULL, NULL);
-
-               pass = account->passwd;
-               if (!pass) {
-                       gchar *tmp_pass;
-                       tmp_pass = input_dialog_query_password(account->recv_server, account->userid);
-                       if (!tmp_pass)
-                               return NULL;
-                       Xstrdup_a(pass, tmp_pass, {g_free(tmp_pass); return NULL;});
-                       g_free(tmp_pass);
-               }
-
-               if (imap_cmd_login(imap_sock, account->userid, pass) != IMAP_SUCCESS) {
-                       imap_cmd_logout(imap_sock);
-                       sock_close(imap_sock);
-                       return NULL;
-               }
-       }
-
        session = g_new(IMAPSession, 1);
 
        SESSION(session)->type             = SESSION_IMAP;
@@ -541,12 +535,38 @@ Session *imap_session_new(const PrefsAccount *account)
        SESSION(session)->destroy          = imap_session_destroy;
 
        session->mbox = NULL;
+       session->authenticated = is_preauth;
 
        session_list = g_list_append(session_list, session);
 
        return SESSION(session);
 }
 
+void imap_session_authenticate(IMAPSession *session, const PrefsAccount *account)
+{
+       gchar *pass;
+
+       g_return_if_fail(account->userid != NULL);
+
+       pass = account->passwd;
+       if (!pass) {
+               gchar *tmp_pass;
+               tmp_pass = input_dialog_query_password(account->recv_server, account->userid);
+               if (!tmp_pass)
+                       return;
+               Xstrdup_a(pass, tmp_pass, {g_free(tmp_pass); return;});
+               g_free(tmp_pass);
+       }
+
+       if (imap_cmd_login(SESSION(session)->sock, account->userid, pass) != IMAP_SUCCESS) {
+               imap_cmd_logout(SESSION(session)->sock);
+               sock_close(SESSION(session)->sock);
+               return;
+       }
+
+       session->authenticated = TRUE;
+}
+
 void imap_session_destroy(Session *session)
 {
        sock_close(session->sock);
index bf6d859..c13763b 100644 (file)
@@ -60,6 +60,7 @@ struct _IMAPSession
 
        gchar *mbox;
        time_t last_access_time;
+       gboolean authenticated;
 };
 
 struct _IMAPNameSpace
@@ -98,6 +99,8 @@ Folder        *imap_folder_new                (const gchar    *name,
 void    imap_folder_destroy            (Folder         *folder);
 
 Session *imap_session_new              (const PrefsAccount *account);
+void imap_session_authenticate         (IMAPSession        *session,
+                                        const PrefsAccount *account);
 void imap_session_destroy              (Session        *session);
 void imap_session_destroy_all          (void);