summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2017-09-19 21:45:10 +0100
committerJeremy Harris <jgh146exb@wizmail.org>2017-09-19 21:45:10 +0100
commit5df838645bcdb135355205a115bf918c85987caf (patch)
treeccbe313ed0cbb57ad0e1ad80de89360498725970 /src
parentac0dcd3f05a8821d7ce042646472be1995a08042 (diff)
Avoid repeated string-copy building command-string for rspamd
Diffstat (limited to 'src')
-rw-r--r--src/src/spam.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/src/spam.c b/src/src/spam.c
index 49776a30d..fa3a4fb68 100644
--- a/src/src/spam.c
+++ b/src/src/spam.c
@@ -369,27 +369,30 @@ start = time(NULL);
(void)fcntl(spamd_sock, F_SETFL, O_NONBLOCK);
/* now we are connected to spamd on spamd_sock */
if (sd->is_rspamd)
- { /* rspamd variant */
- uschar *req_str;
- const uschar * helo;
- const uschar * fcrdns;
- const uschar * authid;
-
- req_str = string_sprintf("CHECK RSPAMC/1.3\r\nContent-length: %lu\r\n"
- "Queue-Id: %s\r\nFrom: <%s>\r\nRecipient-Number: %d\r\n",
- mbox_size, message_id, sender_address, recipients_count);
+ {
+ uschar * req_str = NULL;
+ int size = 0, len = 0;
+ const uschar * s;
+
+ req_str = string_append(req_str, &size, &len, 8,
+ "CHECK RSPAMC/1.3\r\nContent-length: ", string_sprintf("%lu\r\n", mbox_size),
+ "Queue-Id: ", message_id,
+ "\r\nFrom: <", sender_address,
+ ">\r\nRecipient-Number: ", string_sprintf("%d\r\n", recipients_count));
+
for (i = 0; i < recipients_count; i ++)
- req_str = string_sprintf("%sRcpt: <%s>\r\n", req_str, recipients_list[i].address);
- if ((helo = expand_string(US"$sender_helo_name")) != NULL && *helo != '\0')
- req_str = string_sprintf("%sHelo: %s\r\n", req_str, helo);
- if ((fcrdns = expand_string(US"$sender_host_name")) != NULL && *fcrdns != '\0')
- req_str = string_sprintf("%sHostname: %s\r\n", req_str, fcrdns);
- if (sender_host_address != NULL)
- req_str = string_sprintf("%sIP: %s\r\n", req_str, sender_host_address);
- if ((authid = expand_string(US"$authenticated_id")) != NULL && *authid != '\0')
- req_str = string_sprintf("%sUser: %s\r\n", req_str, authid);
- req_str = string_sprintf("%s\r\n", req_str);
- wrote = send(spamd_sock, req_str, Ustrlen(req_str), 0);
+ req_str = string_append(req_str, &size, &len, 3,
+ "Rcpt: <", recipients_list[i].address, ">\r\n");
+ if ((s = expand_string(US"$sender_helo_name")) && *s)
+ req_str = string_append(req_str, &size, &len, 3, "Helo: ", s, "\r\n");
+ if ((s = expand_string(US"$sender_host_name")) && *s)
+ req_str = string_append(req_str, &size, &len, 3, "Hostname: ", s, "\r\n");
+ if (sender_host_address)
+ req_str = string_append(req_str, &size, &len, 3, "IP: ", sender_host_address, "\r\n");
+ if ((s = expand_string(US"$authenticated_id")) && *s)
+ req_str = string_append(req_str, &size, &len, 3, "User: ", s, "\r\n");
+ req_str = string_catn(req_str, &size, &len, "\r\n", 2);
+ wrote = send(spamd_sock, req_str, len, 0);
}
else
{ /* spamassassin variant */