diff options
author | Stef Walter <stef@memberwebs.com> | 2004-09-20 16:07:23 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2004-09-20 16:07:23 +0000 |
commit | 4e45f085f043f8f44236f2b84cf343d8fa03dc18 (patch) | |
tree | bb294882488ab28f1f42aebf30bf978053eeb3ac | |
parent | 41e4eb34e76ac2594861f93b6bb3dc25ec614dd3 (diff) |
Fix the reject code logic
-rw-r--r-- | common/smtppass.c | 39 |
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) |