aboutsummaryrefslogtreecommitdiff
path: root/lib/imap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/imap.c')
-rw-r--r--lib/imap.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/lib/imap.c b/lib/imap.c
index 2aeda785b..42b76fe1b 100644
--- a/lib/imap.c
+++ b/lib/imap.c
@@ -343,6 +343,36 @@ static void imap_to_imaps(struct connectdata *conn)
#define imap_to_imaps(x) Curl_nop_stmt
#endif
+/* for the initial server greeting */
+static CURLcode imap_state_servergreet_resp(struct connectdata *conn,
+ int imapcode,
+ imapstate instate)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+
+ (void)instate; /* no use for this yet */
+
+ if(imapcode != 'O') {
+ failf(data, "Got unexpected imap-server response");
+ return CURLE_FTP_WEIRD_SERVER_REPLY;
+ }
+
+ if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
+ /* We don't have a SSL/TLS connection yet, but SSL is requested. Switch
+ to TLS connection now */
+ const char *str;
+
+ str = getcmdid(conn);
+ result = imapsendf(conn, str, "%s STARTTLS", str);
+ state(conn, IMAP_STARTTLS);
+ }
+ else
+ result = imap_state_login(conn);
+
+ return result;
+}
+
/* for STARTTLS responses */
static CURLcode imap_state_starttls_resp(struct connectdata *conn,
int imapcode,
@@ -373,7 +403,9 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn,
}
}
}
+
state(conn, IMAP_STOP);
+
return result;
}
@@ -400,6 +432,7 @@ static CURLcode imap_state_login_resp(struct connectdata *conn,
{
CURLcode result = CURLE_OK;
struct SessionHandle *data = conn->data;
+
(void)instate; /* no use for this yet */
if(imapcode != 'O') {
@@ -408,6 +441,7 @@ static CURLcode imap_state_login_resp(struct connectdata *conn,
}
state(conn, IMAP_STOP);
+
return result;
}
@@ -422,6 +456,7 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn,
struct FTP *imap = data->state.proto.imap;
struct pingpong *pp = &imapc->pp;
const char *ptr = data->state.buffer;
+
(void)instate; /* no use for this yet */
if('*' != imapcode) {
@@ -489,6 +524,7 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn,
result = CURLE_FTP_WEIRD_SERVER_REPLY; /* TODO: fix this code */
state(conn, IMAP_STOP);
+
return result;
}
@@ -558,7 +594,6 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
{
CURLcode result;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
- struct SessionHandle *data=conn->data;
int imapcode;
struct imap_conn *imapc = &conn->proto.imapc;
struct pingpong *pp = &imapc->pp;
@@ -580,24 +615,7 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
/* we have now received a full IMAP server response */
switch(imapc->state) {
case IMAP_SERVERGREET:
- if(imapcode != 'O') {
- failf(data, "Got unexpected imap-server response");
- return CURLE_FTP_WEIRD_SERVER_REPLY;
- }
-
- if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) {
- /* We don't have a SSL/TLS connection yet, but SSL is requested. Switch
- to TLS connection now */
- const char *str;
-
- str = getcmdid(conn);
- result = imapsendf(conn, str, "%s STARTTLS", str);
- state(conn, IMAP_STARTTLS);
- }
- else
- result = imap_state_login(conn);
- if(result)
- return result;
+ result = imap_state_servergreet_resp(conn, imapcode, imapc->state);
break;
case IMAP_LOGIN: