2005-10-20 [colin] 1.9.15cvs81
[claws.git] / src / etpan / imap-thread.c
index f50617e34fbe2d4868dc3b5cbb75167cc6650c62..9b7a122df2067620d1b96a6c6e6d0f22fe5e82a8 100644 (file)
@@ -8,7 +8,7 @@
 #include <imap.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#if defined (__NetBSD__)
+#if (defined (__NetBSD__) || defined (__FreeBSD__))
 #include <sys/socket.h>
 #endif
 #include <fcntl.h>
@@ -42,7 +42,9 @@ static gboolean thread_manager_event(GIOChannel * source,
 void imap_logger(int direction, const char * str, size_t size) 
 {
        gchar buf[512];
-       strncpy(buf, str, 511);
+
+       memset(buf, 0, 512);
+       strncpy(buf, str, size > 510 ? 510:size);
        buf[511] = '\0';
        if (size < 511)
                buf[size] = '\0';
@@ -320,7 +322,7 @@ int imap_threaded_connect_ssl(Folder * folder, const char * server, int port)
        
        threaded_run(folder, &param, &result, connect_ssl_run);
        
-       debug_print("connect ok\n");
+       debug_print("connect %d\n", result.error);
        
        return result.error;
 }
@@ -347,7 +349,7 @@ static void capability_run(struct etpan_thread_op * op)
        r = mailimap_capability(param->imap, &caps);
        
        result->error = r;
-       result->caps = caps;
+       result->caps = (r == 0 ? caps : NULL);
 }
 
 
@@ -572,7 +574,8 @@ static void status_run(struct etpan_thread_op * op)
 }
 
 int imap_threaded_status(Folder * folder, const char * mb,
-                        struct mailimap_mailbox_data_status ** data_status)
+                        struct mailimap_mailbox_data_status ** data_status,
+                        guint mask)
 {
        struct status_param param;
        struct status_result result;
@@ -581,17 +584,26 @@ int imap_threaded_status(Folder * folder, const char * mb,
        debug_print("imap status - begin\n");
        
        status_att_list = mailimap_status_att_list_new_empty();
-       mailimap_status_att_list_add(status_att_list,
+       if (mask & 1 << 0) {
+               mailimap_status_att_list_add(status_att_list,
                                     MAILIMAP_STATUS_ATT_MESSAGES);
-       mailimap_status_att_list_add(status_att_list,
+       }
+       if (mask & 1 << 1) {
+               mailimap_status_att_list_add(status_att_list,
                                     MAILIMAP_STATUS_ATT_RECENT);
-       mailimap_status_att_list_add(status_att_list,
+       }
+       if (mask & 1 << 2) {
+               mailimap_status_att_list_add(status_att_list,
                                     MAILIMAP_STATUS_ATT_UIDNEXT);
-       mailimap_status_att_list_add(status_att_list,
+       }
+       if (mask & 1 << 3) {
+               mailimap_status_att_list_add(status_att_list,
                                     MAILIMAP_STATUS_ATT_UIDVALIDITY);
-       mailimap_status_att_list_add(status_att_list,
+       }
+       if (mask & 1 << 4) {
+               mailimap_status_att_list_add(status_att_list,
                                     MAILIMAP_STATUS_ATT_UNSEEN);
-       
+       }
        param.imap = get_imap(folder);
        param.mb = mb;
        param.status_att_list = status_att_list;
@@ -1030,6 +1042,14 @@ static void search_run(struct etpan_thread_op * op)
                                                          NULL, NULL, NULL, NULL, NULL,
                                                          NULL, 0, NULL, NULL, NULL);
                break;
+       case IMAP_SEARCH_TYPE_DELETED:
+               search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_DELETED,
+                                                         NULL, NULL, NULL, NULL, NULL,
+                                                         NULL, NULL, NULL, NULL, NULL,
+                                                         NULL, NULL, NULL, NULL, 0,
+                                                         NULL, NULL, NULL, NULL, NULL,
+                                                         NULL, 0, NULL, NULL, NULL);
+               break;
        }
        
        if (search_type_key != NULL) {
@@ -1057,7 +1077,7 @@ int imap_threaded_search(Folder * folder, int search_type,
        mailimap * imap;
        
        debug_print("imap search - begin\n");
-       
+
        imap = get_imap(folder);
        param.imap = imap;
        param.set = set;
@@ -1703,6 +1723,8 @@ fetch_to_env_info(struct mailimap_msg_att * msg_att)
        imap_get_msg_att_info(msg_att, &uid, &headers, &size,
                              &att_dyn);
        
+       if (!headers)
+               return NULL;
        info = malloc(sizeof(* info));
        info->uid = uid;
        info->headers = strdup(headers);
@@ -1719,7 +1741,6 @@ imap_fetch_result_to_envelop_list(clist * fetch_result,
        clistiter * cur;
        unsigned int i;
        carray * env_list;
-  
        i = 0;
   
        env_list = carray_new(16);
@@ -1732,6 +1753,8 @@ imap_fetch_result_to_envelop_list(clist * fetch_result,
                msg_att = clist_content(cur);
 
                env_info = fetch_to_env_info(msg_att);
+               if (!env_info)
+                       return MAILIMAP_ERROR_MEMORY;
                carray_add(env_list, env_info, NULL);
        }