From c6afdb6ef3516ffcd111d546b9b504dd526cc2f2 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 20 Sep 2004 16:07:23 +0000 Subject: Fix the reject code logic --- common/smtppass.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'common/smtppass.c') diff --git a/common/smtppass.c b/common/smtppass.c index 25522de..7f2d833 100644 --- a/common/smtppass.c +++ b/common/smtppass.c @@ -1312,32 +1312,35 @@ cleanup: int sp_fail_data(spctx_t* ctx, const char* smtp_status) { - char* t; + char* t = NULL; int len, x; + int pref = 0; + int crlf = 0; if(smtp_status == NULL) - { smtp_status = SMTP_FAILED; - } - else - { - len = strlen(smtp_status); + x = strtol(smtp_status, &t, 10); + len = strlen(smtp_status); - /* We need 3 digits and CRLF at the end for a premade SMTP message */ - if(strtol(smtp_status, &t, 10) == 0 || t != smtp_status + 3 || - strcmp(smtp_status + (len - KL(CRLF)), CRLF) != 0) - { - if(len > 256) - len = 256; + /* We need 3 digits and CRLF at the end for a premade SMTP message */ + if(x == 0 || t != smtp_status + 3) + pref = 1; - x = len + KL(SMTP_REJPREFIX) + KL(CRLF) + 1; - t = (char*)alloca(x); + /* We need a CRLF at the end */ + if(strcmp(smtp_status + (len - KL(CRLF)), CRLF) != 0) + crlf = 1; - /* Note that we truncate long lines */ - snprintf(t, x, "%s%.256s%s", SMTP_REJPREFIX, smtp_status, CRLF); - smtp_status = t; - } + if(pref || crlf) + { + x = (x > 256 ? 256 : x) + KL(SMTP_REJPREFIX) + KL(CRLF) + 1; + t = (char*)alloca(x + 1); + + /* Note that we truncate long lines */ + snprintf(t, x, "%s%.256s%s", pref ? SMTP_REJPREFIX : "", + smtp_status, crlf ? CRLF : ""); + t[x] = 0; + smtp_status = t; } if(spio_write_data(ctx, &(ctx->client), smtp_status) == -1) -- cgit v1.2.3