]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: reply: Add smtp_reply_get_text_lines_omit_prefix().
authorStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 2 Nov 2018 09:14:57 +0000 (10:14 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 12 Feb 2019 13:41:55 +0000 (15:41 +0200)
This returns a string array of the lines in the reply, omitting the prefix (the
first word), which is usually a "<domain>" value.

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

index 5daa2aa01ce11aa3ea19f5e71396a053437deb46..3e3c6cac75c8c04f5377754e9d0bb786710fe1c8 100644 (file)
@@ -41,6 +41,26 @@ smtp_reply_get_enh_code(const struct smtp_reply *reply)
                reply->enhanced_code.x, reply->enhanced_code.y, reply->enhanced_code.z);
 }
 
+const char *const *
+smtp_reply_get_text_lines_omit_prefix(const struct smtp_reply *reply)
+{
+       unsigned int lines_count, i;
+       const char **lines;
+       const char *p;
+
+       if ((p=strchr(reply->text_lines[0], ' ')) == NULL)
+               return reply->text_lines;
+
+       lines_count = str_array_length(reply->text_lines);
+       lines = t_new(const char *, lines_count + 1);
+
+       lines[0] = p + 1;
+       for (i = 1; i < lines_count; i++)
+               lines[i] = reply->text_lines[i];
+
+       return lines;
+}
+
 void
 smtp_reply_write(string_t *out, const struct smtp_reply *reply)
 {
index 4e7d6f99ac95a3d4b15eff01170c7a0c63d9da0b..1b4c671eb30cad63d96ae32cc40a445eef6311c9 100644 (file)
@@ -52,6 +52,8 @@ void smtp_reply_printf(struct smtp_reply *reply, unsigned int status,
 
 const char *
 smtp_reply_get_enh_code(const struct smtp_reply *reply);
+const char *const *
+smtp_reply_get_text_lines_omit_prefix(const struct smtp_reply *reply);
 
 /* Write the SMTP reply as a sequence of lines according to the SMTP syntax,
    each terminated by CRLF. */