Lines Matching refs:data
86 static CURLcode imap_regular_transfer(struct Curl_easy *data, bool *done);
87 static CURLcode imap_do(struct Curl_easy *data, bool *done);
88 static CURLcode imap_done(struct Curl_easy *data, CURLcode status,
90 static CURLcode imap_connect(struct Curl_easy *data, bool *done);
91 static CURLcode imap_disconnect(struct Curl_easy *data,
93 static CURLcode imap_multi_statemach(struct Curl_easy *data, bool *done);
94 static int imap_getsock(struct Curl_easy *data, struct connectdata *conn,
96 static CURLcode imap_doing(struct Curl_easy *data, bool *dophase_done);
97 static CURLcode imap_setup_connection(struct Curl_easy *data,
100 static CURLcode imap_sendf(struct Curl_easy *data, const char *fmt, ...)
103 static CURLcode imap_parse_url_path(struct Curl_easy *data);
104 static CURLcode imap_parse_custom_request(struct Curl_easy *data);
105 static CURLcode imap_perform_authenticate(struct Curl_easy *data,
108 static CURLcode imap_continue_authenticate(struct Curl_easy *data,
111 static CURLcode imap_cancel_authenticate(struct Curl_easy *data,
113 static CURLcode imap_get_message(struct Curl_easy *data, struct bufref *out);
255 static bool imap_endofresp(struct Curl_easy *data, struct connectdata *conn, in imap_endofresp() argument
258 struct IMAP *imap = data->req.p.imap; in imap_endofresp()
341 failf(data, "Unexpected continuation response"); in imap_endofresp()
358 static CURLcode imap_get_message(struct Curl_easy *data, struct bufref *out) in imap_get_message() argument
360 char *message = Curl_dyn_ptr(&data->conn->proto.imapc.pp.recvbuf); in imap_get_message()
361 size_t len = data->conn->proto.imapc.pp.nfinal; in imap_get_message()
392 static void imap_state(struct Curl_easy *data, imapstate newstate) in imap_state() argument
394 struct imap_conn *imapc = &data->conn->proto.imapc; in imap_state()
417 infof(data, "IMAP %p state change from %s to %s", in imap_state()
431 static CURLcode imap_perform_capability(struct Curl_easy *data, in imap_perform_capability() argument
441 result = imap_sendf(data, "CAPABILITY"); in imap_perform_capability()
444 imap_state(data, IMAP_CAPABILITY); in imap_perform_capability()
455 static CURLcode imap_perform_starttls(struct Curl_easy *data) in imap_perform_starttls() argument
458 CURLcode result = imap_sendf(data, "STARTTLS"); in imap_perform_starttls()
461 imap_state(data, IMAP_STARTTLS); in imap_perform_starttls()
472 static CURLcode imap_perform_upgrade_tls(struct Curl_easy *data, in imap_perform_upgrade_tls() argument
481 result = Curl_ssl_cfilter_add(data, conn, FIRSTSOCKET); in imap_perform_upgrade_tls()
486 result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone); in imap_perform_upgrade_tls()
490 imap_state(data, IMAP_UPGRADETLS); in imap_perform_upgrade_tls()
494 result = imap_perform_capability(data, conn); in imap_perform_upgrade_tls()
507 static CURLcode imap_perform_login(struct Curl_easy *data, in imap_perform_login() argument
516 if(!data->state.aptr.user) { in imap_perform_login()
517 imap_state(data, IMAP_STOP); in imap_perform_login()
527 result = imap_sendf(data, "LOGIN %s %s", user ? user : "", in imap_perform_login()
534 imap_state(data, IMAP_LOGIN); in imap_perform_login()
546 static CURLcode imap_perform_authenticate(struct Curl_easy *data, in imap_perform_authenticate() argument
555 result = imap_sendf(data, "AUTHENTICATE %s %s", mech, ir); in imap_perform_authenticate()
559 result = imap_sendf(data, "AUTHENTICATE %s", mech); in imap_perform_authenticate()
571 static CURLcode imap_continue_authenticate(struct Curl_easy *data, in imap_continue_authenticate() argument
575 struct imap_conn *imapc = &data->conn->proto.imapc; in imap_continue_authenticate()
579 return Curl_pp_sendf(data, &imapc->pp, in imap_continue_authenticate()
589 static CURLcode imap_cancel_authenticate(struct Curl_easy *data, in imap_cancel_authenticate() argument
592 struct imap_conn *imapc = &data->conn->proto.imapc; in imap_cancel_authenticate()
596 return Curl_pp_sendf(data, &imapc->pp, "*"); in imap_cancel_authenticate()
607 static CURLcode imap_perform_authentication(struct Curl_easy *data, in imap_perform_authentication() argument
617 !Curl_sasl_can_authenticate(&imapc->sasl, data)) { in imap_perform_authentication()
618 imap_state(data, IMAP_STOP); in imap_perform_authentication()
623 result = Curl_sasl_start(&imapc->sasl, data, imapc->ir_supported, &progress); in imap_perform_authentication()
627 imap_state(data, IMAP_AUTHENTICATE); in imap_perform_authentication()
630 result = imap_perform_login(data, conn); in imap_perform_authentication()
633 infof(data, "No known authentication mechanisms supported"); in imap_perform_authentication()
647 static CURLcode imap_perform_list(struct Curl_easy *data) in imap_perform_list() argument
650 struct IMAP *imap = data->req.p.imap; in imap_perform_list()
654 result = imap_sendf(data, "%s%s", imap->custom, in imap_perform_list()
664 result = imap_sendf(data, "LIST \"%s\" *", mailbox); in imap_perform_list()
670 imap_state(data, IMAP_LIST); in imap_perform_list()
681 static CURLcode imap_perform_select(struct Curl_easy *data) in imap_perform_select() argument
684 struct connectdata *conn = data->conn; in imap_perform_select()
685 struct IMAP *imap = data->req.p.imap; in imap_perform_select()
695 failf(data, "Cannot SELECT without a mailbox."); in imap_perform_select()
705 result = imap_sendf(data, "SELECT %s", mailbox); in imap_perform_select()
710 imap_state(data, IMAP_SELECT); in imap_perform_select()
721 static CURLcode imap_perform_fetch(struct Curl_easy *data) in imap_perform_fetch() argument
724 struct IMAP *imap = data->req.p.imap; in imap_perform_fetch()
730 result = imap_sendf(data, "UID FETCH %s BODY[%s]<%s>", in imap_perform_fetch()
734 result = imap_sendf(data, "UID FETCH %s BODY[%s]", in imap_perform_fetch()
740 result = imap_sendf(data, "FETCH %s BODY[%s]<%s>", in imap_perform_fetch()
744 result = imap_sendf(data, "FETCH %s BODY[%s]", in imap_perform_fetch()
748 failf(data, "Cannot FETCH without a UID."); in imap_perform_fetch()
752 imap_state(data, IMAP_FETCH); in imap_perform_fetch()
763 static CURLcode imap_perform_append(struct Curl_easy *data) in imap_perform_append() argument
766 struct IMAP *imap = data->req.p.imap; in imap_perform_append()
771 failf(data, "Cannot APPEND without a mailbox."); in imap_perform_append()
777 if(data->set.mimepost.kind != MIMEKIND_NONE) { in imap_perform_append()
779 data->set.mimepost.flags &= ~(unsigned int)MIME_BODY_ONLY; in imap_perform_append()
782 curl_mime_headers(&data->set.mimepost, data->set.headers, 0); in imap_perform_append()
783 result = Curl_mime_prepare_headers(data, &data->set.mimepost, NULL, in imap_perform_append()
787 if(!Curl_checkheaders(data, STRCONST("Mime-Version"))) in imap_perform_append()
788 result = Curl_mime_add_header(&data->set.mimepost.curlheaders, in imap_perform_append()
792 result = Curl_creader_set_mime(data, &data->set.mimepost); in imap_perform_append()
795 data->state.infilesize = Curl_creader_client_length(data); in imap_perform_append()
800 result = Curl_creader_set_fread(data, data->state.infilesize); in imap_perform_append()
806 if(data->state.infilesize < 0) { in imap_perform_append()
807 failf(data, "Cannot APPEND with unknown input file size"); in imap_perform_append()
817 result = imap_sendf(data, "APPEND %s (\\Seen) {%" FMT_OFF_T "}", in imap_perform_append()
818 mailbox, data->state.infilesize); in imap_perform_append()
823 imap_state(data, IMAP_APPEND); in imap_perform_append()
834 static CURLcode imap_perform_search(struct Curl_easy *data) in imap_perform_search() argument
837 struct IMAP *imap = data->req.p.imap; in imap_perform_search()
841 failf(data, "Cannot SEARCH without a query string."); in imap_perform_search()
846 result = imap_sendf(data, "SEARCH %s", imap->query); in imap_perform_search()
849 imap_state(data, IMAP_SEARCH); in imap_perform_search()
860 static CURLcode imap_perform_logout(struct Curl_easy *data) in imap_perform_logout() argument
863 CURLcode result = imap_sendf(data, "LOGOUT"); in imap_perform_logout()
866 imap_state(data, IMAP_LOGOUT); in imap_perform_logout()
872 static CURLcode imap_state_servergreet_resp(struct Curl_easy *data, in imap_state_servergreet_resp() argument
876 struct connectdata *conn = data->conn; in imap_state_servergreet_resp()
883 infof(data, "PREAUTH connection, already authenticated"); in imap_state_servergreet_resp()
886 failf(data, "Got unexpected imap-server response"); in imap_state_servergreet_resp()
890 return imap_perform_capability(data, conn); in imap_state_servergreet_resp()
894 static CURLcode imap_state_capability_resp(struct Curl_easy *data, in imap_state_capability_resp() argument
899 struct connectdata *conn = data->conn; in imap_state_capability_resp()
957 else if(data->set.use_ssl && !Curl_conn_is_ssl(conn, FIRSTSOCKET)) { in imap_state_capability_resp()
961 result = imap_perform_starttls(data); in imap_state_capability_resp()
963 else if(data->set.use_ssl <= CURLUSESSL_TRY) in imap_state_capability_resp()
964 result = imap_perform_authentication(data, conn); in imap_state_capability_resp()
966 failf(data, "STARTTLS not available."); in imap_state_capability_resp()
971 result = imap_perform_authentication(data, conn); in imap_state_capability_resp()
977 static CURLcode imap_state_starttls_resp(struct Curl_easy *data, in imap_state_starttls_resp() argument
982 struct connectdata *conn = data->conn; in imap_state_starttls_resp()
987 if(data->conn->proto.imapc.pp.overflow) in imap_state_starttls_resp()
991 if(data->set.use_ssl != CURLUSESSL_TRY) { in imap_state_starttls_resp()
992 failf(data, "STARTTLS denied"); in imap_state_starttls_resp()
996 result = imap_perform_authentication(data, conn); in imap_state_starttls_resp()
999 result = imap_perform_upgrade_tls(data, conn); in imap_state_starttls_resp()
1005 static CURLcode imap_state_auth_resp(struct Curl_easy *data, in imap_state_auth_resp() argument
1016 result = Curl_sasl_continue(&imapc->sasl, data, imapcode, &progress); in imap_state_auth_resp()
1020 imap_state(data, IMAP_STOP); /* Authenticated */ in imap_state_auth_resp()
1025 result = imap_perform_login(data, conn); in imap_state_auth_resp()
1027 failf(data, "Authentication cancelled"); in imap_state_auth_resp()
1039 static CURLcode imap_state_login_resp(struct Curl_easy *data, in imap_state_login_resp() argument
1047 failf(data, "Access denied. %c", imapcode); in imap_state_login_resp()
1052 imap_state(data, IMAP_STOP); in imap_state_login_resp()
1058 static CURLcode imap_state_listsearch_resp(struct Curl_easy *data, in imap_state_listsearch_resp() argument
1063 char *line = Curl_dyn_ptr(&data->conn->proto.imapc.pp.recvbuf); in imap_state_listsearch_resp()
1064 size_t len = data->conn->proto.imapc.pp.nfinal; in imap_state_listsearch_resp()
1069 result = Curl_client_write(data, CLIENTWRITE_BODY, line, len); in imap_state_listsearch_resp()
1074 imap_state(data, IMAP_STOP); in imap_state_listsearch_resp()
1080 static CURLcode imap_state_select_resp(struct Curl_easy *data, int imapcode, in imap_state_select_resp() argument
1084 struct connectdata *conn = data->conn; in imap_state_select_resp()
1085 struct IMAP *imap = data->req.p.imap; in imap_state_select_resp()
1087 const char *line = Curl_dyn_ptr(&data->conn->proto.imapc.pp.recvbuf); in imap_state_select_resp()
1112 failf(data, "Mailbox UIDVALIDITY has changed"); in imap_state_select_resp()
1123 result = imap_perform_list(data); in imap_state_select_resp()
1125 result = imap_perform_search(data); in imap_state_select_resp()
1127 result = imap_perform_fetch(data); in imap_state_select_resp()
1131 failf(data, "Select failed"); in imap_state_select_resp()
1139 static CURLcode imap_state_fetch_resp(struct Curl_easy *data, in imap_state_fetch_resp() argument
1146 const char *ptr = Curl_dyn_ptr(&data->conn->proto.imapc.pp.recvbuf); in imap_state_fetch_resp()
1147 size_t len = data->conn->proto.imapc.pp.nfinal; in imap_state_fetch_resp()
1154 Curl_pgrsSetDownloadSize(data, -1); in imap_state_fetch_resp()
1155 imap_state(data, IMAP_STOP); in imap_state_fetch_resp()
1170 infof(data, "Found %" FMT_OFF_T " bytes to download", size); in imap_state_fetch_resp()
1171 Curl_pgrsSetDownloadSize(data, size); in imap_state_fetch_resp()
1189 imap_state(data, IMAP_STOP); in imap_state_fetch_resp()
1192 result = Curl_client_write(data, CLIENTWRITE_BODY, in imap_state_fetch_resp()
1197 infof(data, "Written %zu bytes, %" FMT_OFF_TU in imap_state_fetch_resp()
1213 if(data->req.bytecount == size) in imap_state_fetch_resp()
1215 Curl_xfer_setup_nop(data); in imap_state_fetch_resp()
1218 data->req.maxdownload = size; in imap_state_fetch_resp()
1221 data->state.select_bits = CURL_CSELECT_IN; in imap_state_fetch_resp()
1222 Curl_xfer_setup1(data, CURL_XFER_RECV, size, FALSE); in imap_state_fetch_resp()
1227 failf(data, "Failed to parse FETCH response."); in imap_state_fetch_resp()
1232 imap_state(data, IMAP_STOP); in imap_state_fetch_resp()
1238 static CURLcode imap_state_fetch_final_resp(struct Curl_easy *data, in imap_state_fetch_final_resp() argument
1250 imap_state(data, IMAP_STOP); in imap_state_fetch_final_resp()
1256 static CURLcode imap_state_append_resp(struct Curl_easy *data, int imapcode, in imap_state_append_resp() argument
1267 Curl_pgrsSetUploadSize(data, data->state.infilesize); in imap_state_append_resp()
1270 Curl_xfer_setup1(data, CURL_XFER_SEND, -1, FALSE); in imap_state_append_resp()
1273 imap_state(data, IMAP_STOP); in imap_state_append_resp()
1280 static CURLcode imap_state_append_final_resp(struct Curl_easy *data, in imap_state_append_final_resp() argument
1292 imap_state(data, IMAP_STOP); in imap_state_append_final_resp()
1297 static CURLcode imap_statemachine(struct Curl_easy *data, in imap_statemachine() argument
1305 (void)data; in imap_statemachine()
1309 return imap_perform_upgrade_tls(data, conn); in imap_statemachine()
1313 return Curl_pp_flushsend(data, pp); in imap_statemachine()
1317 result = Curl_pp_readresp(data, FIRSTSOCKET, pp, &imapcode, &nread); in imap_statemachine()
1331 result = imap_state_servergreet_resp(data, imapcode, imapc->state); in imap_statemachine()
1335 result = imap_state_capability_resp(data, imapcode, imapc->state); in imap_statemachine()
1339 result = imap_state_starttls_resp(data, imapcode, imapc->state); in imap_statemachine()
1343 result = imap_state_auth_resp(data, conn, imapcode, imapc->state); in imap_statemachine()
1347 result = imap_state_login_resp(data, imapcode, imapc->state); in imap_statemachine()
1352 result = imap_state_listsearch_resp(data, imapcode, imapc->state); in imap_statemachine()
1356 result = imap_state_select_resp(data, imapcode, imapc->state); in imap_statemachine()
1360 result = imap_state_fetch_resp(data, conn, imapcode, imapc->state); in imap_statemachine()
1364 result = imap_state_fetch_final_resp(data, imapcode, imapc->state); in imap_statemachine()
1368 result = imap_state_append_resp(data, imapcode, imapc->state); in imap_statemachine()
1372 result = imap_state_append_final_resp(data, imapcode, imapc->state); in imap_statemachine()
1378 imap_state(data, IMAP_STOP); in imap_statemachine()
1387 static CURLcode imap_multi_statemach(struct Curl_easy *data, bool *done) in imap_multi_statemach() argument
1390 struct connectdata *conn = data->conn; in imap_multi_statemach()
1395 result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone); in imap_multi_statemach()
1401 result = Curl_pp_statemach(data, &imapc->pp, FALSE, FALSE); in imap_multi_statemach()
1407 static CURLcode imap_block_statemach(struct Curl_easy *data, in imap_block_statemach() argument
1415 result = Curl_pp_statemach(data, &imapc->pp, TRUE, disconnecting); in imap_block_statemach()
1422 static CURLcode imap_init(struct Curl_easy *data) in imap_init() argument
1427 imap = data->req.p.imap = calloc(1, sizeof(struct IMAP)); in imap_init()
1435 static int imap_getsock(struct Curl_easy *data, in imap_getsock() argument
1439 return Curl_pp_getsock(data, &conn->proto.imapc.pp, socks); in imap_getsock()
1452 static CURLcode imap_connect(struct Curl_easy *data, bool *done) in imap_connect() argument
1455 struct connectdata *conn = data->conn; in imap_connect()
1468 Curl_sasl_init(&imapc->sasl, data, &saslimap); in imap_connect()
1479 imap_state(data, IMAP_SERVERGREET); in imap_connect()
1484 result = imap_multi_statemach(data, done); in imap_connect()
1498 static CURLcode imap_done(struct Curl_easy *data, CURLcode status, in imap_done() argument
1502 struct connectdata *conn = data->conn; in imap_done()
1503 struct IMAP *imap = data->req.p.imap; in imap_done()
1514 else if(!data->set.connect_only && !imap->custom && in imap_done()
1515 (imap->uid || imap->mindex || data->state.upload || in imap_done()
1516 IS_MIME_POST(data))) { in imap_done()
1519 if(!data->state.upload && !IS_MIME_POST(data)) in imap_done()
1520 imap_state(data, IMAP_FETCH_FINAL); in imap_done()
1523 result = Curl_pp_sendf(data, &conn->proto.imapc.pp, "%s", ""); in imap_done()
1525 imap_state(data, IMAP_APPEND_FINAL); in imap_done()
1530 result = imap_block_statemach(data, conn, FALSE); in imap_done()
1557 static CURLcode imap_perform(struct Curl_easy *data, bool *connected, in imap_perform() argument
1562 struct connectdata *conn = data->conn; in imap_perform()
1563 struct IMAP *imap = data->req.p.imap; in imap_perform()
1567 DEBUGF(infof(data, "DO phase starts")); in imap_perform()
1569 if(data->req.no_body) { in imap_perform()
1585 if(data->state.upload || IS_MIME_POST(data)) in imap_perform()
1587 result = imap_perform_append(data); in imap_perform()
1590 result = imap_perform_list(data); in imap_perform()
1593 result = imap_perform_fetch(data); in imap_perform()
1596 result = imap_perform_search(data); in imap_perform()
1600 result = imap_perform_select(data); in imap_perform()
1603 result = imap_perform_list(data); in imap_perform()
1609 result = imap_multi_statemach(data, dophase_done); in imap_perform()
1614 DEBUGF(infof(data, "DO phase is complete")); in imap_perform()
1628 static CURLcode imap_do(struct Curl_easy *data, bool *done) in imap_do() argument
1634 result = imap_parse_url_path(data); in imap_do()
1639 result = imap_parse_custom_request(data); in imap_do()
1643 result = imap_regular_transfer(data, done); in imap_do()
1655 static CURLcode imap_disconnect(struct Curl_easy *data, in imap_disconnect() argument
1659 (void)data; in imap_disconnect()
1668 if(!imap_perform_logout(data)) in imap_disconnect()
1669 (void)imap_block_statemach(data, conn, TRUE); /* ignore errors */ in imap_disconnect()
1687 static CURLcode imap_dophase_done(struct Curl_easy *data, bool connected) in imap_dophase_done() argument
1689 struct IMAP *imap = data->req.p.imap; in imap_dophase_done()
1695 Curl_xfer_setup_nop(data); in imap_dophase_done()
1701 static CURLcode imap_doing(struct Curl_easy *data, bool *dophase_done) in imap_doing() argument
1703 CURLcode result = imap_multi_statemach(data, dophase_done); in imap_doing()
1706 DEBUGF(infof(data, "DO phase failed")); in imap_doing()
1708 result = imap_dophase_done(data, FALSE /* not connected */); in imap_doing()
1710 DEBUGF(infof(data, "DO phase is complete")); in imap_doing()
1725 static CURLcode imap_regular_transfer(struct Curl_easy *data, in imap_regular_transfer() argument
1732 data->req.size = -1; in imap_regular_transfer()
1735 Curl_pgrsSetUploadCounter(data, 0); in imap_regular_transfer()
1736 Curl_pgrsSetDownloadCounter(data, 0); in imap_regular_transfer()
1737 Curl_pgrsSetUploadSize(data, -1); in imap_regular_transfer()
1738 Curl_pgrsSetDownloadSize(data, -1); in imap_regular_transfer()
1741 result = imap_perform(data, &connected, dophase_done); in imap_regular_transfer()
1745 result = imap_dophase_done(data, connected); in imap_regular_transfer()
1750 static CURLcode imap_setup_connection(struct Curl_easy *data, in imap_setup_connection() argument
1754 CURLcode result = imap_init(data); in imap_setup_connection()
1772 static CURLcode imap_sendf(struct Curl_easy *data, const char *fmt, ...) in imap_sendf() argument
1775 struct imap_conn *imapc = &data->conn->proto.imapc; in imap_sendf()
1781 'A' + curlx_sltosi((long)(data->conn->connection_id % 26)), in imap_sendf()
1796 result = Curl_pp_vsendf(data, &imapc->pp, Curl_dyn_ptr(&imapc->dyn), ap); in imap_sendf()
1953 static CURLcode imap_parse_url_path(struct Curl_easy *data) in imap_parse_url_path() argument
1957 struct IMAP *imap = data->req.p.imap; in imap_parse_url_path()
1958 const char *begin = &data->state.up.path[1]; /* skip leading slash */ in imap_parse_url_path()
2012 DEBUGF(infof(data, "IMAP URL parameter '%s' = '%s'", name, value)); in imap_parse_url_path()
2068 (void)curl_url_get(data->state.uh, CURLUPART_QUERY, &imap->query, in imap_parse_url_path()
2085 static CURLcode imap_parse_custom_request(struct Curl_easy *data) in imap_parse_custom_request() argument
2088 struct IMAP *imap = data->req.p.imap; in imap_parse_custom_request()
2089 const char *custom = data->set.str[STRING_CUSTOMREQUEST]; in imap_parse_custom_request()