mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 17:31:46 -05:00
smtp: Added support for VRFY and EXPN commands
This commit is contained in:
parent
dac01ff6d7
commit
f71b1ad908
67
lib/smtp.c
67
lib/smtp.c
@ -249,7 +249,8 @@ static bool smtp_endofresp(struct connectdata *conn, char *line, size_t len,
|
|||||||
*resp = 0;
|
*resp = 0;
|
||||||
}
|
}
|
||||||
/* Do we have a multiline (continuation) response? */
|
/* Do we have a multiline (continuation) response? */
|
||||||
else if(line[3] == '-' && smtpc->state == SMTP_EHLO) {
|
else if(line[3] == '-' &&
|
||||||
|
(smtpc->state == SMTP_EHLO || smtpc->state == SMTP_COMMAND)) {
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
*resp = 1; /* Internal response code */
|
*resp = 1; /* Internal response code */
|
||||||
}
|
}
|
||||||
@ -562,10 +563,17 @@ static CURLcode smtp_perform_command(struct connectdata *conn)
|
|||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
struct SMTP *smtp = data->req.protop;
|
struct SMTP *smtp = data->req.protop;
|
||||||
|
|
||||||
/* Send the command */
|
if(smtp->custom && smtp->custom[0] != '\0')
|
||||||
result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s",
|
/* Send the custom command */
|
||||||
smtp->custom && smtp->custom[0] != '\0' ?
|
result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s %s", smtp->custom,
|
||||||
smtp->custom : "NOOP");
|
smtp->rcpt ? smtp->rcpt->data : "");
|
||||||
|
else if(smtp->rcpt)
|
||||||
|
/* Send the VRFY command */
|
||||||
|
result = Curl_pp_sendf(&conn->proto.smtpc.pp, "VRFY %s", smtp->rcpt->data);
|
||||||
|
else
|
||||||
|
/* Send the NOOP command */
|
||||||
|
result = Curl_pp_sendf(&conn->proto.smtpc.pp, "%s", "NOOP");
|
||||||
|
|
||||||
if(!result)
|
if(!result)
|
||||||
state(conn, SMTP_COMMAND);
|
state(conn, SMTP_COMMAND);
|
||||||
|
|
||||||
@ -1262,18 +1270,41 @@ static CURLcode smtp_state_command_resp(struct connectdata *conn, int smtpcode,
|
|||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
struct SMTP *smtp = data->req.protop;
|
struct SMTP *smtp = data->req.protop;
|
||||||
|
char *line = data->state.buffer;
|
||||||
|
size_t len = strlen(line);
|
||||||
|
|
||||||
(void)instate; /* no use for this yet */
|
(void)instate; /* no use for this yet */
|
||||||
|
|
||||||
if(smtpcode/100 != 2) {
|
if((smtp->rcpt && smtpcode/100 != 2 && smtpcode != 553 && smtpcode != 1) ||
|
||||||
failf(data, "%s failed: %d",
|
(!smtp->rcpt && smtpcode/100 != 2 && smtpcode != 1)) {
|
||||||
smtp->custom && smtp->custom[0] != '\0' ? smtp->custom : "NOOP",
|
failf(data, "Command failed: %d", smtpcode);
|
||||||
smtpcode);
|
|
||||||
result = CURLE_RECV_ERROR;
|
result = CURLE_RECV_ERROR;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* Temporarily add the LF character back and send as body to the client */
|
||||||
|
if(!data->set.opt_no_body) {
|
||||||
|
line[len] = '\n';
|
||||||
|
result = Curl_client_write(conn, CLIENTWRITE_BODY, line, len + 1);
|
||||||
|
line[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/* End of DO phase */
|
if(smtpcode != 1) {
|
||||||
state(conn, SMTP_STOP);
|
if(smtp->rcpt) {
|
||||||
|
smtp->rcpt = smtp->rcpt->next;
|
||||||
|
|
||||||
|
if(smtp->rcpt) {
|
||||||
|
/* Send the next command */
|
||||||
|
result = smtp_perform_command(conn);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* End of DO phase */
|
||||||
|
state(conn, SMTP_STOP);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* End of DO phase */
|
||||||
|
state(conn, SMTP_STOP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1696,8 +1727,8 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
|
|||||||
*
|
*
|
||||||
* smtp_perform()
|
* smtp_perform()
|
||||||
*
|
*
|
||||||
* This is the actual DO function for SMTP. Transfer a mail or send a command
|
* This is the actual DO function for SMTP. Transfer a mail, send a command
|
||||||
* according to the options previously setup.
|
* or get some data according to the options previously setup.
|
||||||
*/
|
*/
|
||||||
static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
|
static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
|
||||||
bool *dophase_done)
|
bool *dophase_done)
|
||||||
@ -1705,12 +1736,12 @@ static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
|
|||||||
/* This is SMTP and no proxy */
|
/* This is SMTP and no proxy */
|
||||||
CURLcode result = CURLE_OK;
|
CURLcode result = CURLE_OK;
|
||||||
struct SessionHandle *data = conn->data;
|
struct SessionHandle *data = conn->data;
|
||||||
|
struct SMTP *smtp = data->req.protop;
|
||||||
|
|
||||||
DEBUGF(infof(conn->data, "DO phase starts\n"));
|
DEBUGF(infof(conn->data, "DO phase starts\n"));
|
||||||
|
|
||||||
if(data->set.opt_no_body) {
|
if(data->set.opt_no_body) {
|
||||||
/* Requested no body means no transfer */
|
/* Requested no body means no transfer */
|
||||||
struct SMTP *smtp = data->req.protop;
|
|
||||||
smtp->transfer = FTPTRANSFER_INFO;
|
smtp->transfer = FTPTRANSFER_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1720,9 +1751,13 @@ static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
|
|||||||
if(data->set.upload && data->set.mail_rcpt)
|
if(data->set.upload && data->set.mail_rcpt)
|
||||||
/* MAIL transfer */
|
/* MAIL transfer */
|
||||||
result = smtp_perform_mail(conn);
|
result = smtp_perform_mail(conn);
|
||||||
else
|
else {
|
||||||
/* SMTP based command (NOOP or RSET) */
|
/* Store the first recipient (or NULL if not specified) */
|
||||||
|
smtp->rcpt = data->set.mail_rcpt;
|
||||||
|
|
||||||
|
/* SMTP based command (VRFY, EXPN, NOOP, RSET or HELP) */
|
||||||
result = smtp_perform_command(conn);
|
result = smtp_perform_command(conn);
|
||||||
|
}
|
||||||
|
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
@ -47,7 +47,7 @@ typedef enum {
|
|||||||
SMTP_AUTH_XOAUTH2,
|
SMTP_AUTH_XOAUTH2,
|
||||||
SMTP_AUTH_CANCEL,
|
SMTP_AUTH_CANCEL,
|
||||||
SMTP_AUTH_FINAL,
|
SMTP_AUTH_FINAL,
|
||||||
SMTP_COMMAND, /* NOOP and RSET */
|
SMTP_COMMAND, /* VRFY, EXPN, NOOP, RSET and HELP */
|
||||||
SMTP_MAIL, /* MAIL FROM */
|
SMTP_MAIL, /* MAIL FROM */
|
||||||
SMTP_RCPT, /* RCPT TO */
|
SMTP_RCPT, /* RCPT TO */
|
||||||
SMTP_DATA,
|
SMTP_DATA,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user