From 12ffb47ea0274b5080f7438bf9b63f61e1f3fdb4 Mon Sep 17 00:00:00 2001
From: Ruben Rodriguez <ruben@trisquel.info>
Date: Thu, 4 Jun 2020 11:12:04 -0400
Subject: [PATCH] Added make-exim4 fixes RT#1538898

---
 helpers/DATA/exim4/t9eximevent.patch | 59 ++++++++++++++++++++++++++++
 helpers/make-exim4                   | 28 +++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 helpers/DATA/exim4/t9eximevent.patch
 create mode 100644 helpers/make-exim4

diff --git a/helpers/DATA/exim4/t9eximevent.patch b/helpers/DATA/exim4/t9eximevent.patch
new file mode 100644
index 000000000..0c1c0f64e
--- /dev/null
+++ b/helpers/DATA/exim4/t9eximevent.patch
@@ -0,0 +1,59 @@
+--- src/transports/smtp.c.orig	2018-02-08 08:22:40.000000000 -0500
++++ src/transports/smtp.c	2020-05-27 16:12:39.693759381 -0400
+@@ -673,12 +673,13 @@
+ Arguments:
+   addr                  the address item containing error information
+   host                  the current host
++  evstr			the event
+ 
+ Returns:   nothing
+ */
+ 
+ static void
+-deferred_event_raise(address_item *addr, host_item *host)
++deferred_event_raise(address_item * addr, host_item * host, uschar * evstr)
+ {
+ uschar * action = addr->transport->event_action;
+ const uschar * save_domain;
+@@ -700,7 +701,7 @@
+ deliver_domain = addr->domain;
+ deliver_localpart = addr->local_part;
+ 
+-(void) event_raise(action, US"msg:host:defer",
++(void) event_raise(action, evstr,
+     addr->message
+       ? addr->basic_errno > 0
+ 	? string_sprintf("%s: %s", addr->message, strerror(addr->basic_errno))
+@@ -4338,7 +4339,7 @@
+ 
+ #ifndef DISABLE_EVENT
+       if (rc == DEFER)
+-        deferred_event_raise(first_addr, host);
++	deferred_event_raise(first_addr, host, US"msg:host:defer");
+ #endif
+ 
+       /* If STARTTLS was accepted, but there was a failure in setting up the
+@@ -4367,10 +4368,22 @@
+           write_logs(host, first_addr->message, first_addr->basic_errno);
+ # ifndef DISABLE_EVENT
+         if (rc == DEFER)
+-          deferred_event_raise(first_addr, host);
++            deferred_event_raise(first_addr, host, US"msg:host:defer");
+ # endif
+         }
+ #endif	/*SUPPORT_TLS*/
++
++#ifndef DISABLE_EVENT
++      /* If the last host gave a defer raise a per-message event */
++
++      if (  !(  nexthost
++                && unexpired_hosts_tried < ob->hosts_max_try
++                && total_hosts_tried < ob->hosts_max_try_hardlimit
++                )
++            && (message_defer || rc == DEFER)
++          )
++          deferred_event_raise(first_addr, host, US"msg:defer");
++#endif
+       }
+ 
+     /* Delivery attempt finished */
diff --git a/helpers/make-exim4 b/helpers/make-exim4
new file mode 100644
index 000000000..5526f0241
--- /dev/null
+++ b/helpers/make-exim4
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+#    Copyright (C) 2020 Ruben Rodriguez <ruben@trisquel.info>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+#
+
+VERSION=1
+
+. ./config
+
+patch -p0 < $DATA/t9eximevent.patch
+
+changelog "Corrects event management"
+
+compile
-- 
GitLab