1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 # do not add a ssl USE flag. ssl is mandatory
8 inherit autotools ssl-cert systemd toolchain-funcs
11 #MY_S="${PN}-ce-${PV}"
12 major_minor="$(ver_cut 1-2)"
13 sieve_version="0.5.10"
14 if [[ ${PV} == *_rc* ]] ; then
19 SRC_URI="https://dovecot.org/releases/${major_minor}/${rc_dir}${MY_P}.tar.gz
21 https://pigeonhole.dovecot.org/releases/${major_minor}/${rc_dir}${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
24 https://pigeonhole.dovecot.org/releases/${major_minor}/${rc_dir}${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
26 DESCRIPTION="An IMAP and POP3 server written with security primarily in mind"
27 HOMEPAGE="https://www.dovecot.org/"
30 LICENSE="LGPL-2.1 MIT"
31 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86"
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"
37 IUSE="${IUSE_DOVECOT_AUTH} ${IUSE_DOVECOT_COMPRESS} ${IUSE_DOVECOT_OTHER}"
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 )
48 mysql? ( dev-db/mysql-connector-c:0= )
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 )
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"
88 if use postgres || use mysql || use sqlite; then
89 conf="${conf} --with-sql"
92 # turn valgrind tests off. Bug #340791
94 --with-rundir="${EPREFIX}/run/dovecot" \
95 --with-statedir="${EPREFIX}/var/lib/dovecot" \
96 --with-moduledir="${EPREFIX}/usr/$(get_libdir)/dovecot" \
102 --with-systemdsystemunitdir="$(systemd_get_systemunitdir)" \
103 $( use_with argon2 sodium ) \
104 $( use_with bzip2 bzlib ) \
105 $( use_with caps libcap ) \
106 $( use_with kerberos gssapi ) \
109 $( use_with lucene ) \
112 $( use_with mysql ) \
114 $( use_with postgres pgsql ) \
115 $( use_with sqlite ) \
117 $( use_with tcpd libwrap ) \
118 $( use_with textcat ) \
119 $( use_with vpopmail ) \
121 $( use_enable static-libs static ) \
124 if use sieve || use managesieve ; then
125 # The sieve plugin needs this file to be build to determine the plugin
126 # directory and the list of libraries to link to.
128 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
130 $( use_enable static-libs static ) \
131 --localstatedir="${EPREFIX}/var" \
133 --with-dovecot="${S}" \
134 $( use_with managesieve )
140 if use sieve || use managesieve ; then
141 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
142 emake CC="$(tc-getCC)" CFLAGS="${CFLAGS}"
148 if use sieve || use managesieve ; then
149 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
158 # use suid && fperms u+s /usr/libexec/dovecot/deliver
161 einfo "Changing perms to allow deliver to be suided"
162 fowners root:mail "/usr/libexec/dovecot/dovecot-lda"
163 fperms 4750 "/usr/libexec/dovecot/dovecot-lda"
166 newinitd "${FILESDIR}"/dovecot.init-r6 dovecot
168 rm -rf "${ED}"/usr/share/doc/dovecot
170 dodoc AUTHORS NEWS README TODO
171 dodoc doc/*.{txt,cnf,xml,sh}
172 docinto example-config
173 dodoc doc/example-config/*.{conf,ext}
174 docinto example-config/conf.d
175 dodoc doc/example-config/conf.d/*.{conf,ext}
178 doman doc/man/*.{1,7}
180 # Create the dovecot.conf file from the dovecot-example.conf file that
181 # the dovecot folks nicely left for us....
182 local conf="${ED}/etc/dovecot/dovecot.conf"
183 local confd="${ED}/etc/dovecot/conf.d"
186 doins doc/example-config/*.{conf,ext}
187 insinto /etc/dovecot/conf.d
188 doins doc/example-config/conf.d/*.{conf,ext}
189 fperms 0600 /etc/dovecot/dovecot-{ldap,sql}.conf.ext
190 rm -f "${confd}/../README"
192 # .maildir is the Gentoo default
193 local mail_location="maildir:~/.maildir"
195 "s|#mail_location =|mail_location = ${mail_location}|" \
196 "${confd}/10-mail.conf" \
197 || die "failed to update mail location settings in 10-mail.conf"
199 # We're using pam files (imap and pop3) provided by mailbase
201 sed -i -e '/driver = pam/,/^[ \t]*}/ s|#args = dovecot|args = "\*"|' \
202 "${confd}/auth-system.conf.ext" \
203 || die "failed to update PAM settings in auth-system.conf.ext"
204 # mailbase does not provide a sieve pam file
205 use managesieve && dosym imap /etc/pam.d/sieve
207 's/#!include auth-system.conf.ext/!include auth-system.conf.ext/' \
208 "${confd}/10-auth.conf" \
209 || die "failed to update PAM settings in 10-auth.conf"
212 # Disable ipv6 if necessary
214 sed -i -e 's/^#listen = \*, ::/listen = \*/g' "${conf}" \
215 || die "failed to update listen settings in dovecot.conf"
218 # Update ssl cert locations
219 sed -i -e 's:^#ssl = yes:ssl = yes:' "${confd}/10-ssl.conf" \
220 || die "ssl conf failed"
221 sed -i -e 's:^ssl_cert =.*:ssl_cert = </etc/ssl/dovecot/server.pem:' \
222 -e 's:^ssl_key =.*:ssl_key = </etc/ssl/dovecot/server.key:' \
223 "${confd}/10-ssl.conf" || die "failed to update SSL settings in 10-ssl.conf"
225 # Install SQL configuration
226 if use mysql || use postgres; then
228 's/#!include auth-sql.conf.ext/!include auth-sql.conf.ext/' \
229 "${confd}/10-auth.conf" || die "failed to update SQL settings in \
233 # Install LDAP configuration
236 's/#!include auth-ldap.conf.ext/!include auth-ldap.conf.ext/' \
237 "${confd}/10-auth.conf" \
238 || die "failed to update ldap settings in 10-auth.conf"
241 if use vpopmail; then
243 's/#!include auth-vpopmail.conf.ext/!include auth-vpopmail.conf.ext/' \
244 "${confd}/10-auth.conf" \
245 || die "failed to update vpopmail settings in 10-auth.conf"
248 if use sieve || use managesieve ; then
249 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
250 emake DESTDIR="${ED}" install
252 's/^[[:space:]]*#mail_plugins = $mail_plugins/mail_plugins = sieve/' "${confd}/15-lda.conf" \
253 || die "failed to update sieve settings in 15-lda.conf"
254 rm -rf "${ED}"/usr/share/doc/dovecot
255 docinto example-config/conf.d
256 dodoc doc/example-config/conf.d/*.conf
257 insinto /etc/dovecot/conf.d
258 doins doc/example-config/conf.d/90-sieve{,-extprograms}.conf
259 use managesieve && doins doc/example-config/conf.d/20-managesieve.conf
263 dodoc doc/devel/DESIGN
265 dodoc doc/plugins/*.txt
267 dodoc doc/extensions/*.txt
269 dodoc doc/locations/*.txt
270 doman doc/man/*.{1,7}
273 use static-libs || find "${ED}"/usr/lib* -name '*.la' -delete
277 # Let's not make a new certificate if we already have one
278 if ! [[ -e "${ROOT}"/etc/ssl/dovecot/server.pem && \
279 -e "${ROOT}"/etc/ssl/dovecot/server.key ]]; then
280 einfo "Creating SSL certificate"
281 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Dovecot IMAP Server}"
282 install_cert /etc/ssl/dovecot/server
285 elog "Please read https://doc.dovecot.org/installation_guide/upgrading/ for upgrade notes."