summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-09-20 16:07:23 +0000
committerStef Walter <stef@memberwebs.com>2004-09-20 16:07:23 +0000
commitc6afdb6ef3516ffcd111d546b9b504dd526cc2f2 (patch)
tree66bf4db9cd6dd123330bc59190a35469617e0c14 /common
parenta9f0b20334c9fe15bfbde1a4bd26c154de710a27 (diff)
Fix the reject code logic
Diffstat (limited to 'common')
-rw-r--r--common/smtppass.c39
1 files changed, 21 insertions, 18 deletions
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)