]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: Implemented function to write an SMTP reply as a single line.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Mon, 27 Nov 2017 10:44:23 +0000 (11:44 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Mon, 27 Nov 2017 15:21:31 +0000 (16:21 +0100)
Needed for proxying in current LMTP code.

src/lib-smtp/smtp-reply.c
src/lib-smtp/smtp-reply.h

index 7b6ff4bc10d8358c2522094dc2efed1424e213bf..c60733cda3b12d077fdb47afe29c2f183f44f23a 100644 (file)
@@ -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;
index a9b72361d3b14feaaf601782adc25b99bf2d4b5e..4e7d6f99ac95a3d4b15eff01170c7a0c63d9da0b 100644 (file)
@@ -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,