1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

smtp: Added support for the conversion of Unix newlines during mail send

Added support for the automatic conversion of Unix newlines to CRLF
during mail uploads.

Feature: http://curl.haxx.se/bug/view.cgi?id=1456
This commit is contained in:
Steve Holme 2014-11-26 22:44:28 +00:00
parent aa3e8dd3da
commit 4bd860a001
2 changed files with 29 additions and 18 deletions

View File

@ -2320,13 +2320,17 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
ssize_t si; ssize_t si;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
struct SMTP *smtp = data->req.protop; struct SMTP *smtp = data->req.protop;
char *scratch = data->state.scratch;
char *oldscratch = NULL;
/* Do we need to allocate the scatch buffer? */ /* Do we need to allocate the scatch buffer? */
if(!data->state.scratch) { if(!scratch || data->set.crlf) {
data->state.scratch = malloc(2 * BUFSIZE); oldscratch = scratch;
scratch = malloc(2 * BUFSIZE);
if(!scratch) {
failf(data, "Failed to alloc scratch buffer!");
if(!data->state.scratch) {
failf (data, "Failed to alloc scratch buffer!");
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
} }
@ -2345,7 +2349,7 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
} }
else if(smtp->eob) { else if(smtp->eob) {
/* A previous substring matched so output that first */ /* A previous substring matched so output that first */
memcpy(&data->state.scratch[si], SMTP_EOB, smtp->eob); memcpy(&scratch[si], SMTP_EOB, smtp->eob);
si += smtp->eob; si += smtp->eob;
/* Then compare the first byte */ /* Then compare the first byte */
@ -2361,17 +2365,17 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
/* Do we have a match for CRLF. as per RFC-5321, sect. 4.5.2 */ /* Do we have a match for CRLF. as per RFC-5321, sect. 4.5.2 */
if(SMTP_EOB_FIND_LEN == smtp->eob) { if(SMTP_EOB_FIND_LEN == smtp->eob) {
/* Copy the replacement data to the target buffer */ /* Copy the replacement data to the target buffer */
memcpy(&data->state.scratch[si], SMTP_EOB_REPL, SMTP_EOB_REPL_LEN); memcpy(&scratch[si], SMTP_EOB_REPL, SMTP_EOB_REPL_LEN);
si += SMTP_EOB_REPL_LEN; si += SMTP_EOB_REPL_LEN;
smtp->eob = 0; smtp->eob = 0;
} }
else if(!smtp->eob) else if(!smtp->eob)
data->state.scratch[si++] = data->req.upload_fromhere[i]; scratch[si++] = data->req.upload_fromhere[i];
} }
if(smtp->eob) { if(smtp->eob) {
/* A substring matched before processing ended so output that now */ /* A substring matched before processing ended so output that now */
memcpy(&data->state.scratch[si], SMTP_EOB, smtp->eob); memcpy(&scratch[si], SMTP_EOB, smtp->eob);
si += smtp->eob; si += smtp->eob;
smtp->eob = 0; smtp->eob = 0;
} }
@ -2381,11 +2385,19 @@ CURLcode Curl_smtp_escape_eob(struct connectdata *conn, ssize_t nread)
nread = si; nread = si;
/* Upload from the new (replaced) buffer instead */ /* Upload from the new (replaced) buffer instead */
data->req.upload_fromhere = data->state.scratch; data->req.upload_fromhere = scratch;
/* Save the buffer so it can be freed later */
data->state.scratch = scratch;
/* Free the old scratch buffer */
Curl_safefree(oldscratch);
/* Set the new amount too */ /* Set the new amount too */
data->req.upload_present = nread; data->req.upload_present = nread;
} }
else
Curl_safefree(scratch);
return CURLE_OK; return CURLE_OK;
} }

View File

@ -903,15 +903,6 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
/* store number of bytes available for upload */ /* store number of bytes available for upload */
data->req.upload_present = nread; data->req.upload_present = nread;
#ifndef CURL_DISABLE_SMTP
if(conn->handler->protocol & PROTO_FAMILY_SMTP) {
result = Curl_smtp_escape_eob(conn, nread);
if(result)
return result;
}
else
#endif /* CURL_DISABLE_SMTP */
/* convert LF to CRLF if so asked */ /* convert LF to CRLF if so asked */
if((!sending_http_headers) && ( if((!sending_http_headers) && (
#ifdef CURL_DO_LINEEND_CONV #ifdef CURL_DO_LINEEND_CONV
@ -962,6 +953,14 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
that instead of reading more data */ that instead of reading more data */
} }
#ifndef CURL_DISABLE_SMTP
if(conn->handler->protocol & PROTO_FAMILY_SMTP) {
result = Curl_smtp_escape_eob(conn, nread);
if(result)
return result;
}
#endif /* CURL_DISABLE_SMTP */
/* write to socket (send away data) */ /* write to socket (send away data) */
result = Curl_write(conn, result = Curl_write(conn,
conn->writesockfd, /* socket to send to */ conn->writesockfd, /* socket to send to */