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, (gushort)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 struct mailimap_set_item *sc_mailimap_set_item_copy(struct mailimap_set_item *orig)
1078 return mailimap_set_item_new(orig->set_first, orig->set_last);
1081 static struct mailimap_set *sc_mailimap_set_copy(struct mailimap_set *orig)
1083 clist *list = orig ? orig->set_list : NULL;
1084 clist *newlist = clist_new();
1089 for (cur = clist_begin(list); cur; cur = clist_next(cur))
1090 clist_append(newlist,
1091 sc_mailimap_set_item_copy(
1092 (struct mailimap_set_item *)clist_content(cur)));
1093 return mailimap_set_new(newlist);
1096 static void search_run(struct etpan_thread_op * op)
1098 struct search_param * param;
1099 struct search_result * result;
1101 struct mailimap_search_key * key;
1102 struct mailimap_search_key * uid_key;
1103 struct mailimap_search_key * search_type_key;
1104 clist * search_result;
1108 /* we copy the mailimap_set because freeing the key is recursive */
1109 uid_key = mailimap_search_key_new_uid(sc_mailimap_set_copy(param->set));
1111 search_type_key = NULL;
1112 switch (param->type) {
1113 case IMAP_SEARCH_TYPE_SIMPLE:
1114 search_type_key = NULL;
1117 case IMAP_SEARCH_TYPE_SEEN:
1118 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SEEN,
1119 NULL, NULL, NULL, NULL, NULL,
1120 NULL, NULL, NULL, NULL, NULL,
1121 NULL, NULL, NULL, NULL, 0,
1122 NULL, NULL, NULL, NULL, NULL,
1123 NULL, 0, NULL, NULL, NULL);
1126 case IMAP_SEARCH_TYPE_UNSEEN:
1127 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_UNSEEN,
1128 NULL, NULL, NULL, NULL, NULL,
1129 NULL, NULL, NULL, NULL, NULL,
1130 NULL, NULL, NULL, NULL, 0,
1131 NULL, NULL, NULL, NULL, NULL,
1132 NULL, 0, NULL, NULL, NULL);
1135 case IMAP_SEARCH_TYPE_ANSWERED:
1136 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_ANSWERED,
1137 NULL, NULL, NULL, NULL, NULL,
1138 NULL, NULL, NULL, NULL, NULL,
1139 NULL, NULL, NULL, NULL, 0,
1140 NULL, NULL, NULL, NULL, NULL,
1141 NULL, 0, NULL, NULL, NULL);
1144 case IMAP_SEARCH_TYPE_FLAGGED:
1145 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_FLAGGED,
1146 NULL, NULL, NULL, NULL, NULL,
1147 NULL, NULL, NULL, NULL, NULL,
1148 NULL, NULL, NULL, NULL, 0,
1149 NULL, NULL, NULL, NULL, NULL,
1150 NULL, 0, NULL, NULL, NULL);
1152 case IMAP_SEARCH_TYPE_DELETED:
1153 search_type_key = mailimap_search_key_new(MAILIMAP_SEARCH_KEY_DELETED,
1154 NULL, NULL, NULL, NULL, NULL,
1155 NULL, NULL, NULL, NULL, NULL,
1156 NULL, NULL, NULL, NULL, 0,
1157 NULL, NULL, NULL, NULL, NULL,
1158 NULL, 0, NULL, NULL, NULL);
1162 if (search_type_key != NULL) {
1163 key = mailimap_search_key_new_multiple_empty();
1164 mailimap_search_key_multiple_add(key, search_type_key);
1165 mailimap_search_key_multiple_add(key, uid_key);
1171 r = mailimap_uid_search(param->imap, NULL, key, &search_result);
1173 /* free the key (with the imapset) */
1174 mailimap_search_key_free(key);
1176 result = op->result;
1178 result->search_result = search_result;
1179 debug_print("imap search run - end %i\n", r);
1182 int imap_threaded_search(Folder * folder, int search_type,
1183 struct mailimap_set * set, clist ** search_result)
1185 struct search_param param;
1186 struct search_result result;
1189 debug_print("imap search - begin\n");
1191 imap = get_imap(folder);
1194 param.type = search_type;
1196 threaded_run(folder, ¶m, &result, search_run);
1198 if (result.error != MAILIMAP_NO_ERROR)
1199 return result.error;
1201 debug_print("imap search - end\n");
1203 * search_result = result.search_result;
1205 return result.error;
1212 uid_list_to_env_list(clist * fetch_result, carray ** result)
1220 tab = carray_new(128);
1222 res = MAILIMAP_ERROR_MEMORY;
1226 for(cur = clist_begin(fetch_result) ; cur != NULL ;
1227 cur = clist_next(cur)) {
1228 struct mailimap_msg_att * msg_att;
1229 clistiter * item_cur;
1234 msg_att = clist_content(cur);
1238 for(item_cur = clist_begin(msg_att->att_list) ;
1240 item_cur = clist_next(item_cur)) {
1241 struct mailimap_msg_att_item * item;
1243 item = clist_content(item_cur);
1245 switch (item->att_type) {
1246 case MAILIMAP_MSG_ATT_ITEM_STATIC:
1247 switch (item->att_data.att_static->att_type) {
1248 case MAILIMAP_MSG_ATT_UID:
1249 uid = item->att_data.att_static->att_data.att_uid;
1255 puid = malloc(sizeof(* puid));
1257 res = MAILIMAP_ERROR_MEMORY;
1262 r = carray_add(tab, puid, NULL);
1265 res = MAILIMAP_ERROR_MEMORY;
1272 return MAILIMAP_NO_ERROR;
1275 for(i = 0 ; i < carray_count(tab) ; i++)
1276 mailmessage_free(carray_get(tab, i));
1281 static int imap_get_messages_list(mailimap * imap,
1282 uint32_t first_index,
1287 struct mailimap_fetch_att * fetch_att;
1288 struct mailimap_fetch_type * fetch_type;
1289 struct mailimap_set * set;
1290 clist * fetch_result;
1293 set = mailimap_set_new_interval(first_index, 0);
1295 res = MAILIMAP_ERROR_MEMORY;
1299 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
1300 if (fetch_type == NULL) {
1301 res = MAILIMAP_ERROR_MEMORY;
1305 fetch_att = mailimap_fetch_att_new_uid();
1306 if (fetch_att == NULL) {
1307 res = MAILIMAP_ERROR_MEMORY;
1308 goto free_fetch_type;
1311 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1312 if (r != MAILIMAP_NO_ERROR) {
1313 mailimap_fetch_att_free(fetch_att);
1314 res = MAILIMAP_ERROR_MEMORY;
1315 goto free_fetch_type;
1318 r = mailimap_uid_fetch(imap, set,
1319 fetch_type, &fetch_result);
1321 mailimap_fetch_type_free(fetch_type);
1322 mailimap_set_free(set);
1324 if (r != MAILIMAP_NO_ERROR) {
1330 r = uid_list_to_env_list(fetch_result, &env_list);
1331 mailimap_fetch_list_free(fetch_result);
1333 * result = env_list;
1335 return MAILIMAP_NO_ERROR;
1338 mailimap_fetch_type_free(fetch_type);
1340 mailimap_set_free(set);
1348 struct fetch_uid_param {
1350 uint32_t first_index;
1353 struct fetch_uid_result {
1355 carray * fetch_result;
1358 static void fetch_uid_run(struct etpan_thread_op * op)
1360 struct fetch_uid_param * param;
1361 struct fetch_uid_result * result;
1362 carray * fetch_result;
1367 fetch_result = NULL;
1368 r = imap_get_messages_list(param->imap, param->first_index,
1371 result = op->result;
1373 result->fetch_result = fetch_result;
1374 debug_print("imap fetch_uid run - end %i\n", r);
1377 int imap_threaded_fetch_uid(Folder * folder, uint32_t first_index,
1378 carray ** fetch_result)
1380 struct fetch_uid_param param;
1381 struct fetch_uid_result result;
1384 debug_print("imap fetch_uid - begin\n");
1386 imap = get_imap(folder);
1388 param.first_index = first_index;
1390 threaded_run(folder, ¶m, &result, fetch_uid_run);
1392 if (result.error != MAILIMAP_NO_ERROR)
1393 return result.error;
1395 debug_print("imap fetch_uid - end\n");
1397 * fetch_result = result.fetch_result;
1399 return result.error;
1403 void imap_fetch_uid_list_free(carray * uid_list)
1407 for(i = 0 ; i < carray_count(uid_list) ; i ++) {
1410 puid = carray_get(uid_list, i);
1413 carray_free(uid_list);
1418 static int imap_fetch(mailimap * imap,
1421 size_t * result_len)
1424 struct mailimap_set * set;
1425 struct mailimap_fetch_att * fetch_att;
1426 struct mailimap_fetch_type * fetch_type;
1427 clist * fetch_result;
1428 struct mailimap_msg_att * msg_att;
1429 struct mailimap_msg_att_item * msg_att_item;
1434 struct mailimap_section * section;
1436 set = mailimap_set_new_single(msg_index);
1438 res = MAILIMAP_ERROR_MEMORY;
1442 section = mailimap_section_new(NULL);
1443 if (section == NULL) {
1444 res = MAILIMAP_ERROR_MEMORY;
1448 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1449 if (fetch_att == NULL) {
1450 mailimap_section_free(section);
1451 res = MAILIMAP_ERROR_MEMORY;
1455 fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
1456 if (fetch_type == NULL) {
1457 res = MAILIMAP_ERROR_MEMORY;
1458 goto free_fetch_att;
1461 mailstream_logger = imap_logger_fetch;
1463 r = mailimap_uid_fetch(imap, set,
1464 fetch_type, &fetch_result);
1466 mailstream_logger = imap_logger_cmd;
1468 mailimap_fetch_type_free(fetch_type);
1469 mailimap_set_free(set);
1472 case MAILIMAP_NO_ERROR:
1478 if (clist_begin(fetch_result) == NULL) {
1479 mailimap_fetch_list_free(fetch_result);
1480 return MAILIMAP_ERROR_FETCH;
1483 msg_att = clist_begin(fetch_result)->data;
1488 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ;
1489 cur = clist_next(cur)) {
1490 msg_att_item = clist_content(cur);
1492 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
1493 if (msg_att_item->att_data.att_static->att_type ==
1494 MAILIMAP_MSG_ATT_BODY_SECTION) {
1495 text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
1497 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL;
1499 msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
1504 mailimap_fetch_list_free(fetch_result);
1507 return MAILIMAP_ERROR_FETCH;
1510 * result_len = text_length;
1512 return MAILIMAP_NO_ERROR;
1515 mailimap_fetch_att_free(fetch_att);
1517 mailimap_set_free(set);
1522 static int imap_fetch_header(mailimap * imap,
1525 size_t * result_len)
1528 struct mailimap_set * set;
1529 struct mailimap_fetch_att * fetch_att;
1530 struct mailimap_fetch_type * fetch_type;
1531 clist * fetch_result;
1532 struct mailimap_msg_att * msg_att;
1533 struct mailimap_msg_att_item * msg_att_item;
1538 struct mailimap_section * section;
1540 set = mailimap_set_new_single(msg_index);
1542 res = MAILIMAP_ERROR_MEMORY;
1546 section = mailimap_section_new_header();
1547 if (section == NULL) {
1548 res = MAILIMAP_ERROR_MEMORY;
1552 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1553 if (fetch_att == NULL) {
1554 mailimap_section_free(section);
1555 res = MAILIMAP_ERROR_MEMORY;
1559 fetch_type = mailimap_fetch_type_new_fetch_att(fetch_att);
1560 if (fetch_type == NULL) {
1561 res = MAILIMAP_ERROR_MEMORY;
1562 goto free_fetch_att;
1565 r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
1567 mailimap_fetch_type_free(fetch_type);
1568 mailimap_set_free(set);
1571 case MAILIMAP_NO_ERROR:
1577 if (clist_begin(fetch_result) == NULL) {
1578 mailimap_fetch_list_free(fetch_result);
1579 return MAILIMAP_ERROR_FETCH;
1582 msg_att = clist_begin(fetch_result)->data;
1587 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ;
1588 cur = clist_next(cur)) {
1589 msg_att_item = clist_content(cur);
1591 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
1592 if (msg_att_item->att_data.att_static->att_type ==
1593 MAILIMAP_MSG_ATT_BODY_SECTION) {
1594 text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
1595 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = NULL;
1597 msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
1602 mailimap_fetch_list_free(fetch_result);
1605 return MAILIMAP_ERROR_FETCH;
1608 * result_len = text_length;
1610 return MAILIMAP_NO_ERROR;
1613 mailimap_fetch_att_free(fetch_att);
1615 mailimap_set_free(set);
1622 struct fetch_content_param {
1625 const char * filename;
1629 struct fetch_content_result {
1633 static void fetch_content_run(struct etpan_thread_op * op)
1635 struct fetch_content_param * param;
1636 struct fetch_content_result * result;
1638 size_t content_size;
1647 if (param->with_body)
1648 r = imap_fetch(param->imap, param->msg_index,
1649 &content, &content_size);
1651 r = imap_fetch_header(param->imap, param->msg_index,
1652 &content, &content_size);
1654 result = op->result;
1657 if (r == MAILIMAP_NO_ERROR) {
1658 fd = open(param->filename, O_RDWR | O_CREAT, 0600);
1660 result->error = MAILIMAP_ERROR_FETCH;
1664 f = fdopen(fd, "wb");
1666 result->error = MAILIMAP_ERROR_FETCH;
1670 r = fwrite(content, 1, content_size, f);
1677 g_unlink(param->filename);
1688 g_unlink(param->filename);
1691 if (mmap_string_unref(content) != 0)
1695 debug_print("imap fetch_content run - end %i\n", r);
1698 int imap_threaded_fetch_content(Folder * folder, uint32_t msg_index,
1700 const char * filename)
1702 struct fetch_content_param param;
1703 struct fetch_content_result result;
1706 debug_print("imap fetch_content - begin\n");
1708 imap = get_imap(folder);
1710 param.msg_index = msg_index;
1711 param.filename = filename;
1712 param.with_body = with_body;
1714 threaded_run(folder, ¶m, &result, fetch_content_run);
1716 if (result.error != MAILIMAP_NO_ERROR)
1717 return result.error;
1719 debug_print("imap fetch_content - end\n");
1721 return result.error;
1726 static int imap_flags_to_flags(struct mailimap_msg_att_dynamic * att_dyn)
1734 flag_list = att_dyn->att_list;
1735 if (flag_list == NULL)
1738 for(cur = clist_begin(flag_list) ; cur != NULL ;
1739 cur = clist_next(cur)) {
1740 struct mailimap_flag_fetch * flag_fetch;
1742 flag_fetch = clist_content(cur);
1743 if (flag_fetch->fl_type == MAILIMAP_FLAG_FETCH_RECENT)
1746 switch (flag_fetch->fl_flag->fl_type) {
1747 case MAILIMAP_FLAG_ANSWERED:
1748 flags |= MSG_REPLIED;
1750 case MAILIMAP_FLAG_FLAGGED:
1751 flags |= MSG_MARKED;
1753 case MAILIMAP_FLAG_DELETED:
1754 flags |= MSG_DELETED;
1756 case MAILIMAP_FLAG_SEEN:
1757 flags &= ~MSG_UNREAD;
1767 static int imap_get_msg_att_info(struct mailimap_msg_att * msg_att,
1771 struct mailimap_msg_att_dynamic ** patt_dyn)
1773 clistiter * item_cur;
1777 struct mailimap_msg_att_dynamic * att_dyn;
1784 for(item_cur = clist_begin(msg_att->att_list) ; item_cur != NULL ;
1785 item_cur = clist_next(item_cur)) {
1786 struct mailimap_msg_att_item * item;
1788 item = clist_content(item_cur);
1790 switch (item->att_type) {
1791 case MAILIMAP_MSG_ATT_ITEM_STATIC:
1792 switch (item->att_data.att_static->att_type) {
1793 case MAILIMAP_MSG_ATT_UID:
1794 uid = item->att_data.att_static->att_data.att_uid;
1797 case MAILIMAP_MSG_ATT_BODY_SECTION:
1798 if (headers == NULL) {
1799 headers = item->att_data.att_static->att_data.att_body_section->sec_body_part;
1802 case MAILIMAP_MSG_ATT_RFC822_SIZE:
1803 ref_size = item->att_data.att_static->att_data.att_rfc822_size;
1808 case MAILIMAP_MSG_ATT_ITEM_DYNAMIC:
1809 if (att_dyn == NULL) {
1810 att_dyn = item->att_data.att_dyn;
1818 if (pheaders != NULL)
1819 * pheaders = headers;
1820 if (pref_size != NULL)
1821 * pref_size = ref_size;
1822 if (patt_dyn != NULL)
1823 * patt_dyn = att_dyn;
1825 return MAIL_NO_ERROR;
1828 static struct imap_fetch_env_info *
1829 fetch_to_env_info(struct mailimap_msg_att * msg_att)
1831 struct imap_fetch_env_info * info;
1835 struct mailimap_msg_att_dynamic * att_dyn;
1837 imap_get_msg_att_info(msg_att, &uid, &headers, &size,
1842 info = malloc(sizeof(* info));
1844 info->headers = strdup(headers);
1846 info->flags = imap_flags_to_flags(att_dyn);
1852 imap_fetch_result_to_envelop_list(clist * fetch_result,
1853 carray ** p_env_list)
1860 env_list = carray_new(16);
1862 for(cur = clist_begin(fetch_result) ; cur != NULL ;
1863 cur = clist_next(cur)) {
1864 struct mailimap_msg_att * msg_att;
1865 struct imap_fetch_env_info * env_info;
1867 msg_att = clist_content(cur);
1869 env_info = fetch_to_env_info(msg_att);
1871 return MAILIMAP_ERROR_MEMORY;
1872 carray_add(env_list, env_info, NULL);
1875 * p_env_list = env_list;
1877 return MAIL_NO_ERROR;
1880 int imap_add_envelope_fetch_att(struct mailimap_fetch_type * fetch_type)
1882 struct mailimap_fetch_att * fetch_att;
1886 struct mailimap_header_list * imap_hdrlist;
1887 struct mailimap_section * section;
1889 hdrlist = clist_new();
1891 header = strdup("Date");
1892 r = clist_append(hdrlist, header);
1893 header = strdup("From");
1894 r = clist_append(hdrlist, header);
1895 header = strdup("To");
1896 r = clist_append(hdrlist, header);
1897 header = strdup("Cc");
1898 r = clist_append(hdrlist, header);
1899 header = strdup("Subject");
1900 r = clist_append(hdrlist, header);
1901 header = strdup("Message-ID");
1902 r = clist_append(hdrlist, header);
1903 header = strdup("References");
1904 r = clist_append(hdrlist, header);
1905 header = strdup("In-Reply-To");
1906 r = clist_append(hdrlist, header);
1908 imap_hdrlist = mailimap_header_list_new(hdrlist);
1909 section = mailimap_section_new_header_fields(imap_hdrlist);
1910 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1911 mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1913 return MAIL_NO_ERROR;
1916 int imap_add_header_fetch_att(struct mailimap_fetch_type * fetch_type)
1918 struct mailimap_fetch_att * fetch_att;
1919 struct mailimap_section * section;
1921 section = mailimap_section_new_header();
1922 fetch_att = mailimap_fetch_att_new_body_peek_section(section);
1923 mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1925 return MAIL_NO_ERROR;
1929 imap_get_envelopes_list(mailimap * imap, struct mailimap_set * set,
1930 carray ** p_env_list)
1932 struct mailimap_fetch_att * fetch_att;
1933 struct mailimap_fetch_type * fetch_type;
1935 clist * fetch_result;
1937 carray * env_list = NULL;
1941 fetch_type = mailimap_fetch_type_new_fetch_att_list_empty();
1944 fetch_att = mailimap_fetch_att_new_uid();
1945 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1948 fetch_att = mailimap_fetch_att_new_flags();
1949 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1952 fetch_att = mailimap_fetch_att_new_rfc822_size();
1953 r = mailimap_fetch_type_new_fetch_att_list_add(fetch_type, fetch_att);
1957 key.len = sizeof(imap);
1958 r = chash_get(courier_workaround_hash, &key, &value);
1960 r = imap_add_envelope_fetch_att(fetch_type);
1962 r = imap_add_header_fetch_att(fetch_type);
1964 r = mailimap_uid_fetch(imap, set, fetch_type, &fetch_result);
1967 case MAILIMAP_NO_ERROR:
1970 mailimap_fetch_type_free(fetch_type);
1971 debug_print("uid_fetch: %d\n", r);
1975 if (clist_begin(fetch_result) == NULL) {
1976 res = MAILIMAP_ERROR_FETCH;
1977 debug_print("clist_begin = NULL\n");
1981 r = imap_fetch_result_to_envelop_list(fetch_result, &env_list);
1982 mailimap_fetch_list_free(fetch_result);
1984 if (r != MAILIMAP_NO_ERROR) {
1985 mailimap_fetch_type_free(fetch_type);
1986 res = MAILIMAP_ERROR_MEMORY;
1987 debug_print("fetch_result_to_envelop_list: %d\n", res);
1991 mailimap_fetch_type_free(fetch_type);
1993 * p_env_list = env_list;
1995 return MAILIMAP_NO_ERROR;
2001 struct fetch_env_param {
2003 struct mailimap_set * set;
2006 struct fetch_env_result {
2007 carray * fetch_env_result;
2011 static void fetch_env_run(struct etpan_thread_op * op)
2013 struct fetch_env_param * param;
2014 struct fetch_env_result * result;
2021 r = imap_get_envelopes_list(param->imap, param->set,
2024 result = op->result;
2026 result->fetch_env_result = env_list;
2028 debug_print("imap fetch_env run - end %i\n", r);
2031 int imap_threaded_fetch_env(Folder * folder, struct mailimap_set * set,
2032 carray ** p_env_list)
2034 struct fetch_env_param param;
2035 struct fetch_env_result result;
2038 debug_print("imap fetch_env - begin\n");
2040 imap = get_imap(folder);
2044 threaded_run(folder, ¶m, &result, fetch_env_run);
2046 if (result.error != MAILIMAP_NO_ERROR) {
2052 key.len = sizeof(imap);
2053 r = chash_get(courier_workaround_hash, &key, &value);
2057 chash_set(courier_workaround_hash, &key, &value, NULL);
2059 threaded_run(folder, ¶m, &result, fetch_env_run);
2063 if (result.error != MAILIMAP_NO_ERROR)
2064 return result.error;
2066 debug_print("imap fetch_env - end\n");
2068 * p_env_list = result.fetch_env_result;
2070 return result.error;
2073 void imap_fetch_env_free(carray * env_list)
2077 for(i = 0 ; i < carray_count(env_list) ; i ++) {
2078 struct imap_fetch_env_info * env_info;
2080 env_info = carray_get(env_list, i);
2081 free(env_info->headers);
2084 carray_free(env_list);
2091 struct append_param {
2093 const char * mailbox;
2094 const char * filename;
2095 struct mailimap_flag_list * flag_list;
2098 struct append_result {
2103 static void append_run(struct etpan_thread_op * op)
2105 struct append_param * param;
2106 struct append_result * result;
2110 struct stat stat_buf;
2114 result = op->result;
2116 r = stat(param->filename, &stat_buf);
2118 result->error = MAILIMAP_ERROR_APPEND;
2121 size = stat_buf.st_size;
2123 fd = open(param->filename, O_RDONLY);
2125 result->error = MAILIMAP_ERROR_APPEND;
2129 data = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
2130 if (data == (void *) MAP_FAILED) {
2132 result->error = MAILIMAP_ERROR_APPEND;
2136 r = mailimap_append(param->imap, param->mailbox,
2137 param->flag_list, NULL,
2138 data, size/*, &uid */);
2145 debug_print("imap append run - end %i uid %d\n", r, uid);
2148 int imap_threaded_append(Folder * folder, const char * mailbox,
2149 const char * filename,
2150 struct mailimap_flag_list * flag_list,
2153 struct append_param param;
2154 struct append_result result;
2157 debug_print("imap append - begin\n");
2159 imap = get_imap(folder);
2161 param.mailbox = mailbox;
2162 param.filename = filename;
2163 param.flag_list = flag_list;
2165 threaded_run(folder, ¶m, &result, append_run);
2167 if (result.error != MAILIMAP_NO_ERROR)
2168 return result.error;
2170 debug_print("imap append - end\n");
2174 return result.error;
2180 struct expunge_param {
2184 struct expunge_result {
2188 static void expunge_run(struct etpan_thread_op * op)
2190 struct expunge_param * param;
2191 struct expunge_result * result;
2195 r = mailimap_expunge(param->imap);
2197 result = op->result;
2199 debug_print("imap expunge run - end %i\n", r);
2202 int imap_threaded_expunge(Folder * folder)
2204 struct expunge_param param;
2205 struct expunge_result result;
2207 debug_print("imap expunge - begin\n");
2209 param.imap = get_imap(folder);
2211 threaded_run(folder, ¶m, &result, expunge_run);
2213 debug_print("imap expunge - end\n");
2215 return result.error;
2221 struct mailimap_set * set;
2225 struct copy_result {
2229 static void copy_run(struct etpan_thread_op * op)
2231 struct copy_param * param;
2232 struct copy_result * result;
2237 r = mailimap_uid_copy(param->imap, param->set, param->mb);
2239 result = op->result;
2242 debug_print("imap copy run - end %i\n", r);
2245 int imap_threaded_copy(Folder * folder, struct mailimap_set * set,
2248 struct copy_param param;
2249 struct copy_result result;
2252 debug_print("imap copy - begin\n");
2254 imap = get_imap(folder);
2259 threaded_run(folder, ¶m, &result, copy_run);
2261 if (result.error != MAILIMAP_NO_ERROR)
2262 return result.error;
2264 debug_print("imap copy - end\n");
2266 return result.error;
2271 struct store_param {
2273 struct mailimap_set * set;
2274 struct mailimap_store_att_flags * store_att_flags;
2277 struct store_result {
2281 static void store_run(struct etpan_thread_op * op)
2283 struct store_param * param;
2284 struct store_result * result;
2289 r = mailimap_uid_store(param->imap, param->set,
2290 param->store_att_flags);
2292 result = op->result;
2295 debug_print("imap store run - end %i\n", r);
2298 int imap_threaded_store(Folder * folder, struct mailimap_set * set,
2299 struct mailimap_store_att_flags * store_att_flags)
2301 struct store_param param;
2302 struct store_result result;
2305 debug_print("imap store - begin\n");
2307 imap = get_imap(folder);
2310 param.store_att_flags = store_att_flags;
2312 threaded_run(folder, ¶m, &result, store_run);
2314 if (result.error != MAILIMAP_NO_ERROR)
2315 return result.error;
2317 debug_print("imap store - end\n");
2319 return result.error;
2323 #define ENV_BUFFER_SIZE 512
2325 static void do_exec_command(int fd, const char * command,
2326 const char * servername, uint16_t port)
2330 char env_buffer[ENV_BUFFER_SIZE];
2334 /* Fork again to become a child of init rather than
2335 the etpan client. */
2341 snprintf(env_buffer, ENV_BUFFER_SIZE,
2342 "ETPANSERVER=%s", servername);
2344 snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANSERVER=");
2348 setenv("ETPANSERVER", servername, 1);
2350 unsetenv("ETPANSERVER");
2355 snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANPORT=%d", port);
2357 snprintf(env_buffer, ENV_BUFFER_SIZE, "ETPANPORT=");
2363 snprintf(porttext, sizeof(porttext), "%d", port);
2364 setenv("ETPANPORT", porttext, 1);
2367 unsetenv("ETPANPORT");
2371 /* Not a lot we can do if there's an error other than bail. */
2372 if (dup2(fd, 0) == -1)
2374 if (dup2(fd, 1) == -1)
2377 /* Should we close stderr and reopen /dev/null? */
2379 maxopen = sysconf(_SC_OPEN_MAX);
2380 for (i=3; i < maxopen; i++)
2384 /* Detach from the controlling tty if we have one. Otherwise,
2385 SSH might do something stupid like trying to use it instead
2386 of running $SSH_ASKPASS. Doh. */
2387 fd = open("/dev/tty", O_RDONLY);
2389 ioctl(fd, TIOCNOTTY, NULL);
2392 #endif /* TIOCNOTTY */
2394 execl("/bin/sh", "/bin/sh", "-c", command, NULL);
2396 /* Eep. Shouldn't reach this */
2400 static int subcommand_connect(const char *command,
2401 const char *servername, uint16_t port)
2403 /* SEB unsupported on Windows */
2407 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfds))
2412 do_exec_command(sockfds[1], command, servername, port);
2414 else if (childpid == -1) {
2422 /* Reap child, leaving grandchild process to run */
2423 waitpid(childpid, NULL, 0);
2428 int socket_connect_cmd(mailimap * imap, const char * command,
2429 const char * server, int port)
2435 fd = subcommand_connect(command, server, port);
2437 return MAILIMAP_ERROR_STREAM;
2439 s = mailstream_socket_open(fd);
2442 return MAILIMAP_ERROR_STREAM;
2445 r = mailimap_connect(imap, s);
2446 if (r != MAILIMAP_NO_ERROR_AUTHENTICATED
2447 && r != MAILIMAP_NO_ERROR_NON_AUTHENTICATED) {
2448 mailstream_close(s);
2457 struct connect_cmd_param {
2459 const char * command;
2460 const char * server;
2464 struct connect_cmd_result {
2468 static void connect_cmd_run(struct etpan_thread_op * op)
2471 struct connect_cmd_param * param;
2472 struct connect_cmd_result * result;
2475 result = op->result;
2477 r = socket_connect_cmd(param->imap, param->command,
2478 param->server, param->port);
2484 int imap_threaded_connect_cmd(Folder * folder, const char * command,
2485 const char * server, int port)
2487 struct connect_cmd_param param;
2488 struct connect_cmd_result result;
2493 imap = mailimap_new(0, NULL);
2496 key.len = sizeof(folder);
2499 chash_set(session_hash, &key, &value, NULL);
2502 param.command = command;
2503 param.server = server;
2506 threaded_run(folder, ¶m, &result, connect_cmd_run);
2508 debug_print("connect_cmd ok %i\n", result.error);
2510 return result.error;
2514 void imap_main_init(void)
2517 void imap_main_done(void)
2520 void imap_main_set_timeout(int sec)