From: Stephan Bosch Date: Mon, 27 Nov 2017 10:44:23 +0000 (+0100) Subject: lib-smtp: Implemented function to write an SMTP reply as a single line. X-Git-Tag: 2.3.0.rc1~343 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57b18ecb6fdfa9f8503fc00a6869763e6ffcecb2;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: Implemented function to write an SMTP reply as a single line. Needed for proxying in current LMTP code. --- diff --git a/src/lib-smtp/smtp-reply.c b/src/lib-smtp/smtp-reply.c index 7b6ff4bc10..c60733cda3 100644 --- a/src/lib-smtp/smtp-reply.c +++ b/src/lib-smtp/smtp-reply.c @@ -80,6 +80,28 @@ smtp_reply_write(string_t *out, const struct smtp_reply *reply) } } +void smtp_reply_write_one_line(string_t *out, const struct smtp_reply *reply) +{ + const char *enh_code = smtp_reply_get_enh_code(reply); + const char *const *lines; + + i_assert(reply->status < 560); + i_assert(reply->enhanced_code.x < 6); + + str_printfa(out, "%03u", reply->status); + if (enh_code != NULL) { + str_append_c(out, ' '); + str_append(out, enh_code); + } + + lines = reply->text_lines; + while (*lines != NULL) { + str_append_c(out, ' '); + str_append(out, *lines); + lines++; + } +} + const char *smtp_reply_log(const struct smtp_reply *reply) { const char *const *lines; diff --git a/src/lib-smtp/smtp-reply.h b/src/lib-smtp/smtp-reply.h index a9b72361d3..4e7d6f99ac 100644 --- a/src/lib-smtp/smtp-reply.h +++ b/src/lib-smtp/smtp-reply.h @@ -52,7 +52,16 @@ void smtp_reply_printf(struct smtp_reply *reply, unsigned int status, const char * smtp_reply_get_enh_code(const struct smtp_reply *reply); + +/* Write the SMTP reply as a sequence of lines according to the SMTP syntax, + each terminated by CRLF. */ void smtp_reply_write(string_t *out, const struct smtp_reply *reply); +/* Write the SMTP reply as a single line without CRLF, even when it consists + of multiple lines. This function cannot be used with internal client error + replies (status code >= 560). */ +void smtp_reply_write_one_line(string_t *out, const struct smtp_reply *reply); +/* Create a log line from the SMTP reply. This also properly handles internal + client error replies (status_code >= 560). */ const char *smtp_reply_log(const struct smtp_reply *reply); void smtp_reply_copy(pool_t pool, struct smtp_reply *dst,