7 #include "imap-thread.h"
11 #if (defined(__DragonFly__) || defined (__NetBSD__) || defined (__FreeBSD__) || defined (__CYGWIN__))
12 #include <sys/socket.h>
20 #include "etpan-thread-manager.h"
22 #include "ssl_certificate.h"
24 #define DISABLE_LOG_DURING_LOGIN
26 static struct etpan_thread_manager * thread_manager = NULL;
27 static chash * courier_workaround_hash = NULL;
28 static chash * imap_hash = NULL;
29 static chash * session_hash = NULL;
30 static guint thread_manager_signal = 0;
31 static GIOChannel * io_channel = NULL;
34 static gboolean thread_manager_event(GIOChannel * source,
35 GIOCondition condition,
38 etpan_thread_manager_loop(thread_manager);
43 void imap_logger_cmd(int direction, const char * str, size_t size)
50 memset(buf, 0, size+1);
51 strncpy(buf, str, size);
54 if (!strncmp(buf, "<<<<<<<", 7)
55 || !strncmp(buf, ">>>>>>>", 7)) {
59 while (strstr(buf, "\r"))
60 *strstr(buf, "\r") = ' ';
61 while (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
62 buf[strlen(buf)-1] = '\0';
64 lines = g_strsplit(buf, "\n", -1);
66 while (lines[i] && *lines[i]) {
67 log_print("IMAP4%c %s\n", direction?'>':'<', lines[i]);
74 void imap_logger_fetch(int direction, const char * str, size_t size)
81 memset(buf, 0, size+1);
82 strncpy(buf, str, size);
84 if (!strncmp(buf, "<<<<<<<", 7)
85 || !strncmp(buf, ">>>>>>>", 7)) {
89 while (strstr(buf, "\r"))
90 *strstr(buf, "\r") = ' ';
91 while (strlen(buf) > 0 && buf[strlen(buf)-1] == '\n')
92 buf[strlen(buf)-1] = '\0';
94 lines = g_strsplit(buf, "\n", -1);
96 if (direction != 0 || (buf[0] == '*' && buf[1] == ' ') || size < 32) {
97 while (lines[i] && *lines[i]) {
98 log_print("IMAP4%c %s\n", direction?'>':'<', lines[i]);
102 log_print("IMAP4%c [data - %zd bytes]\n", direction?'>':'<', size);
108 #define ETPAN_DEFAULT_NETWORK_TIMEOUT 60
110 void imap_main_init(void)
112 int fd_thread_manager;
114 mailstream_network_delay.tv_sec = ETPAN_DEFAULT_NETWORK_TIMEOUT;
115 mailstream_network_delay.tv_usec = 0;
117 mailstream_debug = 1;
118 mailstream_logger = imap_logger_cmd;
120 imap_hash = chash_new(CHASH_COPYKEY, CHASH_DEFAULTSIZE);
121 session_hash = chash_new(CHASH_COPYKEY, CHASH_DEFAULTSIZE);
122 courier_workaround_hash = chash_new(CHASH_COPYKEY, CHASH_DEFAULTSIZE);
124 thread_manager = etpan_thread_manager_new();
126 fd_thread_manager = etpan_thread_manager_get_fd(thread_manager);
128 io_channel = g_io_channel_unix_new(fd_thread_manager);
130 thread_manager_signal = g_io_add_watch_full(io_channel, 0, G_IO_IN,
131 thread_manager_event,
136 void imap_main_set_timeout(int sec)
138 mailstream_network_delay.tv_sec = sec;
139 mailstream_network_delay.tv_usec = 0;
142 void imap_main_done(void)
144 etpan_thread_manager_stop(thread_manager);
145 etpan_thread_manager_join(thread_manager);
147 g_source_remove(thread_manager_signal);
148 g_io_channel_unref(io_channel);
150 etpan_thread_manager_free(thread_manager);
152 chash_free(courier_workaround_hash);
153 chash_free(session_hash);
154 chash_free(imap_hash);
157 void imap_init(Folder * folder)
159 struct etpan_thread * thread;
163 thread = etpan_thread_manager_get_thread(thread_manager);
166 key.len = sizeof(folder);
170 chash_set(imap_hash, &key, &value, NULL);
173 void imap_done(Folder * folder)
175 struct etpan_thread * thread;
181 key.len = sizeof(folder);
183 r = chash_get(imap_hash, &key, &value);
189 etpan_thread_unbind(thread);
191 chash_delete(imap_hash, &key, NULL);
193 debug_print("remove thread");
196 static struct etpan_thread * get_thread(Folder * folder)
198 struct etpan_thread * thread;
203 key.len = sizeof(folder);
205 chash_get(imap_hash, &key, &value);
211 static mailimap * get_imap(Folder * folder)
219 key.len = sizeof(folder);
221 r = chash_get(session_hash, &key, &value);
231 static void generic_cb(int cancelled, void * result, void * callback_data)
235 p_finished = callback_data;
237 debug_print("generic_cb\n");
242 static void threaded_run(Folder * folder, void * param, void * result,
243 void (* func)(struct etpan_thread_op * ))
245 struct etpan_thread_op * op;
246 struct etpan_thread * thread;
249 imap_folder_ref(folder);
251 op = etpan_thread_op_new();
257 op->callback = generic_cb;
258 op->callback_data = &finished;
263 thread = get_thread(folder);
264 etpan_thread_op_schedule(thread, op);
267 gtk_main_iteration();
270 etpan_thread_op_free(op);
272 imap_folder_unref(folder);
278 struct connect_param {
284 struct connect_result {
288 static void connect_run(struct etpan_thread_op * op)
291 struct connect_param * param;
292 struct connect_result * result;
297 r = mailimap_socket_connect(param->imap,
298 param->server, param->port);
304 int imap_threaded_connect(Folder * folder, const char * server, int port)
306 struct connect_param param;
307 struct connect_result result;
312 imap = mailimap_new(0, NULL);
315 key.len = sizeof(folder);
318 chash_set(session_hash, &key, &value, NULL);
321 param.server = server;
324 threaded_run(folder, ¶m, &result, connect_run);
326 debug_print("connect ok %i\n", result.error);
331 static int etpan_certificate_check(const unsigned char *certificate, int len, void *data)
334 struct connect_param *param = (struct connect_param *)data;
337 if (certificate == NULL || len < 0) {
338 g_warning("no cert presented.\n");
341 cert = d2i_X509(NULL, &certificate, len);
343 g_warning("can't get cert\n");
345 } else if (ssl_certificate_check(cert,
346 (gchar *)param->server, param->port) == TRUE) {
356 static void connect_ssl_run(struct etpan_thread_op * op)
359 struct connect_param * param;
360 struct connect_result * result;
365 r = mailimap_ssl_connect(param->imap,
366 param->server, param->port);
370 int imap_threaded_connect_ssl(Folder * folder, const char * server, int port)
372 struct connect_param param;
373 struct connect_result result;
377 unsigned char *certificate = NULL;
380 imap = mailimap_new(0, NULL);
383 key.len = sizeof(folder);
386 chash_set(session_hash, &key, &value, NULL);
389 param.server = server;
392 threaded_run(folder, ¶m, &result, connect_ssl_run);
394 if (result.error >= 0) {
395 cert_len = mailstream_ssl_get_certificate(imap->imap_stream, &certificate);
396 if (etpan_certificate_check(certificate, cert_len, ¶m) < 0)
401 debug_print("connect %d\n", result.error);
412 struct mailimap_capability_data *caps;
415 static void capability_run(struct etpan_thread_op * op)
418 struct capa_param * param;
419 struct capa_result * result;
420 struct mailimap_capability_data *caps;
425 r = mailimap_capability(param->imap, &caps);
428 result->caps = (r == 0 ? caps : NULL);
432 struct mailimap_capability_data * imap_threaded_capability(Folder *folder)
434 struct capa_param param;
435 struct capa_result result;
438 imap = get_imap(folder);
442 threaded_run(folder, ¶m, &result, capability_run);
444 debug_print("capa ok\n");
450 struct disconnect_param {
454 struct disconnect_result {
458 static void disconnect_run(struct etpan_thread_op * op)
461 struct disconnect_param * param;
462 struct disconnect_result * result;
467 r = mailimap_logout(param->imap);
472 void imap_threaded_disconnect(Folder * folder)
474 struct connect_param param;
475 struct connect_result result;
480 imap = get_imap(folder);
482 debug_print("was disconnected\n");
488 threaded_run(folder, ¶m, &result, disconnect_run);
491 key.len = sizeof(folder);
494 chash_delete(session_hash, &key, NULL);
497 key.len = sizeof(imap);
498 chash_delete(courier_workaround_hash, &key, NULL);
502 debug_print("disconnect ok\n");
509 const char * wildcard;
517 static void list_run(struct etpan_thread_op * op)
519 struct list_param * param;
520 struct list_result * result;
526 r = mailimap_list(param->imap, param->base,
527 param->wildcard, &list);
532 debug_print("imap list run - end\n");
535 int imap_threaded_list(Folder * folder, const char * base,
536 const char * wildcard,
539 struct list_param param;
540 struct list_result result;
542 debug_print("imap list - begin\n");
544 param.imap = get_imap(folder);
546 param.wildcard = wildcard;
548 threaded_run(folder, ¶m, &result, list_run);
550 * p_result = result.list;
552 debug_print("imap list - end %p\n", result.list);
562 const char * password;
566 struct login_result {
570 static void login_run(struct etpan_thread_op * op)
572 struct login_param * param;
573 struct login_result * result;
575 #ifdef DISABLE_LOG_DURING_LOGIN
581 #ifdef DISABLE_LOG_DURING_LOGIN
582 old_debug = mailstream_debug;
583 mailstream_debug = 0;
585 if (!strcmp(param->type, "LOGIN"))
586 r = mailimap_login(param->imap,
587 param->login, param->password);
589 r = mailimap_authenticate(param->imap,
590 param->type, NULL, NULL, NULL,
591 param->login, param->login,
592 param->password, NULL);
593 #ifdef DISABLE_LOG_DURING_LOGIN
594 mailstream_debug = old_debug;
599 debug_print("imap login run - end %i\n", r);
602 int imap_threaded_login(Folder * folder,
603 const char * login, const char * password,
606 struct login_param param;
607 struct login_result result;
609 debug_print("imap login - begin\n");
611 param.imap = get_imap(folder);
613 param.password = password;
616 threaded_run(folder, ¶m, &result, login_run);
618 debug_print("imap login - end\n");
624 struct status_param {
627 struct mailimap_status_att_list * status_att_list;
630 struct status_result {
632 struct mailimap_mailbox_data_status * data_status;
635 static void status_run(struct etpan_thread_op * op)
637 struct status_param * param;
638 struct status_result * result;
644 r = mailimap_status(param->imap, param->mb,
645 param->status_att_list,
646 &result->data_status);
649 debug_print("imap status run - end %i\n", r);
652 int imap_threaded_status(Folder * folder, const char * mb,
653 struct mailimap_mailbox_data_status ** data_status,
656 struct status_param param;
657 struct status_result result;
658 struct mailimap_status_att_list * status_att_list;
660 debug_print("imap status - begin\n");
662 status_att_list = mailimap_status_att_list_new_empty();
664 mailimap_status_att_list_add(status_att_list,
665 MAILIMAP_STATUS_ATT_MESSAGES);
668 mailimap_status_att_list_add(status_att_list,
669 MAILIMAP_STATUS_ATT_RECENT);
672 mailimap_status_att_list_add(status_att_list,
673 MAILIMAP_STATUS_ATT_UIDNEXT);
676 mailimap_status_att_list_add(status_att_list,
677 MAILIMAP_STATUS_ATT_UIDVALIDITY);
680 mailimap_status_att_list_add(status_att_list,
681 MAILIMAP_STATUS_ATT_UNSEEN);
683 param.imap = get_imap(folder);
685 param.status_att_list = status_att_list;
687 threaded_run(folder, ¶m, &result, status_run);
689 debug_print("imap status - end\n");
691 * data_status = result.data_status;
693 mailimap_status_att_list_free(status_att_list);
708 static void noop_run(struct etpan_thread_op * op)
710 struct noop_param * param;
711 struct noop_result * result;
715 r = mailimap_noop(param->imap);
719 debug_print("imap noop run - end %i\n", r);
722 int imap_threaded_noop(Folder * folder, unsigned int * p_exists)
724 struct noop_param param;
725 struct noop_result result;
728 debug_print("imap noop - begin\n");
730 imap = get_imap(folder);
733 threaded_run(folder, ¶m, &result, noop_run);
735 if (imap->imap_selection_info != NULL) {
736 * p_exists = imap->imap_selection_info->sel_exists;
742 debug_print("imap noop - end\n");
748 struct starttls_result {
752 static void starttls_run(struct etpan_thread_op * op)
754 struct connect_param * param;
755 struct starttls_result * result;
759 r = mailimap_starttls(param->imap);
763 debug_print("imap starttls run - end %i\n", r);
766 mailimap *imap = param->imap;
767 mailstream_low *plain_low = NULL;
768 mailstream_low *tls_low = NULL;
771 plain_low = mailstream_get_low(imap->imap_stream);
772 fd = mailstream_low_get_fd(plain_low);
774 debug_print("imap starttls run - can't get fd\n");
775 result->error = MAILIMAP_ERROR_STREAM;
779 tls_low = mailstream_low_tls_open(fd);
780 if (tls_low == NULL) {
781 debug_print("imap starttls run - can't tls_open\n");
782 result->error = MAILIMAP_ERROR_STREAM;
785 mailstream_low_free(plain_low);
786 mailstream_set_low(imap->imap_stream, tls_low);
790 int imap_threaded_starttls(Folder * folder, const gchar *host, int port)
792 struct connect_param param;
793 struct starttls_result result;
795 unsigned char *certificate;
797 debug_print("imap starttls - begin\n");
799 param.imap = get_imap(folder);
803 threaded_run(folder, ¶m, &result, starttls_run);
805 debug_print("imap starttls - end\n");
807 if (result.error == 0) {
808 cert_len = mailstream_ssl_get_certificate(param.imap->imap_stream, &certificate);
809 if (etpan_certificate_check(certificate, cert_len, ¶m) < 0)
810 result.error = MAILIMAP_ERROR_STREAM;
819 struct create_param {
824 struct create_result {
828 static void create_run(struct etpan_thread_op * op)
830 struct create_param * param;
831 struct create_result * result;
835 r = mailimap_create(param->imap, param->mb);
839 debug_print("imap create run - end %i\n", r);
842 int imap_threaded_create(Folder * folder, const char * mb)
844 struct create_param param;
845 struct create_result result;
847 debug_print("imap create - begin\n");
849 param.imap = get_imap(folder);
852 threaded_run(folder, ¶m, &result, create_run);
854 debug_print("imap create - end\n");
862 struct rename_param {
865 const char * new_name;
868 struct rename_result {
872 static void rename_run(struct etpan_thread_op * op)
874 struct rename_param * param;
875 struct rename_result * result;
879 r = mailimap_rename(param->imap, param->mb, param->new_name);
883 debug_print("imap rename run - end %i\n", r);
886 int imap_threaded_rename(Folder * folder,
887 const char * mb, const char * new_name)
889 struct rename_param param;
890 struct rename_result result;
892 debug_print("imap rename - begin\n");
894 param.imap = get_imap(folder);
896 param.new_name = new_name;
898 threaded_run(folder, ¶m, &result, rename_run);
900 debug_print("imap rename - end\n");
908 struct delete_param {
913 struct delete_result {
917 static void delete_run(struct etpan_thread_op * op)
919 struct delete_param * param;
920 struct delete_result * result;
924 r = mailimap_delete(param->imap, param->mb);
928 debug_print("imap delete run - end %i\n", r);
931 int imap_threaded_delete(Folder * folder, const char * mb)
933 struct delete_param param;
934 struct delete_result result;
936 debug_print("imap delete - begin\n");
938 param.imap = get_imap(folder);
941 threaded_run(folder, ¶m, &result, delete_run);
943 debug_print("imap delete - end\n");
950 struct select_param {
955 struct select_result {
959 static void select_run(struct etpan_thread_op * op)
961 struct select_param * param;
962 struct select_result * result;
966 r = mailimap_select(param->imap, param->mb);
970 debug_print("imap select run - end %i\n", r);
973 int imap_threaded_select(Folder * folder, const char * mb,
974 gint * exists, gint * recent, gint * unseen,
975 guint32 * uid_validity)
977 struct select_param param;
978 struct select_result result;
981 debug_print("imap select - begin\n");
983 imap = get_imap(folder);
987 threaded_run(folder, ¶m, &result, select_run);
989 if (result.error != MAILIMAP_NO_ERROR)
992 if (imap->imap_selection_info == NULL)
993 return MAILIMAP_ERROR_PARSE;
995 * exists = imap->imap_selection_info->sel_exists;
996 * recent = imap->imap_selection_info->sel_recent;
997 * unseen = imap->imap_selection_info->sel_unseen;
998 * uid_validity = imap->imap_selection_info->sel_uidvalidity;
1000 debug_print("imap select - end\n");
1002 return result.error;
1007 struct examine_param {
1012 struct examine_result {
1016 static void examine_run(struct etpan_thread_op * op)
1018 struct examine_param * param;
1019 struct examine_result * result;
1023 r = mailimap_examine(param->imap, param->mb);
1025 result = op->result;
1027 debug_print("imap examine run - end %i\n", r);
1030 int imap_threaded_examine(Folder * folder, const char * mb,
1031 gint * exists, gint * recent, gint * unseen,
1032 guint32 * uid_validity)
1034 struct examine_param param;
1035 struct examine_result result;
1038 debug_print("imap examine - begin\n");
1040 imap = get_imap(folder);
1044 threaded_run(folder, ¶m, &result, examine_run);
1046 if (result.error != MAILIMAP_NO_ERROR)
1047 return result.error;
1049 if (imap->imap_selection_info == NULL)
1050 return MAILIMAP_ERROR_PARSE;
1052 * exists = imap->imap_selection_info->sel_exists;
1053 * recent = imap->imap_selection_info->sel_recent;
1054 * unseen = imap->imap_selection_info->sel_unseen;
1055 * uid_validity = imap->imap_selection_info->sel_uidvalidity;
1057 debug_print("imap examine - end\n");
1059 return result.error;
1065 struct search_param {
1068 struct mailimap_set * set;
1071 struct search_result {
1073 clist * search_result;
1076 static void search_run(struct etpan_thread_op * op)
1078 struct search_param * param;
1079 struct search_result * result;
1081 struct mailimap_search_key * key;
1082 struct mailimap_search_key * uid_key;
1083 struct mailimap_search_key * search_type_key;
1084 clist * search_result;
1088 uid_key = mailimap_search_key_new_uid(param->set);
1090 search_type_key = NULL;
1091 switch (param->type) {
1092 case IMAP_SEARCH_TYPE_SIMPLE:
1093 search_type_key = NULL;
1096 case IMAP_SEARCH_TYPE_SEEN:
1097 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SEEN,
1098 NULL, NULL, NULL, NULL, NULL,
1099 NULL, NULL, NULL, NULL, NULL,
1100 NULL, NULL, NULL, NULL, 0,
1101 NULL, NULL, NULL, NULL, NULL,
1102 NULL, 0, NULL, NULL, NULL);
1105 case IMAP_SEARCH_TYPE_UNSEEN:
1106 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_UNSEEN,
1107 NULL, NULL, NULL, NULL, NULL,
1108 NULL, NULL, NULL, NULL, NULL,
1109 NULL, NULL, NULL, NULL, 0,
1110 NULL, NULL, NULL, NULL, NULL,
1111 NULL, 0, NULL, NULL, NULL);
1114 case IMAP_SEARCH_TYPE_ANSWERED:
1115 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_ANSWERED,
1116 NULL, NULL, NULL, NULL, NULL,
1117 NULL, NULL, NULL, NULL, NULL,
1118 NULL, NULL, NULL, NULL, 0,
1119 NULL, NULL, NULL, NULL, NULL,
1120 NULL, 0, NULL, NULL, NULL);
1123 case IMAP_SEARCH_TYPE_FLAGGED:
1124 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_FLAGGED,
1125 NULL, NULL, NULL, NULL, NULL,
1126 NULL, NULL, NULL, NULL, NULL,
1127 NULL, NULL, NULL, NULL, 0,
1128 NULL, NULL, NULL, NULL, NULL,
1129 NULL, 0, NULL, NULL, NULL);
1131 case IMAP_SEARCH_TYPE_DELETED:
1132 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_DELETED,
1133 NULL, NULL, NULL, NULL, NULL,
1134 NULL, NULL, NULL, NULL, NULL,
1135 NULL, NULL, NULL, NULL, 0,
1136 NULL, NULL, NULL, NULL, NULL,
1137 NULL, 0, NULL, NULL, NULL);
1141 if (search_type_key != NULL) {
1142 key = mailimap_search_key_new_multiple_empty();
1143 mailimap_search_key_multiple_add(key, search_type_key);
1144 mailimap_search_key_multiple_add(key, uid_key);
1150 r = mailimap_uid_search(param->imap, NULL, key, &search_result);
1152 result = op->result;
1154 result->search_result = search_result;
1155 debug_print("imap search run - end %i\n", r);
1158 int imap_threaded_search(Folder * folder, int search_type,
1159 struct mailimap_set * set, clist ** search_result)
1161 struct search_param param;
1162 struct search_result result;
1165 debug_print("imap search - begin\n");
1167 imap = get_imap(folder);
1170 param.type = search_type;
1172 threaded_run(folder, ¶m, &result, search_run);
1174 if (result.error != MAILIMAP_NO_ERROR)
1175 return result.error;
1177 debug_print("imap search - end\n");
1179 * search_result = result.search_result;
1181 return result.error;
1188 uid_list_to_env_list(clist * fetch_result, carray ** result)
1196 tab = carray_new(128);
1198 res = MAILIMAP_ERROR_MEMORY;
1202 for(cur = clist_begin(fetch_result) ; cur != NULL ;
1203 cur = clist_next(cur)) {
1204 struct mailimap_msg_att * msg_att;
1205 clistiter * item_cur;
1210 msg_att = clist_content(cur);
1214 for(item_cur = clist_begin(msg_att->att_list) ;
1216 item_cur = clist_next(item_cur)) {
1217 struct mailimap_msg_att_item * item;
1219 item = clist_content(item_cur);
1221 switch (item->att_type) {
1222 case MAILIMAP_MSG_ATT_ITEM_STATIC:
1223 switch (item->att_data.att_static->att_type) {
1224 case MAILIMAP_MSG_ATT_UID:
1225 uid = item->att_data.att_static->att_data.att_uid;
1231 puid = malloc(sizeof(* puid));
1233 res = MAILIMAP_ERROR_MEMORY;
1238 r = carray_add(tab, puid, NULL);
1241 res = MAILIMAP_ERROR_MEMORY;
1248 return MAILIMAP_NO_ERROR;
1251 for(i = 0 ; i < carray_count(tab) ; i++)
1252 mailmessage_free(carray_get(tab, i));
1257 static int imap_get_messages_list(mailimap * imap,
1258 uint32_t first_index,
1263 struct mailimap_fetch_att * fetch_att;
1264 struct mailimap_fetch_type * fetch_type;
1265 struct mailimap_set * set;
1266 clist * fetch_result;
1269 set = mailimap_set_new_interval(first_index, 0);
1271 res = MAILIMAP_ERROR_MEMORY;
1275 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
1276 if (fetch_type == NULL) {
1277 res = MAILIMAP_ERROR_MEMORY;
1281 fetch_att = mailimap_fetch_att_new_uid();
1282 if (fetch_att == NULL) {
1283 res = MAILIMAP_ERROR_MEMORY;
1284 goto free_fetch_type;
1287 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1288 if (r != MAILIMAP_NO_ERROR) {
1289 mailimap_fetch_att_free(fetch_att);
1290 res = MAILIMAP_ERROR_MEMORY;
1291 goto free_fetch_type;
1294 r = mailimap_uid_fetch(imap, set,
1295 fetch_type, &fetch_result);
1297 mailimap_fetch_type_free(fetch_type);
1298 mailimap_set_free(set);
1300 if (r != MAILIMAP_NO_ERROR) {
1306 r = uid_list_to_env_list(fetch_result, &env_list);
1307 mailimap_fetch_list_free(fetch_result);
1309 * result = env_list;
1311 return MAILIMAP_NO_ERROR;
1314 mailimap_fetch_type_free(fetch_type);
1316 mailimap_set_free(set);
1324 struct fetch_uid_param {
1326 uint32_t first_index;
1329 struct fetch_uid_result {
1331 carray * fetch_result;
1334 static void fetch_uid_run(struct etpan_thread_op * op)
1336 struct fetch_uid_param * param;
1337 struct fetch_uid_result * result;
1338 carray * fetch_result;
1343 fetch_result = NULL;
1344 r = imap_get_messages_list(param->imap, param->first_index,
1347 result = op->result;
1349 result->fetch_result = fetch_result;
1350 debug_print("imap fetch_uid run - end %i\n", r);
1353 int imap_threaded_fetch_uid(Folder * folder, uint32_t first_index,
1354 carray ** fetch_result)
1356 struct fetch_uid_param param;
1357 struct fetch_uid_result result;
1360 debug_print("imap fetch_uid - begin\n");
1362 imap = get_imap(folder);
1364 param.first_index = first_index;
1366 threaded_run(folder, ¶m, &result, fetch_uid_run);
1368 if (result.error != MAILIMAP_NO_ERROR)
1369 return result.error;
1371 debug_print("imap fetch_uid - end\n");
1373 * fetch_result = result.fetch_result;
1375 return result.error;
1379 void imap_fetch_uid_list_free(carray * uid_list)
1383 for(i = 0 ; i < carray_count(uid_list) ; i ++) {
1386 puid = carray_get(uid_list, i);
1389 carray_free(uid_list);
1394 static int imap_fetch(mailimap * imap,
1397 size_t * result_len)
1400 struct mailimap_set * set;
1401 struct mailimap_fetch_att * fetch_att;
1402 struct mailimap_fetch_type * fetch_type;
1403 clist * fetch_result;
1404 struct mailimap_msg_att * msg_att;
1405 struct mailimap_msg_att_item * msg_att_item;
1410 struct mailimap_section * section;
1412 set = mailimap_set_new_single(msg_index);
1414 res = MAILIMAP_ERROR_MEMORY;
1418 section = mailimap_section_new(NULL);
1419 if (section == NULL) {
1420 res = MAILIMAP_ERROR_MEMORY;
1424 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1425 if (fetch_att == NULL) {
1426 mailimap_section_free(section);
1427 res = MAILIMAP_ERROR_MEMORY;
1431 fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
1432 if (fetch_type == NULL) {
1433 res = MAILIMAP_ERROR_MEMORY;
1434 goto free_fetch_att;
1437 mailstream_logger = imap_logger_fetch;
1439 r = mailimap_uid_fetch(imap, set,
1440 fetch_type, &fetch_result);
1442 mailstream_logger = imap_logger_cmd;
1444 mailimap_fetch_type_free(fetch_type);
1445 mailimap_set_free(set);
1448 case MAILIMAP_NO_ERROR:
1454 if (clist_begin(fetch_result) == NULL) {
1455 mailimap_fetch_list_free(fetch_result);
1456 return MAILIMAP_ERROR_FETCH;
1459 msg_att = clist_begin(fetch_result)->data;
1464 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ;
1465 cur = clist_next(cur)) {
1466 msg_att_item = clist_content(cur);
1468 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
1469 if (msg_att_item->att_data.att_static->att_type ==
1470 MAILIMAP_MSG_ATT_BODY_SECTION) {
1471 text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
1473 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL;
1475 msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
1480 mailimap_fetch_list_free(fetch_result);
1483 return MAILIMAP_ERROR_FETCH;
1486 * result_len = text_length;
1488 return MAILIMAP_NO_ERROR;
1491 mailimap_fetch_att_free(fetch_att);
1493 mailimap_set_free(set);
1498 static int imap_fetch_header(mailimap * imap,
1501 size_t * result_len)
1504 struct mailimap_set * set;
1505 struct mailimap_fetch_att * fetch_att;
1506 struct mailimap_fetch_type * fetch_type;
1507 clist * fetch_result;
1508 struct mailimap_msg_att * msg_att;
1509 struct mailimap_msg_att_item * msg_att_item;
1514 struct mailimap_section * section;
1516 set = mailimap_set_new_single(msg_index);
1518 res = MAILIMAP_ERROR_MEMORY;
1522 section = mailimap_section_new_header();
1523 if (section == NULL) {
1524 res = MAILIMAP_ERROR_MEMORY;
1528 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1529 if (fetch_att == NULL) {
1530 mailimap_section_free(section);
1531 res = MAILIMAP_ERROR_MEMORY;
1535 fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
1536 if (fetch_type == NULL) {
1537 res = MAILIMAP_ERROR_MEMORY;
1538 goto free_fetch_att;
1541 r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
1543 mailimap_fetch_type_free(fetch_type);
1544 mailimap_set_free(set);
1547 case MAILIMAP_NO_ERROR:
1553 if (clist_begin(fetch_result) == NULL) {
1554 mailimap_fetch_list_free(fetch_result);
1555 return MAILIMAP_ERROR_FETCH;
1558 msg_att = clist_begin(fetch_result)->data;
1563 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ;
1564 cur = clist_next(cur)) {
1565 msg_att_item = clist_content(cur);
1567 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
1568 if (msg_att_item->att_data.att_static->att_type ==
1569 MAILIMAP_MSG_ATT_BODY_SECTION) {
1570 text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
1571 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL;
1573 msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
1578 mailimap_fetch_list_free(fetch_result);
1581 return MAILIMAP_ERROR_FETCH;
1584 * result_len = text_length;
1586 return MAILIMAP_NO_ERROR;
1589 mailimap_fetch_att_free(fetch_att);
1591 mailimap_set_free(set);
1598 struct fetch_content_param {
1601 const char * filename;
1605 struct fetch_content_result {
1609 static void fetch_content_run(struct etpan_thread_op * op)
1611 struct fetch_content_param * param;
1612 struct fetch_content_result * result;
1614 size_t content_size;
1623 if (param->with_body)
1624 r = imap_fetch(param->imap, param->msg_index,
1625 &content, &content_size);
1627 r = imap_fetch_header(param->imap, param->msg_index,
1628 &content, &content_size);
1630 result = op->result;
1633 if (r == MAILIMAP_NO_ERROR) {
1634 fd = open(param->filename, O_RDWR | O_CREAT, 0600);
1636 result->error = MAILIMAP_ERROR_FETCH;
1640 f = fdopen(fd, "wb");
1642 result->error = MAILIMAP_ERROR_FETCH;
1646 r = fwrite(content, 1, content_size, f);
1653 g_unlink(param->filename);
1664 g_unlink(param->filename);
1667 if (mmap_string_unref(content) != 0)
1671 debug_print("imap fetch_content run - end %i\n", r);
1674 int imap_threaded_fetch_content(Folder * folder, uint32_t msg_index,
1676 const char * filename)
1678 struct fetch_content_param param;
1679 struct fetch_content_result result;
1682 debug_print("imap fetch_content - begin\n");
1684 imap = get_imap(folder);
1686 param.msg_index = msg_index;
1687 param.filename = filename;
1688 param.with_body = with_body;
1690 threaded_run(folder, ¶m, &result, fetch_content_run);
1692 if (result.error != MAILIMAP_NO_ERROR)
1693 return result.error;
1695 debug_print("imap fetch_content - end\n");
1697 return result.error;
1702 static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn)
1710 flag_list = att_dyn->att_list;
1711 if (flag_list == NULL)
1714 for(cur = clist_begin(flag_list) ; cur != NULL ;
1715 cur = clist_next(cur)) {
1716 struct mailimap_flag_fetch * flag_fetch;
1718 flag_fetch = clist_content(cur);
1719 if (flag_fetch->fl_type == MAILIMAP_FLAG_FETCH_RECENT)
1722 switch (flag_fetch->fl_flag->fl_type) {
1723 case MAILIMAP_FLAG_ANSWERED:
1724 flags |= MSG_REPLIED;
1726 case MAILIMAP_FLAG_FLAGGED:
1727 flags |= MSG_MARKED;
1729 case MAILIMAP_FLAG_DELETED:
1730 flags |= MSG_DELETED;
1732 case MAILIMAP_FLAG_SEEN:
1733 flags &= ~MSG_UNREAD;
1743 static int imap_get_msg_att_info(struct mailimap_msg_att * msg_att,
1747 struct mailimap_msg_att_dynamic ** patt_dyn)
1749 clistiter * item_cur;
1753 struct mailimap_msg_att_dynamic * att_dyn;
1760 for(item_cur = clist_begin(msg_att->att_list) ; item_cur != NULL ;
1761 item_cur = clist_next(item_cur)) {
1762 struct mailimap_msg_att_item * item;
1764 item = clist_content(item_cur);
1766 switch (item->att_type) {
1767 case MAILIMAP_MSG_ATT_ITEM_STATIC:
1768 switch (item->att_data.att_static->att_type) {
1769 case MAILIMAP_MSG_ATT_UID:
1770 uid = item->att_data.att_static->att_data.att_uid;
1773 case MAILIMAP_MSG_ATT_BODY_SECTION:
1774 if (headers == NULL) {
1775 headers = item->att_data.att_static->att_data.att_body_section->sec_body_part;
1778 case MAILIMAP_MSG_ATT_RFC822_SIZE:
1779 ref_size = item->att_data.att_static->att_data.att_rfc822_size;
1784 case MAILIMAP_MSG_ATT_ITEM_DYNAMIC:
1785 if (att_dyn == NULL) {
1786 att_dyn = item->att_data.att_dyn;
1794 if (pheaders != NULL)
1795 * pheaders = headers;
1796 if (pref_size != NULL)
1797 * pref_size = ref_size;
1798 if (patt_dyn != NULL)
1799 * patt_dyn = att_dyn;
1801 return MAIL_NO_ERROR;
1804 static struct imap_fetch_env_info *
1805 fetch_to_env_info(struct mailimap_msg_att * msg_att)
1807 struct imap_fetch_env_info * info;
1811 struct mailimap_msg_att_dynamic * att_dyn;
1813 imap_get_msg_att_info(msg_att, &uid, &headers, &size,
1818 info = malloc(sizeof(* info));
1820 info->headers = strdup(headers);
1822 info->flags = imap_flags_to_flags(att_dyn);
1828 imap_fetch_result_to_envelop_list(clist * fetch_result,
1829 carray ** p_env_list)
1836 env_list = carray_new(16);
1838 for(cur = clist_begin(fetch_result) ; cur != NULL ;
1839 cur = clist_next(cur)) {
1840 struct mailimap_msg_att * msg_att;
1841 struct imap_fetch_env_info * env_info;
1843 msg_att = clist_content(cur);
1845 env_info = fetch_to_env_info(msg_att);
1847 return MAILIMAP_ERROR_MEMORY;
1848 carray_add(env_list, env_info, NULL);
1851 * p_env_list = env_list;
1853 return MAIL_NO_ERROR;
1856 int imap_add_envelope_fetch_att(struct mailimap_fetch_type * fetch_type)
1858 struct mailimap_fetch_att * fetch_att;
1862 struct mailimap_header_list * imap_hdrlist;
1863 struct mailimap_section * section;
1865 hdrlist = clist_new();
1867 header = strdup("Date");
1868 r = clist_append(hdrlist, header);
1869 header = strdup("From");
1870 r = clist_append(hdrlist, header);
1871 header = strdup("To");
1872 r = clist_append(hdrlist, header);
1873 header = strdup("Cc");
1874 r = clist_append(hdrlist, header);
1875 header = strdup("Subject");
1876 r = clist_append(hdrlist, header);
1877 header = strdup("Message-ID");
1878 r = clist_append(hdrlist, header);
1879 header = strdup("References");
1880 r = clist_append(hdrlist, header);
1881 header = strdup("In-Reply-To");
1882 r = clist_append(hdrlist, header);
1884 imap_hdrlist = mailimap_header_list_new(hdrlist);
1885 section = mailimap_section_new_header_fields(imap_hdrlist);
1886 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1887 mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1889 return MAIL_NO_ERROR;
1892 int imap_add_header_fetch_att(struct mailimap_fetch_type * fetch_type)
1894 struct mailimap_fetch_att * fetch_att;
1895 struct mailimap_section * section;
1897 section = mailimap_section_new_header();
1898 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1899 mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1901 return MAIL_NO_ERROR;
1905 imap_get_envelopes_list(mailimap * imap, struct mailimap_set * set,
1906 carray ** p_env_list)
1908 struct mailimap_fetch_att * fetch_att;
1909 struct mailimap_fetch_type * fetch_type;
1911 clist * fetch_result;
1913 carray * env_list = NULL;
1917 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
1920 fetch_att = mailimap_fetch_att_new_uid();
1921 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1924 fetch_att = mailimap_fetch_att_new_flags();
1925 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1928 fetch_att = mailimap_fetch_att_new_rfc822_size();
1929 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1933 key.len = sizeof(imap);
1934 r = chash_get(courier_workaround_hash, &key, &value);
1936 r = imap_add_envelope_fetch_att(fetch_type);
1938 r = imap_add_header_fetch_att(fetch_type);
1940 r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
1943 case MAILIMAP_NO_ERROR:
1946 mailimap_fetch_type_free(fetch_type);
1947 debug_print("uid_fetch: %d\n", r);
1951 if (clist_begin(fetch_result) == NULL) {
1952 res = MAILIMAP_ERROR_FETCH;
1953 debug_print("clist_begin = NULL\n");
1957 r = imap_fetch_result_to_envelop_list(fetch_result, &env_list);
1958 mailimap_fetch_list_free(fetch_result);
1960 if (r != MAILIMAP_NO_ERROR) {
1961 mailimap_fetch_type_free(fetch_type);
1962 res = MAILIMAP_ERROR_MEMORY;
1963 debug_print("fetch_result_to_envelop_list: %d\n", res);
1967 mailimap_fetch_type_free(fetch_type);
1969 * p_env_list = env_list;
1971 return MAILIMAP_NO_ERROR;
1977 struct fetch_env_param {
1979 struct mailimap_set * set;
1982 struct fetch_env_result {
1983 carray * fetch_env_result;
1987 static void fetch_env_run(struct etpan_thread_op * op)
1989 struct fetch_env_param * param;
1990 struct fetch_env_result * result;
1997 r = imap_get_envelopes_list(param->imap, param->set,
2000 result = op->result;
2002 result->fetch_env_result = env_list;
2004 debug_print("imap fetch_env run - end %i\n", r);
2007 int imap_threaded_fetch_env(Folder * folder, struct mailimap_set * set,
2008 carray ** p_env_list)
2010 struct fetch_env_param param;
2011 struct fetch_env_result result;
2014 debug_print("imap fetch_env - begin\n");
2016 imap = get_imap(folder);
2020 threaded_run(folder, ¶m, &result, fetch_env_run);
2022 if (result.error != MAILIMAP_NO_ERROR) {
2028 key.len = sizeof(imap);
2029 r = chash_get(courier_workaround_hash, &key, &value);
2033 chash_set(courier_workaround_hash, &key, &value, NULL);
2035 threaded_run(folder, ¶m, &result, fetch_env_run);
2039 if (result.error != MAILIMAP_NO_ERROR)
2040 return result.error;
2042 debug_print("imap fetch_env - end\n");
2044 * p_env_list = result.fetch_env_result;
2046 return result.error;
2049 void imap_fetch_env_free(carray * env_list)
2053 for(i = 0 ; i < carray_count(env_list) ; i ++) {
2054 struct imap_fetch_env_info * env_info;
2056 env_info = carray_get(env_list, i);
2057 free(env_info->headers);
2060 carray_free(env_list);
2067 struct append_param {
2069 const char * mailbox;
2070 const char * filename;
2071 struct mailimap_flag_list * flag_list;
2074 struct append_result {
2079 static void append_run(struct etpan_thread_op * op)
2081 struct append_param * param;
2082 struct append_result * result;
2086 struct stat stat_buf;
2090 result = op->result;
2092 r = stat(param->filename, &stat_buf);
2094 result->error = MAILIMAP_ERROR_APPEND;
2097 size = stat_buf.st_size;
2099 fd = open(param->filename, O_RDONLY);
2101 result->error = MAILIMAP_ERROR_APPEND;
2105 data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
2106 if (data == (void *) MAP_FAILED) {
2108 result->error = MAILIMAP_ERROR_APPEND;
2112 r = mailimap_append(param->imap, param->mailbox,
2113 param->flag_list, NULL,
2114 data, size/*, &uid */);
2121 debug_print("imap append run - end %i uid %d\n", r, uid);
2124 int imap_threaded_append(Folder * folder, const char * mailbox,
2125 const char * filename,
2126 struct mailimap_flag_list * flag_list,
2129 struct append_param param;
2130 struct append_result result;
2133 debug_print("imap append - begin\n");
2135 imap = get_imap(folder);
2137 param.mailbox = mailbox;
2138 param.filename = filename;
2139 param.flag_list = flag_list;
2141 threaded_run(folder, ¶m, &result, append_run);
2143 if (result.error != MAILIMAP_NO_ERROR)
2144 return result.error;
2146 debug_print("imap append - end\n");
2150 return result.error;
2156 struct expunge_param {
2160 struct expunge_result {
2164 static void expunge_run(struct etpan_thread_op * op)
2166 struct expunge_param * param;
2167 struct expunge_result * result;
2171 r = mailimap_expunge(param->imap);
2173 result = op->result;
2175 debug_print("imap expunge run - end %i\n", r);
2178 int imap_threaded_expunge(Folder * folder)
2180 struct expunge_param param;
2181 struct expunge_result result;
2183 debug_print("imap expunge - begin\n");
2185 param.imap = get_imap(folder);
2187 threaded_run(folder, ¶m, &result, expunge_run);
2189 debug_print("imap expunge - end\n");
2191 return result.error;
2197 struct mailimap_set * set;
2201 struct copy_result {
2205 static void copy_run(struct etpan_thread_op * op)
2207 struct copy_param * param;
2208 struct copy_result * result;
2213 r = mailimap_uid_copy(param->imap, param->set, param->mb);
2215 result = op->result;
2218 debug_print("imap copy run - end %i\n", r);
2221 int imap_threaded_copy(Folder * folder, struct mailimap_set * set,
2224 struct copy_param param;
2225 struct copy_result result;
2228 debug_print("imap copy - begin\n");
2230 imap = get_imap(folder);
2235 threaded_run(folder, ¶m, &result, copy_run);
2237 if (result.error != MAILIMAP_NO_ERROR)
2238 return result.error;
2240 debug_print("imap copy - end\n");
2242 return result.error;
2247 struct store_param {
2249 struct mailimap_set * set;
2250 struct mailimap_store_att_flags * store_att_flags;
2253 struct store_result {
2257 static void store_run(struct etpan_thread_op * op)
2259 struct store_param * param;
2260 struct store_result * result;
2265 r = mailimap_uid_store(param->imap, param->set,
2266 param->store_att_flags);
2268 result = op->result;
2271 debug_print("imap store run - end %i\n", r);
2274 int imap_threaded_store(Folder * folder, struct mailimap_set * set,
2275 struct mailimap_store_att_flags * store_att_flags)
2277 struct store_param param;
2278 struct store_result result;
2281 debug_print("imap store - begin\n");
2283 imap = get_imap(folder);
2286 param.store_att_flags = store_att_flags;
2288 threaded_run(folder, ¶m, &result, store_run);
2290 if (result.error != MAILIMAP_NO_ERROR)
2291 return result.error;
2293 debug_print("imap store - end\n");
2295 return result.error;
2299 #define ENV_BUFFER_SIZE 512
2301 static void do_exec_command(int fd, const char * command,
2302 const char * servername, uint16_t port)
2306 char env_buffer[ENV_BUFFER_SIZE];
2310 /* Fork again to become a child of init rather than
2311 the etpan client. */
2317 snprintf(env_buffer, ENV_BUFFER_SIZE,
2318 "ETPANSERVER=%s", servername);
2320 snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANSERVER=");
2324 setenv("ETPANSERVER", servername, 1);
2326 unsetenv("ETPANSERVER");
2331 snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANPORT=%d", port);
2333 snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANPORT=");
2339 snprintf(porttext, sizeof(porttext), "%d", port);
2340 setenv("ETPANPORT", porttext, 1);
2343 unsetenv("ETPANPORT");
2347 /* Not a lot we can do if there's an error other than bail. */
2348 if (dup2(fd, 0) == -1)
2350 if (dup2(fd, 1) == -1)
2353 /* Should we close stderr and reopen /dev/null? */
2355 maxopen = sysconf(_SC_OPEN_MAX);
2356 for (i=3; i < maxopen; i++)
2360 /* Detach from the controlling tty if we have one. Otherwise,
2361 SSH might do something stupid like trying to use it instead
2362 of running $SSH_ASKPASS. Doh. */
2363 fd = open("/dev/tty", O_RDONLY);
2365 ioctl(fd, TIOCNOTTY, NULL);
2368 #endif /* TIOCNOTTY */
2370 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
2372 /* Eep. Shouldn't reach this */
2376 static int subcommand_connect(const char *command,
2377 const char *servername, uint16_t port)
2379 /* SEB unsupported on Windows */
2383 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds))
2388 do_exec_command(sockfds[1], command, servername, port);
2390 else if (childpid == -1) {
2398 /* Reap child, leaving grandchild process to run */
2399 waitpid(childpid, NULL, 0);
2404 int socket_connect_cmd(mailimap * imap, const char * command,
2405 const char * server, int port)
2411 fd = subcommand_connect(command, server, port);
2413 return MAILIMAP_ERROR_STREAM;
2415 s = mailstream_socket_open(fd);
2418 return MAILIMAP_ERROR_STREAM;
2421 r = mailimap_connect(imap, s);
2422 if (r != MAILIMAP_NO_ERROR_AUTHENTICATED
2423 && r != MAILIMAP_NO_ERROR_NON_AUTHENTICATED) {
2424 mailstream_close(s);
2433 struct connect_cmd_param {
2435 const char * command;
2436 const char * server;
2440 struct connect_cmd_result {
2444 static void connect_cmd_run(struct etpan_thread_op * op)
2447 struct connect_cmd_param * param;
2448 struct connect_cmd_result * result;
2451 result = op->result;
2453 r = socket_connect_cmd(param->imap, param->command,
2454 param->server, param->port);
2460 int imap_threaded_connect_cmd(Folder * folder, const char * command,
2461 const char * server, int port)
2463 struct connect_cmd_param param;
2464 struct connect_cmd_result result;
2469 imap = mailimap_new(0, NULL);
2472 key.len = sizeof(folder);
2475 chash_set(session_hash, &key, &value, NULL);
2478 param.command = command;
2479 param.server = server;
2482 threaded_run(folder, ¶m, &result, connect_cmd_run);
2484 debug_print("connect_cmd ok %i\n", result.error);
2486 return result.error;
2490 void imap_main_init(void)
2493 void imap_main_done(void)
2496 void imap_main_set_timeout(int sec)