]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: server: Add function that allows submitting duplicate replies.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 13 Jan 2018 12:08:53 +0000 (13:08 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 18 Jan 2018 07:10:12 +0000 (09:10 +0200)
The smtp_server_reply_submit_duplicate() function submits a new reply at the
specified index with content duplicated from an existing earlier reply.

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

index 5392dc2d3c674b585f4cdf433bc21f8e1db4dd91..8c687c0e5253034dcd2682400b16fc2815f23978 100644 (file)
@@ -207,6 +207,30 @@ void smtp_server_reply_submit(struct smtp_server_reply *reply)
        smtp_server_command_submit_reply(reply->command);
 }
 
+void smtp_server_reply_submit_duplicate(struct smtp_server_cmd_ctx *_cmd,
+                                       unsigned int index,
+                                       unsigned int from_index)
+{
+       struct smtp_server_command *cmd = _cmd->cmd;
+       struct smtp_server_reply *reply, *from_reply;
+
+       i_assert(cmd->replies_expected > 0);
+       i_assert(index < cmd->replies_expected);
+       i_assert(from_index < cmd->replies_expected);
+       i_assert(array_is_created(&cmd->replies));
+
+       from_reply = array_idx_modifiable(&cmd->replies, from_index);
+       i_assert(from_reply->content != NULL);
+       i_assert(from_reply->submitted);
+
+       reply = smtp_server_reply_alloc(cmd, index);
+       reply->index = index;
+       reply->command = cmd;
+       reply->content = from_reply->content;
+
+       smtp_server_reply_submit(reply);
+}
+
 void smtp_server_reply_indexv(struct smtp_server_cmd_ctx *_cmd,
        unsigned int index, unsigned int status, const char *enh_code,
        const char *fmt, va_list args)
index c2bf4cdc8557d5a6c8af67695ddd0a6fca82667e..98c5e420bbd76e04dda5ea62a1660884f2962cc5 100644 (file)
@@ -466,6 +466,9 @@ smtp_server_reply_create_forward(struct smtp_server_command *cmd,
 void smtp_server_reply_add_text(struct smtp_server_reply *reply,
        const char *line);
 void smtp_server_reply_submit(struct smtp_server_reply *reply);
+void smtp_server_reply_submit_duplicate(struct smtp_server_cmd_ctx *_cmd,
+                                       unsigned int index,
+                                       unsigned int from_index);
 
 /* Submit a reply for the command at the specified index (> 0 only if more than
    a single reply is expected). */