aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/rspamc.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-05-15 13:48:38 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-05-15 13:48:57 +0100
commit7d750e372b0e5859784e4a162992fb1b3cfaf97f (patch)
tree93b2334ccfa9175d9c4543563c159ff708d8b651 /src/client/rspamc.c
parentfa54ef695dfcfeb9d29ff7832414b942f33aec6f (diff)
downloadrspamd-7d750e372b0e5859784e4a162992fb1b3cfaf97f.tar.gz
rspamd-7d750e372b0e5859784e4a162992fb1b3cfaf97f.zip
[Feature] Allow to pass hostname to `-i` flag in Rspamc
Diffstat (limited to 'src/client/rspamc.c')
-rw-r--r--src/client/rspamc.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 2f09956ca..4bc9dd9cc 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -554,61 +554,122 @@ add_options (GQueue *opts)
gchar **hdr, **rcpt;
ADD_CLIENT_HEADER (opts, "User-Agent", "rspamc");
+
if (ip != NULL) {
+ rspamd_inet_addr_t *addr = NULL;
+
+ if (!rspamd_parse_inet_address (&addr, ip, strlen (ip))) {
+ /* Try to resolve */
+ struct addrinfo hints, *res, *cur;
+ gint r;
+
+ memset (&hints, 0, sizeof (hints));
+ hints.ai_socktype = SOCK_STREAM; /* Type of the socket */
+#ifdef AI_IDN
+ hints.ai_flags = AI_NUMERICSERV|AI_IDN;
+#else
+ hints.ai_flags = AI_NUMERICSERV;
+#endif
+ hints.ai_family = AF_UNSPEC;
+
+ if ((r = getaddrinfo (ip, "25", &hints, &res)) == 0) {
+
+ cur = res;
+ while (cur) {
+ addr = rspamd_inet_address_from_sa (cur->ai_addr,
+ cur->ai_addrlen);
+
+ if (addr != NULL) {
+ ip = g_strdup (rspamd_inet_address_to_string (addr));
+ rspamd_inet_address_free (addr);
+ break;
+ }
+
+ cur = cur->ai_next;
+ }
+
+ freeaddrinfo (res);
+ }
+ else {
+ rspamd_fprintf (stderr, "address resolution for %s failed: %s\n",
+ ip,
+ gai_strerror (r));
+ }
+ }
+ else {
+ rspamd_inet_address_free (addr);
+ }
+
ADD_CLIENT_HEADER (opts, "Ip", ip);
}
+
if (from != NULL) {
ADD_CLIENT_HEADER (opts, "From", from);
}
+
if (user != NULL) {
ADD_CLIENT_HEADER (opts, "User", user);
}
+
if (rcpts != NULL) {
for (rcpt = rcpts; *rcpt != NULL; rcpt ++) {
ADD_CLIENT_HEADER (opts, "Rcpt", *rcpt);
}
}
+
if (deliver_to != NULL) {
ADD_CLIENT_HEADER (opts, "Deliver-To", deliver_to);
}
+
if (helo != NULL) {
ADD_CLIENT_HEADER (opts, "Helo", helo);
}
+
if (hostname != NULL) {
ADD_CLIENT_HEADER (opts, "Hostname", hostname);
}
+
if (password != NULL) {
ADD_CLIENT_HEADER (opts, "Password", password);
}
+
if (pass_all) {
ADD_CLIENT_HEADER (opts, "Pass", "all");
}
+
if (classifier) {
ADD_CLIENT_HEADER (opts, "Classifier", classifier);
}
+
if (weight != 0) {
numbuf = g_string_sized_new (8);
rspamd_printf_gstring (numbuf, "%d", weight);
ADD_CLIENT_HEADER (opts, "Weight", numbuf->str);
}
+
if (fuzzy_symbol != NULL) {
ADD_CLIENT_HEADER (opts, "Symbol", fuzzy_symbol);
}
+
if (flag != 0) {
numbuf = g_string_sized_new (8);
rspamd_printf_gstring (numbuf, "%d", flag);
ADD_CLIENT_HEADER (opts, "Flag", numbuf->str);
}
+
if (extended_urls) {
ADD_CLIENT_HEADER (opts, "URL-Format", "extended");
}
+
if (profile) {
ADD_CLIENT_HEADER (opts, "Profile", "true");
}
+
if (skip_images) {
ADD_CLIENT_HEADER (opts, "Skip-Images", "true");
}
+
if (skip_attachments) {
ADD_CLIENT_HEADER (opts, "Skip-Attachments", "true");
}