1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit perl-functions systemd toolchain-funcs user eapi7-ver
8 MY_P="Mail-SpamAssassin-${PV//_/-}"
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"
14 LICENSE="Apache-2.0 GPL-2"
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 )"
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:=
27 virtual/perl-Archive-Tar
28 virtual/perl-Digest-SHA
30 virtual/perl-Time-HiRes
32 !libressl? ( dev-libs/openssl:0= )
33 libressl? ( dev-libs/libressl )
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.
40 # re2c is needed to compile the rules (sa-compile).
42 # We still need the old Digest-SHA1 because razor2 has not been ported
44 OPTDEPEND="app-crypt/gnupg
47 dev-perl/Encode-Detect
53 dev-perl/Net-CIDR-Lite
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 )
73 ssl? ( dev-perl/IO-Socket-SSL )"
78 virtual/perl-Test-Harness
80 RDEPEND="${REQDEPEND} ${OPTDEPEND}"
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'
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
97 perl_rm_files t/spamc_*.t || die 'failed to remove spamc tests'
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'
106 # This is how and where the perl-module eclass disables the
107 # MakeMaker interactive prompt.
108 export PERL_MM_USE_DEFAULT=1
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).
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).
116 PREFIX="${EPREFIX}/usr" \
118 SYSCONFDIR="${EPREFIX}/etc" \
119 DATADIR="${EPREFIX}/usr/share/spamassassin" \
120 PERL_BIN="${EPREFIX}/usr/bin/perl" \
121 ENABLE_SSL="$(usex ssl)" \
123 || die 'failed to create a Makefile using Makefile.PL'
125 # Now configure spamc.
126 emake CC="$(tc-getCC)" LDFLAGS="${LDFLAGS}" spamc/Makefile
131 use qmail && emake spamc/qmail-spamc
138 # Create the stub dir used by sa-update and friends
139 keepdir /var/lib/spamassassin
141 # Move spamd to sbin where it belongs.
143 mv "${ED}"/usr/bin/spamd "${ED}"/usr/sbin/spamd || die "move spamd failed"
146 dobin spamc/qmail-spamc
149 dosym mail/spamassassin /etc/spamassassin
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"
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
160 systemd_newunit "${FILESDIR}/${PN}.service-r4" "${PN}.service"
161 systemd_install_serviced "${FILESDIR}/${PN}.service.conf-r2" \
164 use postgres && dodoc sql/*_pg.sql
165 use mysql && dodoc sql/*_mysql.sql
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
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
178 dodoc spamc/README.qmail
181 insinto /etc/mail/spamassassin/
183 newins "${FILESDIR}"/secrets.cf secrets.cf.example
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.
191 dodir /etc/mail/spamassassin/sa-update-keys
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
200 # Remove perllocal.pod to avoid file collisions (bug #603338).
201 perl_delete_localpod || die "failed to remove perllocal.pod"
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"
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
216 export SPAMD_HOST=disabled
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
225 if use mysql || use postgres ; then
228 for _v in ${REPLACING_VERSIONS}; do
229 if ver_test "${_v}" -lt "3.4.3"; then
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'
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'
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.'
256 elog 'Configuration and update help can be found on the wiki:'
258 elog ' https://wiki.gentoo.org/wiki/SpamAssassin'
261 if use mysql || use postgres ; then
263 for _v in ${REPLACING_VERSIONS}; do
264 if ver_test "${_v}" -lt "3.4.3"; then
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'
272 # show this only once
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.'