commit:     a580fed3ffd74fc0e1a238425d36f2a681576fe2
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Wed May 13 17:29:43 2015 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Wed May 13 17:29:43 2015 +0000
URL:        https://gitweb.gentoo.org/proj/hardened-dev.git/commit/?id=a580fed3

mail-mta/exim: fix -lnsl.  Bug #533660.

Package-Manager: portage-2.2.18
RepoMan-Options: --force
Manifest-Sign-Key: 0xF52D4BBA

 mail-mta/exim/exim-4.84-r99.ebuild                 |  513 +++++++++
 mail-mta/exim/files/auth_conf.sub                  |   25 +
 mail-mta/exim/files/exim-4.14-tail.patch           |   11 +
 mail-mta/exim/files/exim-4.20-maildir.patch        |   14 +
 mail-mta/exim/files/exim-4.69-r1.27021.patch       |   48 +
 .../exim/files/exim-4.74-localscan_dlopen.patch    |  262 +++++
 .../exim/files/exim-4.74-radius-db-ENV-clash.patch |   22 +
 mail-mta/exim/files/exim-4.76-crosscompile.patch   |   15 +
 mail-mta/exim/files/exim-4.76-dsn.patch            |   18 +
 .../exim/files/exim-4.77-as-needed-ldflags.patch   |  144 +++
 .../exim/files/exim-4.77-makefile-freebsd.patch    |   48 +
 .../exim/files/exim-4.80-spool-mail-group.patch    |   27 +
 .../exim/files/exim-4.82-makefile-freebsd.patch    |   45 +
 mail-mta/exim/files/exim-submission.socket         |   10 +
 mail-mta/exim/files/exim-submission_at.service     |   11 +
 mail-mta/exim/files/exim.confd                     |    5 +
 mail-mta/exim/files/exim.logrotate                 |    9 +
 mail-mta/exim/files/exim.rc8                       |   30 +
 mail-mta/exim/files/exim.rc9                       |   46 +
 mail-mta/exim/files/exim.service                   |   12 +
 mail-mta/exim/files/exim.socket                    |   10 +
 mail-mta/exim/files/exim_482_dsn_1_3.patch         | 1212 ++++++++++++++++++++
 mail-mta/exim/files/exim_at.service                |    7 +
 mail-mta/exim/metadata.xml                         |   50 +
 24 files changed, 2594 insertions(+)

diff --git a/mail-mta/exim/exim-4.84-r99.ebuild 
b/mail-mta/exim/exim-4.84-r99.ebuild
new file mode 100644
index 0000000..e160456
--- /dev/null
+++ b/mail-mta/exim/exim-4.84-r99.ebuild
@@ -0,0 +1,513 @@
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/mail-mta/exim/exim-4.84.ebuild,v 1.17 
2015/03/21 21:18:34 jlec Exp $
+
+EAPI="5"
+
+inherit eutils toolchain-funcs multilib pam systemd
+
+IUSE="dcc +dkim dlfunc dmarc +dnsdb doc dovecot-sasl dsn exiscan-acl gnutls 
ipv6 ldap lmtp maildir mbx mysql nis pam perl pkcs11 postgres +prdr proxy 
radius redis sasl selinux spf sqlite srs ssl syslog tcpd tpda X"
+REQUIRED_USE="spf? ( exiscan-acl ) srs? ( exiscan-acl ) dmarc? ( spf dkim ) 
pkcs11? ( gnutls )"
+
+COMM_URI="ftp://ftp.exim.org/pub/exim/exim4$([[ ${PV} == *_rc* ]] && echo 
/test)"
+
+DESCRIPTION="A highly configurable, drop-in replacement for sendmail"
+SRC_URI="${COMM_URI}/${P//rc/RC}.tar.bz2
+       mirror://gentoo/system_filter.exim.gz
+       doc? ( ${COMM_URI}/${PN}-html-${PV//rc/RC}.tar.bz2 )"
+HOMEPAGE="http://www.exim.org/";
+
+SLOT="0"
+LICENSE="GPL-2"
+KEYWORDS="amd64 ppc ~mips  x86"
+
+COMMON_DEPEND=">=sys-apps/sed-4.0.5
+       >=sys-libs/db-3.2
+       dev-libs/libpcre
+       perl? ( dev-lang/perl:= )
+       pam? ( virtual/pam )
+       tcpd? ( sys-apps/tcp-wrappers )
+       ssl? ( dev-libs/openssl )
+       gnutls? ( net-libs/gnutls[pkcs11?]
+                         dev-libs/libtasn1 )
+       ldap? ( >=net-nds/openldap-2.0.7 )
+       mysql? ( virtual/mysql )
+       postgres? ( dev-db/postgresql )
+       sasl? ( >=dev-libs/cyrus-sasl-2.1.26-r2 )
+       redis? ( dev-libs/hiredis )
+       spf? ( >=mail-filter/libspf2-1.2.5-r1 )
+       dmarc? ( mail-filter/opendmarc )
+       srs? ( mail-filter/libsrs_alt )
+       X? ( x11-proto/xproto
+               x11-libs/libX11
+               x11-libs/libXmu
+               x11-libs/libXt
+               x11-libs/libXaw
+       )
+       sqlite? ( dev-db/sqlite )
+       radius? ( net-dialup/radiusclient )
+       virtual/libiconv
+       "
+       # added X check for #57206
+DEPEND="${COMMON_DEPEND}
+       virtual/pkgconfig"
+RDEPEND="${COMMON_DEPEND}
+       !mail-mta/courier
+       !mail-mta/esmtp
+       !mail-mta/mini-qmail
+       !<mail-mta/msmtp-1.4.19-r1
+       !>=mail-mta/msmtp-1.4.19-r1[mta]
+       !mail-mta/netqmail
+       !mail-mta/nullmailer
+       !mail-mta/postfix
+       !mail-mta/qmail-ldap
+       !mail-mta/sendmail
+       !mail-mta/opensmtpd
+       !<mail-mta/ssmtp-2.64-r2
+       !>=mail-mta/ssmtp-2.64-r2[mta]
+       !net-mail/mailwrapper
+       >=net-mail/mailbase-0.00-r5
+       virtual/logger
+       dcc? ( mail-filter/dcc )
+       selinux? ( sec-policy/selinux-exim )
+       "
+
+S=${WORKDIR}/${P//rc/RC}
+
+src_prepare() {
+       epatch "${FILESDIR}"/exim-4.14-tail.patch
+       epatch "${FILESDIR}"/exim-4.74-localscan_dlopen.patch
+       epatch "${FILESDIR}"/exim-4.69-r1.27021.patch
+       epatch "${FILESDIR}"/exim-4.74-radius-db-ENV-clash.patch # 287426
+       epatch "${FILESDIR}"/exim-4.82-makefile-freebsd.patch # 235785
+       epatch "${FILESDIR}"/exim-4.77-as-needed-ldflags.patch # 352265, 391279
+       epatch "${FILESDIR}"/exim-4.76-crosscompile.patch # 266591
+
+       if use maildir ; then
+               epatch "${FILESDIR}"/exim-4.20-maildir.patch
+       else
+               epatch "${FILESDIR}"/exim-4.80-spool-mail-group.patch # 438606
+       fi
+
+       # user Exim believes it should be
+       MAILUSER=mail
+       MAILGROUP=mail
+       if use prefix && [[ ${EUID} != 0 ]] ; then
+               MAILUSER=$(id -un)
+               MAILGROUP=$(id -gn)
+       fi
+}
+
+src_configure() {
+       # general config and paths
+
+       sed -i.orig \
+               -e 
"/SYSTEM_ALIASES_FILE/s'SYSTEM_ALIASES_FILE'${EPREFIX}/etc/mail/aliases'" \
+               "${S}"/src/configure.default || die
+
+       sed -i -e 's/^buildname=.*/buildname=exim-gentoo/g' Makefile || die
+
+       sed -e "48i\CFLAGS=${CFLAGS}" \
+               -e 
"s:BIN_DIRECTORY=/usr/exim/bin:BIN_DIRECTORY=${EPREFIX}/usr/sbin:" \
+               -e "s:EXIM_USER=:EXIM_USER=${MAILUSER}:" \
+               -e 
"s:CONFIGURE_FILE=/usr/exim/configure:CONFIGURE_FILE=${EPREFIX}/etc/exim/exim.conf:"
 \
+               -e "s:ZCAT_COMMAND=.*$:ZCAT_COMMAND=${EPREFIX}/bin/zcat:" \
+               -e 
"s:COMPRESS_COMMAND=.*$:COMPRESS_COMMAND=${EPREFIX}/bin/gzip:" \
+               src/EDITME > Local/Makefile
+
+       if use elibc_musl; then
+               sed -e 's/^LIBS = -lnsl/LIBS =/g' \
+               -e 's/^HAVE_ICONV=yes/#HAVE_ICONV=yes/' \
+               -i OS/Makefile-Linux
+       fi
+
+       cd Local
+
+       cat >> Makefile <<- EOC
+               INFO_DIRECTORY=${EPREFIX}/usr/share/info
+               PID_FILE_PATH=${EPREFIX}/run/exim.pid
+               SPOOL_DIRECTORY=${EPREFIX}/var/spool/exim
+       EOC
+
+       # if we use libiconv, now is the time to tell so
+       use !elibc_glibc && use !elibc_musl && echo "EXTRALIBS_EXIM=-liconv" >> 
Makefile
+
+       # support for IPv6
+       if use ipv6; then
+               cat >> Makefile <<- EOC
+                       HAVE_IPV6=YES
+               EOC
+       fi
+
+       #
+       # mail storage formats
+
+       # mailstore is Exim's traditional storage format
+       cat >> Makefile <<- EOC
+               SUPPORT_MAILSTORE=yes
+       EOC
+
+       # mbox
+       if use mbx; then
+               cat >> Makefile <<- EOC
+                       SUPPORT_MBX=yes
+               EOC
+       fi
+
+       # maildir
+       if use maildir; then
+               cat >> Makefile <<- EOC
+                       SUPPORT_MAILDIR=yes
+               EOC
+       fi
+
+       #
+       # lookup methods
+
+       # use the "native" interfaces to the DBM and CDB libraries, support
+       # passwd and directory lookups by default
+       cat >> Makefile <<- EOC
+               USE_DB=yes
+               DBMLIB=-ldb
+               LOOKUP_CDB=yes
+               LOOKUP_PASSWD=yes
+               LOOKUP_DSEARCH=yes
+       EOC
+
+       if ! use dnsdb; then
+               # DNSDB lookup is enabled by default
+               sed -i "s:^LOOKUP_DNSDB=yes:# LOOKUP_DNSDB=yes:" Makefile
+       fi
+
+       if use ldap; then
+               cat >> Makefile <<- EOC
+                       LOOKUP_LDAP=yes
+                       LDAP_LIB_TYPE=OPENLDAP2
+                       LOOKUP_INCLUDE += -I"${EROOT}"usr/include/ldap
+                       LOOKUP_LIBS += -lldap -llber
+               EOC
+       fi
+
+       if use mysql; then
+               cat >> Makefile <<- EOC
+                       LOOKUP_MYSQL=yes
+                       LOOKUP_INCLUDE += $(mysql_config --include)
+                       LOOKUP_LIBS += $(mysql_config --libs)
+               EOC
+       fi
+
+       if use nis; then
+               cat >> Makefile <<- EOC
+                       LOOKUP_NIS=yes
+                       LOOKUP_NISPLUS=yes
+               EOC
+       fi
+
+       if use postgres; then
+               cat >> Makefile <<- EOC
+                       LOOKUP_PGSQL=yes
+                       LOOKUP_INCLUDE += -I$(pg_config --includedir)
+                       LOOKUP_LIBS += -L$(pg_config --libdir) -lpq
+               EOC
+       fi
+
+       if use sqlite; then
+               cat >> Makefile <<- EOC
+                       LOOKUP_SQLITE=yes
+                       LOOKUP_SQLITE_PC=sqlite3
+               EOC
+       fi
+
+       if use redis; then
+               cat >> Makefile <<- EOC
+                       EXPERIMENTAL_REDIS=yes
+                       LOOKUP_LIBS += -lhiredis
+               EOC
+       fi
+
+       #
+       # Exim monitor, enabled by default, controlled via X USE-flag,
+       # disable if not requested, bug #46778
+       if use X; then
+               cp ../exim_monitor/EDITME eximon.conf || die
+       else
+               sed -i -e '/^EXIM_MONITOR=/s/^/# /' Makefile
+       fi
+
+       #
+       # features
+
+       # content scanning support
+       if use exiscan-acl; then
+               cat >> Makefile <<- EOC
+                       WITH_CONTENT_SCAN=yes
+                       WITH_OLD_DEMIME=yes
+               EOC
+       fi
+
+       # DomainKeys Identified Mail, RFC4871
+       if ! use dkim; then
+               # DKIM is enabled by default
+               cat >> Makefile <<- EOC
+                       DISABLE_DKIM=yes
+               EOC
+       fi
+
+       # Per-Recipient-Data-Response
+       if ! use prdr; then
+               # PRDR is enabled by default
+               cat >> Makefile <<- EOC
+                       DISABLE_PRDR=yes
+               EOC
+       fi
+
+       # log to syslog
+       if use syslog; then
+               sed -i 
"s:LOG_FILE_PATH=/var/log/exim/exim_%s.log:LOG_FILE_PATH=syslog:" Makefile
+               cat >> Makefile <<- EOC
+                       LOG_FILE_PATH=syslog
+               EOC
+       else
+               cat >> Makefile <<- EOC
+                       LOG_FILE_PATH=${EPREFIX}/var/log/exim/exim_%s.log
+               EOC
+       fi
+
+       # starttls support (ssl)
+       if use ssl; then
+               echo "SUPPORT_TLS=yes" >> Makefile
+               if use gnutls; then
+                       echo "USE_GNUTLS=yes" >> Makefile
+                       echo "USE_GNUTLS_PC=gnutls" >> Makefile
+                       use pkcs11 || echo "AVOID_GNUTLS_PKCS11=yes" >> Makefile
+               else
+                       echo "USE_OPENSSL_PC=openssl" >> Makefile
+               fi
+       fi
+
+       # TCP wrappers
+       if use tcpd; then
+               cat >> Makefile <<- EOC
+                       USE_TCP_WRAPPERS=yes
+                       EXTRALIBS_EXIM += -lwrap
+               EOC
+       fi
+
+       # Light Mail Transport Protocol
+       if use lmtp; then
+               cat >> Makefile <<- EOC
+                       TRANSPORT_LMTP=yes
+               EOC
+       fi
+
+       # embedded Perl
+       if use perl; then
+               cat >> Makefile <<- EOC
+                       EXIM_PERL=perl.o
+               EOC
+       fi
+
+       # dlfunc
+       if use dlfunc; then
+               cat >> Makefile <<- EOC
+                       EXPAND_DLFUNC=yes
+               EOC
+       fi
+
+       #
+       # experimental features
+
+       # Distributed Checksum Clearinghouse
+       if use dcc; then
+               echo "EXPERIMENTAL_DCC=yes">> Makefile
+       fi
+
+       # Sender Policy Framework
+       if use spf; then
+               cat >> Makefile <<- EOC
+                       EXPERIMENTAL_SPF=yes
+                       EXTRALIBS_EXIM += -lspf2
+               EOC
+       fi
+
+       # Sender Rewriting Scheme
+       if use srs; then
+               cat >> Makefile <<- EOC
+                       EXPERIMENTAL_SRS=yes
+                       EXTRALIBS_EXIM += -lsrs_alt
+               EOC
+       fi
+
+       # DMARC
+       if use dmarc; then
+               cat >> Makefile <<- EOC
+                       EXPERIMENTAL_DMARC=yes
+                       EXTRALIBS_EXIM += -lopendmarc
+               EOC
+       fi
+
+       # Transport post-delivery actions
+       if use tpda; then
+               cat >> Makefile <<- EOC
+                       EXPERIMENTAL_TPDA=yes
+               EOC
+       fi
+
+       # Proxy Protocol
+       if use proxy; then
+               cat >> Makefile <<- EOC
+                       EXPERIMENTAL_PROXY=yes
+               EOC
+       fi
+
+       # Delivery Sender Notifications
+       if use dsn; then
+               cat >> Makefile <<- EOC
+                       EXPERIMENTAL_DSN=yes
+               EOC
+       fi
+
+       #
+       # authentication (SMTP AUTH)
+
+       # standard bits
+       cat >> Makefile <<- EOC
+               AUTH_SPA=yes
+               AUTH_CRAM_MD5=yes
+               AUTH_PLAINTEXT=yes
+       EOC
+
+       # Cyrus SASL
+       if use sasl; then
+               cat >> Makefile <<- EOC
+                       CYRUS_SASLAUTHD_SOCKET=${EPREFIX}/run/saslauthd/mux
+                       AUTH_CYRUS_SASL=yes
+                       AUTH_LIBS += -lsasl2
+               EOC
+       fi
+
+       # Dovecot
+       if use dovecot-sasl; then
+               cat >> Makefile <<- EOC
+                       AUTH_DOVECOT=yes
+               EOC
+       fi
+
+       # Pluggable Authentication Modules
+       if use pam; then
+               cat >> Makefile <<- EOC
+                       SUPPORT_PAM=yes
+                       AUTH_LIBS += -lpam
+               EOC
+       fi
+
+       # Radius
+       if use radius; then
+               cat >> Makefile <<- EOC
+                       
RADIUS_CONFIG_FILE=${EPREFIX}/etc/radiusclient/radiusclient.conf
+                       RADIUS_LIB_TYPE=RADIUSCLIENT
+                       AUTH_LIBS += -lradiusclient
+               EOC
+       fi
+}
+
+src_compile() {
+       emake -j1 CC="$(tc-getCC)" HOSTCC="$(tc-getCC $CBUILD)" \
+               AR="$(tc-getAR) cq" RANLIB="$(tc-getRANLIB)" FULLECHO='' \
+               || die "make failed"
+}
+
+src_install () {
+       cd "${S}"/build-exim-gentoo || die
+       dosbin exim
+       if use X; then
+               dosbin eximon.bin
+               dosbin eximon
+       fi
+       fperms 4755 /usr/sbin/exim
+
+       dosym exim /usr/sbin/sendmail
+       dosym exim /usr/sbin/rsmtp
+       dosym exim /usr/sbin/rmail
+       dosym /usr/sbin/exim /usr/bin/mailq
+       dosym /usr/sbin/exim /usr/bin/newaliases
+       dosym /usr/sbin/sendmail /usr/lib/sendmail
+
+       for i in exicyclog exim_dbmbuild exim_dumpdb exim_fixdb exim_lock \
+               exim_tidydb exinext exiwhat exigrep eximstats exiqsumm exiqgrep 
\
+               convert4r3 convert4r4 exipick
+       do
+               dosbin $i
+       done
+
+       dodoc "${S}"/doc/*
+       doman "${S}"/doc/exim.8
+       use dsn && dodoc "${S}"/README.DSN
+       use doc && dohtml -r 
"${WORKDIR}"/${PN}-html-${PV//rc/RC}/doc/html/spec_html/*
+
+       # conf files
+       insinto /etc/exim
+       newins "${S}"/src/configure.default exim.conf.dist
+       if use exiscan-acl; then
+               newins "${S}"/src/configure.default exim.conf.exiscan-acl
+       fi
+       doins "${WORKDIR}"/system_filter.exim
+       doins "${FILESDIR}"/auth_conf.sub
+
+       pamd_mimic system-auth exim auth account
+
+       # headers, #436406
+       if use dlfunc ; then
+               # fixup includes so they actually can be found when including
+               sed -i \
+                       -e '/#include 
"\(config\|store\|mytypes\).h"/s:"\(.\+\)":<exim/\1>:' \
+                       local_scan.h || die
+               insinto /usr/include/exim
+               doins {config,local_scan}.h ../src/{mytypes,store}.h
+       fi
+
+       insinto /etc/logrotate.d
+       newins "${FILESDIR}/exim.logrotate" exim
+
+       newinitd "${FILESDIR}"/exim.rc8 exim
+       newconfd "${FILESDIR}"/exim.confd exim
+
+       systemd_dounit 
"${FILESDIR}"/{exim.service,exim.socket,exim-submission.socket}
+       systemd_newunit "${FILESDIR}"/exim_at.service '[email protected]'
+       systemd_newunit "${FILESDIR}"/exim-submission_at.service 
'[email protected]'
+
+       DIROPTIONS="-m 0750 -o ${MAILUSER} -g ${MAILGROUP}"
+       dodir /var/log/${PN}
+}
+
+pkg_postinst() {
+       if [[ ! -f ${EROOT}etc/exim/exim.conf ]] ; then
+               einfo "${EROOT}etc/exim/system_filter.exim is a sample 
system_filter."
+               einfo "${EROOT}etc/exim/auth_conf.sub contains the 
configuration sub for using smtp auth."
+               einfo "Please create ${EROOT}etc/exim/exim.conf from 
${EROOT}etc/exim/exim.conf.dist."
+       fi
+       if use dcc ; then
+               einfo "DCC support is experimental, you can find some limited"
+               einfo "documentation at the bottom of this prerelease message:"
+               einfo "http://article.gmane.org/gmane.mail.exim.devel/3579";
+       fi
+       use spf && einfo "SPF support is experimental"
+       use srs && einfo "SRS support is experimental"
+       if use dmarc ; then
+               einfo "DMARC support is experimental.  See global settings to"
+               einfo "configure DMARC, for usage see the documentation at "
+               einfo "experimental-spec.txt."
+       fi
+       use tpda && einfo "TPDA support is experimental"
+       use proxy && einfo "proxy support is experimental"
+       if use dsn ; then
+               einfo "Starting from Exim 4.83, DSN support comes from 
upstream."
+               einfo "DSN support is an experimental feature.  If you used DSN"
+               einfo "support prior to 4.83, make sure to remove all 
dsn_process"
+               einfo "switches from your routers, see 
http://bugs.gentoo.org/511818";
+       fi
+       einfo "Exim maintains some db files under its spool directory that need"
+       einfo "cleaning from time to time.  (${EROOT}var/spool/exim/db)"
+       einfo "Please use the exim_tidydb tool as documented in the Exim 
manual:"
+       einfo 
"http://www.exim.org/exim-html-current/doc/html/spec_html/ch-exim_utilities.html#SECThindatmai";
+}

diff --git a/mail-mta/exim/files/auth_conf.sub 
b/mail-mta/exim/files/auth_conf.sub
new file mode 100644
index 0000000..24434a7
--- /dev/null
+++ b/mail-mta/exim/files/auth_conf.sub
@@ -0,0 +1,25 @@
+######################################################################
+#                   AUTHENTICATION CONFIGURATION                     #
+######################################################################
+# If you're using PAM to authenticate, lifes real simple.
+# This plain directive works for nearly everything except windows MUA's the
+# login directive will allow you to authenticate your Outlook 2000 and
+# outlook express clients.
+
+
+
+plain:
+  driver = plaintext
+  public_name = PLAIN
+  server_condition = "${if pam{$2:$3}{1}{0}}"
+  server_set_id = $2
+
+login:
+  driver = plaintext
+  public_name = LOGIN
+  server_prompts = "Username:: : Password::"
+  server_condition = "${if pam{$1:${sg{$2}{:}{::}}}{1}{0}}"
+  server_set_id = $1
+#
+# FIXME
+# Need to add authenticator for SPA!!

diff --git a/mail-mta/exim/files/exim-4.14-tail.patch 
b/mail-mta/exim/files/exim-4.14-tail.patch
new file mode 100644
index 0000000..481dca9
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.14-tail.patch
@@ -0,0 +1,11 @@
+--- scripts/Configure-config.h.orig    2003-07-17 18:01:19.000000000 -0400
++++ scripts/Configure-config.h 2003-07-17 18:01:25.000000000 -0400
+@@ -41,7 +41,7 @@
+ 
+ # Double-check that config.h is complete.
+ 
+-if [ "`tail -1 config.h`" != "/* End of config.h */" ] ; then
++if [ "`tail -n 1 config.h`" != "/* End of config.h */" ] ; then
+   echo "*** config.h appears to be incomplete"
+   echo "*** unexpected failure in buildconfig program"
+   exit 1

diff --git a/mail-mta/exim/files/exim-4.20-maildir.patch 
b/mail-mta/exim/files/exim-4.20-maildir.patch
new file mode 100644
index 0000000..3cb198d
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.20-maildir.patch
@@ -0,0 +1,14 @@
+diff -urN ./exim-4.20.orig/src/configure.default 
exim-4.20/src/configure.default
+--- ./exim-4.20.orig/src/configure.default     2003-06-27 16:48:22.000000000 
-0700
++++ exim-4.20/src/configure.default    2003-06-27 16:52:20.000000000 -0700
+@@ -451,7 +451,9 @@
+ 
+ local_delivery:
+   driver = appendfile
+-  file = /var/mail/$local_part
++#  file = /var/mail/$local_part
++  directory = /home/$local_part/.maildir
++  maildir_format
+   delivery_date_add
+   envelope_to_add
+   return_path_add

diff --git a/mail-mta/exim/files/exim-4.69-r1.27021.patch 
b/mail-mta/exim/files/exim-4.69-r1.27021.patch
new file mode 100644
index 0000000..804e16d
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.69-r1.27021.patch
@@ -0,0 +1,48 @@
+diff -urN exim-4.69.orig/src/configure.default exim-4.69/src/configure.default
+--- exim-4.69.orig/src/configure.default       2008-05-05 10:17:44.000000000 
+0100
++++ exim-4.69/src/configure.default    2008-05-05 10:18:26.000000000 +0100
+@@ -592,6 +592,22 @@
+   pipe_transport = address_pipe
+   reply_transport = address_reply
+ 
++# This router runs procmail if users have a .procmailrc file
++procmail:
++  check_local_user
++  driver = accept
++  transport = procmail_pipe
++  require_files = 
${local_part}:+${home}:+${home}/.procmailrc:+/usr/bin/procmail
++  no_verify
++ 
++# This router runs maildrop if users have a .mailfilter file
++maildrop:
++  check_local_user
++  driver = accept
++  transport = maildrop_pipe
++  require_files = 
${local_part}:+${home}:+${home}/.mailfilter:+/usr/bin/maildrop
++  no_verify
++
+ 
+ # This router matches local user mailboxes. If the router fails, the error
+ # message is "Unknown user".
+@@ -676,6 +692,21 @@
+ address_reply:
+   driver = autoreply
+ 
++# This transport is used for procmail
++procmail_pipe:
++  driver = pipe
++  command = "/usr/bin/procmail -d ${local_part}"
++  return_path_add
++  delivery_date_add
++  envelope_to_add
++
++# This transport is used for courier-maildrop filtering (Maildir filter 
system)
++maildrop_pipe:
++  driver = pipe
++  command = "/usr/bin/maildrop -d ${local_part}"
++  return_path_add
++  delivery_date_add
++  envelope_to_add
+ 
+ 
+ ######################################################################

diff --git a/mail-mta/exim/files/exim-4.74-localscan_dlopen.patch 
b/mail-mta/exim/files/exim-4.74-localscan_dlopen.patch
new file mode 100644
index 0000000..3bb57c1
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.74-localscan_dlopen.patch
@@ -0,0 +1,262 @@
+diff -Naur exim-4.32/src/EDITME exim-4.32-dlopen/src/EDITME
+--- src/EDITME 2004-04-15 08:27:01.000000000 +0000
++++ src/EDITME 2004-05-06 16:15:47.000000000 +0000
+@@ -505,6 +505,24 @@
+ 
+ 
+ 
#------------------------------------------------------------------------------
++# On systems which support dynamic loading of shared libraries, Exim can
++# load a local_scan function specified in its config file instead of having
++# to be recompiled with the desired local_scan function. For a full
++# description of the API to this function, see the Exim specification.
++
++DLOPEN_LOCAL_SCAN=yes
++
++# If you set DLOPEN_LOCAL_SCAN, then you need to include -rdynamic in the
++# linker flags.  Without it, the loaded .so won't be able to access any
++# functions from exim.
++
++LFLAGS = -rdynamic
++ifeq ($(OSTYPE),Linux)
++LFLAGS += -ldl
++endif
++
++
++#------------------------------------------------------------------------------
+ # The default distribution of Exim contains only the plain text form of the
+ # documentation. Other forms are available separately. If you want to install
+ # the documentation in "info" format, first fetch the Texinfo documentation
+diff -Naur exim-4.32/src/config.h.defaults 
exim-4.32-dlopen/src/config.h.defaults
+--- src/config.h.defaults      2004-04-15 08:27:01.000000000 +0000
++++ src/config.h.defaults      2004-05-06 16:16:30.000000000 +0000
+@@ -20,6 +20,8 @@
+ #define AUTH_PLAINTEXT
+ #define AUTH_SPA
+ 
++#define DLOPEN_LOCAL_SCAN
++
+ #define BIN_DIRECTORY
+ 
+ #define CONFIGURE_FILE
+diff -Naur exim-4.32/src/globals.c exim-4.32-dlopen/src/globals.c
+--- src/globals.c      2004-04-15 08:27:01.000000000 +0000
++++ src/globals.c      2004-05-06 16:17:07.000000000 +0000
+@@ -109,6 +109,10 @@
+ uschar *tls_verify_hosts       = NULL;
+ #endif
+ 
++#ifdef DLOPEN_LOCAL_SCAN
++uschar *local_scan_path        = NULL;
++#endif
++
+ 
+ /* Input-reading functions for messages, so we can use special ones for
+ incoming TCP/IP. The defaults use stdin. We never need these for any
+diff -Naur exim-4.32/src/globals.h exim-4.32-dlopen/src/globals.h
+--- src/globals.h      2004-04-15 08:27:01.000000000 +0000
++++ src/globals.h      2004-05-06 16:17:50.000000000 +0000
+@@ -73,6 +73,9 @@
+ extern uschar *tls_verify_hosts;       /* Mandatory client verification */
+ #endif
+ 
++#ifdef DLOPEN_LOCAL_SCAN
++extern uschar *local_scan_path;        /* Path to local_scan() library */
++#endif
+ 
+ /* Input-reading functions for messages, so we can use special ones for
+ incoming TCP/IP. */
+diff -Naur exim-4.32/src/local_scan.c exim-4.32-dlopen/src/local_scan.c
+--- src/local_scan.c   2004-04-15 08:27:01.000000000 +0000
++++ src/local_scan.c   2004-05-06 16:21:57.000000000 +0000
+@@ -5,60 +5,131 @@
+ /* Copyright (c) University of Cambridge 1995 - 2004 */
+ /* See the file NOTICE for conditions of use and distribution. */
+ 
++#include "exim.h"
+ 
+-/******************************************************************************
+-This file contains a template local_scan() function that just returns ACCEPT.
+-If you want to implement your own version, you should copy this file to, say
+-Local/local_scan.c, and edit the copy. To use your version instead of the
+-default, you must set
+-
+-LOCAL_SCAN_SOURCE=Local/local_scan.c
+-
+-in your Local/Makefile. This makes it easy to copy your version for use with
+-subsequent Exim releases.
+-
+-For a full description of the API to this function, see the Exim 
specification.
+-******************************************************************************/
+-
+-
+-/* This is the only Exim header that you should include. The effect of
+-including any other Exim header is not defined, and may change from release to
+-release. Use only the documented interface! */
+-
+-#include "local_scan.h"
+-
+-
+-/* This is a "do-nothing" version of a local_scan() function. The arguments
+-are:
+-
+-  fd             The file descriptor of the open -D file, which contains the
+-                   body of the message. The file is open for reading and
+-                   writing, but modifying it is dangerous and not recommended.
+-
+-  return_text    A pointer to an unsigned char* variable which you can set in
+-                   order to return a text string. It is initialized to NULL.
+-
+-The return values of this function are:
+-
+-  LOCAL_SCAN_ACCEPT
+-                 The message is to be accepted. The return_text argument is
+-                   saved in $local_scan_data.
+-
+-  LOCAL_SCAN_REJECT
+-                 The message is to be rejected. The returned text is used
+-                   in the rejection message.
+-
+-  LOCAL_SCAN_TEMPREJECT
+-                 This specifies a temporary rejection. The returned text
+-                   is used in the rejection message.
+-*/
++#ifdef DLOPEN_LOCAL_SCAN
++#include <dlfcn.h>
++static int (*local_scan_fn)(int fd, uschar **return_text) = NULL;
++static int load_local_scan_library(void);
++#endif
+ 
+ int
+ local_scan(int fd, uschar **return_text)
+ {
+ fd = fd;                      /* Keep picky compilers happy */
+ return_text = return_text;
+-return LOCAL_SCAN_ACCEPT;
++#ifdef DLOPEN_LOCAL_SCAN
++/* local_scan_path is defined AND not the empty string */
++if (local_scan_path && *local_scan_path)
++  {
++  if (!local_scan_fn)
++    {
++    if (!load_local_scan_library())
++      {
++        char *base_msg , *error_msg , *final_msg ;
++        int final_length = -1 ;
++
++        base_msg=US"Local configuration error - local_scan() library 
failure\n";
++        error_msg = dlerror() ;
++
++        final_length = strlen(base_msg) + strlen(error_msg) + 1 ;
++        final_msg = (char*)malloc( final_length*sizeof(char) ) ;
++        *final_msg = '\0' ;
++
++        strcat( final_msg , base_msg ) ;
++        strcat( final_msg , error_msg ) ;
++
++        *return_text = final_msg ;
++      return LOCAL_SCAN_TEMPREJECT;
++      }
++    }
++    return local_scan_fn(fd, return_text);
++  }
++else
++#endif
++  return LOCAL_SCAN_ACCEPT;
++}
++
++#ifdef DLOPEN_LOCAL_SCAN
++
++static int load_local_scan_library(void)
++{
++/* No point in keeping local_scan_lib since we'll never dlclose() anyway */
++void *local_scan_lib = NULL;
++int (*local_scan_version_fn)(void);
++int vers_maj;
++int vers_min;
++
++local_scan_lib = dlopen(local_scan_path, RTLD_NOW);
++if (!local_scan_lib)
++  {
++  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library open failed - "
++    "message temporarily rejected");
++  return FALSE;
++  }
++
++local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_major");
++if (!local_scan_version_fn)
++  {
++  dlclose(local_scan_lib);
++  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
++    "local_scan_version_major() function - message temporarily rejected");
++  return FALSE;
++  }
++
++/* The major number is increased when the ABI is changed in a non
++   backward compatible way. */
++vers_maj = local_scan_version_fn();
++
++local_scan_version_fn = dlsym(local_scan_lib, "local_scan_version_minor");
++if (!local_scan_version_fn)
++  {
++  dlclose(local_scan_lib);
++  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
++    "local_scan_version_minor() function - message temporarily rejected");
++  return FALSE;
++  }
++
++/* The minor number is increased each time a new feature is added (in a
++   way that doesn't break backward compatibility) -- Marc */
++vers_min = local_scan_version_fn();
++
++
++if (vers_maj != LOCAL_SCAN_ABI_VERSION_MAJOR)
++  {
++  dlclose(local_scan_lib);
++  local_scan_lib = NULL;
++  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible major"
++    "version number, you need to recompile your module for this version"
++    "of exim (The module was compiled for version %d.%d and this exim 
provides"
++    "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
++    LOCAL_SCAN_ABI_VERSION_MINOR);
++  return FALSE;
++  }
++else if (vers_min > LOCAL_SCAN_ABI_VERSION_MINOR)
++  {
++  dlclose(local_scan_lib);
++  local_scan_lib = NULL;
++  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() has an incompatible minor"
++    "version number, you need to recompile your module for this version"
++    "of exim (The module was compiled for version %d.%d and this exim 
provides"
++    "ABI version %d.%d)", vers_maj, vers_min, LOCAL_SCAN_ABI_VERSION_MAJOR,
++    LOCAL_SCAN_ABI_VERSION_MINOR);
++  return FALSE;
++  }
++
++local_scan_fn = dlsym(local_scan_lib, "local_scan");
++if (!local_scan_fn)
++  {
++  dlclose(local_scan_lib);
++  log_write(0, LOG_MAIN|LOG_REJECT, "local_scan() library doesn't contain "
++    "local_scan() function - message temporarily rejected");
++  return FALSE;
++  }
++
++return TRUE;
+ }
+ 
++#endif /* DLOPEN_LOCAL_SCAN */
++
+ /* End of local_scan.c */
+diff -Naur exim-4.32/src/readconf.c exim-4.32-dlopen/src/readconf.c
+--- src/readconf.c     2004-04-15 08:27:01.000000000 +0000
++++ src/readconf.c     2004-05-06 16:23:12.000000000 +0000
+@@ -223,6 +223,9 @@
+   { "local_from_prefix",        opt_stringptr,   &local_from_prefix },
+   { "local_from_suffix",        opt_stringptr,   &local_from_suffix },
+   { "local_interfaces",         opt_stringptr,   &local_interfaces },
++#ifdef DLOPEN_LOCAL_SCAN
++  { "local_scan_path",          opt_stringptr,   &local_scan_path },
++#endif
+   { "local_scan_timeout",       opt_time,        &local_scan_timeout },
+   { "local_sender_retain",      opt_bool,        &local_sender_retain },
+   { "localhost_number",         opt_stringptr,   &host_number_string },

diff --git a/mail-mta/exim/files/exim-4.74-radius-db-ENV-clash.patch 
b/mail-mta/exim/files/exim-4.74-radius-db-ENV-clash.patch
new file mode 100644
index 0000000..247668e
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.74-radius-db-ENV-clash.patch
@@ -0,0 +1,22 @@
+Nasty workaround for
+http://bugs.gentoo.org/show_bug.cgi?id=287426
+
+--- src/auths/call_radius.c
++++ src/auths/call_radius.c
+@@ -10,6 +10,16 @@
+ /* This file was originally supplied by Ian Kirk. The libradius support came
+ from Alex Kiernan. */
+ 
++/* ugly hack to work around redefinition of ENV by radiusclient.h and
++ * db.h: define _DB_H_ so the db.h include thinks it's already included,
++ * we can get away with it like this, since this file doesn't use any db
++ * functions. */
++#ifndef _DB_H_
++#define _DB_H_ 1
++#define _DB_EXT_PROT_IN_ 1
++#define DB void
++#endif
++
+ #include "../exim.h"
+ 
+ /* This module contains functions that call the Radius authentication

diff --git a/mail-mta/exim/files/exim-4.76-crosscompile.patch 
b/mail-mta/exim/files/exim-4.76-crosscompile.patch
new file mode 100644
index 0000000..cf47ade
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.76-crosscompile.patch
@@ -0,0 +1,15 @@
+https://bugs.gentoo.org/show_bug.cgi?id=266591
+
+--- OS/Makefile-Base
++++ OS/Makefile-Base
+@@ -114,8 +114,8 @@
+ 
+ # Targets for special-purpose configuration header builders
+ buildconfig: buildconfig.c
+-      @echo "$(CC) buildconfig.c"
+-      $(FE)$(CC) $(CFLAGS) $(INCLUDE) -o buildconfig buildconfig.c $(LIBS)
++      @echo "$(HOSTCC) buildconfig.c"
++      $(FE)$(HOSTCC) $(HOSTCFLAGS) $(INCLUDE) -o buildconfig buildconfig.c 
$(LIBS)
+ 
+ 
+ # Target for the exicyclog utility script

diff --git a/mail-mta/exim/files/exim-4.76-dsn.patch 
b/mail-mta/exim/files/exim-4.76-dsn.patch
new file mode 100644
index 0000000..8a608ba
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.76-dsn.patch
@@ -0,0 +1,18 @@
+http://bugs.gentoo.org/show_bug.cgi?id=366835
+https://sourceforge.net/tracker/?func=detail&aid=3300653&group_id=121058&atid=689120
+
+--- exim_469_dsn_1_3.patch
++++ exim_469_dsn_1_3.patch
+@@ -524,10 +524,10 @@
+ diff -urN exim-4.69-orig/src/readconf.c exim-4.69-dsn/src/readconf.c
+ --- exim-4.69-orig/src/readconf.c     2007-08-23 12:01:49.000000000 +0100
+ +++ exim-4.69-dsn/src/readconf.c      2008-07-28 09:52:55.000000000 +0100
+-@@ -207,6 +207,9 @@
+-   { "dns_ipv4_lookup",          opt_stringptr,   &dns_ipv4_lookup },
++@@ -219,6 +219,9 @@
+    { "dns_retrans",              opt_time,        &dns_retrans },
+    { "dns_retry",                opt_int,         &dns_retry },
++   { "dns_use_edns0",            opt_int,         &dns_use_edns0 },
+ +#ifdef SUPPORT_DSN
+ +  { "dsn",                      opt_bool,        &dsn },
+ +#endif

diff --git a/mail-mta/exim/files/exim-4.77-as-needed-ldflags.patch 
b/mail-mta/exim/files/exim-4.77-as-needed-ldflags.patch
new file mode 100644
index 0000000..4eac9aa
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.77-as-needed-ldflags.patch
@@ -0,0 +1,144 @@
+https://bugs.gentoo.org/show_bug.cgi?id=352265
+
+Make sure LDFLAGS comes first, such that all libraries are considered,
+and not discarded when --as-needed is in effect.
+
+https://bugs.gentoo.org/show_bug.cgi?id=391279
+
+Use LDFLAGS for all targets, not just the exim binary, such that
+--as-needed works as well.
+
+
+--- OS/Makefile-Base
++++ OS/Makefile-Base
+@@ -327,12 +327,12 @@
+       $(FE)$(CC) -c $(CFLAGS) $(INCLUDE) $(IPV6_INCLUDE) $(TLS_INCLUDE) 
version.c
+       rm -f exim
+       @echo "$(LNCC) -o exim"
+-      $(FE)$(PURIFY) $(LNCC) -o exim $(LFLAGS) $(OBJ_EXIM) version.o \
++      $(FE)$(PURIFY) $(LNCC) -o exim $(LDFLAGS) $(OBJ_EXIM) version.o \
+         routers/routers.a transports/transports.a lookups/lookups.a \
+         auths/auths.a pdkim/pdkim.a \
+         $(LIBRESOLV) $(LIBS) $(LIBS_EXIM) $(IPV6_LIBS) $(EXTRALIBS) \
+         $(EXTRALIBS_EXIM) $(DBMLIB) $(LOOKUP_LIBS) $(AUTH_LIBS) \
+-        $(PERL_LIBS) $(TLS_LIBS) $(PCRE_LIBS) $(LDFLAGS)
++        $(PERL_LIBS) $(TLS_LIBS) $(PCRE_LIBS) $(LFLAGS)
+       @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+         echo $(STRIP_COMMAND) exim; \
+         $(STRIP_COMMAND) exim; \
+@@ -340,8 +340,8 @@
+ 
+ exim_dumpdb: $(OBJ_DUMPDB)
+       @echo "$(LNCC) -o exim_dumpdb"
+-      $(FE)$(LNCC) $(CFLAGS) $(INCLUDE) -o exim_dumpdb $(LFLAGS) 
$(OBJ_DUMPDB) \
+-        $(LIBS) $(EXTRALIBS) $(DBMLIB)
++      $(FE)$(LNCC) $(CFLAGS) $(INCLUDE) -o exim_dumpdb $(LDFLAGS) 
$(OBJ_DUMPDB) \
++        $(LIBS) $(EXTRALIBS) $(DBMLIB) $(LFLAGS)
+       @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+         echo $(STRIP_COMMAND) exim_dumpdb; \
+         $(STRIP_COMMAND) exim_dumpdb; \
+@@ -355,8 +355,8 @@
+ 
+ exim_fixdb:  $(OBJ_FIXDB) auths/auths.a
+       @echo "$(LNCC) -o exim_fixdb"
+-      $(FE)$(LNCC) $(CFLAGS) $(INCLUDE) -o exim_fixdb $(LFLAGS) $(OBJ_FIXDB) \
+-        auths/auths.a $(LIBS) $(EXTRALIBS) $(DBMLIB)
++      $(FE)$(LNCC) $(CFLAGS) $(INCLUDE) -o exim_fixdb $(LDFLAGS) $(OBJ_FIXDB) 
\
++        auths/auths.a $(LIBS) $(EXTRALIBS) $(DBMLIB) $(LFLAGS)
+       @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+         echo $(STRIP_COMMAND) exim_fixdb; \
+         $(STRIP_COMMAND) exim_fixdb; \
+@@ -370,8 +370,8 @@
+ 
+ exim_tidydb: $(OBJ_TIDYDB)
+       @echo "$(LNCC) -o exim_tidydb"
+-      $(FE)$(LNCC) $(CFLAGS) $(INCLUDE) -o exim_tidydb $(LFLAGS) 
$(OBJ_TIDYDB) \
+-        $(LIBS) $(EXTRALIBS) $(DBMLIB)
++      $(FE)$(LNCC) $(CFLAGS) $(INCLUDE) -o exim_tidydb $(LDFLAGS) 
$(OBJ_TIDYDB) \
++        $(LIBS) $(EXTRALIBS) $(DBMLIB) $(LFLAGS)
+       @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+         echo $(STRIP_COMMAND) exim_tidydb; \
+         $(STRIP_COMMAND) exim_tidydb; \
+@@ -383,8 +383,8 @@
+ 
+ exim_dbmbuild: exim_dbmbuild.o
+       @echo "$(LNCC) -o exim_dbmbuild"
+-      $(FE)$(LNCC) -o exim_dbmbuild $(LFLAGS) exim_dbmbuild.o \
+-        $(LIBS) $(EXTRALIBS) $(DBMLIB)
++      $(FE)$(LNCC) -o exim_dbmbuild $(LDFLAGS) exim_dbmbuild.o \
++        $(LIBS) $(EXTRALIBS) $(DBMLIB) $(LFLAGS)
+       @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+         echo $(STRIP_COMMAND) exim_dbmbuild; \
+         $(STRIP_COMMAND) exim_dbmbuild; \
+@@ -398,8 +398,8 @@
+       @echo "$(CC) exim_lock.c"
+       $(FE)$(CC) -c $(CFLAGS) $(INCLUDE) exim_lock.c
+       @echo "$(LNCC) -o exim_lock"
+-      $(FE)$(LNCC) -o exim_lock $(LFLAGS) exim_lock.o  \
+-        $(LIBS) $(EXTRALIBS)
++      $(FE)$(LNCC) -o exim_lock $(LDFLAGS) exim_lock.o  \
++        $(LIBS) $(EXTRALIBS) $(LFLAGS)
+       @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+         echo $(STRIP_COMMAND) exim_lock; \
+         $(STRIP_COMMAND) exim_lock; \
+@@ -429,9 +429,9 @@
+       $(FE)$(CC) -o em_version.o -c \
+         $(CFLAGS) $(XINCLUDE) -I. ../exim_monitor/em_version.c
+       @echo "$(LNCC) -o eximon.bin"
+-      $(FE)$(PURIFY) $(LNCC) -o eximon.bin em_version.o $(LFLAGS) $(XLFLAGS) \
++      $(FE)$(PURIFY) $(LNCC) -o eximon.bin em_version.o $(LDFLAGS) $(XLFLAGS) 
\
+       $(OBJ_MONBIN) -lXaw -lXmu -lXt -lXext -lX11 $(PCRE_LIBS) \
+-        $(LIBS) $(LIBS_EXIMON) $(EXTRALIBS) $(EXTRALIBS_EXIMON) -lc
++        $(LIBS) $(LIBS_EXIMON) $(EXTRALIBS) $(EXTRALIBS_EXIMON) -lc $(LFLAGS)
+       @if [ x"$(STRIP_COMMAND)" != x"" ]; then \
+         echo $(STRIP_COMMAND) eximon.bin; \
+         $(STRIP_COMMAND) eximon.bin; \
+@@ -706,9 +706,9 @@
+ test_dbfn:   config.h dbfn.c dummies.o sa-globals.o sa-os.o store.o \
+              string.o tod.o version.o
+       $(CC) -c $(CFLAGS) $(INCLUDE) -DSTAND_ALONE dbfn.c
+-      $(LNCC) -o test_dbfn $(LFLAGS) dbfn.o \
++      $(LNCC) -o test_dbfn $(LDFLAGS) dbfn.o \
+         dummies.o sa-globals.o sa-os.o store.o string.o \
+-        tod.o version.o $(LIBS) $(DBMLIB)
++        tod.o version.o $(LIBS) $(DBMLIB) $(LFLAGS)
+       rm -f dbfn.o
+ 
+ test_host:   config.h child.c host.c dns.c dummies.c sa-globals.o os.o \
+@@ -717,28 +717,28 @@
+       $(CC) -c $(CFLAGS) $(INCLUDE) -DSTAND_ALONE -DTEST_HOST host.c
+       $(CC) -c $(CFLAGS) $(INCLUDE) -DSTAND_ALONE -DTEST_HOST dns.c
+       $(CC) -c $(CFLAGS) $(INCLUDE) -DSTAND_ALONE -DTEST_HOST dummies.c
+-      $(LNCC) -o test_host $(LFLAGS) \
++      $(LNCC) -o test_host $(LDFLAGS) \
+         host.o child.o dns.o dummies.o sa-globals.o os.o store.o string.o \
+-        tod.o tree.o $(LIBS) $(LIBRESOLV)
++        tod.o tree.o $(LIBS) $(LIBRESOLV) $(LFLAGS)
+       rm -f child.o dummies.o host.o dns.o
+ 
+ test_os:     os.h os.c dummies.o sa-globals.o store.o string.o tod.o
+       $(CC) -c $(CFLAGS) $(INCLUDE) -DSTAND_ALONE os.c
+-      $(LNCC) -o test_os $(LFLAGS) os.o dummies.o \
+-        sa-globals.o store.o string.o tod.o $(LIBS)
++      $(LNCC) -o test_os $(LDFLAGS) os.o dummies.o \
++        sa-globals.o store.o string.o tod.o $(LIBS) $(LFLAGS)
+       rm -f os.o
+ 
+ test_parse:  config.h parse.c dummies.o sa-globals.o \
+            store.o string.o tod.o version.o
+       $(CC) -c $(CFLAGS) $(INCLUDE) -DSTAND_ALONE parse.c
+-      $(LNCC) -o test_parse $(LFLAGS) parse.o \
+-        dummies.o sa-globals.o store.o string.o tod.o version.o
++      $(LNCC) -o test_parse $(LDFLAGS) parse.o \
++        dummies.o sa-globals.o store.o string.o tod.o version.o $(LFLAGS)
+       rm -f parse.o
+ 
+ test_string: config.h string.c dummies.o sa-globals.o store.o tod.o
+       $(CC) -c $(CFLAGS) $(INCLUDE) -DSTAND_ALONE string.c
+-      $(LNCC) -o test_string $(LFLAGS) -DSTAND_ALONE string.o \
+-        dummies.o sa-globals.o store.o tod.o $(LIBS)
++      $(LNCC) -o test_string $(LDFLAGS) -DSTAND_ALONE string.o \
++        dummies.o sa-globals.o store.o tod.o $(LIBS) $(LFLAGS)
+       rm -f string.o
+ 
+ # End

diff --git a/mail-mta/exim/files/exim-4.77-makefile-freebsd.patch 
b/mail-mta/exim/files/exim-4.77-makefile-freebsd.patch
new file mode 100644
index 0000000..f3c0332
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.77-makefile-freebsd.patch
@@ -0,0 +1,48 @@
+--- OS/Makefile-FreeBSD
++++ OS/Makefile-FreeBSD
+@@ -1,12 +1,10 @@
+-# Exim: OS-specific make file for FreeBSD
+-# There's no setting of CFLAGS here, to allow the system default
+-# for "make" to be the default.
+-
+-PORTOBJFORMAT!= test -x /usr/bin/objformat && /usr/bin/objformat || echo aout
+-
+-CHOWN_COMMAND=/usr/sbin/chown
+-STRIP_COMMAND=/usr/bin/strip
+-CHMOD_COMMAND=/bin/chmod
++# Exim: OS-specific FreeBSD make file, modified for Gentoo Prefix
++
++
++BASENAME_COMMAND=look_for_it
++CHOWN_COMMAND=look_for_it
++CHGRP_COMMAND=look_for_it
++CHMOD_COMMAND=look_for_it
+ 
+ HAVE_SA_LEN=YES
+ 
+@@ -18,23 +16,12 @@
+ # Dynamicly loaded modules need to be built with -fPIC
+ CFLAGS_DYNAMIC=-shared -rdynamic -fPIC
+ 
+-# FreeBSD always ships with Berkeley DB
++DBMLIB = -ldb
+ USE_DB=yes
+ 
+-# This code for building outside ports suggested by Richard Clayton
+-.ifdef   X11BASE
+-X11=${X11BASE}
+-.elifdef LOCALBASE
+-X11=$(LOCALBASE)
+-.else
+-X11=/usr/local
+-.endif
+-
++X11=/usr/X11R6
+ XINCLUDE=-I$(X11)/include
+ XLFLAGS=-L$(X11)/lib
+-.if ${PORTOBJFORMAT} == "elf"
+-XLFLAGS+=-Wl,-rpath,${X11}/lib
+-.endif
+ X11_LD_LIB=$(X11)/lib
+ 
+ EXIWHAT_PS_ARG=-ax

diff --git a/mail-mta/exim/files/exim-4.80-spool-mail-group.patch 
b/mail-mta/exim/files/exim-4.80-spool-mail-group.patch
new file mode 100644
index 0000000..6f88d85
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.80-spool-mail-group.patch
@@ -0,0 +1,27 @@
+Change default such that we run on a stock Gentoo system.  Bug #438606
+
+--- src/configure.default
++++ src/configure.default
+@@ -674,8 +674,9 @@
+ # BSD mailbox format. By default it will be run under the uid and gid of the
+ # local user, and requires the sticky bit to be set on the /var/mail 
directory.
+ # Some systems use the alternative approach of running mail deliveries under a
+-# particular group instead of using the sticky bit. The commented options 
below
+-# show how this can be done.
++# particular group instead of using the sticky bit. This is also the
++# default case on Gentoo, therefore group and mode are set below.
++# Comment them out, to get the default behaviour.
+ 
+ local_delivery:
+   driver = appendfile
+@@ -683,8 +684,8 @@
+   delivery_date_add
+   envelope_to_add
+   return_path_add
+-# group = mail
+-# mode = 0660
++  group = mail
++  mode = 0660
+ 
+ 
+ # This transport is used for handling pipe deliveries generated by alias or

diff --git a/mail-mta/exim/files/exim-4.82-makefile-freebsd.patch 
b/mail-mta/exim/files/exim-4.82-makefile-freebsd.patch
new file mode 100644
index 0000000..9693d49
--- /dev/null
+++ b/mail-mta/exim/files/exim-4.82-makefile-freebsd.patch
@@ -0,0 +1,45 @@
+--- OS/Makefile-FreeBSD.orig   2013-09-30 19:59:09.000000000 +0200
++++ OS/Makefile-FreeBSD        2013-09-30 20:01:22.000000000 +0200
+@@ -1,10 +1,8 @@
+-# Exim: OS-specific make file for FreeBSD
+-# There's no setting of CFLAGS here, to allow the system default
+-# for "make" to be the default.
+-
+-CHOWN_COMMAND=/usr/sbin/chown
+-STRIP_COMMAND=/usr/bin/strip
+-CHMOD_COMMAND=/bin/chmod
++# Exim: OS-specific FreeBSD make file, modified for Gentoo Prefix
++
++CHOWN_COMMAND=look_for_it
++STRIP_COMMAND=
++CHMOD_COMMAND=look_for_it
+ 
+ HAVE_SA_LEN=YES
+ 
+@@ -15,17 +13,9 @@
+ CFLAGS_DYNAMIC=-shared -rdynamic -fPIC
+ 
+ # FreeBSD always ships with Berkeley DB
++DBMLIB = -ldb
+ USE_DB=yes
+ 
+-# This code for building outside ports suggested by Richard Clayton
+-.ifdef   X11BASE
+-X11=${X11BASE}
+-.elifdef LOCALBASE
+-X11=$(LOCALBASE)
+-.else
+-X11=/usr/local
+-.endif
+-
+ # nb: FreeBSD is entirely elf; objformat was removed prior to FreeBSD 7
+ # 
http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/objformat/Attic/objformat.c
+ # deleted Jan 2007.
+@@ -37,6 +27,7 @@
+ # switch to default to ELF came with FreeBSD 3.  elf(5) claims ELF support
+ # introduced in FreeBSD 2.2.6.
+ #
++X11=/usr/X11R6
+ XINCLUDE=-I$(X11)/include
+ XLFLAGS=-L$(X11)/lib -Wl,-rpath,${X11}/lib
+ X11_LD_LIB=$(X11)/lib

diff --git a/mail-mta/exim/files/exim-submission.socket 
b/mail-mta/exim/files/exim-submission.socket
new file mode 100644
index 0000000..b9593e2
--- /dev/null
+++ b/mail-mta/exim/files/exim-submission.socket
@@ -0,0 +1,10 @@
+[Unit]
+Description=Exim Mail Transfer Agent (message submission)
+Conflicts=exim.service
+
+[Socket]
+ListenStream=587
+Accept=yes
+
+[Install]
+WantedBy=sockets.target

diff --git a/mail-mta/exim/files/exim-submission_at.service 
b/mail-mta/exim/files/exim-submission_at.service
new file mode 100644
index 0000000..4f90cd8
--- /dev/null
+++ b/mail-mta/exim/files/exim-submission_at.service
@@ -0,0 +1,11 @@
+# It doesn't make sense for this to be separate from [email protected]
+# However, I couldn't think of a way to have two .socket files point
+# to it ([Socket] Service= is rejected if Accept=yes is set).
+
+[Unit]
+Description=Exim Mail Daemon per-connection server (message submission)
+
+[Service]
+ExecStart=-/usr/bin/exim -bs
+StandardInput=socket
+StandardError=syslog

diff --git a/mail-mta/exim/files/exim.confd b/mail-mta/exim/files/exim.confd
new file mode 100644
index 0000000..1534d9d
--- /dev/null
+++ b/mail-mta/exim/files/exim.confd
@@ -0,0 +1,5 @@
+# Command-line options for running exim
+EXIM_OPTS="-bd -q15m"
+
+# Additional flags passed to exim_tidydb upon start (e.g. -t 7d)
+TIDY_OPTS=""

diff --git a/mail-mta/exim/files/exim.logrotate 
b/mail-mta/exim/files/exim.logrotate
new file mode 100644
index 0000000..f54f8c4
--- /dev/null
+++ b/mail-mta/exim/files/exim.logrotate
@@ -0,0 +1,9 @@
+/var/log/exim/exim*.log {
+       daily
+       missingok
+       rotate 28
+       compress
+       delaycompress
+       notifempty
+       create 640 mail mail
+}

diff --git a/mail-mta/exim/files/exim.rc8 b/mail-mta/exim/files/exim.rc8
new file mode 100644
index 0000000..f84d772
--- /dev/null
+++ b/mail-mta/exim/files/exim.rc8
@@ -0,0 +1,30 @@
+#!/sbin/runscript
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/mail-mta/exim/files/exim.rc8,v 1.1 
2013/10/08 18:16:18 grobian Exp $
+
+extra_started_commands="reload"
+
+depend() {
+       need logger
+       use antivirus net
+       provide mta
+}
+
+start() {
+       ebegin "Starting ${SVCNAME}"
+       start-stop-daemon --start --exec /usr/sbin/exim --pidfile 
/run/${SVCNAME}.pid -- -C /etc/exim/${SVCNAME}.conf ${EXIM_OPTS:--bd -q15m}
+       eend $?
+}
+
+stop() {
+       ebegin "Stopping ${SVCNAME}"
+       start-stop-daemon --stop --pidfile /run/${SVCNAME}.pid --name exim
+       eend $?
+}
+
+reload() {
+       ebegin "Reloading ${SVCNAME}"
+       start-stop-daemon --signal HUP --pidfile /run/${SVCNAME}.pid --name exim
+       eend $?
+}

diff --git a/mail-mta/exim/files/exim.rc9 b/mail-mta/exim/files/exim.rc9
new file mode 100644
index 0000000..c88f653
--- /dev/null
+++ b/mail-mta/exim/files/exim.rc9
@@ -0,0 +1,46 @@
+#!/sbin/runscript
+# Copyright 1999-2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/mail-mta/exim/files/exim.rc9,v 1.1 
2015/05/05 12:55:34 grobian Exp $
+
+extra_started_commands="reload"
+
+depend() {
+       need logger
+       use antivirus net
+       provide mta
+}
+
+tidy_dbs() {
+       local spooldir=$(/usr/sbin/exim -C /etc/exim/${SVCNAME}.conf -bP -n 
spool_directory)
+       local db
+       local ret=0
+       ebegin "Tidying hints databases in ${spooldir}/db"
+       for db in "${spooldir}"/db/* ; do
+               [[ ${db} == *".lockfile" || ${db} == *"*" ]] && continue
+               /usr/sbin/exim_tidydb ${TIDY_OPTS} "${spooldir}" ${db##*/} > 
/dev/null
+               : $((ret += $?))
+       done
+       eend ${ret}
+}
+
+start() {
+       # if you use multiple instances, make sure you set spool_directory
+       # in the configfile
+       tidy_dbs
+       ebegin "Starting ${SVCNAME}"
+       start-stop-daemon --start --exec /usr/sbin/exim --pidfile 
/run/${SVCNAME}.pid -- -C /etc/exim/${SVCNAME}.conf ${EXIM_OPTS:--bd -q15m}
+       eend $?
+}
+
+stop() {
+       ebegin "Stopping ${SVCNAME}"
+       start-stop-daemon --stop --pidfile /run/${SVCNAME}.pid --name exim
+       eend $?
+}
+
+reload() {
+       ebegin "Reloading ${SVCNAME}"
+       start-stop-daemon --signal HUP --pidfile /run/${SVCNAME}.pid --name exim
+       eend $?
+}

diff --git a/mail-mta/exim/files/exim.service b/mail-mta/exim/files/exim.service
new file mode 100644
index 0000000..c8a61cd
--- /dev/null
+++ b/mail-mta/exim/files/exim.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Exim Mail Transport Agent
+After=network.target
+
+[Service]
+Environment=QUEUE=15m
+ExecStart=/usr/sbin/exim -bdf -q${QUEUE}
+ExecReload=/bin/kill -HUP $MAINPID
+PrivateTmp=true
+
+[Install]
+WantedBy=multi-user.target

diff --git a/mail-mta/exim/files/exim.socket b/mail-mta/exim/files/exim.socket
new file mode 100644
index 0000000..36d2868
--- /dev/null
+++ b/mail-mta/exim/files/exim.socket
@@ -0,0 +1,10 @@
+[Unit]
+Description=Exim Mail Transfer Agent
+Conflicts=exim.service
+
+[Socket]
+ListenStream=25
+Accept=yes
+
+[Install]
+WantedBy=sockets.target

diff --git a/mail-mta/exim/files/exim_482_dsn_1_3.patch 
b/mail-mta/exim/files/exim_482_dsn_1_3.patch
new file mode 100644
index 0000000..c300699
--- /dev/null
+++ b/mail-mta/exim/files/exim_482_dsn_1_3.patch
@@ -0,0 +1,1212 @@
+Modified for 4.82 by Gentoo -- not the official patch from
+http://sourceforge.net/projects/eximdsn/
+
+diff -Naur exim-4.82_RC5.orig/README.DSN exim-4.82_RC5/README.DSN
+--- exim-4.82_RC5.orig/README.DSN      1970-01-01 01:00:00.000000000 +0100
++++ exim-4.82_RC5/README.DSN   2013-10-27 21:47:32.000000000 +0100
+@@ -0,0 +1,118 @@
++Exim DSN Patch (4.76)
++---------------------
++
++This patch 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 patch 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 patch; if not, write to the Free Software
++Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
++
++Install
++-------
++cd into the source tree for a vanilla exim
++
++patch -p1 </path/to/patch/file.patch
++
++Example :-
++[root@linuxbuild exim-4.72-test]# patch -p1 <../exim.dsn.patch-472
++
++Expected Output :-
++patching file README.DSN
++patching file src/config.h.defaults
++patching file src/deliver.c
++patching file src/exim.c
++patching file src/exim.h
++patching file src/globals.c
++patching file src/globals.h
++patching file src/local_scan.h
++patching file src/macros.h
++patching file src/readconf.c
++patching file src/route.c
++patching file src/smtp_in.c
++patching file src/spool_in.c
++patching file src/spool_out.c
++patching file src/structs.h
++patching file src/transport.c
++patching file src/transports/smtp.c
++
++
++This patch can be included / excluded from the compilation by use of the 
#define SUPPORT_DSN
++which gets added into src/config.h.defaults & src/EDITME by the patch.
++
++Use
++---
++
++The facility (once compiled in) can be turned on for a particular router via 
the
++dsn_process directive Eg :-
++
++dest_delivery_int:
++  driver = manualroute
++  domains = +relay_to_domains
++  condition = ${if eq {${lc:$sender_address_domain}}\
++                                 {domain.com}\
++                                 {yes}{no}\
++                       }
++  dsn_process
++  hide route_data = ${lc:${extract{mailHost}{$address_data}{$value}{}}}
++  transport = remote_smtp
++
++Exim will produce 1 of 2 DSN's back to the originator, or pass on the DSN 
request.
++The 2 DSN's will either contain (relayed via non "Remote SMTP" router) or
++(relayed to non-DSN-aware mailer) depending on if the delivery was VIA an SMTP
++transport or not.
++
++
++Credits
++-------
++
++The original work for the patch was done by Philip Hazel in Exim 3
++
++The extract was taken and re-applied to Exim 4 by the following :-
++Phil Bingham   ([email protected])
++Steve Falla    ([email protected])
++Ray Edah       ([email protected])
++Andrew Johnson ([email protected])
++Adrian Hungate ([email protected])
++
++Now Primarily maintained by :-
++Andrew Johnson ([email protected])
++
++Contributions
++-------------
++Andrey J. Melnikoff (TEMHOTA) ([email protected]) 
++
++
++ChangeLog
++---------
++
++14-Apr-2006 : Changed subject to "Delivery Status Notification"
++
++17-May-2006 : debug_printf in spool-in.c were not wrapped with #ifndef 
COMPILE_UTILITY
++              thanks to Andrey J. Melnikoff for this information
++
++12-Sep-2006 : Now supports Exim 4.63
++
++12-Sep-2006 : src/EDITME did not include the #define SUPPORT_DSN as stated
++              in the documentation, this has now been corrected
++              thanks to Robert Kehl for this information
++
++28-Jul-2008 : New version for exim 4.69 released.
++
++02-Jul-2010 : New version for exim 4.72 released.
++
++20-May-2011 : New version for exim 4.76 released.
++
++
++Support for this patch (limited though it is) will only be provided through 
the SourceForge
++project page (http://sourceforge.net/projects/eximdsn/)
++
++--
++Andrew Johnson Cable & Wireless
+diff -Naur exim-4.82_RC5.orig/src/config.h.defaults 
exim-4.82_RC5/src/config.h.defaults
+--- exim-4.82_RC5.orig/src/config.h.defaults   2013-10-27 21:46:25.000000000 
+0100
++++ exim-4.82_RC5/src/config.h.defaults        2013-10-27 21:47:32.000000000 
+0100
+@@ -136,6 +136,7 @@
+ #define SUPPORT_MOVE_FROZEN_MESSAGES
+ #define SUPPORT_PAM
+ #define SUPPORT_TLS
++#define SUPPORT_DSN
+ #define SUPPORT_TRANSLATE_IP_ADDRESS
+ 
+ #define SYSLOG_LOG_PID
+diff -Naur exim-4.82_RC5.orig/src/deliver.c exim-4.82_RC5/src/deliver.c
+--- exim-4.82_RC5.orig/src/deliver.c   2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/deliver.c        2013-10-27 21:47:32.000000000 +0100
+@@ -63,6 +63,9 @@
+ static address_item *addr_remote = NULL;
+ static address_item *addr_route = NULL;
+ static address_item *addr_succeed = NULL;
++#ifdef SUPPORT_DSN
++static address_item *addr_dsntmp = NULL;
++#endif
+ 
+ static FILE *message_log = NULL;
+ static BOOL update_spool;
+@@ -2966,6 +2969,15 @@
+       addr->flags |= af_prdr_used; break;
+ #endif
+ 
++    #ifdef SUPPORT_DSN
++    case 'D':
++    if (addr == NULL) break;
++    addr->dsn_aware = (*ptr)? string_copy(ptr) : string_copy(" ");
++    while (*ptr++);
++    DEBUG(D_deliver) debug_printf("DSN read: addr->dsn_aware = %s\n", 
addr->dsn_aware);
++    break;
++    #endif
++
+     case 'A':
+     if (addr == NULL)
+       {
+@@ -4074,6 +4086,15 @@
+       if (addr->flags & af_prdr_used) rmt_dlv_checked_write(fd, "P", 1);
+       #endif
+ 
++      #ifdef SUPPORT_DSN
++      if (addr->dsn_aware == NULL)
++        addr->dsn_aware = string_copy(" ");
++      DEBUG(D_deliver) debug_printf("DSN write: addr->dsn_aware = %s\n", 
addr->dsn_aware);     
++      sprintf(big_buffer, "D%s", addr->dsn_aware);
++      DEBUG(D_deliver) debug_printf("DSN write: big_buffer = %s (%d)\n", 
big_buffer, strlen(big_buffer)+1);
++      write(fd, big_buffer, strlen(big_buffer)+1);
++      #endif
++
+       /* Retry information: for most success cases this will be null. */
+ 
+       for (r = addr->retries; r != NULL; r = r->next)
+@@ -5219,6 +5240,14 @@
+       if (r->pno >= 0)
+         new->onetime_parent = recipients_list[r->pno].address;
+ 
++      #ifdef SUPPORT_DSN
++      /* If DSN support is enabled, set the dsn flags and the original 
receipt 
++         to be passed on to other DSN enabled MTAs */
++      new->dsn_flags = r->dsn_flags & rf_dsnflags;
++      new->dsn_orcpt = r->orcpt;
++      debug_printf("DSN (deliver): orcpt: %s  flags: %d\n", new->dsn_orcpt, 
new->dsn_flags);   
++      #endif
++
+       switch (process_recipients)
+         {
+         /* RECIP_DEFER is set when a system filter freezes a message. */
+@@ -6163,6 +6192,12 @@
+     regex_must_compile(US"\\n250[\\s\\-]PRDR(\\s|\\n|$)", FALSE, TRUE);
+   #endif
+ 
++  #ifdef SUPPORT_DSN
++  /* Set the regex to check for DSN support on remote MTA */
++  if (regex_DSN == NULL) regex_DSN  =
++    regex_must_compile(US"\\n250[\\s\\-]DSN(\\s|\\n|$)", FALSE, TRUE);
++  #endif
++
+   /* Now sort the addresses if required, and do the deliveries. The yield of
+   do_remote_deliveries is FALSE when mua_wrapper is set and all addresses
+   cannot be delivered in one transaction. */
+@@ -6267,6 +6302,179 @@
+ 
+ else if (!dont_deliver) retry_update(&addr_defer, &addr_failed, 
&addr_succeed);
+ 
++#ifdef SUPPORT_DSN
++/* ********** philb - Send DSN for successful messages */
++
++addr_dsntmp = addr_succeed;
++
++while(addr_dsntmp != NULL)
++{
++   BOOL dsn_sendmessage = FALSE;
++   uschar dsnmsgbuf[4096];
++ 
++   DEBUG(D_deliver)
++      debug_printf("DSN: processing router : %s\n", 
addr_dsntmp->router->name);
++
++   DEBUG(D_deliver)
++      debug_printf("DSN: processing successful delivery address: %s\n", 
addr_dsntmp->address);
++  
++   if (testflag(addr_dsntmp, af_ignore_error))
++   {   
++      DEBUG(D_deliver)
++         debug_printf("DSN: Ignore error for: %s\n", addr_dsntmp->address);
++   }
++   else
++   {
++     DEBUG(D_deliver) debug_printf("DSN: Checking Flag\n");    
++     if (addr_dsntmp->dsn_aware == NULL) {
++         DEBUG(D_deliver) debug_printf("DSN: dsn_aware was NULL, setting to 
space at %s %d\n", __FILE__, __LINE__);
++         addr_dsntmp->dsn_aware = string_copy(" ");
++     }
++     DEBUG(D_deliver) debug_printf("DSN: Sender_address: %s\n", 
sender_address);       
++     DEBUG(D_deliver) debug_printf("DSN: orcpt: %s  flags: %d\n", 
addr_dsntmp->dsn_orcpt, addr_dsntmp->dsn_flags);     
++     DEBUG(D_deliver) debug_printf("DSN: envid: %s  ret: %d\n", dsn_envid, 
dsn_ret);   
++     DEBUG(D_deliver) debug_printf("DSN: Remote SMTP server supports DSN: 
%s\n", addr_dsntmp->dsn_aware);      
++              
++      /* Process the flags */
++     if((addr_dsntmp->dsn_flags & rf_dsnflags) != 0) 
++     {
++         /* We've got at least one flag set */
++
++       /* set flag so we don't send bounces */
++       setflag(addr_dsntmp, af_ignore_error);
++
++       if((addr_dsntmp->dsn_flags & rf_notify_never) != 0)
++         {
++            DEBUG(D_deliver) debug_printf("DSN: NEVER FLAG\n");
++
++            /* nothing to do here */
++         }
++         
++         if((addr_dsntmp->dsn_flags & rf_notify_success) != 0)
++         {
++            DEBUG(D_deliver) debug_printf("DSN: SUCCESS FLAG\n");
++
++            dsn_sendmessage = TRUE;
++         }
++
++         if((addr_dsntmp->dsn_flags & rf_notify_failure) != 0)
++         {
++            DEBUG(D_deliver) debug_printf("DSN: FAILURE FLAG\n");
++
++            /* allow bounce messages */
++            clearflag(addr_dsntmp, af_ignore_error);
++         }
++
++         if((addr_dsntmp->dsn_flags & rf_notify_delay) != 0)
++         {
++            DEBUG(D_deliver) debug_printf("DSN: DELAY FLAG\n");
++
++            /* hmm, what to do here? */
++         }
++      }
++
++      if ((addr_dsntmp->dsn_aware != 0) && (addr_dsntmp->dsn_aware[0] != 'Y') 
&& (dsn_sendmessage == TRUE) && (addr_dsntmp->router->dsn_process == TRUE))
++      {
++         pid_t pid;
++         int fd;
++      
++       /* remote MTA does not support DSN, so we need to send message */
++       
++       /* create exim process to send message */       
++       pid = child_open_exim(&fd);
++
++         DEBUG(D_deliver) debug_printf("DSN: child_open_exim returns: %d\n", 
pid);
++       
++       if (pid < 0)  /* Creation of child failed */
++       {
++          log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Process %d (parent %d) failed 
to "
++               "create child process to send failure message: %s", getpid(),
++               getppid(), strerror(errno));
++
++             DEBUG(D_deliver) debug_printf("DSN: child_open_exim failed\n");
++
++         }     
++       else  /* Creation of child succeeded */
++       {
++           FILE *f = fdopen(fd, "wb");
++         int topt = topt_add_return_path;
++         uschar boundaryStr[64];
++         
++           DEBUG(D_deliver) debug_printf("sending error message to: %s\n", 
sender_address);
++      
++           /* build unique id for MIME boundary */
++           snprintf(boundaryStr, 63, "%d-cwdsn-%d", pid, rand());      
++           DEBUG(D_deliver) debug_printf("DSN: MIME boundary: %s\n", 
boundaryStr);
++      
++           /* if the sender doesn't want the whole message returned, don't 
send the body */
++           if (dsn_ret != dsn_ret_full) topt |= topt_no_body;
++      
++           if (errors_reply_to != NULL) fprintf(f,"Reply-To: %s\n", 
errors_reply_to);
++     
++         fprintf(f,"Auto-Submitted: auto-generated\n");
++         fprintf(f,"From: Mail Delivery System <Mailer-Daemon@%s>\n", 
qualify_domain_sender);
++         fprintf(f,"To: %s\n", sender_address);
++         fprintf(f,"Subject: Delivery Status Notification\n");
++         fprintf(f,"Content-Type: multipart/report; 
report-type=delivery-status; boundary=%s\n", boundaryStr);
++           fprintf(f,"MIME-Version: 1.0\n\n");
++
++           fprintf(f,"--%s\n", boundaryStr);
++         fprintf(f,"Content-type: text/plain; charset=us-ascii\n\n");
++         
++         fprintf(f,"This message was created automatically by mail delivery 
software.\n");
++         fprintf(f," ----- The following addresses had successful delivery 
notifications -----\n");
++/* AH: added specific message for non "Remote SMTP" situations */
++           if (addr_dsntmp->dsn_aware[0] == 'N') {
++           fprintf(f,"<%s> (relayed to non-DSN-aware mailer)\n\n", 
addr_dsntmp->address);
++           } else {
++           fprintf(f,"<%s> (relayed via non \"Remote SMTP\" router)\n\n", 
addr_dsntmp->address);
++           }
++
++         fprintf(f,"--%s\n", boundaryStr);
++         fprintf(f,"Content-type: message/delivery-status\n\n");
++         
++           if (dsn_envid) { /* Test for NULL added by GC */
++               fprintf(f,"Original-Envelope-Id: %s\n", dsn_envid);
++           }
++         fprintf(f,"Reporting-MTA: dns; %s\n", qualify_domain_sender);
++           if (addr_dsntmp->dsn_orcpt) { /* Test for NULL added by GC */
++               fprintf(f,"Original-Recipient: %s\n", addr_dsntmp->dsn_orcpt);
++           }
++         fprintf(f,"Action: delivered\n\n");
++         
++         fprintf(f,"--%s\n", boundaryStr);
++         fprintf(f,"Content-type: message/rfc822\n\n");
++         
++         fflush(f);
++         transport_filter_argv = NULL;   /* Just in case */
++           return_path = sender_address;   /* In case not previously set */
++         
++         /* Write the original email out */
++         transport_write_message(NULL, fileno(f), topt, 2048, NULL, NULL, 
NULL, NULL, NULL, 0);          
++         fflush(f);
++            
++         fprintf(f,"\n");        
++         fprintf(f,"--%s--\n", boundaryStr);
++         
++         fflush(f);              
++         fclose(f);
++           rc = child_close(pid, 0);     /* Waits for child to close, no 
timeout */
++      }
++      }
++      else
++      {  if (addr_dsntmp->router->dsn_process == TRUE)
++       DEBUG(D_deliver) debug_printf("DSN: *** NOT SENDING DSN SUCCESS 
Message ***\n"); 
++         if (addr_dsntmp->router->dsn_process == FALSE)
++       DEBUG(D_deliver) debug_printf("DSN: *** NOT SENDING DSN SUCCESS 
Message (gagged) ***\n"); 
++      }
++   }
++
++   addr_dsntmp = addr_dsntmp->next;
++}
++
++/* ********** philb - end of mod */
++#endif
++
+ /* If any addresses failed, we must send a message to somebody, unless
+ af_ignore_error is set, in which case no action is taken. It is possible for
+ several messages to get sent if there are addresses with different
+diff -Naur exim-4.82_RC5.orig/src/EDITME exim-4.82_RC5/src/EDITME
+--- exim-4.82_RC5.orig/src/EDITME      2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/EDITME   2013-10-27 21:47:32.000000000 +0100
+@@ -192,6 +192,8 @@
+ # least one type of lookup. You should consider whether you want to build
+ # the Exim monitor or not.
+ 
++# Support DSN
++SUPPORT_DSN=yes
+ 
+ 
#------------------------------------------------------------------------------
+ # These settings determine which individual router drivers are included in the
+diff -Naur exim-4.82_RC5.orig/src/exim.c exim-4.82_RC5/src/exim.c
+--- exim-4.82_RC5.orig/src/exim.c      2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/exim.c   2013-10-27 21:47:32.000000000 +0100
+@@ -831,6 +831,9 @@
+ #ifdef EXPERIMENTAL_REDIS
+   fprintf(f, " Experimental_Redis");
+ #endif
++#ifdef SUPPORT_DSN
++  fprintf(f, " C&W_DSN_1.3");
++#endif
+ fprintf(f, "\n");
+ 
+ fprintf(f, "Lookups (built-in):");
+@@ -2653,6 +2656,16 @@
+       break;
+       }
+ 
++    #ifdef SUPPORT_DSN
++    /* -MCD: set the smtp_use_dsn flag; this indicates that the host
++       that exim is connected to supports the esmtp extension DSN */
++    else if (strcmp(argrest, "CD") == 0)
++      {
++      smtp_use_dsn = TRUE;
++      break;
++      }
++    #endif
++
+     /* -MCP: set the smtp_use_pipelining flag; this is useful only when
+     it preceded -MC (see above) */
+ 
+diff -Naur exim-4.82_RC5.orig/src/globals.c exim-4.82_RC5/src/globals.c
+--- exim-4.82_RC5.orig/src/globals.c   2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/globals.c        2013-10-27 21:47:32.000000000 +0100
+@@ -124,6 +124,13 @@
+ uschar *local_scan_path        = NULL;
+ #endif
+ 
++#ifdef SUPPORT_DSN
++BOOL   dsn                    = TRUE;
++uschar  *dsn_envid            = NULL;
++int    dsn_ret                = 0;
++const pcre  *regex_DSN        = NULL;
++BOOL   smtp_use_dsn           = FALSE;
++#endif
+ 
+ #ifdef SUPPORT_TLS
+ BOOL    gnutls_compat_mode     = FALSE;
+@@ -341,6 +348,11 @@
+   NULL,                       /* authenticator */
+   NULL,                       /* auth_id */
+   NULL,                       /* auth_sndr */
++  #ifdef SUPPORT_DSN
++  NULL,                 /* dsn_orcpt */
++  0,                    /* dsn_flags */
++  NULL,                 /* dsn_aware */
++  #endif
+   (uid_t)(-1),          /* uid */
+   (gid_t)(-1),          /* gid */
+   0,                    /* flags */
+@@ -1096,6 +1108,9 @@
+     TRUE,                      /* verify_sender */
+     FALSE,                     /* uid_set */
+     FALSE,                     /* unseen */
++#ifdef SUPPORT_DSN
++    FALSE,                     /* dsn_process */
++#endif
+ 
+     self_freeze,               /* self_code */
+     (uid_t)(-1),               /* uid */
+@@ -1105,6 +1120,7 @@
+     NULL,                      /* transport instance */
+     NULL,                      /* pass_router */
+     NULL                       /* redirect_router */
++
+ };
+ 
+ uschar *router_name            = NULL;
+diff -Naur exim-4.82_RC5.orig/src/globals.h exim-4.82_RC5/src/globals.h
+--- exim-4.82_RC5.orig/src/globals.h   2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/globals.h        2013-10-27 21:47:32.000000000 +0100
+@@ -130,6 +130,13 @@
+ extern int (*receive_ferror)(void);
+ extern BOOL (*receive_smtp_buffered)(void);
+ 
++#ifdef SUPPORT_DSN
++extern BOOL   dsn;                    /* FALSE if DSN not to be used */
++extern uschar  *dsn_envid;            /* DSN envid string */
++extern int    dsn_ret;                /* DSN ret type*/
++extern const pcre  *regex_DSN;        /* For recognizing DSN settings */
++extern BOOL   smtp_use_dsn;           /* Global for passed connections */
++#endif
+ 
+ /* For clearing, saving, restoring address expansion variables. We have to 
have
+ the size of this vector set explicitly, because it is referenced from more 
than
+diff -Naur exim-4.82_RC5.orig/src/local_scan.h exim-4.82_RC5/src/local_scan.h
+--- exim-4.82_RC5.orig/src/local_scan.h        2013-10-27 21:46:25.000000000 
+0100
++++ exim-4.82_RC5/src/local_scan.h     2013-10-27 21:47:32.000000000 +0100
+@@ -124,9 +124,13 @@
+ field is always NULL except for one_time aliases that had errors_to on the
+ routers that generated them. */
+ 
++/* Added the dsn attributes orcpt and dsn_flags for DSN support*/
++
+ typedef struct recipient_item {
+   uschar *address;              /* the recipient address */
+   int     pno;                  /* parent number for "one_time" alias, or -1 
*/
++  uschar *orcpt;                /* DSN orcpt */
++  int    dsn_flags;             /* DSN flags */
+   uschar *errors_to;            /* the errors_to address or NULL */
+ #ifdef EXPERIMENTAL_BRIGHTMAIL
+   uschar *bmi_optin;
+diff -Naur exim-4.82_RC5.orig/src/macros.h exim-4.82_RC5/src/macros.h
+--- exim-4.82_RC5.orig/src/macros.h    2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/macros.h 2013-10-27 21:47:32.000000000 +0100
+@@ -778,6 +778,22 @@
+ #define topt_no_body            0x040  /* Omit body */
+ #define topt_escape_headers     0x080  /* Apply escape check to headers */
+ 
++ /* Flags for recipient_block, used in DSN support */
++
++ #define rf_onetime              0x01  /* A one-time alias */
++ #define rf_notify_never         0x02  /* NOTIFY= settings */
++ #define rf_notify_success       0x04
++ #define rf_notify_failure       0x08
++ #define rf_notify_delay         0x10
++
++ #define rf_dsnflags  (rf_notify_never | rf_notify_success | \
++                       rf_notify_failure | rf_notify_delay)
++
++ /* DSN RET types */
++
++ #define dsn_ret_full            1
++ #define dsn_ret_hdrs            2
++
+ /* Codes for the host_find_failed and host_all_ignored options. */
+ 
+ #define hff_freeze   0
+diff -Naur exim-4.82_RC5.orig/src/readconf.c exim-4.82_RC5/src/readconf.c
+--- exim-4.82_RC5.orig/src/readconf.c  2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/readconf.c       2013-10-27 21:49:15.000000000 +0100
+@@ -229,6 +229,9 @@
+  /* This option is now a no-op, retained for compability */
+   { "drop_cr",                  opt_bool,        &drop_cr },
+ /*********************************************************/
++#ifdef SUPPORT_DSN
++  { "dsn",                      opt_bool,        &dsn },
++#endif
+   { "dsn_from",                 opt_stringptr,   &dsn_from },
+   { "envelope_to_remove",       opt_bool,        &envelope_to_remove },
+   { "errors_copy",              opt_stringptr,   &errors_copy },
+diff -Naur exim-4.82_RC5.orig/src/receive.c exim-4.82_RC5/src/receive.c
+--- exim-4.82_RC5.orig/src/receive.c   2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/receive.c        2013-10-27 21:47:32.000000000 +0100
+@@ -490,6 +490,8 @@
+     memcpy(recipients_list, oldlist, oldmax * sizeof(recipient_item));
+   }
+ 
++/* memset added by GC to blank dsn records, etc. */
++memset(&recipients_list[recipients_count], 0, sizeof(recipient_item));
+ recipients_list[recipients_count].address = recipient;
+ recipients_list[recipients_count].pno = pno;
+ #ifdef EXPERIMENTAL_BRIGHTMAIL
+diff -Naur exim-4.82_RC5.orig/src/route.c exim-4.82_RC5/src/route.c
+--- exim-4.82_RC5.orig/src/route.c     2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/route.c  2013-10-27 21:47:32.000000000 +0100
+@@ -58,6 +58,10 @@
+                  (void *)offsetof(router_instance, domains) },
+   { "driver",             opt_stringptr|opt_public,
+                  (void *)offsetof(router_instance, driver_name) },
++  #ifdef SUPPORT_DSN
++  { "dsn_process",        opt_bool|opt_public,
++                 (void *)offsetof(router_instance, dsn_process) },
++  #endif
+   { "errors_to",          opt_stringptr|opt_public,
+                  (void *)(offsetof(router_instance, errors_to)) },
+   { "expn",               opt_bool|opt_public,
+@@ -270,6 +274,13 @@
+ 
+   if (r->pass_router_name != NULL)
+     set_router(r, r->pass_router_name, &(r->pass_router), TRUE);
++
++  #ifdef SUPPORT_DSN
++    if (r->dsn_process == FALSE)
++      DEBUG(D_route) debug_printf("%s router skipping DSN - add dsn_process 
to router\n", r->name);
++    if (r->dsn_process == TRUE)
++      DEBUG(D_route) debug_printf("%s router performing DSN \n", r->name);
++  #endif
+   }
+ }
+ 
+@@ -1412,7 +1423,10 @@
+ 
+ copyflag(new, addr, af_propagate);
+ new->p.address_data = addr->p.address_data;
+-
++#ifdef SUPPORT_DSN
++  new->dsn_flags = addr->dsn_flags;
++  new->dsn_orcpt = addr->dsn_orcpt;
++#endif
+ 
+ /* As it has turned out, we haven't set headers_add or headers_remove for the
+  * clone. Thinking about it, it isn't entirely clear whether they should be
+diff -Naur exim-4.82_RC5.orig/src/smtp_in.c exim-4.82_RC5/src/smtp_in.c
+--- exim-4.82_RC5.orig/src/smtp_in.c   2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/smtp_in.c        2013-10-27 21:47:32.000000000 +0100
+@@ -213,6 +213,9 @@
+ #ifdef EXPERIMENTAL_PRDR
+   ENV_MAIL_OPT_PRDR,
+ #endif
++#ifdef SUPPORT_DSN
++  ENV_MAIL_OPT_RET, ENV_MAIL_OPT_ENVID,
++#endif
+   ENV_MAIL_OPT_NULL
+   };
+ typedef struct {
+@@ -228,6 +231,10 @@
+ #ifdef EXPERIMENTAL_PRDR
+     { US"PRDR",   ENV_MAIL_OPT_PRDR,   FALSE },
+ #endif
++#ifdef SUPPORT_DSN
++    { US"RET",    ENV_MAIL_OPT_RET,    FALSE },
++    { US"ENVID",  ENV_MAIL_OPT_ENVID,  FALSE },
++#endif
+     { US"NULL",   ENV_MAIL_OPT_NULL,   FALSE }
+   };
+ 
+@@ -1073,6 +1080,13 @@
+ sender_verified_list = NULL;        /* No senders verified */
+ memset(sender_address_cache, 0, sizeof(sender_address_cache));
+ memset(sender_domain_cache, 0, sizeof(sender_domain_cache));
++
++#ifdef SUPPORT_DSN
++/* Reset the DSN flags */
++dsn_ret = 0;
++dsn_envid = NULL;
++#endif
++
+ authenticated_sender = NULL;
+ #ifdef EXPERIMENTAL_BRIGHTMAIL
+ bmi_run = 0;
+@@ -2679,6 +2693,10 @@
+   int ptr, size, rc;
+   int c, i;
+   auth_instance *au;
++#ifdef SUPPORT_DSN
++  uschar *orcpt = NULL;
++  int flags;
++#endif
+ 
+   switch(smtp_read_command(TRUE))
+     {
+@@ -3106,6 +3124,12 @@
+         s = string_cat(s, &size, &ptr, US"-8BITMIME\r\n", 11);
+         }
+ 
++      #ifdef SUPPORT_DSN
++      /* Advertise DSN support if configured to do so. */
++      if (dsn) 
++        s = string_cat(s, &size, &ptr, US"250-DSN\r\n", 9);
++      #endif
++
+       /* Advertise ETRN if there's an ACL checking whether a host is
+       permitted to issue it; a check is made when any host actually tries. */
+ 
+@@ -3360,6 +3384,42 @@
+           arg_error = TRUE;
+           break;
+ 
++#ifdef SUPPORT_DSN
++
++        /* Handle the two DSN options, but only if configured to do so
++         * (which will have caused "DSN" to be given in the EHLO
++         * response). The code itself is included only if configured in
++         * at build time. */
++
++        case ENV_MAIL_OPT_RET:
++          /* Check if RET has already been set */
++          if (dsn_ret > 0) {
++            synprot_error(L_smtp_syntax_error, 501, NULL,
++              US"RET can be specified once only");
++            goto COMMAND_LOOP;
++          }
++          dsn_ret = (strcmpic(value, US"HDRS") == 0)? dsn_ret_hdrs :
++                  (strcmpic(value, US"FULL") == 0)? dsn_ret_full : 0;
++          DEBUG(D_receive) debug_printf("DSN_RET: %d\n", dsn_ret);
++          /* Check for invalid invalid value, and exit with error */
++          if (dsn_ret == 0) {
++            synprot_error(L_smtp_syntax_error, 501, NULL,
++              US"Value for RET is invalid");
++            goto COMMAND_LOOP;
++          }
++          break;
++        case ENV_MAIL_OPT_ENVID:
++          /* Check if the dsn envid has been already set */
++          if (dsn_envid != NULL) {
++            synprot_error(L_smtp_syntax_error, 501, NULL,
++              US"ENVID can be specified once only");
++            goto COMMAND_LOOP;
++          }
++          dsn_envid = string_copy(value);
++          DEBUG(D_receive) debug_printf("DSN_ENVID: %s\n", dsn_envid);
++          break;
++#endif
++
+         /* Handle the AUTH extension. If the value given is not "<>" and 
either
+         the ACL says "yes" or there is no ACL but the sending host is
+         authenticated, we set it up as the authenticated sender. However, if 
the
+@@ -3633,6 +3693,89 @@
+       rcpt_fail_count++;
+       break;
+       }
++    
++    #ifdef SUPPORT_DSN
++    /* Set the DSN flags orcpt and dsn_flags from the session*/
++    orcpt = NULL;
++    flags = 0;
++    
++    if (esmtp) for(;;)
++      {
++      uschar *name, *value, *end;
++      int size;
++
++      if (!extract_option(&name, &value))
++      {
++         break;
++      }
++
++      if (strcmpic(name, US"ORCPT") == 0)
++      {
++        /* Check whether orcpt has been already set */
++        if (orcpt != NULL) {
++          synprot_error(L_smtp_syntax_error, 501, NULL,
++            US"ORCPT can be specified once only");
++          goto COMMAND_LOOP;
++        }
++        orcpt = string_copy(value);
++        DEBUG(D_receive) debug_printf("DSN orcpt: %s\n", orcpt);
++      }
++
++      else if (strcmpic(name, US"NOTIFY") == 0)
++      {
++        /* Check if the notify flags have been already set */
++        if (flags > 0)
++        {
++          synprot_error(L_smtp_syntax_error, 501, NULL,
++              US"NOTIFY can be specified once only");
++          goto COMMAND_LOOP;
++        }
++        if (strcmpic(value, US"NEVER") == 0) flags |= rf_notify_never; else
++          {
++          uschar *p = value;
++          while (*p != 0)
++            {
++            uschar *pp = p;
++            while (*pp != 0 && *pp != ',') pp++;
++              if (*pp == ',') *pp++ = 0;
++            if (strcmpic(p, US"SUCCESS") == 0) {
++                DEBUG(D_receive) debug_printf("GC: Setting notify success\n");
++                flags |= rf_notify_success;
++            }
++            else if (strcmpic(p, US"FAILURE") == 0) {
++                DEBUG(D_receive) debug_printf("GC: Setting notify failure\n");
++                flags |= rf_notify_failure;
++            }
++            else if (strcmpic(p, US"DELAY") == 0) {
++                DEBUG(D_receive) debug_printf("GC: Setting notify delay\n");
++                flags |= rf_notify_delay;
++            }
++            else
++            {
++              /* Catch any strange values */
++              synprot_error(L_smtp_syntax_error, 501, NULL,
++                US"Invalid value for NOTIFY parameter");
++              goto COMMAND_LOOP;
++            }
++            p = pp;
++            }
++            DEBUG(D_receive) debug_printf("DSN Flags: %x\n", flags);
++          }
++      }
++
++      /* Unknown option. Stick back the terminator characters and break
++      the loop. An error for a malformed address will occur. */
++
++      else
++        {
++        DEBUG(D_receive) debug_printf("Invalid dsn command: %s : %s\n", name, 
value);
++        name[-1] = ' ';
++        value[-1] = '=';
++        break;
++        }
++      }
++    #endif
++
+ 
+     /* Apply SMTP rewriting then extract the working address. Don't allow "<>"
+     as a recipient address */
+@@ -3747,6 +3890,24 @@
+       if (user_msg == NULL) smtp_printf("250 Accepted\r\n");
+         else smtp_user_msg(US"250", user_msg);
+       receive_add_recipient(recipient, -1);
++      
++      #ifdef SUPPORT_DSN
++      
++      /* Set the dsn flags in the recipients_list */
++      if (orcpt != NULL)
++         recipients_list[recipients_count-1].orcpt = orcpt;
++      else
++         recipients_list[recipients_count-1].orcpt = NULL;
++         
++      if (flags != 0)
++         recipients_list[recipients_count-1].dsn_flags = flags;
++      else
++         recipients_list[recipients_count-1].dsn_flags = 0;
++         debug_printf("DSN-AJ(smtp-in): orcpt: %s  flags: %d\n", 
recipients_list[recipients_count-1].orcpt, 
recipients_list[recipients_count-1].dsn_flags);
++
++
++      #endif
++      
+       }
+ 
+     /* The recipient was discarded */
+diff -Naur exim-4.82_RC5.orig/src/spool_in.c exim-4.82_RC5/src/spool_in.c
+--- exim-4.82_RC5.orig/src/spool_in.c  2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/spool_in.c       2013-10-27 21:47:32.000000000 +0100
+@@ -293,6 +293,13 @@
+ spam_score_int = NULL;
+ #endif
+ 
++#ifdef SUPPORT_DSN
++#ifndef COMPILE_UTILITY
++dsn_ret = 0;
++dsn_envid = NULL;
++#endif  /* COMPILE_UTILITY */
++#endif
++
+ /* Generate the full name and open the file. If message_subdir is already
+ set, just look in the given directory. Otherwise, look in both the split
+ and unsplit directories, as for the data file above. */
+@@ -467,6 +474,19 @@
+     case 'd':
+     if (Ustrcmp(p, "eliver_firsttime") == 0)
+       deliver_firsttime = TRUE;
++    #ifdef SUPPORT_DSN
++    #ifndef COMPILE_UTILITY
++    /* Check if the dsn flags have been set in the header file */
++    else if (Ustrncmp(p, "sn_ret", 6) == 0)
++    {
++      dsn_ret= atoi(big_buffer + 8);
++    }
++    else if (Ustrncmp(p, "sn_envid", 8) == 0)
++    {
++      dsn_envid = string_copy(big_buffer + 11);
++    }
++    #endif  /* COMPILE_UTILITY */
++    #endif
+     break;
+ 
+     case 'f':
+@@ -554,7 +574,7 @@
+       tls_in.sni = string_unprinting(string_copy(big_buffer + 9));
+     break;
+     #endif
+-
++ 
+     default:    /* Present because some compilers complain if all */
+     break;      /* possibilities are not covered. */
+     }
+@@ -604,6 +624,10 @@
+   {
+   int nn;
+   int pno = -1;
++  #ifdef SUPPORT_DSN
++  int dsn_flags = 0;
++  uschar *orcpt = NULL;
++  #endif
+   uschar *errors_to = NULL;
+   uschar *p;
+ 
+@@ -672,10 +696,19 @@
+     }
+ 
+   /* Handle current format Exim 4 spool files */
++  /* Spool file is modified if DSN is supported
++     Original was "address errors_to len(errors_to),pno
++     New for DSN support is now:
++     "address errors_to orcpt len(errors_to),len(orcpt),pno,dsn_flags */
+ 
+   else if (*p == '#')
+     {
+     int flags;
++
++    #ifndef COMPILE_UTILITY
++      DEBUG(D_deliver) debug_printf("**** SPOOL_IN - Exim 4 standard format 
spoolfile\n");
++    #endif  /* COMPILE_UTILITY */
++
+     (void)sscanf(CS p+1, "%d", &flags);
+ 
+     if ((flags & 0x01) != 0)      /* one_time data exists */
+@@ -688,15 +721,82 @@
+         {
+         p -= len;
+         errors_to = string_copy(p);
++        }     
++      }
++
++    *(--p) = 0;   /* Terminate address */
++    }
++    #ifdef SUPPORT_DSN
++    else if (*p == '!') /* Handle Exim4 + DSN spool files */
++    {
++    int flags;
++    int temp_dsn_flags;
++
++    #ifndef COMPILE_UTILITY
++      DEBUG(D_deliver) debug_printf("**** SPOOL_IN - C&W DSN format 
spoolfile\n");
++    #endif  /* COMPILE_UTILITY */
++    
++    sscanf(CS p+1, "%d,%d", &flags, &temp_dsn_flags);
++    
++    if (((flags & 0x01) != 0) || (temp_dsn_flags > 0)) /* one_time data or 
dsn_flags exist */  
++      {
++      int len;
++      int len_orcpt;
++
++      #ifndef COMPILE_UTILITY
++        DEBUG(D_deliver) debug_printf("**** spool_in dsn_flags = 0\n");
++      #endif  /* COMPILE_UTILITY */
++
++      dsn_flags = 0;
++      
++      while (isdigit(*(--p)) || *p == ',' || *p == '-');
++      sscanf(CS p+1, "%d,%d,%d,%d", &len, &len_orcpt, &pno, &dsn_flags);
++       
++      *p = 0;
++      if (len_orcpt > 0)
++        {
++          p -= len_orcpt;
++          orcpt = string_copy(p);
+         }
++      *(--p) = 0; /* change the space to a NULL */
++
++      if (len > 0)
++        {
++        p -= len;
++        errors_to = string_copy(p);
++        }     
+       }
+ 
+     *(--p) = 0;   /* Terminate address */
+     }
++    #endif
++    #ifndef COMPILE_UTILITY
++    else
++    {
++       DEBUG(D_deliver) debug_printf("**** SPOOL_IN - No additional 
fields\n");
++    }
++    #endif  /* COMPILE_UTILITY */
++  
++  #ifdef SUPPORT_DSN
++    #ifndef COMPILE_UTILITY
++      DEBUG(D_deliver) debug_printf("**** SPOOL_IN - address: |%s| errorsto: 
|%s| orcpt: |%s| dsn_flags: %d\n",
++      big_buffer, errors_to, orcpt, dsn_flags);
++    #endif  /* COMPILE_UTILITY */
++  #endif
++  #ifndef SUPPORT_DSN
++    #ifndef COMPILE_UTILITY
++      DEBUG(D_deliver) debug_printf("**** SPOOL_IN - address: |%s| errorsto: 
|%s|\n",
++      big_buffer, errors_to);
++    #endif  /* COMPILE_UTILITY */
++  #endif
+ 
+   recipients_list[recipients_count].address = string_copy(big_buffer);
+   recipients_list[recipients_count].pno = pno;
+   recipients_list[recipients_count].errors_to = errors_to;
++  #ifdef SUPPORT_DSN
++  recipients_list[recipients_count].orcpt = orcpt;
++  recipients_list[recipients_count].dsn_flags = dsn_flags;
++  #endif
+   }
+ 
+ /* The remainder of the spool header file contains the headers for the 
message,
+diff -Naur exim-4.82_RC5.orig/src/spool_out.c exim-4.82_RC5/src/spool_out.c
+--- exim-4.82_RC5.orig/src/spool_out.c 2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/spool_out.c      2013-10-27 21:47:32.000000000 +0100
+@@ -234,6 +234,15 @@
+ if (tls_in.sni != NULL)                fprintf(f, "-tls_sni %s\n",    
string_printing(tls_in.sni));
+ #endif
+ 
++#ifdef SUPPORT_DSN
++/* Write the dsn flags to the spool header file */
++DEBUG(D_deliver) debug_printf("DSN: Write SPOOL :-dsn_envid %s\n", dsn_envid);
++if (dsn_envid != NULL) fprintf(f, "-dsn_envid %s\n", dsn_envid);
++DEBUG(D_deliver) debug_printf("DSN: Write SPOOL :-dsn_ret %d\n", dsn_ret);
++if (dsn_ret != 0) fprintf(f, "-dsn_ret %d\n", dsn_ret);
++#endif
++
++
+ /* To complete the envelope, write out the tree of non-recipients, followed by
+ the list of recipients. These won't be disjoint the first time, when no
+ checking has been done. If a recipient is a "one-time" alias, it is followed 
by
+@@ -244,14 +253,36 @@
+ for (i = 0; i < recipients_count; i++)
+   {
+   recipient_item *r = recipients_list + i;
+-  if (r->pno < 0 && r->errors_to == NULL)
++#ifdef SUPPORT_DSN
++DEBUG(D_deliver) debug_printf("DSN: Flags :%d\n", r->dsn_flags);
++#endif
++  if (r->pno < 0 && r->errors_to == NULL
++    #ifdef SUPPORT_DSN
++     && r->dsn_flags == 0
++    #endif
++    )
+     fprintf(f, "%s\n", r->address);
+   else
+     {
+     uschar *errors_to = (r->errors_to == NULL)? US"" : r->errors_to;
++    #ifdef SUPPORT_DSN
++    uschar *orcpt = (r->orcpt == NULL)? US"" : r->orcpt;
++    fprintf(f, "%s %s %s %d,%d,%d,%d!1\n", r->address, errors_to, orcpt, 
++      Ustrlen(errors_to), Ustrlen(orcpt), r->pno, r->dsn_flags);
++    #else
+     fprintf(f, "%s %s %d,%d#1\n", r->address, errors_to,
+       Ustrlen(errors_to), r->pno);
++    #endif
+     }
++    
++    #ifdef SUPPORT_DSN
++      DEBUG(D_deliver) debug_printf("DSN :**** SPOOL_OUT - address: |%s| 
errorsto: |%s| orcpt: |%s| dsn_flags: %d\n",
++         r->address, r->errors_to, r->orcpt, r->dsn_flags);
++    #endif
++    #ifndef SUPPORT_DSN
++      DEBUG(D_deliver) debug_printf("**** SPOOL_OUT - address: |%s| errorsto: 
|%s|\n",
++         r->address, r->errors_to);
++    #endif
+   }
+ 
+ /* Put a blank line before the headers */
+diff -Naur exim-4.82_RC5.orig/src/structs.h exim-4.82_RC5/src/structs.h
+--- exim-4.82_RC5.orig/src/structs.h   2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/structs.h        2013-10-27 21:47:32.000000000 +0100
+@@ -282,7 +282,9 @@
+   BOOL    verify_sender;          /* Use this router when verifying a sender 
*/
+   BOOL    uid_set;                /* Flag to indicate uid is set */
+   BOOL    unseen;                 /* If TRUE carry on, even after success */
+-
++#ifdef SUPPORT_DSN
++  BOOL    dsn_process;            /* If TRUE, activate DSN for this router */
++#endif
+   int     self_code;              /* Encoded version of "self" */
+   uid_t   uid;                    /* Fixed uid value */
+   gid_t   gid;                    /* Fixed gid value */
+@@ -547,6 +549,12 @@
+   uschar *auth_id;              /* auth "login" name used by transport */
+   uschar *auth_sndr;            /* AUTH arg to SMTP MAIL, used by transport */
+ 
++  #ifdef SUPPORT_DSN
++  uschar *dsn_orcpt;              /* DSN orcpt value */
++  int  dsn_flags;                 /* DSN flags */
++  uschar *dsn_aware;              /* DSN aware flag */
++  #endif
++
+   uid_t   uid;                    /* uid for transporting */
+   gid_t   gid;                    /* gid for transporting */
+ 
+diff -Naur exim-4.82_RC5.orig/src/transport.c exim-4.82_RC5/src/transport.c
+--- exim-4.82_RC5.orig/src/transport.c 2013-10-27 21:46:25.000000000 +0100
++++ exim-4.82_RC5/src/transport.c      2013-10-27 21:47:32.000000000 +0100
+@@ -1802,6 +1802,11 @@
+ 
+   argv = child_exec_exim(CEE_RETURN_ARGV, TRUE, &i, FALSE, 0);
+ 
++  #ifdef SUPPORT_DSN
++  /* Call with the dsn flag */
++  if (smtp_use_dsn) argv[i++] = US"-MCD";
++  #endif
++
+   if (smtp_authenticated) argv[i++] = US"-MCA";
+ 
+   #ifdef SUPPORT_TLS
+diff -Naur exim-4.82_RC5.orig/src/transports/smtp.c 
exim-4.82_RC5/src/transports/smtp.c
+--- exim-4.82_RC5.orig/src/transports/smtp.c   2013-10-27 21:46:25.000000000 
+0100
++++ exim-4.82_RC5/src/transports/smtp.c        2013-10-27 21:47:32.000000000 
+0100
+@@ -242,6 +242,16 @@
+ #endif
+ };
+ 
++#ifdef SUPPORT_DSN
++/* some DSN flags for use later */
++
++static int   rf_list[] = {rf_notify_never, rf_notify_success,
++  rf_notify_failure, rf_notify_delay };
++
++static uschar *rf_names[] = { "NEVER", "SUCCESS", "FAILURE", "DELAY" };
++#endif
++
++
+ 
+ /* Local statics */
+ 
+@@ -1079,6 +1089,27 @@
+   else if (new[0] != 0) local_authenticated_sender = new;
+   }
+ 
++#ifdef SUPPORT_DSN
++/* Add any DSN flags to the mail command */
++
++if (smtp_use_dsn)
++  {
++  uschar *p = buffer;
++  if (dsn_ret == dsn_ret_hdrs)
++    {
++    strcpy(p, " RET=HDRS");
++    while (*p) p++;
++    }
++  else if (dsn_ret == dsn_ret_full)
++    {
++    strcpy(p, " RET=FULL");
++    while (*p) p++;
++    }
++  if (dsn_envid != NULL)
++    string_format(p, sizeof(buffer) - (p-buffer), " ENVID=%s", dsn_envid);
++  }
++#endif
++
+ /* Add the authenticated sender address if present */
+ 
+ if ((smtp_authenticated || ob->authenticated_sender_force) &&
+@@ -1587,6 +1618,14 @@
+     {DEBUG(D_transport) debug_printf("PRDR usable\n");}
+ #endif
+ 
++  #ifdef SUPPORT_DSN
++  /* Note if the server supports DSN */
++  smtp_use_dsn = dsn &&
++    esmtp && pcre_exec(regex_DSN, NULL, CS buffer, (int)Ustrlen(CS buffer), 0,
++       PCRE_EOPT, NULL, 0) >= 0;
++  DEBUG(D_transport) debug_printf("use_dsn=%d\n", smtp_use_dsn);
++  #endif
++
+   /* Note if the response to EHLO specifies support for the AUTH extension.
+   If it has, check that this host is one we want to authenticate to, and do
+   the business. The host name and address must be available when the
+@@ -1746,18 +1785,66 @@
+   int count;
+   BOOL no_flush;
+ 
++  #ifdef SUPPORT_DSN
++  /* philb - set dsn_aware flag for this recipient */
++  if(smtp_use_dsn)
++     addr->dsn_aware = string_copy("Y");
++  else
++     addr->dsn_aware = string_copy("N");
++  #endif
++
+   if (addr->transport_return != PENDING_DEFER) continue;
+ 
+   address_count++;
+   no_flush = smtp_use_pipelining && (!mua_wrapper || addr->next != NULL);
+ 
++   #ifdef SUPPORT_DSN
++   /* Add any DSN flags to the rcpt command and add to the sent string */
++
++   p = buffer;
++   *p = 0;
++
++   if (smtp_use_dsn)
++     {
++     if ((addr->dsn_flags & rf_dsnflags) != 0)
++       {
++       int i;
++       BOOL first = TRUE;
++       strcpy(p, " NOTIFY=");
++       while (*p) p++;
++       for (i = 0; i < 4; i++)
++         {
++         if ((addr->dsn_flags & rf_list[i]) != 0)
++           {
++           if (!first) *p++ = ',';
++           first = FALSE;
++           strcpy(p, rf_names[i]);
++           while (*p) p++;
++           }
++         }
++       }
++
++     if (addr->dsn_orcpt != NULL)
++       string_format(p, sizeof(buffer) - (p-buffer), " ORCPT=%s",
++         addr->dsn_orcpt);
++     }
++
++   #endif
++
++
+   /* Now send the RCPT command, and process outstanding responses when
+   necessary. After a timeout on RCPT, we just end the function, leaving the
+   yield as OK, because this error can often mean that there is a problem with
+   just one address, so we don't want to delay the host. */
+ 
++ #ifdef SUPPORT_DSN
++  count = smtp_write_command(&outblock, no_flush, "RCPT TO:<%s>%s%s\r\n",
++    transport_rcpt_address(addr, tblock->rcpt_include_affixes), igquotstr, 
buffer);
++ #else
+   count = smtp_write_command(&outblock, no_flush, "RCPT TO:<%s>%s\r\n",
+     transport_rcpt_address(addr, tblock->rcpt_include_affixes), igquotstr);
++ #endif
++
+   if (count < 0) goto SEND_FAILED;
+   if (count > 0)
+     {

diff --git a/mail-mta/exim/files/exim_at.service 
b/mail-mta/exim/files/exim_at.service
new file mode 100644
index 0000000..19c07a5
--- /dev/null
+++ b/mail-mta/exim/files/exim_at.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Exim Mail Daemon per-connection server
+
+[Service]
+ExecStart=-/usr/bin/exim -bs
+StandardInput=socket
+StandardError=syslog

diff --git a/mail-mta/exim/metadata.xml b/mail-mta/exim/metadata.xml
new file mode 100644
index 0000000..c94ff4f
--- /dev/null
+++ b/mail-mta/exim/metadata.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+       <herd>net-mail</herd>
+       <maintainer>
+               <email>[email protected]</email>
+       </maintainer>
+       <longdescription>
+               Exim is a message transfer agent (MTA) developed at the 
University of
+               Cambridge for use on Unix systems connected to the Internet. It 
is
+               freely available under the terms of the GNU General Public 
Licence. In
+               style it is similar to Smail 3, but its facilities are more 
general.
+               There is a great deal of flexibility in the way mail can be 
routed, and
+               there are extensive facilities for checking incoming mail. Exim 
can be
+               installed in place of sendmail, although the configuration of 
exim is
+               quite different to that of sendmail.
+       </longdescription>
+       <use>
+               <flag name='dcc'>Adds support for Distributed Checksum 
Clearinghouse
+                       (DCC)</flag>
+               <flag name='dkim'>Adds support for DomainKeys Identified Mail
+                       (DKIM)</flag>
+               <flag name='dnsdb'>Adds support for a DNS search for a record 
whose
+                       domain name is the supplied query</flag>
+               <flag name='dovecot-sasl'>Adds support for Dovecot's
+                       authentication</flag>
+               <flag name='dlfunc'>Install local_scan.h header to compile 
separate
+                       dlfunc libraries</flag>
+               <flag name='dmarc'>Adds support for DMARC</flag>
+               <flag name='dsn'>Adds support for Delivery Status Notifications
+                       (DSN)</flag>
+               <flag name='exiscan-acl'>Patch providing support for content
+                       scanning</flag>
+               <flag name='lmtp'>Adds support for lmtp</flag>
+               <flag name='mbx'>Adds support for UW's mbx format</flag>
+               <flag name='spf'>Adds support for Sender Policy Framework</flag>
+               <flag name='srs'>Adds support for Sender Rewriting Scheme</flag>
+               <flag name='proxy'>Add support for being behind a proxy, such 
as HAProxy</flag>
+               <flag name='pkcs11'>Require pkcs11 support in 
<pkg>net-libs/gnutls</pkg> with USE=gnutls</flag>
+               <flag name='redis'>Adds support for querying 
<pkg>dev-db/redis</pkg></flag>
+               <flag name='prdr'>Adds support for Per-Recipient Data 
Response</flag>
+               <flag name='tpda'>Adds support for Transport Post-Delivery 
Actions</flag>
+       </use>
+       <upstream>
+               <bugs-to>http://bugs.exim.org/</bugs-to>
+               <!-- stupid DTD doesn't allow this
+               <vcs>http://git.exim.org/exim.git</vcs>
+               -->
+       </upstream>
+</pkgmetadata>

Reply via email to