Skip to content

Commit

Permalink
lib-smtp: server: Fix forwarding a multi-line reply.
Browse files Browse the repository at this point in the history
A multi-line reply had the '-' on the first line stripped upon sending, which
makes clients see two separate responses rather than just one. This was caused
by the fact that forwarded replies had the last_line field not set properly,
in which case the '-' was substituted on the first line, rather than the last.
The fix makes a forwarded reply indistinguishable from a normally created reply
by also allowing for amending the reply with additional lines using
smtp_server_reply_add_text().
  • Loading branch information
stephanbosch authored and sirainen committed Jan 18, 2019
1 parent 8658620 commit d830785
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/lib-smtp/smtp-server-reply.c
Expand Up @@ -153,10 +153,36 @@ smtp_server_reply_create_forward(struct smtp_server_command *cmd,
unsigned int index, const struct smtp_reply *from)
{
struct smtp_server_reply *reply;
string_t *textbuf;
char *text;
size_t last_line, i;

reply = smtp_server_reply_create_index(cmd, index,
from->status, smtp_reply_get_enh_code(from));
smtp_reply_write(reply->content->text, from);

i_assert(reply->content != NULL);
textbuf = reply->content->text;
text = str_c_modifiable(textbuf);

/* Find the last line */
reply->content->last_line = last_line = 0;
for (i = 0; i < str_len(textbuf); i++) {
if (text[i] == '\n') {
reply->content->last_line = last_line;
last_line = i + 1;
}
}

/* Make this reply suitable for further amendment with
smtp_server_reply_add_text() */
if ((reply->content->last_line + 3) < str_len(textbuf)) {
i_assert(text[reply->content->last_line + 3] == ' ');
text[reply->content->last_line + 3] = '-';
} else {
str_append_c(textbuf, '-');
}

reply->forwarded = TRUE;

return reply;
Expand Down

0 comments on commit d830785

Please sign in to comment.