1 # Copyright 1999-2024 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 inherit autotools readme.gentoo-r1 systemd
7 DESCRIPTION="An IMAP daemon designed specifically for maildirs"
8 HOMEPAGE="https://www.courier-mta.org/imap/"
9 SRC_URI="https://downloads.sourceforge.net/courier/${P}.tar.bz2"
13 KEYWORDS="~alpha amd64 arm arm64 ~hppa ~mips ~ppc ppc64 ~s390 sparc x86"
15 IUSE="berkdb debug fam +gdbm gnutls ipv6 selinux trashquota"
16 REQUIRED_USE="|| ( berkdb gdbm )"
19 gnutls? ( net-libs/gnutls:=[tools] )
23 >=net-libs/courier-authlib-0.71
24 >=net-libs/courier-unicode-2:=
25 >=net-mail/mailbase-0.00-r8
27 berkdb? ( sys-libs/db:= )
29 gdbm? ( >=sys-libs/gdbm-1.8.0:= )
37 selinux? ( sec-policy/selinux-courier )
40 # get rid of old style virtual - bug 350792
49 # make check is not supported by this package due to the
50 # --enable-workarounds-for-imap-client-bugs option.
53 DISABLE_AUTOFORMATTING="yes"
55 Please read http://www.courier-mta.org/imap/INSTALL.html#upgrading
56 and remove TLS_DHPARAMS from configuration files or run mkdhparams
58 For a quick-start howto please refer to
59 ${PN}-gentoo.readme in /usr/share/doc/${PF}
61 Please convert maildir to utf8
62 and rerun mkdhparams if needed. Location has changed
66 "${FILESDIR}/${PN}-4.17-aclocal-fix.patch"
67 "${FILESDIR}/${PN}-5.0.8-ar-fix.patch"
73 # These patches should fix problems detecting BerkeleyDB.
74 # We now can compile with db4 support.
76 eapply "${FILESDIR}/${PN}-4.17-db4-bdbobj_configure.ac.patch"
77 eapply "${FILESDIR}/${PN}-4.17-db4-configure.ac.patch"
86 # Default to gdbm if both berkdb and gdbm are present.
88 einfo "Building with GDBM support"
89 myconf="${myconf} --with-db=gdbm"
90 elif use berkdb ; then
91 einfo "Building with BerkeleyDB support"
92 myconf="${myconf} --with-db=db"
95 if use trashquota ; then
96 einfo "Building with Trash Quota Support"
97 myconf="${myconf} --with-trashquota"
100 use debug && myconf="${myconf} debug=true"
103 --with-notice=unicode \
104 --disable-root-check \
106 --sysconfdir="/etc/${PN}" \
107 --libexecdir="/usr/$(get_libdir)/${PN}" \
108 --localstatedir="/var/lib/${PN}" \
109 --with-authdaemonvar="/var/lib/${PN}/authdaemon" \
110 --enable-workarounds-for-imap-client-bugs \
111 --with-mailuser=mail \
112 --with-mailgroup=mail \
113 --with-certsdir="/etc/courier-imap" \
121 # spurious failures with parallel compiles, bug #????
126 dodir "/var/lib/${PN}" /etc/pam.d
127 keepdir /var/lib/courier-imap
130 rm -r "${D}/etc/pam.d" || die
132 # Avoid name collisions in /usr/sbin wrt imapd and pop3d
133 for name in imapd pop3d ; do
134 mv "${D}/usr/sbin/"{,courier-}${name} \
135 || die "failed to rename ${name} to courier-${name}"
138 # Hack /usr/lib/courier-imap/foo.rc to use ${MAILDIR} instead of
139 # 'Maildir', and to use /usr/sbin/courier-foo names.
140 for service in {imapd,pop3d}{,-ssl} ; do
141 sed -e 's/Maildir/${MAILDIR}/' \
142 -i "${D}/usr/$(get_libdir)/${PN}/${service}.rc" \
144 sed -e "s/\/usr\/sbin\/${service}/\/usr\/sbin\/courier-${service}/" \
145 -i "${D}/usr/$(get_libdir)/${PN}/${service}.rc" \
149 # Rename the config files correctly and add a value for ${MAILDIR}
151 for service in {imapd,pop3d}{,-ssl} ; do
152 mv "${D}/etc/${PN}/${service}"{.dist,} \
153 || die "failed to rename ${service}.dist to ${service}"
154 echo -e '\n# Hardwire a value for ${MAILDIR}' \
155 >> "${D}/etc/${PN}/${service}"
156 echo 'MAILDIR=.maildir' >> "${D}/etc/${PN}/${service}"
157 echo 'MAILDIRPATH=.maildir' >> "${D}/etc/${PN}/${service}"
160 for service in imapd pop3d ; do
161 echo -e '# Put any program for ${PRERUN} here' \
162 >> "${D}/etc/${PN}/${service}"
163 echo 'PRERUN=' >> "${D}/etc/${PN}/${service}"
164 echo -e '# Put any program for ${LOGINRUN} here' \
165 >> "${D}/etc/${PN}/${service}"
166 echo -e '# this is for relay-ctrl-allow in 4*' \
167 >> "${D}/etc/${PN}/${service}"
168 echo 'LOGINRUN=' >> "${D}/etc/${PN}/${service}"
171 for x in "${D}/usr/sbin"/* ; do
172 if [[ -L "${x}" ]] ; then
173 rm "${x}" || die "failed to remove ${x}"
177 mv "${D}/usr/share"/* "${D}/usr/sbin/" || die
178 mv "${D}/usr/sbin/man" "${D}/usr/share/" || die
180 rm "${D}/usr/sbin/"{mkimapdcert,mkpop3dcert} || die
182 dosbin "${FILESDIR}/mkimapdcert" "${FILESDIR}/mkpop3dcert"
184 dosym ../../sbin/courierlogger "/usr/$(get_libdir)/${PN}/courierlogger"
186 for initd in courier-{imapd,pop3d}{,-ssl} ; do
187 sed -e "s:GENTOO_LIBDIR:$(get_libdir):g" \
188 "${FILESDIR}/${PN}-${INITD_VER}-${initd}.rc6" \
190 || die "initd libdir-sed failed"
191 doinitd "${T}/${initd}"
194 cp "${FILESDIR}"/courier-*-r1.service .
197 -e "s:/usr/lib/:/usr/$(get_libdir)/:" \
198 courier-*-r1.service \
201 systemd_newunit courier-authdaemond-r1.service \
202 courier-authdaemond.service
203 systemd_newunit courier-imapd-ssl-r1.service \
204 courier-imapd-ssl.service
205 systemd_newunit courier-imapd-r1.service \
206 courier-imapd.service
208 exeinto "/usr/$(get_libdir)/${PN}"
209 for exe in gentoo-{imapd,pop3d}{,-ssl}.rc courier-{imapd,pop3d}.indirect ; do
210 sed -e "s:GENTOO_LIBDIR:$(get_libdir):g" \
211 "${FILESDIR}/${PN}-${RC_VER}-${exe}" \
213 || die "exe libdir-sed failed"
217 # Avoid a collision with mail-mta/netqmail, bug 482098.
218 mv "${D}/usr/sbin/"{,courier-}maildirmake \
219 || die "failed to rename maildirmake to courier-maildirmake"
220 mv "${D}/usr/share/man/man1/"{,courier-}maildirmake.1 \
221 || die "failed to rename maildirmake.1 to courier-maildirmake.1"
223 dodoc AUTHORS INSTALL NEWS README ChangeLog
224 readme.gentoo_create_doc
225 dodoc "${FILESDIR}/${PN}-gentoo.readme"
227 dodoc libs/imap/ChangeLog libs/imap/BUGS* libs/imap/README*
229 dodoc libs/maildir/AUTHORS libs/maildir/*.html libs/maildir/README*
231 dodoc libs/rfc2045/*.html
233 dodoc libs/tcpd/README* libs/tcpd/*.html
234 exeinto /etc/cron.monthly
235 newexe "${FILESDIR}"/${PN}.cron ${PN}
239 # Some users have been reporting that permissions on this directory were
240 # getting scrambled, so let's ensure that they are sane.
241 chmod 0755 "${ROOT}/usr/$(get_libdir)/${PN}"
243 readme.gentoo_print_elog
246 elog "Courier Imap now run as user mail:mail."
248 elog "This require you to enable read/write access to the caches:"
249 elog "/var/lib/courier-imap/courierssl*cache (chown mail:mail)"
250 elog "and read access to the certificates (e.g. /etc/courier-imap/pop3d.pem )"