mail-filter/spamassassin: new revision to fix the build with openssl-1.1.
[gentoo.git] / mail-filter / spamassassin / spamassassin-3.4.1-r18.ebuild
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit perl-functions systemd toolchain-funcs user
7
8 MY_P="Mail-SpamAssassin-${PV//_/-}"
9 S="${WORKDIR}/${MY_P}"
10 DESCRIPTION="An extensible mail filter which can identify and tag spam"
11 HOMEPAGE="https://spamassassin.apache.org/"
12 SRC_URI="mirror://apache/spamassassin/source/${MY_P}.tar.bz2"
13
14 LICENSE="Apache-2.0 GPL-2"
15 SLOT="0"
16 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~x86-fbsd ~amd64-linux ~x86-linux ~x86-macos"
17 IUSE="berkdb cron ipv6 ldap libressl mysql postgres qmail sqlite ssl test"
18
19 # The Makefile.PL script checks for dependencies, but only fails if a
20 # required (i.e. not optional) dependency is missing. We therefore
21 # require most of the optional modules only at runtime.
22 REQDEPEND="dev-lang/perl:=
23         dev-perl/HTML-Parser
24         dev-perl/Net-DNS
25         dev-perl/NetAddr-IP
26         virtual/perl-Archive-Tar
27         virtual/perl-Digest-SHA
28         virtual/perl-IO-Zlib
29         virtual/perl-Time-HiRes
30         ssl? (
31                 !libressl? ( dev-libs/openssl:0 )
32                 libressl? ( dev-libs/libressl )
33         )"
34
35 # SpamAssassin doesn't use libwww-perl except as a fallback for when
36 # curl/wget are missing, so we depend on one of those instead. Some
37 # mirrors use https, so we need those utilities to support SSL.
38 #
39 # re2c is needed to compile the rules (sa-compile).
40 #
41 # We still need the old Digest-SHA1 because razor2 has not been ported
42 # to Digest-SHA.
43 OPTDEPEND="app-crypt/gnupg
44         dev-perl/Digest-SHA1
45         dev-perl/Encode-Detect
46         dev-perl/Geo-IP
47         dev-perl/HTTP-Date
48         dev-perl/Mail-DKIM
49         dev-perl/Mail-SPF
50         dev-perl/Net-Patricia
51         dev-perl/Net-CIDR-Lite
52         dev-util/re2c
53         || ( net-misc/wget[ssl] net-misc/curl[ssl] )
54         virtual/perl-MIME-Base64
55         virtual/perl-Pod-Parser
56         berkdb? ( virtual/perl-DB_File )
57         ipv6? ( dev-perl/IO-Socket-INET6 )
58         ldap? ( dev-perl/perl-ldap )
59         mysql? (
60                 dev-perl/DBI
61                 dev-perl/DBD-mysql
62         )
63         postgres? (
64                 dev-perl/DBI
65                 dev-perl/DBD-Pg
66         )
67         sqlite? (
68                 dev-perl/DBI
69                 dev-perl/DBD-SQLite
70         )
71         ssl? ( dev-perl/IO-Socket-SSL )"
72
73 DEPEND="${REQDEPEND}
74         test? (
75                 ${OPTDEPEND}
76                 virtual/perl-Test-Harness
77         )"
78 RDEPEND="${REQDEPEND} ${OPTDEPEND}"
79
80 PATCHES=(
81         "${FILESDIR}/spamassassin-3.4.1-bug_7199.patch"
82         "${FILESDIR}/spamassassin-3.4.1-bug_7223.patch"
83         "${FILESDIR}/spamassassin-3.4.1-bug_7231.patch"
84         "${FILESDIR}/spamassassin-3.4.1-bug_7265.patch"
85         "${FILESDIR}/spamassassin-3.4.1-bug_7231-extra.patch"
86         "${FILESDIR}/spamassassin-3.4.1-bug_7404.patch"
87         "${FILESDIR}/spamassassin-3.4.1-bug_7462.patch"
88         "${FILESDIR}/spamassassin-3.4.1-perl526.patch"
89         "${FILESDIR}/spamassassin-3.4.1-bug_7361.patch"
90 )
91
92 src_prepare() {
93         default
94
95         # The sa_compile test does some weird stuff like hopping around in
96         # the directory tree and calling "make" to create a dist tarball
97         # from ${S}. It fails, and is more trouble than it's worth...
98         perl_rm_files t/sa_compile.t || die 'failed to remove sa_compile test'
99
100         # The spamc tests (which need the networked spamd daemon) fail for
101         # irrelevant reasons. It's too hard to disable them (unlike the
102         # spamd tests themselves -- see src_test), so use a crude
103         # workaround.
104         perl_rm_files t/spamc_*.t || die 'failed to remove spamc tests'
105 }
106
107 src_configure() {
108         # This is how and where the perl-module eclass disables the
109         # MakeMaker interactive prompt.
110         export PERL_MM_USE_DEFAULT=1
111
112         # Set SYSCONFDIR explicitly so we can't get bitten by bug 48205 again
113         # (just to be sure, nobody knows how it could happen in the first place).
114         #
115         # We also set the path to the perl executable explictly. This will be
116         # used to create the initial shebang line in the scripts (bug 62276).
117         perl Makefile.PL \
118                 PREFIX="${EPREFIX}/usr" \
119                 INSTALLDIRS=vendor \
120                 SYSCONFDIR="${EPREFIX}/etc" \
121                 DATADIR="${EPREFIX}/usr/share/spamassassin" \
122                 PERL_BIN="${EPREFIX}/usr/bin/perl" \
123                 ENABLE_SSL="$(usex ssl)" \
124                 DESTDIR="${D}" \
125                 || die 'failed to create a Makefile using Makefile.PL'
126
127         # Now configure spamc.
128         emake CC="$(tc-getCC)" LDFLAGS="${LDFLAGS}" spamc/Makefile
129 }
130
131 src_compile() {
132         emake
133         use qmail && emake spamc/qmail-spamc
134 }
135
136 src_install () {
137         emake install
138         einstalldocs
139
140         # Create the stub dir used by sa-update and friends
141         keepdir /var/lib/spamassassin
142
143         # Move spamd to sbin where it belongs.
144         dodir /usr/sbin
145         mv "${ED}"/usr/bin/spamd "${ED}"/usr/sbin/spamd  || die "move spamd failed"
146
147         if use qmail; then
148                 dobin spamc/qmail-spamc
149         fi
150
151         ln -s mail/spamassassin "${ED}"/etc/spamassassin || die
152
153         # Disable plugin by default
154         sed -i -e 's/^loadplugin/\#loadplugin/g' \
155                 "${ED}/etc/mail/spamassassin/init.pre" \
156                 || die "failed to disable plugins by default"
157
158         # Add the init and config scripts.
159         newinitd "${FILESDIR}/3.4.1-spamd.init-r2" spamd
160         newconfd "${FILESDIR}/3.4.1-spamd.conf-r1" spamd
161
162         systemd_newunit "${FILESDIR}/${PN}.service-r3" "${PN}.service"
163         systemd_install_serviced "${FILESDIR}/${PN}.service.conf-r1" \
164                                                          "${PN}.service"
165
166         use postgres && dodoc sql/*_pg.sql
167         use mysql && dodoc sql/*_mysql.sql
168
169         dodoc NOTICE TRADEMARK CREDITS UPGRADE USAGE sql/README.bayes \
170                 sql/README.awl procmailrc.example sample-nonspam.txt \
171                 sample-spam.txt spamd/PROTOCOL spamd/README.vpopmail \
172                 spamd-apache2/README.apache
173
174         # Rename some files so that they don't clash with others.
175         newdoc spamd/README README.spamd
176         newdoc sql/README README.sql
177         newdoc ldap/README README.ldap
178
179         if use qmail; then
180                 dodoc spamc/README.qmail
181         fi
182
183         insinto /etc/mail/spamassassin/
184         insopts -m0400
185         newins "${FILESDIR}"/secrets.cf secrets.cf.example
186
187         # Create the directory where sa-update stores its GPG key (if you
188         # choose to import one). If this directory does not exist, the
189         # import will fail. This is bug 396307. We expect that the import
190         # will be performed as root, and making the directory accessible
191         # only to root prevents a warning on the command-line.
192         diropts -m0700
193         dodir /etc/mail/spamassassin/sa-update-keys
194
195         if use cron; then
196                 # Install the cron job if they want it.
197                 exeinto /etc/cron.daily
198                 newexe "${FILESDIR}/update-spamassassin-rules.cron" \
199                            update-spamassassin-rules
200         fi
201
202         # Remove perllocal.pod to avoid file collisions (bug #603338).
203         perl_delete_localpod || die "failed to remove perllocal.pod"
204
205         # The perl-module eclass calls three other functions to clean
206         # up in src_install. The first fixes references to ${D} in the
207         # packlist, and is useful to us, too. The other two functions,
208         # perl_delete_emptybsdir and perl_remove_temppath, don't seem
209         # to be needed: there are no empty directories, *.bs files, or
210         # ${D} paths remaining in our installed image.
211         perl_fix_packlist || die "failed to fix paths in packlist"
212 }
213
214 src_test() {
215         # Trick the test suite into skipping the spamd tests. Setting
216         # SPAMD_HOST to a non-localhost value causes SKIP_SPAMD_TESTS to be
217         # set in SATest.pm.
218         export SPAMD_HOST=disabled
219         default
220 }
221
222 pkg_preinst() {
223         # The spamd daemon runs as this user. Use a real home directory so
224         # that it can hold SA configuration.
225         enewuser spamd -1 -1 /home/spamd
226 }
227
228 pkg_postinst() {
229         elog
230         elog 'No rules are installed by default. You will need to run sa-update'
231         elog 'at least once, and most likely configure SpamAssassin before it'
232         elog 'will work.'
233
234         if ! use cron; then
235                 elog
236                 elog 'You should consider a cron job for sa-update. One is provided'
237                 elog 'for daily updates if you enable the "cron" USE flag.'
238         fi
239         elog
240         elog 'Configuration and update help can be found on the wiki:'
241         elog
242         elog '  https://wiki.gentoo.org/wiki/SpamAssassin'
243         elog
244
245         ewarn 'If this version of SpamAssassin causes permissions issues'
246         ewarn 'with your user configurations or bayes databases, you may'
247         ewarn 'need to set SPAMD_RUN_AS_ROOT=true in your OpenRC service'
248         ewarn 'configuration file.'
249 }