2006-08-10 [colin] 2.4.0cvs39
[claws.git] / src / etpan / imap-thread.c
index f3d0d192f963f724544fbd2401cdb3b197434e7b..263e0dcbee70be25ead47a26aecc8c22bd63c6f9 100644 (file)
@@ -20,6 +20,7 @@
 #include "etpan-thread-manager.h"
 #include "utils.h"
 #include "ssl_certificate.h"
+#include "socket.h"
 
 #define DISABLE_LOG_DURING_LOGIN
 
@@ -127,7 +128,7 @@ void imap_logger_append(int direction, const char * str, size_t size)
 
        lines = g_strsplit(buf, "\n", -1);
 
-       if (direction == 0 || (buf[0] == '*' && buf[1] == ' ') || size < 32) {
+       if (direction == 0 || (buf[0] == '*' && buf[1] == ' ') || size < 64) {
                while (lines[i] && *lines[i]) {
                        log_print("IMAP4%c %s\n", direction?'>':'<', lines[i]);
                        i++;
@@ -357,6 +358,7 @@ int imap_threaded_connect(Folder * folder, const char * server, int port)
        param.server = server;
        param.port = port;
        
+       refresh_resolvers();
        threaded_run(folder, &param, &result, connect_run);
        
        debug_print("connect ok %i\n", result.error);
@@ -374,7 +376,7 @@ static int etpan_certificate_check(const unsigned char *certificate, int len, vo
                g_warning("no cert presented.\n");
                return 0;
        }
-       cert = d2i_X509(NULL, &certificate, len);
+       cert = d2i_X509(NULL, (unsigned char **) &certificate, len);
        if (cert == NULL) {
                g_warning("can't get cert\n");
                return 0;
@@ -427,6 +429,7 @@ int imap_threaded_connect_ssl(Folder * folder, const char * server, int port)
        param.server = server;
        param.port = port;
        
+       refresh_resolvers();
        threaded_run(folder, &param, &result, connect_ssl_run);
        
        if (result.error >= 0 && !etpan_skip_ssl_cert_check) {
@@ -467,7 +470,7 @@ static void capability_run(struct etpan_thread_op * op)
 }
 
 
-struct mailimap_capability_data * imap_threaded_capability(Folder *folder)
+struct mailimap_capability_data * imap_threaded_capability(Folder *folder, int *ok)
 {
        struct capa_param param;
        struct capa_result result;
@@ -479,8 +482,11 @@ struct mailimap_capability_data * imap_threaded_capability(Folder *folder)
        
        threaded_run(folder, &param, &result, capability_run);
        
-       debug_print("capa ok\n");
+       debug_print("capa %d\n", result.error);
        
+       if (ok)
+               *ok = result.error;
+
        return result.caps;
        
 }
@@ -1136,15 +1142,20 @@ static void search_run(struct etpan_thread_op * op)
        struct search_param * param;
        struct search_result * result;
        int r;
-       struct mailimap_search_key * key;
-       struct mailimap_search_key * uid_key;
+       struct mailimap_search_key * key = NULL;
+       struct mailimap_search_key * uid_key = NULL;
        struct mailimap_search_key * search_type_key;
        clist * search_result;
        
        param = op->param;
        
+       if (param->set == NULL && param->type == IMAP_SEARCH_TYPE_SIMPLE) {
+               g_warning("broken search");
+       }
+       
        /* we copy the mailimap_set because freeing the key is recursive */
-       uid_key = mailimap_search_key_new_uid(sc_mailimap_set_copy(param->set));
+       if (param->set != NULL)
+               uid_key = mailimap_search_key_new_uid(sc_mailimap_set_copy(param->set));
        
        search_type_key = NULL;
        switch (param->type) {
@@ -1198,23 +1209,33 @@ static void search_run(struct etpan_thread_op * op)
        }
        
        if (search_type_key != NULL) {
-               key = mailimap_search_key_new_multiple_empty();
-               mailimap_search_key_multiple_add(key, search_type_key);
-               mailimap_search_key_multiple_add(key, uid_key);
-       }
-       else {
+               if (param->set != NULL) {
+                       key = mailimap_search_key_new_multiple_empty();
+                       mailimap_search_key_multiple_add(key, search_type_key);
+                       mailimap_search_key_multiple_add(key, uid_key);
+               } else {
+                       key = search_type_key;
+               }
+       } else if (uid_key != NULL) {
                key = uid_key;
        }
        
-       r = mailimap_uid_search(param->imap, NULL, key, &search_result);
-       
-       /* free the key (with the imapset) */
-       mailimap_search_key_free(key);
+       if (key == NULL) {
+               g_warning("no key!");
+               result = op->result;
+               result->error = -1;
+               result->search_result = NULL;
+       } else {
+               r = mailimap_uid_search(param->imap, NULL, key, &search_result);
 
-       result = op->result;
-       result->error = r;
-       result->search_result = search_result;
-       debug_print("imap search run - end %i\n", r);
+               /* free the key (with the imapset) */
+               mailimap_search_key_free(key);
+
+               result = op->result;
+               result->error = r;
+               result->search_result = search_result;
+       }
+       debug_print("imap search run - end %i\n", result->error);
 }
 
 int imap_threaded_search(Folder * folder, int search_type,