2007-12-06 [colin] 3.1.0cvs62
[claws.git] / src / etpan / imap-thread.c
index 4a83b2b70ee2891a6a53f5def519cc6f8f5ca7e1..20b0e2a99ca2b63ff1441816c17c9cb55d4035d2 100644 (file)
@@ -372,6 +372,11 @@ static mailimap * get_imap(Folder * folder)
        return imap;
 }
 
+static gboolean cb_show_error(gpointer data)
+{
+       mainwindow_show_error();
+       return FALSE;
+}
 
 static void generic_cb(int cancelled, void * result, void * callback_data)
 {
@@ -384,7 +389,7 @@ static void generic_cb(int cancelled, void * result, void * callback_data)
            op->imap->imap_response_info->rsp_alert) {
                log_error(LOG_PROTOCOL, "IMAP4< Alert: %s\n", 
                        op->imap->imap_response_info->rsp_alert);
-               mainwindow_show_error();
+               g_timeout_add(10, cb_show_error, NULL);
        } 
        op->finished = 1;
 }
@@ -896,6 +901,8 @@ static void login_run(struct etpan_thread_op * op)
 #endif
        
        result->error = r;
+       if (param->imap->imap_response)
+               imap_logger_cmd(0, param->imap->imap_response, strlen(param->imap->imap_response));
        debug_print("imap login run - end %i\n", r);
 }
 
@@ -1853,6 +1860,8 @@ result_to_uid_flags_list(clist * fetch_result, carray ** result)
                int flags;
                int * pflags;
                
+               tags = NULL;
+
                msg_att = clist_content(cur);
                
                uid = 0;
@@ -2339,6 +2348,8 @@ static void fetch_content_run(struct etpan_thread_op * op)
                g_unlink(param->filename);
        
        free:
+               /* mmap_string_unref is a simple free in libetpan
+                * when it has MMAP_UNAVAILABLE defined */
                if (mmap_string_unref(content) != 0)
                        free(content);
        }
@@ -2410,17 +2421,14 @@ static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn, GSList
                                flags &= ~MSG_NEW;
                                break;
                        case MAILIMAP_FLAG_KEYWORD:
-                               tags = g_slist_prepend(tags, g_strdup(flag_fetch->fl_flag->fl_data.fl_keyword));
+                               if (s_tags)
+                                       tags = g_slist_prepend(tags, g_strdup(flag_fetch->fl_flag->fl_data.fl_keyword));
                                break;
                        }
                }
        }
        if (s_tags)
                *s_tags = tags;
-       else {
-               slist_free_strings(tags);
-               g_slist_free(tags);
-       }
        return flags;
 }
 
@@ -2493,7 +2501,7 @@ fetch_to_env_info(struct mailimap_msg_att * msg_att, GSList **tags)
        char * headers;
        size_t size;
        struct mailimap_msg_att_dynamic * att_dyn;
-       GSList *s_tags = NULL;
+
        imap_get_msg_att_info(msg_att, &uid, &headers, &size,
                              &att_dyn);
        
@@ -2503,14 +2511,8 @@ fetch_to_env_info(struct mailimap_msg_att * msg_att, GSList **tags)
        info->uid = uid;
        info->headers = strdup(headers);
        info->size = size;
-       info->flags = imap_flags_to_flags(att_dyn, &s_tags);
+       info->flags = imap_flags_to_flags(att_dyn, tags);
        
-       if (tags)
-               *tags = s_tags;
-       else {
-               slist_free_strings(s_tags);
-               g_slist_free(s_tags);
-       }
        return info;
 }
 
@@ -2521,15 +2523,16 @@ imap_fetch_result_to_envelop_list(clist * fetch_result,
        clistiter * cur;
        unsigned int i;
        carray * env_list;
+
        i = 0;
-       GSList *tags = NULL;
        env_list = carray_new(16);
   
        for(cur = clist_begin(fetch_result) ; cur != NULL ;
            cur = clist_next(cur)) {
                struct mailimap_msg_att * msg_att;
                struct imap_fetch_env_info * env_info;
-    
+               GSList *tags = NULL;
+
                msg_att = clist_content(cur);
 
                env_info = fetch_to_env_info(msg_att, &tags);
@@ -2779,8 +2782,10 @@ static void append_run(struct etpan_thread_op * op)
        int r;
        char * data;
        size_t size;
+#ifndef G_OS_WIN32
        struct stat stat_buf;
        int fd;
+#endif
        guint32 uid = 0, val = 0;
        
        param = op->param;
@@ -2788,6 +2793,7 @@ static void append_run(struct etpan_thread_op * op)
        
        CHECK_IMAP();
 
+#ifndef G_OS_WIN32
        r = stat(param->filename, &stat_buf);
        if (r < 0) {
                result->error = MAILIMAP_ERROR_APPEND;
@@ -2807,7 +2813,14 @@ static void append_run(struct etpan_thread_op * op)
                result->error = MAILIMAP_ERROR_APPEND;
                return;
        }
-       
+#else
+       data = file_read_to_str_no_recode(param->filename);
+       if (data == NULL) {
+               result->error = MAILIMAP_ERROR_APPEND;
+               return;
+       }
+       size = strlen(data);
+#endif
        mailstream_logger = imap_logger_append;
        
        r = mailimap_uidplus_append(param->imap, param->mailbox,
@@ -2816,8 +2829,12 @@ static void append_run(struct etpan_thread_op * op)
 
        mailstream_logger = imap_logger_cmd;
        
+#ifndef G_OS_WIN32
        munmap(data, size);
        close(fd);
+#else
+       g_free(data);
+#endif
        
        result->error = r;
        result->uid = uid;
@@ -3024,7 +3041,7 @@ int imap_threaded_store(Folder * folder, struct mailimap_set * set,
 
 
 #define ENV_BUFFER_SIZE 512
-
+#ifndef G_OS_WIN32
 static void do_exec_command(int fd, const char * command,
                            const char * servername, uint16_t port)
 {
@@ -3223,6 +3240,7 @@ int imap_threaded_connect_cmd(Folder * folder, const char * command,
        
        return result.error;
 }
+#endif /* G_OS_WIN32 */
 
 void imap_threaded_cancel(Folder * folder)
 {