From 14a465c3f0ae93b383f57f12b2ac8709ac0d55b6 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Wed, 27 Aug 2014 17:00:39 +0100 Subject: Further TPDA events msg:complete msg:fail:internal msg:fail:delivery --- src/src/deliver.c | 79 +++++++++++++++++++++++++++++++++++++++++------------- src/src/globals.c | 5 ++-- src/src/globals.h | 3 ++- src/src/readconf.c | 3 +++ 4 files changed, 68 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/src/deliver.c b/src/src/deliver.c index 48d3fd7ec..b3a5a49b2 100644 --- a/src/src/deliver.c +++ b/src/src/deliver.c @@ -708,6 +708,8 @@ d_tlslog(uschar * s, int * sizep, int * ptrp, address_item * addr) #endif + + #ifdef EXPERIMENTAL_TPDA int tpda_raise_event(uschar * action, uschar * event, uschar * ev_data) @@ -742,7 +744,32 @@ if (action) } return OK; } -#endif + +static void +tpda_msg_event(uschar * event, address_item * addr) +{ +uschar * save_domain = deliver_domain; +uschar * save_local = deliver_localpart; + +if (!addr->transport) + return; + +router_name = addr->router ? addr->router->name : NULL; +transport_name = addr->transport->name; +deliver_domain = addr->domain; +deliver_localpart = addr->local_part; + +(void) tpda_raise_event(addr->transport->tpda_event_action, event, + addr->host_used || Ustrcmp(addr->transport->driver_name, "lmtp") == 0 + ? addr->message : NULL); + +deliver_localpart = save_local; +deliver_domain = save_domain; +router_name = transport_name = NULL; +} +#endif /*EXPERIMENTAL_TPDA*/ + + /* If msg is NULL this is a delivery log and logchar is used. Otherwise this is a nonstandard call; no two-character delivery flag is written @@ -902,24 +929,10 @@ s[ptr] = 0; log_write(0, flags, "%s", s); #ifdef EXPERIMENTAL_TPDA - { - uschar * save_domain = deliver_domain; - uschar * save_local = deliver_localpart; - - router_name = addr->router ? addr->router->name : NULL; - transport_name = addr->transport ? addr->transport->name : NULL; - deliver_domain = addr->domain; - deliver_localpart = addr->local_part; - - (void) tpda_raise_event(addr->transport->tpda_event_action, US"msg:delivery", - addr->host_used || Ustrcmp(addr->transport->driver_name, "lmtp") == 0 - ? addr->message : NULL); - - deliver_localpart = save_local; - deliver_domain = save_domain; - router_name = transport_name = NULL; - } +/*XXX cutthrough calls this also for non-delivery...*/ +tpda_msg_event(US"msg:delivery", addr); #endif + store_reset(reset_point); return; } @@ -1347,6 +1360,11 @@ else deliver_msglog("%s %s\n", now, s); log_write(0, LOG_MAIN, "** %s", s); + +#ifdef EXPERIMENTAL_TPDA + tpda_msg_event(US"msg:fail:delivery", addr); +#endif + store_reset(reset_point); } @@ -5462,6 +5480,25 @@ if (process_recipients != RECIP_IGNORE) addr_last = new; break; } + +#ifdef EXPERIMENTAL_TPDA + if (process_recipients != RECIP_ACCEPT) + { + uschar * save_local = deliver_localpart; + uschar * save_domain = deliver_domain; + + deliver_localpart = expand_string( + string_sprintf("${local_part:%s}", new->address)); + deliver_domain = expand_string( + string_sprintf("${domain:%s}", new->address)); + + (void) tpda_raise_event(delivery_event_action, + US"msg:fail:internal", new->message); + + deliver_localpart = save_local; + deliver_domain = save_domain; + } +#endif } } } @@ -7217,7 +7254,11 @@ if (addr_defer == NULL) /* Unset deliver_freeze so that we won't try to move the spool files further down */ deliver_freeze = FALSE; - } + +#ifdef EXPERIMENTAL_TPDA + (void) tpda_raise_event(delivery_event_action, US"msg:complete", NULL); +#endif +} /* If there are deferred addresses, we are keeping this message because it is not yet completed. Lose any temporary files that were catching output from diff --git a/src/src/globals.c b/src/src/globals.c index f1b771ad3..ef1c1fd02 100644 --- a/src/src/globals.c +++ b/src/src/globals.c @@ -1327,8 +1327,9 @@ BOOL timestamps_utc = FALSE; #ifdef EXPERIMENTAL_TPDA int tpda_defer_errno = 0; -uschar *tpda_event = NULL; -uschar *tpda_data = NULL; +uschar *tpda_event = NULL; /* event name */ +uschar *tpda_data = NULL; /* auxilary data for event */ +uschar *delivery_event_action = NULL; /* expansion for delivery events */ #endif transport_instance *transports = NULL; diff --git a/src/src/globals.h b/src/src/globals.h index f0a3091df..73793aa2e 100644 --- a/src/src/globals.h +++ b/src/src/globals.h @@ -872,7 +872,8 @@ extern BOOL timestamps_utc; /* Use UTC for all times */ #ifdef EXPERIMENTAL_TPDA extern int tpda_defer_errno; /* error number set when a remote delivery is deferred with a host error */ extern uschar *tpda_event; /* event classification */ -extern uschar *tpda_data;; /* event data */ +extern uschar *tpda_data; /* event data */ +extern uschar *delivery_event_action; /* expansion for delivery events */ #endif extern uschar *transport_name; /* Name of transport last started */ diff --git a/src/src/readconf.c b/src/src/readconf.c index adb538c59..2e18b670e 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -205,6 +205,9 @@ static optionlist optionlist_config[] = { { "deliver_drop_privilege", opt_bool, &deliver_drop_privilege }, { "deliver_queue_load_max", opt_fixed, &deliver_queue_load_max }, { "delivery_date_remove", opt_bool, &delivery_date_remove }, +#ifdef EXPERIMENTAL_TPDA + { "delivery_event_action", opt_stringptr, &delivery_event_action }, +#endif #ifdef ENABLE_DISABLE_FSYNC { "disable_fsync", opt_bool, &disable_fsync }, #endif -- cgit v1.2.3