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 eapi7-ver ssl-cert systemd toolchain-funcs user
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
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_STORAGE} ${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 )
68 "${FILESDIR}/${PN}-userdb-passwd-fix.patch"
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"
76 # default internal user
78 enewuser dovecot 97 -1 /dev/null dovecot
80 enewuser dovenull -1 -1 /dev/null
93 if use postgres || use mysql || use sqlite; then
94 conf="${conf} --with-sql"
97 # turn valgrind tests off. Bug #340791
99 --with-rundir="${EPREFIX}/run/dovecot" \
100 --with-statedir="${EPREFIX}/var/lib/dovecot" \
101 --with-moduledir="${EPREFIX}/usr/$(get_libdir)/dovecot" \
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 ) \
114 $( use_with lucene ) \
117 $( use_with mysql ) \
119 $( use_with postgres pgsql ) \
120 $( use_with sqlite ) \
122 $( use_with tcpd libwrap ) \
123 $( use_with textcat ) \
124 $( use_with vpopmail ) \
126 $( use_enable static-libs static ) \
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.
133 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
135 $( use_enable static-libs static ) \
136 --localstatedir="${EPREFIX}/var" \
138 --with-dovecot="${S}" \
139 $( use_with managesieve )
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}"
153 if use sieve || use managesieve ; then
154 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
163 # use suid && fperms u+s /usr/libexec/dovecot/deliver
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"
171 newinitd "${FILESDIR}"/dovecot.init-r6 dovecot
173 rm -rf "${ED}"/usr/share/doc/dovecot
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}
183 doman doc/man/*.{1,7}
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"
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"
197 # .maildir is the Gentoo default
198 local mail_location="maildir:~/.maildir"
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"
204 # We're using pam files (imap and pop3) provided by mailbase
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
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"
217 # Disable ipv6 if necessary
219 sed -i -e 's/^#listen = \*, ::/listen = \*/g' "${conf}" \
220 || die "failed to update listen settings in dovecot.conf"
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"
230 # Install SQL configuration
231 if use mysql || use postgres; then
233 's/#!include auth-sql.conf.ext/!include auth-sql.conf.ext/' \
234 "${confd}/10-auth.conf" || die "failed to update SQL settings in \
238 # Install LDAP configuration
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"
246 if use vpopmail; then
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"
253 if use sieve || use managesieve ; then
254 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
255 emake DESTDIR="${ED}" install
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
268 dodoc doc/devel/DESIGN
270 dodoc doc/plugins/*.txt
272 dodoc doc/extensions/*.txt
274 dodoc doc/locations/*.txt
275 doman doc/man/*.{1,7}
278 use static-libs || find "${ED}"/usr/lib* -name '*.la' -delete
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
290 elog "Please read https://doc.dovecot.org/installation_guide/upgrading/ for upgrade notes."