From: Jeremy Harris Date: Sat, 6 Jul 2013 19:56:18 +0000 (+0100) Subject: Make success expansion a per-transport option X-Git-Url: https://git.exim.org/users/jgh/exim.git/commitdiff_plain/71da6ae46ebda11989094def47c4145e6286c67a?hp=993e3ef1b0190835fbb69a537c30990db232b4ae Make success expansion a per-transport option --- diff --git a/doc/doc-txt/experimental-spec.txt b/doc/doc-txt/experimental-spec.txt index 565c01851..a7651f6c0 100644 --- a/doc/doc-txt/experimental-spec.txt +++ b/doc/doc-txt/experimental-spec.txt @@ -847,11 +847,10 @@ b. Configure, somewhere before the DATA ACL, the control option to DBL (Database Logging) -------------------------------------------------------------- -This feature allows to write exim internal log information +An arbitrary per-transport string can be expanded on successful delivery, +and (for SMTP transports) a second string on deferrals caused by a host error. +This feature allows the writing of exim internal log information (not available otherwise) into a database. -Initially implemented is logging of details about successfully -completed remote deliveries, which are needed for reputation -systems, and deferrals caused by a host error. In order to use DBL, you must set @@ -859,7 +858,7 @@ EXPERIMENTAL_DBL=yes in your Local/Makefile -and define the database queries in the runtime config file, to +and define the expandable strings in the runtime config file, to be executed at end of delivery. Additionally, there are 8 more variables, available at end of @@ -871,14 +870,17 @@ dbl_delivery_fqdn FQDN of host, which has accepted delivery dbl_delivery_local_part local part of address being delivered dbl_delivery_domain domain part of address being delivered dbl_delivery_confirmation SMTP confirmation message +router_name name of router +transport_name name of transport In case of a deferral caused by a host-error: dbl_defer_errno Error number dbl_defer_errstr Error string possibly containing more details -To log successful deliveries, set the following option in the main -option part of runtime config. + +To log successful deliveries, set the following option +on any transport of interest. dbl_delivery_query @@ -894,6 +896,10 @@ ${lookup pgsql {SELECT * FROM record_Delivery( \ '${quote_pgsql:${lc:$dbl_delivery_fqdn}}', \ '${quote_pgsql:$message_exim_id}')}} +The string is expanded after the delivery completes and any +side-effects will happen. The result is then discarded. +Note that for complex operations an ACL expansion can be used. + In order to log host deferrals, add the following option to an SMTP transport: diff --git a/src/src/deliver.c b/src/src/deliver.c index 29ce05653..5e4a2a1e1 100644 --- a/src/src/deliver.c +++ b/src/src/deliver.c @@ -697,6 +697,11 @@ pointer to a single host item in their host list, for use by the transport. */ #ifdef EXPERIMENTAL_DBL dbl_delivery_ip = NULL; /* presume no successful remote delivery */ + dbl_delivery_port = 0; + dbl_delivery_fqdn = NULL; + dbl_delivery_local_part = NULL; + dbl_delivery_domain = NULL; + dbl_delivery_confirmation = NULL; #endif s = reset_point = store_get(size); @@ -745,7 +750,12 @@ if ((log_extra_selector & LX_delivery_size) != 0) if (addr->transport->info->local) { if (addr->host_list != NULL) + { s = string_append(s, &size, &ptr, 2, US" H=", addr->host_list->name); + #ifdef EXPERIMENTAL_DBL + dbl_delivery_fqdn = addr->host_list->name; + #endif + } if (addr->shadow_message != NULL) s = string_cat(s, &size, &ptr, addr->shadow_message, Ustrlen(addr->shadow_message)); @@ -766,12 +776,12 @@ else s = string_cat(s, &size, &ptr, US"*", 1); #ifdef EXPERIMENTAL_DBL - dbl_delivery_ip = string_copy(addr->host_used->address); - dbl_delivery_port = addr->host_used->port; - dbl_delivery_fqdn = string_copy(addr->host_used->name); - dbl_delivery_local_part = string_copy(addr->local_part); - dbl_delivery_domain = string_copy(addr->domain); - dbl_delivery_confirmation = string_copy(addr->message); + dbl_delivery_ip = addr->host_used->address; + dbl_delivery_port = addr->host_used->port; + dbl_delivery_fqdn = addr->host_used->name; + dbl_delivery_local_part = addr->local_part; + dbl_delivery_domain = addr->domain; + dbl_delivery_confirmation = addr->message; #endif } @@ -840,16 +850,18 @@ store we used to build the line after writing it. */ s[ptr] = 0; log_write(0, flags, "%s", s); + #ifdef EXPERIMENTAL_DBL -if (dbl_delivery_ip != NULL && dbl_delivery_query != NULL) +if (addr->transport->dbl_delivery_query) { DEBUG(D_deliver) { - debug_printf(" DBL(Delivery): dbl_delivery_query=|%s| dbl_delivery_IP=%s\n", dbl_delivery_query, dbl_delivery_ip); + debug_printf(" DBL(Delivery): dbl_delivery_query=|%s| dbl_delivery_IP=%s\n", + addr->transport->dbl_delivery_query, dbl_delivery_ip); } - router_name = addr->router->name; + router_name = addr->router->name; transport_name = addr->transport->name; - expand_string(dbl_delivery_query); + expand_string(addr->transport->dbl_delivery_query); router_name = NULL; transport_name = NULL; } diff --git a/src/src/globals.c b/src/src/globals.c index e9f626665..2345ac4e1 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -486,7 +486,6 @@ int daemon_startup_sleep = 30; #ifdef EXPERIMENTAL_DBL int dbl_defer_errno = 0; uschar *dbl_defer_errstr = NULL; -uschar *dbl_delivery_query = NULL; uschar *dbl_delivery_ip = NULL; int dbl_delivery_port = 0; uschar *dbl_delivery_fqdn = NULL; diff --git a/src/src/globals.h b/src/src/globals.h index 4f2283296..ad36bf79f 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -286,7 +286,6 @@ extern uschar *dccifd_options; /* options for the dccifd daemon */ #ifdef EXPERIMENTAL_DBL extern int dbl_defer_errno; /* error number set when a remote delivery is deferred with a host error */ extern uschar *dbl_defer_errstr; /* error string set when a remote delivery is deferred with a host error */ -extern uschar *dbl_delivery_query; /* query string to log delivery info in DB */ extern uschar *dbl_delivery_ip; /* IP of host, which has accepted delivery */ extern int dbl_delivery_port; /* port of host, which has accepted delivery */ extern uschar *dbl_delivery_fqdn; /* FQDN of host, which has accepted delivery */ diff --git a/src/src/readconf.c b/src/src/readconf.c index 29ad4e7e0..b1b26ff67 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -195,9 +195,6 @@ static optionlist optionlist_config[] = { { "daemon_smtp_ports", opt_stringptr, &daemon_smtp_port }, { "daemon_startup_retries", opt_int, &daemon_startup_retries }, { "daemon_startup_sleep", opt_time, &daemon_startup_sleep }, -#ifdef EXPERIMENTAL_DBL - { "dbl_delivery_query", opt_stringptr, &dbl_delivery_query }, -#endif #ifdef EXPERIMENTAL_DCC { "dcc_direct_add_header", opt_bool, &dcc_direct_add_header }, { "dccifd_address", opt_stringptr, &dccifd_address }, diff --git a/src/src/structs.h b/src/src/structs.h index 53aa2106b..d7f01c3b4 100644 --- a/src/src/structs.h +++ b/src/src/structs.h @@ -184,6 +184,9 @@ typedef struct transport_instance { BOOL log_fail_output; BOOL log_defer_output; BOOL retry_use_local_part; /* Defaults true for local, false for remote */ +#ifdef EXPERIMENTAL_DBL + uschar *dbl_delivery_query; /* String to expand on success */ +#endif } transport_instance; diff --git a/src/src/transport.c b/src/src/transport.c index 7dd1afb85..ef00fe275 100644 --- a/src/src/transport.c +++ b/src/src/transport.c @@ -56,6 +56,10 @@ optionlist optionlist_transports[] = { (void *)offsetof(transport_instance, body_only) }, { "current_directory", opt_stringptr|opt_public, (void *)offsetof(transport_instance, current_dir) }, +#ifdef EXPERIMENTAL_DBL + { "dbl_delivery_query",opt_stringptr | opt_public, + (void *)offsetof(transport_instance, dbl_delivery_query) }, +#endif { "debug_print", opt_stringptr | opt_public, (void *)offsetof(transport_instance, debug_string) }, { "delivery_date_add", opt_bool|opt_public, diff --git a/test/confs/5700 b/test/confs/5700 index 172416605..700b360a8 100644 --- a/test/confs/5700 +++ b/test/confs/5700 @@ -13,8 +13,6 @@ gecos_name = CALLER_NAME acl_smtp_rcpt = accept acl_smtp_data = accept -dbl_delivery_query = ${acl {logger}{delivery}} - # ----- ACL ----- @@ -56,6 +54,7 @@ smtp: port = PORT_S command_timeout = 1s final_timeout = 1s + dbl_delivery_query = ${acl {logger}{delivery}} dbl_host_defer_query = ${acl {logger}{deferral}} # End diff --git a/test/scripts/5700-deliv-log/5700 b/test/scripts/5700-deliv-log/5700 index 2082b14f5..dccf02ca5 100644 --- a/test/scripts/5700-deliv-log/5700 +++ b/test/scripts/5700-deliv-log/5700 @@ -22,7 +22,7 @@ DATA QUIT 220 OK **** -exim -d+deliver+expand+acl -qqf +exim -qqf **** # # @@ -32,7 +32,7 @@ server PORT_S EHLO *sleep 4 **** -exim -d-all+deliver+acl+expand -odi userx@domain1.com +exim -odi userx@domain1.com A message which will hit a timeout . ****