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