2005-08-27 [colin] 1.9.13cvs63
authorColin Leroy <colin@colino.net>
Sat, 27 Aug 2005 17:42:27 +0000 (17:42 +0000)
committerColin Leroy <colin@colino.net>
Sat, 27 Aug 2005 17:42:27 +0000 (17:42 +0000)
* src/imap.c
* src/etpan/imap-thread.c
* src/etpan/imap-thread.h
Implement automatic choosing of login method
Fixes bug #791
* src/gtk/.cvsignore
Add sylpheed-marshal.[ch]

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/etpan/imap-thread.c
src/etpan/imap-thread.h
src/gtk/.cvsignore
src/imap.c

index 280b9297836d2d490a60ac1720a0cc9be229cfe5..dc978c7da51e606bce5b0a6a2b85e2dc94fa989c 100644 (file)
@@ -1,3 +1,13 @@
+2005-08-27 [colin]     1.9.13cvs63
+
+       * src/imap.c
+       * src/etpan/imap-thread.c
+       * src/etpan/imap-thread.h
+               Implement automatic choosing of login method
+               Fixes bug #791
+       * src/gtk/.cvsignore
+               Add sylpheed-marshal.[ch]
+
 2005-08-27 [colin]     1.9.13cvs62
 
        * src/common/utils.c
index 704ed27da1b8c115cff827e93a642ef4210570dc..14922eb1a3d20c6d6ac7436478720ca6d7dfb39c 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.49.2.56 -r 1.49.2.57 src/procmime.c;  ) > 1.9.13cvs60.patchset
 ( cvs diff -u -r 1.43.2.21 -r 1.43.2.22 src/toolbar.c;  cvs diff -u -r 1.19.2.4 -r 1.19.2.5 src/toolbar.h;  ) > 1.9.13cvs61.patchset
 ( cvs diff -u -r 1.36.2.40 -r 1.36.2.41 src/common/utils.c;  ) > 1.9.13cvs62.patchset
+( cvs diff -u -r 1.179.2.60 -r 1.179.2.61 src/imap.c;  cvs diff -u -r 1.1.4.17 -r 1.1.4.18 src/etpan/imap-thread.c;  cvs diff -u -r 1.1.4.4 -r 1.1.4.5 src/etpan/imap-thread.h;  cvs diff -u -r 1.1 -r 1.2 src/gtk/.cvsignore;  ) > 1.9.13cvs63.patchset
index f996a1fa8cf7a2d3f6389928a65de79b8a531b8b..2cc1ab1eb57ea3d312d0cd72c6b4effe331c27e6 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=13
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=62
+EXTRA_VERSION=63
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 7317a963fb6cfcad1b78fd77eb910bdd767e1e50..f50617e34fbe2d4868dc3b5cbb75167cc6650c62 100644 (file)
@@ -324,6 +324,50 @@ int imap_threaded_connect_ssl(Folder * folder, const char * server, int port)
        
        return result.error;
 }
+
+struct capa_param {
+       mailimap * imap;
+};
+
+struct capa_result {
+       int error;
+       struct mailimap_capability_data *caps;
+};
+
+static void capability_run(struct etpan_thread_op * op)
+{
+       int r;
+       struct capa_param * param;
+       struct capa_result * result;
+       struct mailimap_capability_data *caps;
+
+       param = op->param;
+       result = op->result;
+       
+       r = mailimap_capability(param->imap, &caps);
+       
+       result->error = r;
+       result->caps = caps;
+}
+
+
+struct mailimap_capability_data * imap_threaded_capability(Folder *folder)
+{
+       struct capa_param param;
+       struct capa_result result;
+       mailimap *imap;
+       
+       imap = get_imap(folder);
+       
+       param.imap = imap;
+       
+       threaded_run(folder, &param, &result, capability_run);
+       
+       debug_print("capa ok\n");
+       
+       return result.caps;
+       
+}
        
 struct disconnect_param {
        mailimap * imap;
index ecaa5f7fb2410809551dc7181284ca49ad2b9497..cbda7c9a4b8021707f7b7bde8ddcd3110a1db1d2 100644 (file)
@@ -16,6 +16,7 @@ void imap_done(Folder * folder);
 
 int imap_threaded_connect(Folder * folder, const char * server, int port);
 int imap_threaded_connect_ssl(Folder * folder, const char * server, int port);
+struct mailimap_capability_data * imap_threaded_capability(Folder *folder);
 int imap_threaded_connect_cmd(Folder * folder, const char * command,
                              const char * server, int port);
 
index 2a6ab490b14aa1c1ec5139c7f6a039196a0a07e6..9a8dc662a7476c372ff96ac0a6cd403b5000a531 100644 (file)
@@ -5,3 +5,5 @@ Makefile.in
 *.o
 *.lo
 *.la
+sylpheed-marshal.h
+sylpheed-marshal.c
index f7323b5ed85939fbb042eb86bb1ad405f949301e..0df9ae7bac0af7cdf13d17409bb603df40316010 100644 (file)
@@ -96,7 +96,7 @@ struct _IMAPSession
 
        gboolean authenticated;
 
-       gchar **capability;
+       GSList *capability;
        gboolean uidplus;
 
        gchar *mbox;
@@ -527,25 +527,84 @@ static void imap_reset_uid_lists(Folder *folder)
        g_node_traverse(folder->node, G_IN_ORDER, G_TRAVERSE_ALL, -1, imap_reset_uid_lists_func, NULL); 
 }
 
+void imap_get_capabilities(IMAPSession *session)
+{
+       struct mailimap_capability_data *capabilities = NULL;
+       clistiter *cur;
+
+       if (session->capability != NULL)
+               return;
+
+       capabilities = imap_threaded_capability(session->folder);
+       for(cur = clist_begin(capabilities->cap_list) ; cur != NULL ;
+           cur = clist_next(cur)) {
+               struct mailimap_capability * cap = 
+                       clist_content(cur);
+               if (cap->cap_data.cap_name == NULL)
+                       continue;
+               session->capability = g_slist_append
+                               (session->capability,
+                                g_strdup(cap->cap_data.cap_name));
+               debug_print("got capa %s\n", cap->cap_data.cap_name);
+       }
+       mailimap_capability_data_free(capabilities);
+}
+
+gboolean imap_has_capability(IMAPSession *session, const gchar *cap) 
+{
+       GSList *cur;
+       for (cur = session->capability; cur; cur = cur->next) {
+               if (!g_ascii_strcasecmp(cur->data, cap))
+                       return TRUE;
+       }
+       return FALSE;
+}
+
 static gint imap_auth(IMAPSession *session, const gchar *user, const gchar *pass,
                      IMAPAuthType type)
 {
-       gint ok;
+       gint ok = IMAP_ERROR;
+       static time_t last_login_err = 0;
        
-       /* TODO: implement Automatic mode */
+       imap_get_capabilities(session);
 
        switch(type) {
        case IMAP_AUTH_CRAM_MD5:
                ok = imap_cmd_login(session, user, pass, "CRAM-MD5");
                break;
        case IMAP_AUTH_LOGIN:
-       default:
                ok = imap_cmd_login(session, user, pass, "LOGIN");
                break;
+       default:
+               debug_print("capabilities:\n"
+                               "\t CRAM-MD5 %d\n"
+                               "\t LOGIN %d\n", 
+                       imap_has_capability(session, "CRAM-MD5"),
+                       imap_has_capability(session, "LOGIN"));
+               if (imap_has_capability(session, "CRAM-MD5"))
+                       ok = imap_cmd_login(session, user, pass, "CRAM-MD5");
+               if (ok == IMAP_ERROR) /* we always try LOGIN before giving up */
+                       ok = imap_cmd_login(session, user, pass, "LOGIN");
        }
        if (ok == IMAP_SUCCESS)
                session->authenticated = TRUE;
-
+       else {
+               gchar *ext_info = NULL;
+               
+               if (type == IMAP_AUTH_CRAM_MD5) {
+                       ext_info = _("\n\nCRAM-MD5 logins only work if libetpan has been "
+                                    "compiled with SASL support and the "
+                                    "CRAM-MD5 SASL plugin is installed.");
+               } else {
+                       ext_info = "";
+               }
+               
+               if (time(NULL) - last_login_err > 10) {
+                       alertpanel_error(_("Connection to %s failed: login refused.%s"),
+                                       SESSION(session)->server, ext_info);
+               }
+               last_login_err = time(NULL);
+       }
        return ok;
 }
 
@@ -826,7 +885,7 @@ static gchar *imap_fetch_msg_full(Folder *folder, FolderItem *item, gint uid,
                if (cached)
                        debug_print("message %d has been already %scached (%d/%d).\n", uid,
                                have_size == cached->size ? "fully ":"",
-                               have_size, cached->size);
+                               have_size, (int)cached->size);
                
                if (cached && (cached->size == have_size || !body)) {
                        procmsg_msginfo_free(cached);
@@ -2135,7 +2194,8 @@ static gint imap_status(IMAPSession *session, IMAPFolder *folder,
 
 static void imap_free_capabilities(IMAPSession *session)
 {
-       g_strfreev(session->capability);
+       slist_free_strings(session->capability);
+       g_slist_free(session->capability);
        session->capability = NULL;
 }
 
@@ -2191,26 +2251,13 @@ static gint imap_cmd_login(IMAPSession *session,
 {
        int r;
        gint ok;
-       static time_t last_login_err = 0;
 
-       log_print("IMAP4> Logging in to %s\n", SESSION(session)->server);
+       log_print("IMAP4> Logging %s to %s using %s\n", 
+                       user,
+                       SESSION(session)->server,
+                       type);
        r = imap_threaded_login(session->folder, user, pass, type);
        if (r != MAILIMAP_NO_ERROR) {
-               gchar *ext_info = NULL;
-               
-               if (strcmp(type, "CRAM-MD5") == 0) {
-                       ext_info = _("\n\nCRAM-MD5 logins only work if libetpan has been "
-                                    "compiled with SASL support and the "
-                                    "CRAM-MD5 SASL plugin is installed.");
-               } else {
-                       ext_info = "";
-               }
-               
-               if (time(NULL) - last_login_err > 10) {
-                       alertpanel_error(_("Connection to %s failed: login refused.%s"),
-                                       SESSION(session)->server, ext_info);
-               }
-               last_login_err = time(NULL);
                log_error("IMAP4< Error logging in to %s\n",
                                SESSION(session)->server);
                ok = IMAP_ERROR;