File cyrus-imapd.spec of Package cyrus-imapd.import5240

# spec file for package cyrus-imapd
# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

# norootforbuild

%define prjname cyrus-imapd

# Define and use _name because the macro expansion is not smart enough.  Without
# this construction the name definition of cyrus-imapd-kolab is changed to cyrus-imapd.
%if ! %{defined with_kolab}
%define with_kolab 0
%define _name cyrus-imapd

%define _name cyrus-imapd-kolab


Name:           %_name

%if %{with_kolab}
%define         pkg_perl_Cyrus_IMAP perl-Cyrus-IMAP-kolab
%define         pkg_perl_Cyrus_SIEVE_managesieve perl-Cyrus-SIEVE-managesieve-kolab
BuildRequires:  openldap2-devel

%define         pkg_perl_Cyrus_IMAP perl-Cyrus-IMAP
%define         pkg_perl_Cyrus_SIEVE_managesieve perl-Cyrus-SIEVE-managesieve


BuildRequires:  bison cyrus-sasl-devel db-devel drac ed flex krb5-devel openslp-devel openssl-devel opie pwdutils tcpd-devel
License:        BSD3c(or similar)
Group:          Productivity/Networking/Email/Servers
Requires:       %pkg_perl_Cyrus_IMAP %pkg_perl_Cyrus_SIEVE_managesieve
Recommends:     perl-TermReadLine-Gnu
Conflicts:      imap courier-imap
%if %{with_kolab}
Conflicts:      cyrus-imapd
Conflicts:      cyrus-imapd-kolab
Summary:        The Cyrus IMAP and POP Mail Server
Version:        2.3.16
Release:        16.<RELEASE21>
Source:         %{prjname}-%{version}.tar.bz2
Source1:        cyrus-imapd-rc.tar.gz
Source2:        DB_CONFIG
# The autocreate Patchset is maintained at:
Patch1:         cyrus-imapd-2.3.16-autocreate-0.10-0.drac.diff
Patch3:         auth_krb5-sentinel.patch
Patch4:         luser_relay.patch
Patch5:         user_deny_db-once.patch
Patch6:         murder-backend-empty-mechlist.patch
Patch7:         syslog-facility-doc.patch
Patch10:        cyrus-imapd-openslp.patch
Patch12:        pie.patch
Patch18:        cyrus-imapd-perl-path.patch
Patch19:        cyrus-imapd-libdb-4_8.patch
Patch20:        cyrus-imapd-STARTTLS-plaintext-command-injection.dif
Patch21:        cyrus-imapd_nntp-overflow.dif
Patch22:        cyrus-imapd_references_header-dos.dif
Patch23:        cyrus-imapd_nntp-auth-vuln.dif

%if %{with_kolab}
# KOLAB_cyrus-imapd patches are maintained at
Patch100:       KOLAB_cyrus-imapd-%{version}_Cyradm_Annotations.patch
Patch102:       KOLAB_cyrus-imapd-%{version}_Folder-names.patch
Patch103:       KOLAB_cyrus-imapd-%{version}_Groups2.patch
Patch104:       KOLAB_cyrus-imapd-%{version}_Logging.patch
Patch105:       KOLAB_cyrus-imapd-%{version}_timsieved_starttls-sendcaps.patch
Patch106:       KOLAB_cyrus-imapd-%{version}_UID.patch
Patch107:       KOLAB_cyrus-imapd-%{version}_cross-domain-acls.patch

Requires(pre):  /usr/sbin/useradd /usr/sbin/usermod %insserv_prereq %fillup_prereq /bin/sed
Requires(pre):  /bin/awk /bin/grep /bin/cat /usr/bin/find /usr/bin/db_verify sh-utils
Requires(pre):  fileutils cyrus-sasl netcfg /usr/bin/strings
Recommends:     cron
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%package -n %pkg_perl_Cyrus_IMAP

%if %{with_kolab}
Conflicts:      perl-Cyrus-IMAP
Conflicts:      perl-Cyrus-IMAP-kolab
License:        BSD3c(or similar)
Summary:        Cyrus IMAP Perl Module
Requires:       perl = %{perl_version}
Group:          Development/Libraries/Perl

%package -n %pkg_perl_Cyrus_SIEVE_managesieve

%if %{with_kolab}
Conflicts:      perl-Cyrus-SIEVE-managesieve
Conflicts:      perl-Cyrus-SIEVE-managesieve-kolab
License:        BSD3c(or similar)
Summary:        A Perl Module for Cyrus SIEVE
Requires:       perl = %{perl_version}
Recommends:     perl-TermReadLine-Gnu
Group:          Development/Libraries/Perl

%package -n %{name}-devel

%if %{with_kolab}
Conflicts:      cyrus-imapd
Conflicts:      cyrus-imapd-kolab
License:        BSD3c(or similar)
Summary:        Libraries and Includes for Cyrus IMAPd
Group:          Development/Libraries/C and C++

Cyrus is a highly scalable enterprise mail system designed for use in
enterprise environments of various sizes using standards based
technologies. Cyrus technologies scale from independent use in email
departments to a system centrally managed in a large enterprise.

    Office of Technology Transfer Carnegie Mellon University <>

%description -n %pkg_perl_Cyrus_IMAP
A Cyrus IMAP Perl module for the Cyrus IMAPD.

    Office of Technology Transfer Carnegie Mellon University <>

%description -n %pkg_perl_Cyrus_SIEVE_managesieve
A Perl module for Cyrus SIEVE.

    Office of Technology Transfer Carnegie Mellon University <>

%description -n %{name}-devel
This package provides the libraries and include files for Cyrus IMAPd.

    Office of Technology Transfer Carnegie Mellon University <>

%define cyrus_uid 96

%setup -q -a 1 -n %{prjname}-%{version}
patch -s -p0 < contrib/drac_auth.patch
%patch1 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch12 -p1
%patch19 -p1
%patch20 -p2
%patch21 -p1
%patch22 -p1
%patch23 -p1

%if %{with_kolab}
%patch100 -p1
%patch102 -p1
%patch103 -p1
%patch104 -p1
%patch105 -p1
%patch106 -p1
%patch107 -p1

rm -fr aclocal.m4 configure autom4te.cache
sh SMakefile

%if %{with_kolab}
  # CONFIGURE_ARGS="--with-ldap=%{_includedir}"
  # For unknow reason the configure argument --with-ldap=%{_includedir} is not
  # picked up by configure, use the line below as a workaround until the
  # configure --with-ldap actually works
  sed -i 's;\(IMAP_LIBS="${LIB_SASL}\) \(.*"\);\1 -lldap -llber \2;g' configure

export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing -I/usr/include/kerberosIV -I%{_libdir}/sasl2/include"
./configure --prefix=/usr \
	    --mandir=%{_mandir} \
	    --libdir=%{_libdir} \
	    --localstatedir=/var/lib \
	    --enable-idled \
	    --enable-murder \
            --enable-netscapehack \
	    --enable-nntp \
            --enable-replication \
	    --with-com_err=yes \
            --with-cyrus-user=cyrus \
            --with-cyrus-group=mail \
            --with-cyrus-prefix=/usr/lib/cyrus \
	    --with-drac=%{_libdir} \
	    --with-gss_impl=auto \
	    --with-libwrap=/usr \
	    --with-lock=fcntl \
	    --with-openslp=%{_libdir} \
            --with-openssl \
	    --with-perl=/usr/bin/perl \
	    --with-syslogfacility=DAEMON \
	    --without-ucdsnmp $CONFIGURE_ARGS
make depend

mkdir -p $RPM_BUILD_ROOT/etc/init.d
mkdir -p $RPM_BUILD_ROOT/etc/pam.d
install -m 644 SuSE/imap $RPM_BUILD_ROOT/etc/pam.d/imap
install -m 644 SuSE/pop $RPM_BUILD_ROOT/etc/pam.d/pop
install -m 644 SuSE/sieve $RPM_BUILD_ROOT/etc/pam.d/sieve
mkdir -p $RPM_BUILD_ROOT/etc/cron.daily
mkdir -p $RPM_BUILD_ROOT/sbin
mkdir -p $RPM_BUILD_ROOT/var/adm
install -m 755 SuSE/rc.cyrus $RPM_BUILD_ROOT/etc/init.d/cyrus
ln -sf ../etc/init.d/cyrus $RPM_BUILD_ROOT/sbin/rccyrus
install -m 755 SuSE/cron.daily.cyrus $RPM_BUILD_ROOT/etc/cron.daily/
rm -f tools/config2*
rm -rf tools/CVS
rm -rf contrib
chmod 644 doc/internal/*.html
mkdir -p $RPM_BUILD_ROOT/usr/lib/cyrus/tools/
install -m 755 tools/* $RPM_BUILD_ROOT/usr/lib/cyrus/tools/
# SuSEfirewall2 Services
install -d $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services/
install -m 644 SuSE/SuSEfirewall2.cyrus-imapd $RPM_BUILD_ROOT/etc/sysconfig/SuSEfirewall2.d/services/cyrus-imapd
make install
# make install results in make install within the perl modules subdir, so
# remove the stuff from buildroot to satisfy the picky rpm4, as we don't need
# it and use install_vendor for perl modules below
rm -rf $RPM_BUILD_ROOT/%{perl_sitelib}
rm -rf $RPM_BUILD_ROOT/%{perl_sitearch}
# perl modules
# Cyrus IMAP
cd perl/imap
make DESTDIR=$RPM_BUILD_ROOT install_vendor
%perl_process_packlist -n %pkg_perl_Cyrus_IMAP
cd -
# Cyrus SIEVE managesieve
cd perl/sieve/managesieve
make DESTDIR=$RPM_BUILD_ROOT install_vendor
%perl_process_packlist -n %pkg_perl_Cyrus_SIEVE_managesieve
cd -
install -m 644 SuSE/imapd.conf $RPM_BUILD_ROOT/etc/imapd.conf
install -m 644 SuSE/cyrus.conf $RPM_BUILD_ROOT/etc/cyrus.conf
install -d -m 750 $RPM_BUILD_ROOT/var/lib/imap/user
install -d -m 750 $RPM_BUILD_ROOT/var/lib/imap/quota
install -d -m 750 $RPM_BUILD_ROOT/var/lib/imap/proc
install -d -m 750 $RPM_BUILD_ROOT/var/lib/imap/log
install -d -m 750 $RPM_BUILD_ROOT/var/lib/imap/msg
install -d -m 750 $RPM_BUILD_ROOT/var/lib/imap/db
install -m 644 %{SOURCE2} $RPM_BUILD_ROOT/var/lib/imap/db
install -d -m 750 $RPM_BUILD_ROOT/var/lib/imap/socket
install -d -m 750 $RPM_BUILD_ROOT/var/lib/sieve
for i in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
	install -d -m 755 $RPM_BUILD_ROOT/var/lib/imap/user/$i
	install -d -m 755 $RPM_BUILD_ROOT/var/lib/imap/quota/$i
	install -d -m 750 $RPM_BUILD_ROOT/var/lib/sieve/$i
#chown -R cyrus:mail $RPM_BUILD_ROOT/var/lib/imap
#chown -R cyrus:mail $RPM_BUILD_ROOT/var/lib/sieve
install -d -m 750 $RPM_BUILD_ROOT/var/spool/imap
install -d -m 750 $RPM_BUILD_ROOT/var/adm/backup/imap
#chown cyrus:mail $RPM_BUILD_ROOT/var/spool/imap
mv $RPM_BUILD_ROOT/%{_mandir}/man8/master.8 \
mv $RPM_BUILD_ROOT/%{_mandir}/man8/idled.8 \
mv $RPM_BUILD_ROOT/%{_mandir}/man8/fetchnews.8 \
find . -type d -a -name CVS | xargs rm -rfv
find . -type f -a -name .cvsignore | xargs rm -rfv

/usr/sbin/useradd -r -o -g mail -u %{cyrus_uid} -s /bin/bash -c "User for cyrus-imapd" -d /var/lib/imap cyrus 2> /dev/null || :
/usr/sbin/usermod -d /var/lib/imap cyrus || :

%stop_on_removal cyrus

grep -E "^sieve" etc/services >/dev/null || {
   echo "Adding sieve service to /etc/services"
   CFBAK=services.`date +%Y-%m-%d`
   cat etc/services | awk '
BEGIN                   { OFS="\t"; ORS="\n"; }
/^#/                    { print; next; }
/[[:space:]]+2000\/(tcp|udp)/       { printf "sieve\t\t%s\t# Cyrus SIEVE\n", $2; next; } 
                        { print; next; };' > etc/$CFNEW
   echo "Backing up old services as $CFBAK"
   cp --remove-destination etc/services etc/$CFBAK
   mv etc/$CFNEW etc/services
test $1 -gt 1 && test -d usr/sieve -a ! -L usr/sieve && SIEVEUP=yes
test $1 -gt 1 && test -d var/imap  -a ! -L var/imap  && IMAPUP=yes
test -n "`find var/lib/sieve -type f`" && {
test -n "`find var/lib/imap -type f`" && {
test -n "$SIEVEUP" && {
     echo "Creating compatibility symlink /var/lib/sieve -> /usr/sieve"
     rm -rf var/lib/sieve
     ln -sf ../../usr/sieve var/lib/sieve
test -n "$IMAPUP" && {
     echo "Creating compatibility symlink /var/lib/imap -> /var/imap"
     rm -rf var/lib/imap
     ln -sf  ../imap /var/lib/imap
%{fillup_and_insserv cyrus}

%restart_on_update cyrus

%config /etc/pam.d/*
%config /etc/cron.daily/
%config(noreplace) /etc/imapd.conf
%config(noreplace) /etc/cyrus.conf
%config /etc/sysconfig/SuSEfirewall2.d/services/cyrus-imapd
%dir %attr(0750, cyrus, mail) /var/lib/imap
%attr(0750, cyrus, mail) /var/lib/imap/log
%attr(0750, cyrus, mail) /var/lib/imap/msg
%attr(0750, cyrus, mail) /var/lib/imap/proc
%attr(0750, cyrus, mail) /var/lib/imap/quota
%attr(0750, cyrus, mail) /var/lib/imap/user
%attr(0750, cyrus, mail) /var/lib/imap/socket
%dir %attr(0750, cyrus, mail) /var/lib/imap/db
%config(noreplace) /var/lib/imap/db/DB_CONFIG
%attr(0750, cyrus, mail) /var/lib/sieve
%attr(0750, cyrus, mail) /var/spool/imap
%attr(0750, cyrus, mail) /var/adm/backup/imap
%doc %{_mandir}/man1/cyradm.1.gz
%doc %{_mandir}/man1/imtest.1.gz
%doc %{_mandir}/man1/lmtptest.1.gz
%doc %{_mandir}/man1/mupdatetest.1.gz
%doc %{_mandir}/man1/nntptest.1.gz
%doc %{_mandir}/man1/pop3test.1.gz
%doc %{_mandir}/man1/sivtest.1.gz
%doc %{_mandir}/man1/smtptest.1.gz
%doc %{_mandir}/man3/imclient.3.gz
%doc %{_mandir}/man5/*.gz
%doc %{_mandir}/man8/*.gz

%files -n %{name}-devel

%files -n %pkg_perl_Cyrus_IMAP
%dir %{perl_vendorarch}/Cyrus
%dir %{perl_vendorarch}/auto/Cyrus
%if %{suse_version} < 1140
%doc %{_mandir}/man3/Cyrus::IMAP*

%files -n %pkg_perl_Cyrus_SIEVE_managesieve
%doc %{_mandir}/man1/installsieve.1.gz
%doc %{_mandir}/man1/sieveshell.1.gz
%dir %{perl_vendorarch}/Cyrus
%dir %{perl_vendorarch}/Cyrus/SIEVE
%dir %{perl_vendorarch}/auto/Cyrus
%dir %{perl_vendorarch}/auto/Cyrus/SIEVE
%if %{suse_version} < 1140
%doc %{_mandir}/man3/Cyrus::SIEVE::managesieve.3pm.gz