mirror of https://github.com/moparisthebest/curl
imap: Code tidy up prior to adding support for the CAPABILITY command
* Changing the order of the state machine to represent the order in which commands are sent to the server. * Reworking the imap_endofresp() function as the FETCH response doesn't include the command id and shouldn't be part of the length comparison that takes into account the id string.
This commit is contained in:
parent
c02449ca53
commit
bd8ae68006
|
@ -31,10 +31,10 @@ typedef enum {
|
||||||
IMAP_STOP, /* do nothing state, stops the state machine */
|
IMAP_STOP, /* do nothing state, stops the state machine */
|
||||||
IMAP_SERVERGREET, /* waiting for the initial greeting immediately after
|
IMAP_SERVERGREET, /* waiting for the initial greeting immediately after
|
||||||
a connect */
|
a connect */
|
||||||
IMAP_LOGIN,
|
|
||||||
IMAP_STARTTLS,
|
IMAP_STARTTLS,
|
||||||
IMAP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS
|
IMAP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS
|
||||||
(multi mode only) */
|
(multi mode only) */
|
||||||
|
IMAP_LOGIN,
|
||||||
IMAP_SELECT,
|
IMAP_SELECT,
|
||||||
IMAP_FETCH,
|
IMAP_FETCH,
|
||||||
IMAP_LOGOUT,
|
IMAP_LOGOUT,
|
||||||
|
|
21
lib/imap.c
21
lib/imap.c
|
@ -329,15 +329,18 @@ static int imap_endofresp(struct pingpong *pp, int *resp)
|
||||||
const char *id = imapc->idstr;
|
const char *id = imapc->idstr;
|
||||||
size_t id_len = strlen(id);
|
size_t id_len = strlen(id);
|
||||||
|
|
||||||
|
/* Do we have a generic command response? */
|
||||||
if(len >= id_len + 3) {
|
if(len >= id_len + 3) {
|
||||||
if(!memcmp(id, line, id_len) && (line[id_len] == ' ') ) {
|
if(!memcmp(id, line, id_len) && (line[id_len] == ' ') ) {
|
||||||
/* end of response */
|
|
||||||
*resp = line[id_len+1]; /* O, N or B */
|
*resp = line[id_len+1]; /* O, N or B */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else if((imapc->state == IMAP_FETCH) &&
|
}
|
||||||
!memcmp("* ", line, 2) ) {
|
|
||||||
/* FETCH response we're interested in */
|
/* Are we processing FETCH command responses? */
|
||||||
|
if(imapc->state == IMAP_FETCH) {
|
||||||
|
/* Do we have a valid response? */
|
||||||
|
if(len >= 2 && !memcmp("* ", line, 2)) {
|
||||||
*resp = '*';
|
*resp = '*';
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -356,9 +359,9 @@ static void state(struct connectdata *conn,
|
||||||
static const char * const names[]={
|
static const char * const names[]={
|
||||||
"STOP",
|
"STOP",
|
||||||
"SERVERGREET",
|
"SERVERGREET",
|
||||||
"LOGIN",
|
|
||||||
"STARTTLS",
|
"STARTTLS",
|
||||||
"UPGRADETLS",
|
"UPGRADETLS",
|
||||||
|
"LOGIN",
|
||||||
"SELECT",
|
"SELECT",
|
||||||
"FETCH",
|
"FETCH",
|
||||||
"LOGOUT",
|
"LOGOUT",
|
||||||
|
@ -687,14 +690,14 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
|
||||||
result = imap_state_servergreet_resp(conn, imapcode, imapc->state);
|
result = imap_state_servergreet_resp(conn, imapcode, imapc->state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IMAP_LOGIN:
|
|
||||||
result = imap_state_login_resp(conn, imapcode, imapc->state);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IMAP_STARTTLS:
|
case IMAP_STARTTLS:
|
||||||
result = imap_state_starttls_resp(conn, imapcode, imapc->state);
|
result = imap_state_starttls_resp(conn, imapcode, imapc->state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case IMAP_LOGIN:
|
||||||
|
result = imap_state_login_resp(conn, imapcode, imapc->state);
|
||||||
|
break;
|
||||||
|
|
||||||
case IMAP_FETCH:
|
case IMAP_FETCH:
|
||||||
result = imap_state_fetch_resp(conn, imapcode, imapc->state);
|
result = imap_state_fetch_resp(conn, imapcode, imapc->state);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue