Swap return value and argument of imap_threaded_capability()
[claws.git] / src / etpan / imap-thread.c
index be7dca5f8949217e0c70860980747b995b51ab2e..66514ff8e6a329c4245bc0fbefbd06d4106a3f73 100644 (file)
@@ -361,13 +361,17 @@ static struct etpan_thread * get_thread(Folder * folder)
        struct etpan_thread * thread;
        chashdatum key;
        chashdatum value;
-       
+       int r;
+
        key.data = &folder;
        key.len = sizeof(folder);
-       
-       chash_get(imap_hash, &key, &value);
+
+       r = chash_get(imap_hash, &key, &value);
+       if (r < 0)
+               return NULL;
+
        thread = value.data;
-       
+
        return thread;
 }
 
@@ -519,7 +523,7 @@ int imap_threaded_connect(Folder * folder, const char * server, int port)
 
        return result.error;
 }
-
+#ifdef USE_GNUTLS
 static void connect_ssl_run(struct etpan_thread_op * op)
 {
        int r;
@@ -582,7 +586,7 @@ int imap_threaded_connect_ssl(Folder * folder, const char * server, int port)
 
        return result.error;
 }
-
+#endif
 struct capa_param {
        mailimap * imap;
 };
@@ -611,7 +615,7 @@ static void capability_run(struct etpan_thread_op * op)
 }
 
 
-struct mailimap_capability_data * imap_threaded_capability(Folder *folder, int *ok)
+int imap_threaded_capability(Folder *folder, struct mailimap_capability_data ** caps)
 {
        struct capa_param param;
        struct capa_result result;
@@ -625,10 +629,10 @@ struct mailimap_capability_data * imap_threaded_capability(Folder *folder, int *
        
        debug_print("capa %d\n", result.error);
        
-       if (ok)
-               *ok = result.error;
+       if (result.error == MAILIMAP_NO_ERROR)
+               *caps = result.caps;
 
-       return result.caps;
+       return result.error;
        
 }
        
@@ -1049,7 +1053,7 @@ int imap_threaded_noop(Folder * folder, unsigned int * p_exists,
        return result.error;
 }
 
-
+#ifdef USE_GNUTLS
 struct starttls_result {
        int error;
 };
@@ -1122,8 +1126,7 @@ int imap_threaded_starttls(Folder * folder, const gchar *host, int port)
        }       
        return result.error;
 }
-
-
+#endif
 
 struct create_param {
        mailimap * imap;
@@ -1499,15 +1502,24 @@ static struct mailimap_set_item *sc_mailimap_set_item_copy(struct mailimap_set_i
 static struct mailimap_set *sc_mailimap_set_copy(struct mailimap_set *orig)
 {
        clist *list = orig ? orig->set_list : NULL;
-       clist *newlist = clist_new();
+       clist *newlist;
        clistiter *cur;
-       
+
        if (!orig)
                return NULL;
-       for (cur = clist_begin(list); cur; cur = clist_next(cur))
-               clist_append(newlist, 
+
+       newlist = clist_new();
+       if (!newlist)
+               return NULL;
+
+       for (cur = clist_begin(list); cur; cur = clist_next(cur)) {
+               if (clist_append(newlist,
                        sc_mailimap_set_item_copy(
-                       (struct mailimap_set_item *)clist_content(cur)));
+                       (struct mailimap_set_item *)clist_content(cur))) != 0) {
+                       clist_free(newlist);
+                       return NULL;
+               }
+       }
        return mailimap_set_new(newlist);
 }
 
@@ -2695,11 +2707,11 @@ imap_fetch_result_to_envelop_list(clist * fetch_result,
                                  carray ** p_env_list)
 {
        clistiter * cur;
-       carray * env_list;
 
-       env_list = carray_new(16);
-  
        if (fetch_result) {
+               carray * env_list;
+               env_list = carray_new(16);
+
                for(cur = clist_begin(fetch_result) ; cur != NULL ;
                    cur = clist_next(cur)) {
                        struct mailimap_msg_att * msg_att;
@@ -2709,10 +2721,12 @@ imap_fetch_result_to_envelop_list(clist * fetch_result,
                        msg_att = clist_content(cur);
 
                        env_info = fetch_to_env_info(msg_att, &tags);
-                       if (!env_info)
+                       if (!env_info
+                        || carray_add(env_list, env_info, NULL) != 0
+                        || carray_add(env_list, tags, NULL) != 0) {
+                               carray_free(env_list);
                                return MAILIMAP_ERROR_MEMORY;
-                       carray_add(env_list, env_info, NULL);
-                       carray_add(env_list, tags, NULL);
+                       }
                }
                * p_env_list = env_list;
        } else {
@@ -2736,19 +2750,23 @@ static int imap_add_envelope_fetch_att(struct mailimap_fetch_type * fetch_type)
                };
 
        hdrlist = clist_new();
+       if (!hdrlist)
+               return MAIL_ERROR_MEMORY;
        i = 0;
        while (headers[i] != NULL) {
                header = strdup(headers[i]);
-               if (header == NULL || clist_append(hdrlist, header) != 0)
+               if (header == NULL || clist_append(hdrlist, header) != 0) {
+                       clist_free(hdrlist);
                        return MAIL_ERROR_MEMORY;
+               }
                ++i;
        }
-  
+
        imap_hdrlist = mailimap_header_list_new(hdrlist);
        section = mailimap_section_new_header_fields(imap_hdrlist);
        fetch_att = mailimap_fetch_att_new_body_peek_section(section);
        mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
-  
+
        return MAIL_NO_ERROR;
 }