imap: Removed the need for separate custom request functions
Moved the custom request processing into the LIST command as the logic is the same.
This commit is contained in:
parent
69eca5c252
commit
6bdd3d4a88
65
lib/imap.c
65
lib/imap.c
@ -398,7 +398,12 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case IMAP_LIST:
|
case IMAP_LIST:
|
||||||
if(!imap_matchresp(line, len, "LIST"))
|
if((!imap->custom && !imap_matchresp(line, len, "LIST")) ||
|
||||||
|
(imap->custom && !imap_matchresp(line, len, imap->custom) &&
|
||||||
|
(strcmp(imap->custom, "STORE") ||
|
||||||
|
!imap_matchresp(line, len, "FETCH")) &&
|
||||||
|
strcmp(imap->custom, "SELECT") &&
|
||||||
|
strcmp(imap->custom, "EXAMINE")))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -412,20 +417,6 @@ static bool imap_endofresp(struct connectdata *conn, char *line, size_t len,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IMAP_CUSTOM:
|
|
||||||
/* When dealing with a custom command, we are interested in all
|
|
||||||
intermediate responses which match the parameter name. The
|
|
||||||
exceptions are STORE, which returns untagged responses as FETCH,
|
|
||||||
and SELECT and EXAMINE commands, for which no filtering is (or can
|
|
||||||
be easily) done. */
|
|
||||||
if(!imap_matchresp(line, len, imap->custom) &&
|
|
||||||
(strcmp(imap->custom, "STORE") ||
|
|
||||||
!imap_matchresp(line, len, "FETCH")) &&
|
|
||||||
strcmp(imap->custom, "SELECT") &&
|
|
||||||
strcmp(imap->custom, "EXAMINE"))
|
|
||||||
return FALSE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Ignore other untagged responses */
|
/* Ignore other untagged responses */
|
||||||
default:
|
default:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -493,7 +484,6 @@ static void state(struct connectdata *conn, imapstate newstate)
|
|||||||
"FETCH_FINAL",
|
"FETCH_FINAL",
|
||||||
"APPEND",
|
"APPEND",
|
||||||
"APPEND_FINAL",
|
"APPEND_FINAL",
|
||||||
"CUSTOM",
|
|
||||||
"LOGOUT",
|
"LOGOUT",
|
||||||
/* LAST */
|
/* LAST */
|
||||||
};
|
};
|
||||||
@ -696,15 +686,21 @@ static CURLcode imap_list(struct connectdata *conn)
|
|||||||
struct IMAP *imap = data->state.proto.imap;
|
struct IMAP *imap = data->state.proto.imap;
|
||||||
char *mailbox;
|
char *mailbox;
|
||||||
|
|
||||||
/* Make sure the mailbox is in the correct atom format */
|
if(imap->custom)
|
||||||
mailbox = imap_atom(imap->mailbox ? imap->mailbox : "");
|
/* Send the custom request */
|
||||||
if(!mailbox)
|
result = imap_sendf(conn, "%s%s", imap->custom,
|
||||||
return CURLE_OUT_OF_MEMORY;
|
imap->custom_params ? imap->custom_params : "");
|
||||||
|
else {
|
||||||
|
/* Make sure the mailbox is in the correct atom format */
|
||||||
|
mailbox = imap_atom(imap->mailbox ? imap->mailbox : "");
|
||||||
|
if(!mailbox)
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* Send the LIST command */
|
/* Send the LIST command */
|
||||||
result = imap_sendf(conn, "LIST \"%s\" *", mailbox);
|
result = imap_sendf(conn, "LIST \"%s\" *", mailbox);
|
||||||
|
|
||||||
Curl_safefree(mailbox);
|
Curl_safefree(mailbox);
|
||||||
|
}
|
||||||
|
|
||||||
if(!result)
|
if(!result)
|
||||||
state(conn, IMAP_LIST);
|
state(conn, IMAP_LIST);
|
||||||
@ -803,24 +799,6 @@ static CURLcode imap_append(struct connectdata *conn)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CURLcode imap_custom(struct connectdata *conn)
|
|
||||||
{
|
|
||||||
struct IMAP *imap = conn->data->state.proto.imap;
|
|
||||||
|
|
||||||
/* Send the custom request */
|
|
||||||
CURLcode result = imap_sendf(conn, "%s%s", imap->custom,
|
|
||||||
imap->custom_params ? imap->custom_params : "");
|
|
||||||
|
|
||||||
if(!result) {
|
|
||||||
/* We don't know how much data will be received */
|
|
||||||
Curl_pgrsSetDownloadSize(conn->data, -1);
|
|
||||||
|
|
||||||
state(conn, IMAP_CUSTOM);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* imap_logout()
|
* imap_logout()
|
||||||
@ -1391,7 +1369,7 @@ static CURLcode imap_state_select_resp(struct connectdata *conn, int imapcode,
|
|||||||
imapc->mailbox = strdup(imap->mailbox);
|
imapc->mailbox = strdup(imap->mailbox);
|
||||||
|
|
||||||
if(imap->custom)
|
if(imap->custom)
|
||||||
result = imap_custom(conn);
|
result = imap_list(conn);
|
||||||
else
|
else
|
||||||
result = imap_fetch(conn);
|
result = imap_fetch(conn);
|
||||||
}
|
}
|
||||||
@ -1650,7 +1628,6 @@ static CURLcode imap_statemach_act(struct connectdata *conn)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case IMAP_LIST:
|
case IMAP_LIST:
|
||||||
case IMAP_CUSTOM:
|
|
||||||
result = imap_state_list_resp(conn, imapcode, imapc->state);
|
result = imap_state_list_resp(conn, imapcode, imapc->state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1891,7 +1868,7 @@ static CURLcode imap_perform(struct connectdata *conn, bool *connected,
|
|||||||
result = imap_append(conn);
|
result = imap_append(conn);
|
||||||
else if(imap->custom && (selected || !imap->mailbox))
|
else if(imap->custom && (selected || !imap->mailbox))
|
||||||
/* Custom command using the same mailbox or no mailbox */
|
/* Custom command using the same mailbox or no mailbox */
|
||||||
result = imap_custom(conn);
|
result = imap_list(conn);
|
||||||
else if(!imap->custom && selected && imap->uid)
|
else if(!imap->custom && selected && imap->uid)
|
||||||
/* FETCH from the same mailbox */
|
/* FETCH from the same mailbox */
|
||||||
result = imap_fetch(conn);
|
result = imap_fetch(conn);
|
||||||
|
@ -51,7 +51,6 @@ typedef enum {
|
|||||||
IMAP_FETCH_FINAL,
|
IMAP_FETCH_FINAL,
|
||||||
IMAP_APPEND,
|
IMAP_APPEND,
|
||||||
IMAP_APPEND_FINAL,
|
IMAP_APPEND_FINAL,
|
||||||
IMAP_CUSTOM,
|
|
||||||
IMAP_LOGOUT,
|
IMAP_LOGOUT,
|
||||||
IMAP_LAST /* never used */
|
IMAP_LAST /* never used */
|
||||||
} imapstate;
|
} imapstate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user