-
- if (spamd_sock == -1)
- {
- log_write(0, LOG_MAIN|LOG_PANIC,
- "programming fault, spamd_sock unexpectedly unset");
- (void)fclose(mbox_file);
- (void)close(spamd_sock);
- return DEFER;
- }
-
- (void)fcntl(spamd_sock, F_SETFL, O_NONBLOCK);
- /* now we are connected to spamd on spamd_sock */
- if (is_rspamd)
- { /* rspamd variant */
- uschar *req_str;
- const char *helo;
- const char *fcrdns;
-
- 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);
- 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);
- req_str = string_sprintf("%s\r\n", req_str);
- wrote = send(spamd_sock, req_str, Ustrlen(req_str), 0);
- }
- else
- { /* spamassassin variant */
- (void)string_format(spamd_buffer,
- sizeof(spamd_buffer),
- "REPORT SPAMC/1.2\r\nUser: %s\r\nContent-length: %ld\r\n\r\n",
- user_name,
- mbox_size);
- /* send our request */
- wrote = send(spamd_sock, spamd_buffer, Ustrlen(spamd_buffer), 0);
- }
- if (wrote == -1)
- {
- (void)close(spamd_sock);
- log_write(0, LOG_MAIN|LOG_PANIC,
- "%s spamd send failed: %s", loglabel, strerror(errno));
- (void)fclose(mbox_file);
- (void)close(spamd_sock);
- return DEFER;
- }
-
- /* now send the file */
- /* spamd sometimes accepts conections but doesn't read data off
- * the connection. We make the file descriptor non-blocking so
- * that the write will only write sufficient data without blocking
- * and we poll the desciptor to make sure that we can write without
- * blocking. Short writes are gracefully handled and if the whole
- * trasaction takes too long it is aborted.
- * Note: poll() is not supported in OSX 10.2 and is reported to be
- * broken in more recent versions (up to 10.4).
- */
+ }
+
+(void)fcntl(spamd_cctx.sock, F_SETFL, O_NONBLOCK);
+/* now we are connected to spamd on spamd_cctx.sock */
+if (sd->is_rspamd)
+ {
+ gstring * req_str;
+ const uschar * s;
+
+ req_str = string_append(NULL, 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 (int i = 0; i < recipients_count; i++)
+ req_str = string_append(req_str, 3,
+ "Rcpt: <", recipients_list[i].address, ">\r\n");
+ if ((s = expand_string(US"$sender_helo_name")) && *s)
+ req_str = string_append(req_str, 3, "Helo: ", s, "\r\n");
+ if ((s = expand_string(US"$sender_host_name")) && *s)
+ req_str = string_append(req_str, 3, "Hostname: ", s, "\r\n");
+ if (sender_host_address)
+ req_str = string_append(req_str, 3, "IP: ", sender_host_address, "\r\n");
+ if ((s = expand_string(US"$authenticated_id")) && *s)
+ req_str = string_append(req_str, 3, "User: ", s, "\r\n");
+ req_str = string_catn(req_str, US"\r\n", 2);
+ wrote = send(spamd_cctx.sock, req_str->s, req_str->ptr, 0);
+ }
+else
+ { /* spamassassin variant */
+ (void)string_format(spamd_buffer,
+ sizeof(spamd_buffer),
+ "REPORT SPAMC/1.2\r\nUser: %s\r\nContent-length: %ld\r\n\r\n",
+ user_name,
+ mbox_size);
+ /* send our request */
+ wrote = send(spamd_cctx.sock, spamd_buffer, Ustrlen(spamd_buffer), 0);
+ }
+
+if (wrote == -1)
+ {
+ (void)close(spamd_cctx.sock);
+ log_write(0, LOG_MAIN|LOG_PANIC,
+ "%s spamd %s send failed: %s", loglabel, callout_address, strerror(errno));
+ goto defer;
+ }
+
+/* now send the file */
+/* spamd sometimes accepts connections but doesn't read data off
+ * the connection. We make the file descriptor non-blocking so
+ * that the write will only write sufficient data without blocking
+ * and we poll the descriptor to make sure that we can write without
+ * blocking. Short writes are gracefully handled and if the whole
+ * transaction takes too long it is aborted.
+ * Note: poll() is not supported in OSX 10.2 and is reported to be
+ * broken in more recent versions (up to 10.4).
+ */