net-mail/tnef: ppc64 stable wrt bug #701816
[gentoo.git] / net-mail / dovecot / dovecot-2.3.7.2.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 # do not add a ssl USE flag.  ssl is mandatory
7 SSL_DEPS_SKIP=1
8 inherit autotools eapi7-ver ssl-cert systemd toolchain-funcs user
9
10 MY_P="${P/_/.}"
11 #MY_S="${PN}-ce-${PV}"
12 major_minor="$(ver_cut 1-2)"
13 sieve_version="0.5.7.2"
14 if [[ ${PV} == *_rc* ]] ; then
15         rc_dir="rc/"
16 else
17         rc_dir=""
18 fi
19 SRC_URI="https://dovecot.org/releases/${major_minor}/${rc_dir}${MY_P}.tar.gz
20         sieve? (
21         https://pigeonhole.dovecot.org/releases/${major_minor}/${rc_dir}${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
22         )
23         managesieve? (
24         https://pigeonhole.dovecot.org/releases/${major_minor}/${rc_dir}${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
25         ) "
26 DESCRIPTION="An IMAP and POP3 server written with security primarily in mind"
27 HOMEPAGE="https://www.dovecot.org/"
28
29 SLOT="0"
30 LICENSE="LGPL-2.1 MIT"
31 KEYWORDS="~alpha amd64 arm hppa ia64 ~mips ppc ppc64 s390 ~sparc x86"
32
33 IUSE_DOVECOT_AUTH="kerberos ldap lua mysql pam postgres sqlite vpopmail"
34 IUSE_DOVECOT_COMPRESS="bzip2 lzma lz4 zlib"
35 IUSE_DOVECOT_OTHER="argon2 caps doc ipv6 libressl lucene managesieve selinux sieve solr static-libs suid tcpd textcat"
36
37 IUSE="${IUSE_DOVECOT_AUTH} ${IUSE_DOVECOT_STORAGE} ${IUSE_DOVECOT_COMPRESS} ${IUSE_DOVECOT_OTHER}"
38
39 DEPEND="argon2? ( dev-libs/libsodium )
40         bzip2? ( app-arch/bzip2 )
41         caps? ( sys-libs/libcap )
42         kerberos? ( virtual/krb5 )
43         ldap? ( net-nds/openldap )
44         lua? ( dev-lang/lua:* )
45         lucene? ( >=dev-cpp/clucene-2.3 )
46         lzma? ( app-arch/xz-utils )
47         lz4? ( app-arch/lz4 )
48         mysql? ( dev-db/mysql-connector-c:0= )
49         pam? ( sys-libs/pam )
50         postgres? ( dev-db/postgresql:* !dev-db/postgresql[ldap,threads] )
51         selinux? ( sec-policy/selinux-dovecot )
52         solr? ( net-misc/curl dev-libs/expat )
53         sqlite? ( dev-db/sqlite:* )
54         !libressl? ( dev-libs/openssl:0= )
55         libressl? ( dev-libs/libressl:0= )
56         suid? ( acct-group/mail )
57         tcpd? ( sys-apps/tcp-wrappers )
58         textcat? ( app-text/libexttextcat )
59         vpopmail? ( net-mail/vpopmail )
60         zlib? ( sys-libs/zlib )
61         virtual/libiconv
62         dev-libs/icu:="
63
64 RDEPEND="${DEPEND}
65         net-mail/mailbase"
66
67 PATCHES=(
68         "${FILESDIR}/${PN}-userdb-passwd-fix.patch"
69 )
70
71 pkg_setup() {
72         if use managesieve && ! use sieve; then
73                 ewarn "managesieve USE flag selected but sieve USE flag unselected"
74                 ewarn "sieve USE flag will be turned on"
75         fi
76         # default internal user
77         enewgroup dovecot 97
78         enewuser dovecot 97 -1 /dev/null dovecot
79         # default login user
80         enewuser dovenull -1 -1 /dev/null
81 }
82
83 src_prepare() {
84         default
85         # bug 657108
86         elibtoolize
87         #eautoreconf
88 }
89
90 src_configure() {
91         local conf=""
92
93         if use postgres || use mysql || use sqlite; then
94                 conf="${conf} --with-sql"
95         fi
96
97         # turn valgrind tests off. Bug #340791
98         VALGRIND=no econf \
99                 --with-rundir="${EPREFIX}/run/dovecot" \
100                 --with-statedir="${EPREFIX}/var/lib/dovecot" \
101                 --with-moduledir="${EPREFIX}/usr/$(get_libdir)/dovecot" \
102                 --without-stemmer \
103                 --disable-rpath \
104                 --without-libbsd \
105                 --with-icu \
106                 --with-ssl \
107                 --with-systemdsystemunitdir="$(systemd_get_systemunitdir)" \
108                 $( use_with argon2 sodium ) \
109                 $( use_with bzip2 bzlib ) \
110                 $( use_with caps libcap ) \
111                 $( use_with kerberos gssapi ) \
112                 $( use_with lua ) \
113                 $( use_with ldap ) \
114                 $( use_with lucene ) \
115                 $( use_with lz4 ) \
116                 $( use_with lzma ) \
117                 $( use_with mysql ) \
118                 $( use_with pam ) \
119                 $( use_with postgres pgsql ) \
120                 $( use_with sqlite ) \
121                 $( use_with solr ) \
122                 $( use_with tcpd libwrap ) \
123                 $( use_with textcat ) \
124                 $( use_with vpopmail ) \
125                 $( use_with zlib ) \
126                 $( use_enable static-libs static ) \
127                 ${conf}
128
129         if use sieve || use managesieve ; then
130                 # The sieve plugin needs this file to be build to determine the plugin
131                 # directory and the list of libraries to link to.
132                 emake dovecot-config
133                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
134                 econf \
135                         $( use_enable static-libs static ) \
136                         --localstatedir="${EPREFIX}/var" \
137                         --enable-shared \
138                         --with-dovecot="${S}" \
139                         $( use_with managesieve )
140         fi
141 }
142
143 src_compile() {
144         default
145         if use sieve || use managesieve ; then
146                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
147                 emake CC="$(tc-getCC)" CFLAGS="${CFLAGS}"
148         fi
149 }
150
151 src_test() {
152         default
153         if use sieve || use managesieve ; then
154                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
155                 default
156         fi
157 }
158
159 src_install() {
160         default
161
162         # insecure:
163         # use suid && fperms u+s /usr/libexec/dovecot/deliver
164         # better:
165         if use suid;then
166                 einfo "Changing perms to allow deliver to be suided"
167                 fowners root:mail "/usr/libexec/dovecot/dovecot-lda"
168                 fperms 4750 "/usr/libexec/dovecot/dovecot-lda"
169         fi
170
171         newinitd "${FILESDIR}"/dovecot.init-r6 dovecot
172
173         rm -rf "${ED}"/usr/share/doc/dovecot
174
175         dodoc AUTHORS NEWS README TODO
176         dodoc doc/*.{txt,cnf,xml,sh}
177         docinto example-config
178         dodoc doc/example-config/*.{conf,ext}
179         docinto example-config/conf.d
180         dodoc doc/example-config/conf.d/*.{conf,ext}
181         docinto wiki
182         dodoc doc/wiki/*
183         doman doc/man/*.{1,7}
184
185         # Create the dovecot.conf file from the dovecot-example.conf file that
186         # the dovecot folks nicely left for us....
187         local conf="${ED}/etc/dovecot/dovecot.conf"
188         local confd="${ED}/etc/dovecot/conf.d"
189
190         insinto /etc/dovecot
191         doins doc/example-config/*.{conf,ext}
192         insinto /etc/dovecot/conf.d
193         doins doc/example-config/conf.d/*.{conf,ext}
194         fperms 0600 /etc/dovecot/dovecot-{ldap,sql}.conf.ext
195         rm -f "${confd}/../README"
196
197         # .maildir is the Gentoo default
198         local mail_location="maildir:~/.maildir"
199         sed -i -e \
200                 "s|#mail_location =|mail_location = ${mail_location}|" \
201                 "${confd}/10-mail.conf" \
202                 || die "failed to update mail location settings in 10-mail.conf"
203
204         # We're using pam files (imap and pop3) provided by mailbase
205         if use pam; then
206                 sed -i -e '/driver = pam/,/^[ \t]*}/ s|#args = dovecot|args = "\*"|' \
207                         "${confd}/auth-system.conf.ext" \
208                         || die "failed to update PAM settings in auth-system.conf.ext"
209                 # mailbase does not provide a sieve pam file
210                 use managesieve && dosym imap /etc/pam.d/sieve
211                 sed -i -e \
212                         's/#!include auth-system.conf.ext/!include auth-system.conf.ext/' \
213                         "${confd}/10-auth.conf" \
214                         || die "failed to update PAM settings in 10-auth.conf"
215         fi
216
217         # Disable ipv6 if necessary
218         if ! use ipv6; then
219                 sed -i -e 's/^#listen = \*, ::/listen = \*/g' "${conf}" \
220                         || die "failed to update listen settings in dovecot.conf"
221         fi
222
223         # Update ssl cert locations
224         sed -i -e 's:^#ssl = yes:ssl = yes:' "${confd}/10-ssl.conf" \
225                 || die "ssl conf failed"
226         sed -i -e 's:^ssl_cert =.*:ssl_cert = </etc/ssl/dovecot/server.pem:' \
227                 -e 's:^ssl_key =.*:ssl_key = </etc/ssl/dovecot/server.key:' \
228                 "${confd}/10-ssl.conf" || die "failed to update SSL settings in 10-ssl.conf"
229
230         # Install SQL configuration
231         if use mysql || use postgres; then
232                 sed -i -e \
233                         's/#!include auth-sql.conf.ext/!include auth-sql.conf.ext/' \
234                         "${confd}/10-auth.conf" || die "failed to update SQL settings in \
235                         10-auth.conf"
236         fi
237
238         # Install LDAP configuration
239         if use ldap; then
240                 sed -i -e \
241                         's/#!include auth-ldap.conf.ext/!include auth-ldap.conf.ext/' \
242                         "${confd}/10-auth.conf" \
243                         || die "failed to update ldap settings in 10-auth.conf"
244         fi
245
246         if use vpopmail; then
247                 sed -i -e \
248                         's/#!include auth-vpopmail.conf.ext/!include auth-vpopmail.conf.ext/' \
249                         "${confd}/10-auth.conf" \
250                         || die "failed to update vpopmail settings in 10-auth.conf"
251         fi
252
253         if use sieve || use managesieve ; then
254                 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
255                 emake DESTDIR="${ED}" install
256                 sed -i -e \
257                         's/^[[:space:]]*#mail_plugins = $mail_plugins/mail_plugins = sieve/' "${confd}/15-lda.conf" \
258                         || die "failed to update sieve settings in 15-lda.conf"
259                 rm -rf "${ED}"/usr/share/doc/dovecot
260                 docinto example-config/conf.d
261                 dodoc doc/example-config/conf.d/*.conf
262                 insinto /etc/dovecot/conf.d
263                 doins doc/example-config/conf.d/90-sieve{,-extprograms}.conf
264                 use managesieve && doins doc/example-config/conf.d/20-managesieve.conf
265                 docinto sieve/rfc
266                 dodoc doc/rfc/*.txt
267                 docinto sieve/devel
268                 dodoc doc/devel/DESIGN
269                 docinto plugins
270                 dodoc doc/plugins/*.txt
271                 docinto extensions
272                 dodoc doc/extensions/*.txt
273                 docinto locations
274                 dodoc doc/locations/*.txt
275                 doman doc/man/*.{1,7}
276         fi
277
278         use static-libs || find "${ED}"/usr/lib* -name '*.la' -delete
279 }
280
281 pkg_postinst() {
282         # Let's not make a new certificate if we already have one
283         if ! [[ -e "${ROOT}"/etc/ssl/dovecot/server.pem && \
284                 -e "${ROOT}"/etc/ssl/dovecot/server.key ]];     then
285                 einfo "Creating SSL     certificate"
286                 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Dovecot IMAP Server}"
287                 install_cert /etc/ssl/dovecot/server
288         fi
289
290         elog "Please read https://doc.dovecot.org/installation_guide/upgrading/ for upgrade notes."
291 }