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 versionator
11 major_minor="$(ver_cut 1-2)"
12 sieve_version="0.4.24.2"
13 if [[ ${PV} == *_rc* ]] ; then
18 SRC_URI="https://dovecot.org/releases/${major_minor}/${rc_dir}${MY_P}.tar.gz
20 https://pigeonhole.dovecot.org/releases/${major_minor}/${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
23 https://pigeonhole.dovecot.org/releases/${major_minor}/${PN}-${major_minor}-pigeonhole-${sieve_version}.tar.gz
25 DESCRIPTION="An IMAP and POP3 server written with security primarily in mind"
26 HOMEPAGE="https://www.dovecot.org/"
29 LICENSE="LGPL-2.1 MIT"
30 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~ppc ~ppc64 ~s390 ~sparc ~x86"
32 IUSE_DOVECOT_AUTH="kerberos ldap mysql pam postgres sqlite vpopmail"
33 IUSE_DOVECOT_COMPRESS="bzip2 lzma lz4 zlib"
34 IUSE_DOVECOT_OTHER="caps doc ipv6 libressl lucene managesieve selinux sieve solr static-libs suid tcpd textcat"
36 IUSE="${IUSE_DOVECOT_AUTH} ${IUSE_DOVECOT_STORAGE} ${IUSE_DOVECOT_COMPRESS} ${IUSE_DOVECOT_OTHER}"
38 DEPEND="bzip2? ( app-arch/bzip2 )
39 caps? ( sys-libs/libcap )
40 kerberos? ( virtual/krb5 )
41 ldap? ( net-nds/openldap )
42 lucene? ( >=dev-cpp/clucene-2.3 )
43 lzma? ( app-arch/xz-utils )
45 mysql? ( dev-db/mysql-connector-c:0= )
47 postgres? ( dev-db/postgresql:* !dev-db/postgresql[ldap,threads] )
48 selinux? ( sec-policy/selinux-dovecot )
49 solr? ( net-misc/curl dev-libs/expat )
50 sqlite? ( dev-db/sqlite:* )
51 !libressl? ( dev-libs/openssl:0= )
52 libressl? ( dev-libs/libressl:0= )
53 tcpd? ( sys-apps/tcp-wrappers )
54 textcat? ( app-text/libexttextcat )
55 vpopmail? ( net-mail/vpopmail )
56 zlib? ( sys-libs/zlib )
64 "${FILESDIR}/${PN}-userdb-passwd-fix.patch"
68 if use managesieve && ! use sieve; then
69 ewarn "managesieve USE flag selected but sieve USE flag unselected"
70 ewarn "sieve USE flag will be turned on"
72 # default internal user
74 enewuser dovecot 97 -1 /dev/null dovecot
76 enewuser dovenull -1 -1 /dev/null
77 # add "mail" group for suid'ing. Better security isolation.
92 if use postgres || use mysql || use sqlite; then
93 conf="${conf} --with-sql"
96 # turn valgrind tests off. Bug #340791
98 --with-statedir="${EPREFIX}/var/lib/dovecot" \
99 --with-rundir="${EPREFIX}/run/dovecot" \
100 --with-moduledir="${EPREFIX}/usr/$(get_libdir)/dovecot" \
105 --with-systemdsystemunitdir="$(systemd_get_systemunitdir)" \
106 $( use_with bzip2 bzlib ) \
107 $( use_with caps libcap ) \
108 $( use_with kerberos gssapi ) \
110 $( use_with lucene ) \
113 $( use_with mysql ) \
115 $( use_with postgres pgsql ) \
116 $( use_with sqlite ) \
118 $( use_with tcpd libwrap ) \
119 $( use_with textcat ) \
120 $( use_with vpopmail ) \
122 $( use_enable static-libs static ) \
125 if use sieve || use managesieve ; then
126 # The sieve plugin needs this file to be build to determine the plugin
127 # directory and the list of libraries to link to.
129 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
131 $( use_enable static-libs static ) \
132 --localstatedir="${EPREFIX}/var" \
134 --with-dovecot="${S}" \
135 $( use_with managesieve )
141 if use sieve || use managesieve ; then
142 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
143 emake CC="$(tc-getCC)" CFLAGS="${CFLAGS}"
149 if use sieve || use managesieve ; then
150 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
159 # use suid && fperms u+s /usr/libexec/dovecot/deliver
162 einfo "Changing perms to allow deliver to be suided"
163 fowners root:mail "/usr/libexec/dovecot/dovecot-lda"
164 fperms 4750 "/usr/libexec/dovecot/dovecot-lda"
167 newinitd "${FILESDIR}"/dovecot.init-r6 dovecot
169 rm -rf "${ED}"/usr/share/doc/dovecot
171 dodoc AUTHORS NEWS README TODO
172 dodoc doc/*.{txt,cnf,xml,sh}
173 docinto example-config
174 dodoc doc/example-config/*.{conf,ext}
175 docinto example-config/conf.d
176 dodoc doc/example-config/conf.d/*.{conf,ext}
179 doman doc/man/*.{1,7}
181 # Create the dovecot.conf file from the dovecot-example.conf file that
182 # the dovecot folks nicely left for us....
183 local conf="${ED}/etc/dovecot/dovecot.conf"
184 local confd="${ED}/etc/dovecot/conf.d"
187 doins doc/example-config/*.{conf,ext}
188 insinto /etc/dovecot/conf.d
189 doins doc/example-config/conf.d/*.{conf,ext}
190 fperms 0600 /etc/dovecot/dovecot-{ldap,sql}.conf.ext
191 rm -f "${confd}/../README"
193 # .maildir is the Gentoo default
194 local mail_location="maildir:~/.maildir"
196 "s|#mail_location =|mail_location = ${mail_location}|" \
197 "${confd}/10-mail.conf" \
198 || die "failed to update mail location settings in 10-mail.conf"
200 # We're using pam files (imap and pop3) provided by mailbase
202 sed -i -e '/driver = pam/,/^[ \t]*}/ s|#args = dovecot|args = "\*"|' \
203 "${confd}/auth-system.conf.ext" \
204 || die "failed to update PAM settings in auth-system.conf.ext"
205 # mailbase does not provide a sieve pam file
206 use managesieve && dosym imap /etc/pam.d/sieve
208 's/#!include auth-system.conf.ext/!include auth-system.conf.ext/' \
209 "${confd}/10-auth.conf" \
210 || die "failed to update PAM settings in 10-auth.conf"
213 # Disable ipv6 if necessary
215 sed -i -e 's/^#listen = \*, ::/listen = \*/g' "${conf}" \
216 || die "failed to update listen settings in dovecot.conf"
219 # Update ssl cert locations
220 sed -i -e 's:^#ssl = yes:ssl = yes:' "${confd}/10-ssl.conf" \
221 || die "ssl conf failed"
222 sed -i -e 's:^ssl_cert =.*:ssl_cert = </etc/ssl/dovecot/server.pem:' \
223 -e 's:^ssl_key =.*:ssl_key = </etc/ssl/dovecot/server.key:' \
224 "${confd}/10-ssl.conf" || die "failed to update SSL settings in 10-ssl.conf"
226 # Install SQL configuration
227 if use mysql || use postgres; then
229 's/#!include auth-sql.conf.ext/!include auth-sql.conf.ext/' \
230 "${confd}/10-auth.conf" || die "failed to update SQL settings in \
234 # Install LDAP configuration
237 's/#!include auth-ldap.conf.ext/!include auth-ldap.conf.ext/' \
238 "${confd}/10-auth.conf" \
239 || die "failed to update ldap settings in 10-auth.conf"
242 if use vpopmail; then
244 's/#!include auth-vpopmail.conf.ext/!include auth-vpopmail.conf.ext/' \
245 "${confd}/10-auth.conf" \
246 || die "failed to update vpopmail settings in 10-auth.conf"
249 if use sieve || use managesieve ; then
250 cd "../dovecot-${major_minor}-pigeonhole-${sieve_version}" || die "cd failed"
251 emake DESTDIR="${ED}" install
253 's/^[[:space:]]*#mail_plugins = $mail_plugins/mail_plugins = sieve/' "${confd}/15-lda.conf" \
254 || die "failed to update sieve settings in 15-lda.conf"
255 rm -rf "${ED}"/usr/share/doc/dovecot
256 docinto example-config/conf.d
257 dodoc doc/example-config/conf.d/*.conf
258 insinto /etc/dovecot/conf.d
259 doins doc/example-config/conf.d/90-sieve{,-extprograms}.conf
260 use managesieve && doins doc/example-config/conf.d/20-managesieve.conf
264 dodoc doc/devel/DESIGN
266 dodoc doc/plugins/*.txt
268 dodoc doc/extensions/*.txt
270 dodoc doc/locations/*.txt
271 doman doc/man/*.{1,7}
274 use static-libs || find "${ED}"/usr/lib* -name '*.la' -delete
278 # Let's not make a new certificate if we already have one
279 if ! [[ -e "${ROOT}"/etc/ssl/dovecot/server.pem && \
280 -e "${ROOT}"/etc/ssl/dovecot/server.key ]]; then
281 einfo "Creating SSL certificate"
282 SSL_ORGANIZATION="${SSL_ORGANIZATION:-Dovecot IMAP Server}"
283 install_cert /etc/ssl/dovecot/server
286 elog "Please read https://doc.dovecot.org/installation_guide/upgrading/ for upgrade notes."