File cyrus-imapd.spec of Package cyrus-imapd

#
# spec file for package cyrus-imapd
#
# Copyright (c) 1999-2025 SUSE LLC
# Copyright (c) 2018-2025 Matthias Fehring <buschmann23@opensuse.org>
#
# 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 http://bugs.opensuse.org/
#

# disables the build of cyr_clamav
%bcond_without clamav
# disables the support for Simple Network Management Protocol (deprecated)
%bcond_without snmp
# disables support for GSSAPI/Kerberos v5 authentication capabilities
%bcond_without gssapi
# disables support for HTTP (CalDAV/CardDAV/etc), also required for JMAP support
%bcond_without http
# disables HTTP/2 support for the HTTP module
%bcond_without nghttp2
# disables WebSocket support for the HTTP module
%bcond_without wslay
# disables zstd compression support for the HTTP module
%bcond_without zstd
# disables Brotli compression support for the HTTP module
%bcond_without brotli
# disables CalDAV alarm support
%bcond_without calalarmd
# disables libcap system capabilities handling
%bcond_without libcap
# disables the build of ptloader to interface with LDAP directly
%bcond_without ldap
# disables MySQL/MariaDB databsae backend
%bcond_without mysql
# disables PostgreSQL databse backend
%bcond_without pgsql
# disables Xapian search engine support
%bcond_without xapian
# disables integrated backup support
%bcond_without backup
# disables Sender Rewriting Scheme support for SIEVE redirects
%bcond_without srs
# disables unit tests
%bcond_without tests
# enables IMAP integrations test suite
%bcond_with cassandane
# enables Zeroskip database backend
%bcond_with zeroskip
# enables JMAP support (also enables HTTP an Xapian support)
%bcond_without jmap

%global cyrus_user      cyrus
%global cyrus_group     mail
%global _servicename    cyrus-imapd

# Cassandane commit hash. Cassandane doesn't have releases often, but it
# receives constant development.  This was fetched on 20200727.
%global casch 568a98e84ec600057253b232d8b4989269716fe3

%define _sover 0

# Cyrus currently not support Link Time Optimization
%define _lto_cflags %{nil}

Name:           cyrus-imapd
Version:        3.2.12
Release:        0
Summary:        The Cyrus IMAP and POP Mail Server
License:        BSD-3-Clause
Group:          Productivity/Networking/Email/Servers
Url:            http://www.cyrusimap.org
# Upstream sources
Source0:        https://github.com/cyrusimap/cyrus-imapd/releases/download/%{name}-%{version}/%{name}-%{version}.tar.gz
Source90:       https://github.com/cyrusimap/cyrus-imapd/releases/download/%{name}-%{version}/%{name}-%{version}.tar.gz.sig
Source1:        http://ftp.andrew.cmu.edu/pub/mibs/cmu/cmu.mib
# Distribution specific sources
Source10:       cyrus-imapd-rc-3.tar.gz
Source11:       cyrus-user.conf
# PATCH-FIX-UPSTREAM -- Have the correct #include when using implicit definitions
Patch34:        cyrus-imapd-2.5.13_implicit-definitions.patch
# PATCH-FIX-UPSTREAM cyrus-imapd-3.2.12-fix-perl-linking.patch buschmann23@opensuse.org
Patch43:        cyrus-imapd-3.2.12-fix-perl-linking.patch
# PATCH-FIX-OPENSUSE cyrus-imapd-3.2.12-rename-quota.patch buschmann23@opensuse.org -- rename some conflicting binaries and man pages
Patch44:        cyrus-imapd-3.2.12-rename.patch

# Source files for running the Cassandane test suite at build time.
Source80:       https://github.com/cyrusimap/cassandane/archive/%{casch}.tar.gz#/cassandane-568a98e.tar.gz

# Used for testing calendaring.
# This archive was generated by running:
#   svn export https://github.com/brong/Net-CalDAVTalk/trunk/testdata
#   tar cfz cassandane-testdata-20170523.tar.gz testdata
# Note that this changes very rarely.  See
#   https://github.com/brong/Net-CalDAVTalk/tree/master/testdata
Source81:       cassandane-testdata-20200727.tar.gz

# A template config file for cassandane; we will substitute in varions values.
Source82:       cassandane.ini

# Prevent cassandane from trying to syslog things
Source91:       cassandane-no-syslog.patch

# Tell the annotator script to run as the current user/group
# Upstream ticket https://github.com/cyrusimap/cyrus-imapd/issues/1995
Source92:       cassandane-fix-annotator.patch

# Add lib/cyrus/bin and libexec/cyrus/bin to the paths to look into for cyrus binaries
Source93:       cassandane-set-libexecdir.patch

BuildRequires:  sysuser-tools
BuildRequires:  systemd-rpm-macros
BuildRequires:  bison
BuildRequires:  pkgconfig(libsasl2)
BuildRequires:  flex
BuildRequires:  gcc gcc-c++
BuildRequires:  gperf
BuildRequires:  pkgconfig(jansson) >= 2.3
BuildRequires:  pkgconfig(libbsd)
BuildRequires:  libtool
BuildRequires:  pkgconfig(icu-uc) >= 55
BuildRequires:  pkgconfig(icu-i18n) >= 55
BuildRequires:  pkgconfig(uuid)
BuildRequires:  libopenssl-1_1-devel
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(sqlite3)
BuildRequires:  systemd
BuildRequires:  pkgconfig(libpcre2-posix)
BuildRequires:  pkgconfig(com_err)

%if %{with clamav}
BuildRequires:  pkgconfig(libclamav)
%endif

%if %{with snmp}
BuildRequires:  net-snmp-devel
%endif

%if %{with gssapi}
BuildRequires:  pkgconfig(mit-krb5-gssapi)
%endif

%if %{with srs}
BuildRequires:  libsrs2-devel
%endif

%if %{with http} || %{with jmap}
BuildRequires:  pkgconfig(libxml-2.0)
BuildRequires:  pkgconfig(libical) >= 3.0.0
BuildRequires:  pkgconfig(zlib)
BuildRequires:  pkgconfig(cyrus-timezones)
BuildRequires:  pkgconfig(shapelib) >= 1.3.0
%if %{with nghttp2}
BuildRequires:  pkgconfig(libnghttp2) >= 1.5
%endif
%if %{with brotli}
BuildRequires:  pkgconfig(libbrotlienc)
%endif
%if %{with zstd}
BuildRequires:  pkgconfig(libzstd) >= 1.4.0
%endif
%if %{with jmap}
BuildRequires:  pkgconfig(chardet)
%if %{with wslay}
BuildRequires:  pkgconfig(libwslay) >= 1.1.1
%endif
%endif
%endif

%if %{with libcap}
BuildRequires:  pkgconfig(libcap)
%endif

%if %{with ldap}
BuildRequires:  openldap2-devel
%endif

%if %{with mysql}
BuildRequires:  pkgconfig(libmariadb)
%endif

%if %{with pgsql}
BuildRequires:  pkgconfig(libpq)
%endif

%if %{with xapian} || %{with jmap}
BuildRequires:  pkgconfig(xapian-core) >= 1.4.0
BuildRequires:  rsync
%endif

%if %{with zeroskip}
BuildRequires:  pkgconfig(libzeroskip)
%endif

%if %{with tests}
BuildRequires:  pkgconfig(cunit)
BuildRequires:  cyrus-sasl-plain cyrus-sasl-digestmd5 cyrus-sasl-crammd5

%if %{with cassandane}
BuildRequires:  dovecot-imaptest net-tools-deprecated words
BuildRequires:  perl(DBI) perl(Net::LDAP::Constant) perl(Net::LDAP::Server)

BuildRequires:  perl(AnyEvent) perl(AnyEvent::Handle) perl(AnyEvent::Socket)
BuildRequires:  perl(AnyEvent::Util) perl(attributes) perl(base)
BuildRequires:  perl(BSD::Resource) perl(bytes) perl(Carp) perl(charnames)
BuildRequires:  perl(Clone) perl(Config) perl(Config::IniFiles) perl(constant)
BuildRequires:  perl(Cwd) perl(Data::Dumper) perl(DateTime)
BuildRequires:  perl(DateTime::Format::ISO8601) perl(Digest::MD5) perl(Encode)
BuildRequires:  perl(Errno) perl(experimental) perl(Exporter)
BuildRequires:  perl(File::Basename) perl(File::chdir) perl(File::Find)
BuildRequires:  perl(File::Path) perl(File::Slurp) perl(File::stat)
BuildRequires:  perl(File::Temp) perl(Getopt::Long) perl(HTTP::Tiny)
BuildRequires:  perl(IO::File) perl(IO::Handle) perl(IO::Scalar)
BuildRequires:  perl(IO::Socket::INET) perl(IO::Socket::INET6)
BuildRequires:  perl(IO::Socket::UNIX) perl(JSON) perl(JSON::XS) perl(lib)
BuildRequires:  perl(Mail::IMAPTalk) perl(Mail::JMAPTalk) >= 0.11
BuildRequires:  perl(Math::Int64) perl(MIME::Base64)
BuildRequires:  perl(Net::CalDAVTalk) >= 0.12 perl(Net::CardDAVTalk) >= 0.05
BuildRequires:  perl(Net::CardDAVTalk::VCard) perl(Net::DAVTalk)
BuildRequires:  perl(Net::POP3) perl(Net::Server::PreForkSimple)
BuildRequires:  perl(News::NNTPClient) perl(overload)
BuildRequires:  perl(POSIX) perl(Scalar::Util) perl(Storable) perl(strict)
BuildRequires:  perl(String::CRC32) perl(Sys::Hostname) perl(Sys::Syslog)
BuildRequires:  perl(Test::Unit::Exception) perl(Test::Unit::Listener)
BuildRequires:  perl(Test::Unit::Result) perl(Test::Unit::Runner)
BuildRequires:  perl(Test::Unit::TestCase) perl(Test::Unit::TestRunner)
BuildRequires:  perl(Time::HiRes) perl(URI) perl(URI::Escape) perl(User::pwent)
BuildRequires:  perl(utf8) perl(vars) perl(warnings) perl(XML::DOM)
BuildRequires:  perl(XML::Generator) perl(XML::Spice)
BuildRequires:  clamav perl(Unix::Syslog)
%endif
%endif

%sysusers_requires
PreReq:         system-user-mail
Requires:       perl-Cyrus-IMAP = %{version}
Requires:       perl-Cyrus-SIEVE-managesieve = %{version}
Requires:       perl-Cyrus-Annotator = %{version}
%if %{with http}
Requires:       cyrus-timezones
%endif
Requires(post): cyrus-sasl
Requires(post): fileutils
Requires(pre):  %fillup_prereq
Recommends:     cyradm
Recommends:     perl-TermReadLine-Gnu
Conflicts:      courier-imap
Conflicts:      imap
%systemd_requires


%description
This package contains the core of the Cyrus IMAP server. It is a mail
system designed for use with standards-based Internet mail
technologies.

A full Cyrus IMAP implementation allows a mail and bulletin
board environment to be set up across multiple servers. It differs from
other IMAP server implementations in that it is run on "sealed"
servers, where users are not normally permitted to log in and have no
system account on the server. The mailbox database is stored in parts
of the filesystem that are private to the Cyrus IMAP server. All user
access to mail is through software using the IMAP, POP3, KPOP or JMAP
protocols. It also includes support for virtual domains, NNTP, and
mailbox annotations. Multiple concurrent read/write connections to the
same mailbox are permitted. The server supports access control lists on
mailboxes and storage quotas on mailbox hierarchies.

The Cyrus IMAP server supports the IMAP4rev1 protocol described
in RFC 3501. IMAP4rev1 has been approved as a proposed standard.
It supports any authentication mechanism available from the SASL
library, imaps/pop3s/nntps (IMAP/POP3/NNTP encrypted using SSL and
TLSv1) can be used for security. The server supports single instance
store where possible when an email message is addressed to multiple
recipients. SIEVE provides server side email filtering.

%package doc
Summary:        HTML Documentation for the Cyrus IMAP and POP Mail Server
Group:          Documentation/HTML
BuildArch:      noarch

%description doc
This packages contains documentation for the Cyrus IMAP and POP Mail Server.

%if %{with snmp}
%package snmp
Summary:        SNMP support for the Cyrus IMAP and POP Mail Server
Group:          Productivity/Networking/Email/Utilities
Requires:       %{name} = %{version}
Requires:       %{name}-snmp-mibs = %{version}
Requires:       net-snmp >= 5.0

%description snmp
This package contains the core of the Cyrus IMAP server. It is a mail
system designed for use with standards-based Internet mail
technologies.

This package pulls in dependencies to enable SNMP support for %{name}.

%package snmp-mibs
Summary:        MIBs for the Cyrus IMAP and POP Mail Server
Group:          Productivity/Networking/Email/Utilities

%description snmp-mibs
This package contains MIBs for the Cyrus IMAP server. They are required to use %{name} with SNMP.
%endif

%package utils
Summary:        Test tools for mail servers
Group:          Productivity/Networking/Email/Utilities
Requires:       cyrus-sasl-plain
Conflicts:      cyrus-imapd <= 2.3.18

%description utils
This package contains test tools for mail protocols (not only %{name} specific).

%package -n perl-Cyrus-IMAP
Summary:        Cyrus IMAP Perl Module
Group:          Development/Libraries/Perl
%{perl_requires}

%description -n perl-Cyrus-IMAP
This package contains a Perl module for the Cyrus IMAP server.

%package -n perl-Cyrus-Annotator
Summary:        Cyrus Annotator Perl Module
Group:          Development/Libraries/Perl
Requires:       perl(Net::Server)
Requires:       perl(Unix::Syslog)
Requires:       perl(File::Path)
Requires:       perl(URI::Escape)
Requires:       perl(Encode)
Requires:       perl(MIME::Base64) perl(MIME::QuotedPrint)
%{perl_requires}

%description -n perl-Cyrus-Annotator
Cyrus::Annotator::Daemon provides a framework for writing daemons which can
be used to add annotations or flags to messages which are delivered into the
Cyrus mail server.

Cyrus::Annotator::Message encapsulates a message which is being processed by the
annotator daemon.

%package -n cyradm
Summary:        Administration tool for the Cyrus IMAP server
Group:          Productivity/Networking/Email/Utilities
Requires:       perl(Cyrus::IMAP::Shell)
Requires:       perl(Term::ReadLine)
Conflicts:      cyrus-imapd <= 2.3.18
BuildArch:      noarch

%description -n cyradm
This package contains an administration tool for the Cyrus IMAP server.

%package -n perl-Cyrus-SIEVE-managesieve
Summary:        Cyrus SIEVE Perl Module
Group:          Development/Libraries/Perl
Recommends:     perl-TermReadLine-Gnu
Conflicts:      python-managesieve
%{perl_requires}

%description -n perl-Cyrus-SIEVE-managesieve
This package contains a Perl module for Cyrus SIEVE.

%package devel
Summary:        Libraries and Includes for %{name}
Group:          Development/Libraries/C and C++
Requires:       cyrus-imapd = %{version}
Requires:       libcyrus%{?_sover} = %{version}

%description devel
The %{name}-devel package contains header files and libraries
necessary for developing applications which use the imclient library.

%package -n libcyrus%{?_sover}
Summary:        Cyrus IMAP Shared Libraries
Group:          System/Libraries

%description -n libcyrus%{?_sover}
Shared libraries used by the Cyrus IMAP server.

%prep
%autosetup -p1 -a 10

# Set perl script interpreter
sed -i 's|^#!/usr/bin/env perl|#!%__perl|' tools/rehash

# The pm files have shebang lines for some reason
sed -i -e '1{/usr.bin.perl/d}' perl/annotator/{Message,Daemon}.pm

# Set the correct path to the cyrus binaries
sed -i -e 's|@CYRUSBINPATH@|%{_libexecdir}/cyrus|' SUSE/backup-cyrus.service
sed -i -e 's|@CYRUSBINPATH@|%{_libexecdir}/cyrus|' SUSE/cyrus-imapd.service
sed -i -e 's|@CYRUSBINPATH@|%{_libexecdir}/cyrus|' SUSE/cron.daily.cyrus

# fix some wrong end of line encodings
sed -i 's/\r$//' doc/html/_static/cyrus.css
sed -i 's/\r$//' doc/html/_static/event_notifications/CalendarAlarm.json

# Use packaged socket and home directory
sed -i -e s?/run/cyrus?/run/cyrus-imapd? -e s?/var/lib/cyrus?/var/lib/imap? doc/examples/*/*.conf
sed -i -e s?/var/spool/cyrus/mail?/var/spool/imap? -e s?/var/spool/sieve?/var/lib/sieve? doc/examples/imapd_conf/*.conf

%if %{with tests}
%if %{with cassandane}
# unpack and prepare cassandane
tar xf %SOURCE80
ln -s cassandane-%{casch} cassandane
pushd cassandane
mkdir work
tar xf %SOURCE81

patch -p1 < %SOURCE91
patch -p1 < %SOURCE92
patch -p1 < %SOURCE93

cp %SOURCE82 cassandane.ini
# RF rpm-buildroot-usage
sed -i \
    -e "s!CASSDIR!$(pwd)!" \
    -e "s!BUILDROOT!%buildroot!" \
    cassandane.ini

popd
%endif
%endif

%build
#Generate cyrus user
%sysusers_generate_pre %{SOURCE11} cyrus cyrus-user.conf

# This is the test suite, which doesn't build much but does verify its dependencies.
# If this is done after the configure call, the one thing it does build fails
# because the configure macro puts some hardening flags into the environment.
%if %{with tests}
%if %{with cassandane}
pushd cassandane
make
popd
%endif
%endif

CFLAGS="%{optflags} -fpie"
export CFLAGS
CXXFLAGS="%{optflags} -fpie"
export CXXFLAGS
LDFLAGS="%{?build_ldflags} -pie"
export LDFLAGS
%configure \
    --localstatedir=%{_var}/lib \
    --libexecdir=%{_libexecdir}/cyrus \
    --enable-idled \
    --enable-murder \
    --enable-nntp \
    --enable-replication \
    --enable-autocreate \
%if 0%{with xapian} || 0%{with jmap}
    --enable-xapian \
%endif
    %{?with_backup:--enable-backup} \
    %{?with_srs:--enable-srs} \
%if 0%{with http} || 0%{with jmap}
    --enable-http \
    %{!?with_nghttp2:--without-nghttp2} \
    %{?with_calalarmd:--enable-calalarmd} \
%endif
%if 0%{with jmap}
    --enable-jmap \
    %{!?with_wslay:--without-wslay} \
%endif
    %{?with_tests:--enable-unit-tests} \
%if 0%{with gssapi}
    --enable-gssapi \
    --with-gss_impl=mit \
%endif
%if 0%{with krb5}
    --with-krbimpl=mit \
%endif
    %{!?with_clamav:--without-clamav} \
    %{?with_snmp:--with-snmp} \
    %{?with_libcap:--with-libcap} \
%if 0%{with ldap}
    --with-ldap=%{_prefix} \
%endif
    %{?with_mysql:--with-mysql} \
%if 0%{with pgsql}
    --with-pgsql \
    --with-pgsql-incdir=%{_includedir}/pgsql \
%endif
    --with-cyrus-user=%{cyrus_user} \
    --with-syslogfacility=DAEMON \
    --with-lock=fcntl \
    --with-perl=%__perl \
    --with-sqlite \
    --with-com_err \
    --disable-pcre

%make_build

make notifyd/notifytest

%install
# Cyrus IMAP
%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 %{buildroot}%{perl_sitelib}
rm -rf %{buildroot}%{perl_sitearch}

# Cyrus IMAP Perl modules
cd perl/imap
%perl_make_install
%perl_process_packlist -n perl-Cyrus-IMAP
cd -

# Cyrus ANNOTATOR Perl modules
cd perl/annotator
%perl_make_install
%perl_process_packlist -n perl-Cyrus-Annotator
cd -

# Cyrus SIEVE managesieve Perl modules
cd perl/sieve/managesieve
%perl_make_install
%perl_process_packlist -n perl-Cyrus-SIEVE-managesieve
cd -

# after make install we can remove stuff we don't want in our packages
rm -f doc/html/.buildinfo

# remove Perl bootstrap files
find %{buildroot}%{perl_vendorarch}/ -name '*.bs' -type f -delete

# create /var/* directories
install -d -m 750 %{buildroot}%{_var}/lib/imap/{db,log,msg,proc,quota,socket,user,sync}
install -d -m 700 %{buildroot}%{_var}/lib/imap/ptclient
install -d -m 750 %{buildroot}%{_var}/lib/sieve
install -d -m 750 %{buildroot}%{_var}/spool/imap
install -d -m 750 %{buildroot}%{_var}/spool/imap/{stage.,sync.}
install -d -m 750 %{buildroot}%{_var}/adm/backup/imap
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 %{buildroot}%{_var}/lib/imap/user/$i
    install -d -m 755 %{buildroot}%{_var}/lib/imap/quota/$i
    install -d -m 750 %{buildroot}%{_var}/lib/sieve/$i
done

# sysconfig
install -d %{buildroot}%{_fillupdir}
install -m 644 SUSE/sysconfig.cyrus-imapd %{buildroot}%{_fillupdir}/sysconfig.%{_servicename}

# systemd
install -d %{buildroot}{%{_unitdir},%{_sbindir},%{_sysconfdir}/profile.d,%{_tmpfilesdir}}
install -m 644 SUSE/cyrus-imapd.service %{buildroot}%{_unitdir}/%{_servicename}.service
ln -s service %{buildroot}%{_sbindir}/rc%{_servicename}
echo 'alias rccyrus >/dev/null 2>&1 || alias rccyrus=%{_sbindir}/rc%{_servicename}' > %{buildroot}%{_sysconfdir}/profile.d/%{name}.alias.sh

# tmpfiles
install -m 644 SUSE/tmpfiles.conf %{buildroot}%{_tmpfilesdir}/%{_servicename}.conf

# tools
install -d %{buildroot}%{_libexecdir}/cyrus/tools
install -m 755 tools/* %{buildroot}%{_libexecdir}/cyrus/tools
rm %{buildroot}%{_libexecdir}/cyrus/tools/config2*
libtool --mode=install install -m 755 notifyd/notifytest %{buildroot}%{_bindir}/

# backup timer
install -m 755 SUSE/cron.daily.cyrus %{buildroot}%{_libexecdir}/cyrus/tools/daily-backup.sh
install -m 644 SUSE/backup-cyrus.*   %{buildroot}%{_unitdir}

# pam
install -d %{buildroot}%{_sysconfdir}/pam.d
install -m 644 SUSE/imap %{buildroot}%{_sysconfdir}/pam.d/imap
install -m 644 SUSE/pop %{buildroot}%{_sysconfdir}/pam.d/pop
install -m 644 SUSE/sieve %{buildroot}%{_sysconfdir}/pam.d/sieve

# default config
install -m 644 SUSE/imapd.conf %{buildroot}%{_sysconfdir}/imapd.conf
install -m 644 SUSE/imapd.annotations.conf %{buildroot}%{_sysconfdir}/imapd.annotations.conf
install -m 644 SUSE/cyrus.conf %{buildroot}%{_sysconfdir}/cyrus.conf

# snmp
%if %{with snmp}
install -d %{buildroot}%{_datadir}/snmp/mibs/
install -m 644 %{SOURCE1} %{buildroot}%{_datadir}/snmp/mibs/CMU.mib
install -m 644 master/CYRUS-MASTER.mib %{buildroot}%{_datadir}/snmp/mibs/CYRUS-MASTER.mib
%endif

# Rename some executables that conflict with other packages

# Rename 'fetchnews' binary and manpage to avoid conflict with leafnode
mv %{buildroot}%{_sbindir}/fetchnews %{buildroot}%{_sbindir}/cyr_fetchnews
mv %{buildroot}%{_mandir}/man8/fetchnews.8 %{buildroot}%{_mandir}/man8/cyr_fetchnews.8

# Rename 'restore' binary and manpage that conflicts with dump
mv %{buildroot}%{_sbindir}/restore %{buildroot}%{_sbindir}/cyr_restore
mv %{buildroot}%{_mandir}/man8/restore.8 %{buildroot}%{_mandir}/man8/cyr_restore.8

# Rename 'quota' binary and manpage that conflicts with quota
mv %{buildroot}%{_sbindir}/quota %{buildroot}%{_sbindir}/cyr_quota
mv %{buildroot}%{_mandir}/man8/quota.8 %{buildroot}%{_mandir}/man8/cyr_quota.8

# rename man pages to avoid conflicts
mv %{buildroot}%{_mandir}/man8/master.8 %{buildroot}%{_mandir}/man8/cyrus_master.8
mv %{buildroot}%{_mandir}/man8/imapd.8 %{buildroot}%{_mandir}/man8/cyrus_imapd.8
mv %{buildroot}%{_mandir}/man8/pop3d.8 %{buildroot}%{_mandir}/man8/cyrus_pop3d.8
%if 0%{with http}
mv %{buildroot}%{_mandir}/man8/httpd.8 %{buildroot}%{_mandir}/man8/cyrus_httpd.8
%endif

# Install cyrus user information
mkdir -p %{buildroot}%{_sysusersdir}
install -m 644 %{SOURCE11} %{buildroot}%{_sysusersdir}/

# Remove pointless libtool archives
rm %{buildroot}/%{_libdir}/*.la

# remove executable permission
chmod -x %{buildroot}%{perl_vendorlib}/Cyrus/Annotator/Daemon.pm

%if %{with tests}
%check
export LD_LIBRARY_PATH=%buildroot/%_libdir
export CYRUS_USER=$USER

%{__make} %{?_smp_mflags} check || exit 1

%if %{without cassandane}
exit 0
%endif

# Create working directory for Cassandane.
# I first tried to create this inside the BUILD directory, but the path name
# will be so long that perl will shorten some socket path names because they
# are longer than 108 chars.
if [ -e /tmp/cass ]; then
    rm -rf /tmp/cass
fi
mkdir /tmp/cass

# Run the Cassandane test suite.  This will exhaustively test the various
# server components, but running it in a mock chroot is rather an exercise.
pushd cassandane

mkdir -p imaptest/src
ln -s /usr/bin/imaptest imaptest/src
ln -s /usr/share/imaptest/tests imaptest/src

# Construct the set of excluded tests to pass to Cassandane
# ---------------------------------------------------------
exclude=()
tests=(
    # This is more a test of system performance and according to upstream won't
    # be reliable on shared hardware like our builders.
    Metronome

    # This tests coredumping and won't work on a machine where systemd
    # intercepts coredumps, which includes our builders.
    Cassandane::Test::Core

    # Upstream recommends disabling this because it has an internal race and
    # will fail randomly.  https://github.com/cyrusimap/cassandane/issues/17
    Master.sighup_recycling

    # Fails because our Xapian is too old for proper CJK support.  1.5 will be
    # OK, but it is not yet released.  The alternative is to bundle.
    SearchFuzzy.cjk_words

    # These additionally fail because Cyrus 3.0.7 no longer enables
    # SNIPPET_EMPTY_WITHOUT_MATCH when the Cyrus-patched Xapian is not in use.
    # https://github.com/cyrusimap/cyrus-imapd/commit/f008060cb53b3286fcedf7b8b4dd12c1980d665f
    SearchFuzzy.normalize_snippets
    SearchFuzzy.snippet_wildcard
    SearchFuzzy.snippets_termcover
    SearchFuzzy.snippets_escapehtml
    SearchFuzzy.stem_verbs

    # Can't currently be run at build time because of compiled-in paths.  See
    # https://github.com/cyrusimap/cyrus-imapd/issues/2386
    Admin.imap_admins

    # Upstream on IRC indicates that these two are expected to fail on 3.0.
    Carddav.sharing_contactpaths
    Metadata.set_specialuse_twice

    # This one needs a patch to xapian.
    # https://github.com/cyrusimap/cyrus-imapd/issues/2348
    SearchFuzzy.search_subjectsnippet

    # This test fails beginning with 3.0.11 because the old behavior of only
    # preserving 20 nested folder deletions has been removed.
    Delete.repeated_delete

    # FIXME temporary disabling clamav test
    # https://bugzilla.redhat.com/show_bug.cgi?id=1819685
    ClamAV.remove_infected
)
for i in ${tests[@]}; do exclude+=("!$i"); done

# Add -vvv for too much output
./testrunner.pl %{?_smp_mflags} -v -f pretty ${exclude[@]} 2>&1
%endif

%pre -f cyrus.pre
%service_add_pre %{_servicename}.service backup-cyrus.timer

%preun
%service_del_preun %{_servicename}.service backup-cyrus.timer

%post
SIEVEUP=
IMAPUP=
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`" && {
     SIEVEUP=
}
test -n "`find var/lib/imap -type f`" && {
     IMAPUP=
}
test -n "$SIEVEUP" && {
     echo "Creating compatibility symlink %{_localstatedir}/lib/sieve -> %{_prefix}/sieve"
     rm -rf var/lib/sieve
     ln -sf ../..%{_prefix}/sieve var/lib/sieve
}
test -n "$IMAPUP" && {
     echo "Creating compatibility symlink %{_localstatedir}/lib/imap -> %{_localstatedir}/imap"
     rm -rf var/lib/imap
     ln -sf  ../imap %{_localstatedir}/lib/imap
}
%{fillup_only %{_servicename}}
%tmpfiles_create %{_tmpfilesdir}/%{_servicename}.conf
%service_add_post %{_servicename}.service backup-cyrus.timer

%postun
%service_del_postun %{_servicename}.service backup-cyrus.timer

%post   -n libcyrus%{?_sover} -p /sbin/ldconfig
%postun -n libcyrus%{?_sover} -p /sbin/ldconfig

%files
%defattr(-, root, root)
%doc README.md
%doc SUSE/README.SUSE
%license COPYING
%config %{_sysconfdir}/pam.d/*
%config(noreplace) %{_sysconfdir}/imapd.conf
%config(noreplace) %{_sysconfdir}/imapd.annotations.conf
%config(noreplace) %{_sysconfdir}/cyrus.conf
%dir %attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/log
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/msg
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/proc
%attr(0700, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/ptclient
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/quota
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/socket
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/user
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/db
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/imap/sync
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/lib/sieve
%dir %attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/spool/imap
%attr(0700, %{cyrus_user}, %{cyrus_group}) %{_var}/spool/imap/stage.
%attr(0700, %{cyrus_user}, %{cyrus_group}) %{_var}/spool/imap/sync.
%attr(0750, %{cyrus_user}, %{cyrus_group}) %{_var}/adm/backup/imap
%{_sysusersdir}/cyrus-user.conf
%{_fillupdir}/sysconfig.%{_servicename}
%{_unitdir}/*
%{_tmpfilesdir}/%{_servicename}.conf
%config %{_sysconfdir}/profile.d/%{name}.alias.sh
%{_sbindir}/rc%{_servicename}
%{_libexecdir}/cyrus
%{_mandir}/man1/dav_reconstruct.1%{ext_man}
%{_mandir}/man3/imclient.3%{ext_man}
%{_mandir}/man5/*%{ext_man}
%{_mandir}/man8/*%{ext_man}
%{_sbindir}/arbitron
%{_sbindir}/{chk,ctl,cvt,cyr}_*
%{_sbindir}/cyrdump
%{_sbindir}/dav_reconstruct
%{_sbindir}/deliver
%{_sbindir}/ipurge
%{_sbindir}/mbexamine
%{_sbindir}/mbpath
%{_sbindir}/mbtool
%{_sbindir}/ptdump
%{_sbindir}/ptexpire
%{_sbindir}/reconstruct
%{_sbindir}/sievec
%{_sbindir}/sieved
%{_sbindir}/squatter
%{_sbindir}/sync_client
%{_sbindir}/sync_reset
%{_sbindir}/tls_prune
%{_sbindir}/unexpunge
%ghost %dir /run/%{name}
%ghost /run/%{name}/lock
%ghost /run/%{name}/proc
%ghost /run/%{name}/socket

%files doc
%defattr(-, root, root)
%doc doc

%if %{with snmp}
%files snmp
%defattr(-, root, root)
%doc SUSE/README.SNMP

%files snmp-mibs
%defattr(-, root, root)
%dir %{_datadir}/snmp
%dir %{_datadir}/snmp/mibs
%{_datadir}/snmp/mibs/CMU.mib
%{_datadir}/snmp/mibs/CYRUS-MASTER.mib
%endif

%files utils
%defattr(-, root, root)
%{_bindir}/imtest
%{_bindir}/lmtptest
%{_bindir}/mupdatetest
%{_bindir}/nntptest
%{_bindir}/pop3test
%{_bindir}/sivtest
%{_bindir}/smtptest
%{_bindir}/synctest
%{_bindir}/notifytest
%{_bindir}/httptest
%{_mandir}/man1/imtest.1%{ext_man}
%{_mandir}/man1/lmtptest.1%{ext_man}
%{_mandir}/man1/mupdatetest.1%{ext_man}
%{_mandir}/man1/nntptest.1%{ext_man}
%{_mandir}/man1/pop3test.1%{ext_man}
%{_mandir}/man1/sivtest.1%{ext_man}
%{_mandir}/man1/smtptest.1%{ext_man}
%{_mandir}/man1/httptest.1%{ext_man}
%{_mandir}/man1/synctest.1%{ext_man}

%files -n cyradm
%defattr(-, root, root)
%{_bindir}/cyradm
%{_mandir}/man1/cyradm.1%{ext_man}

%files -n perl-Cyrus-IMAP
%defattr(-, root, root)
%dir %{perl_vendorarch}/Cyrus
%{perl_vendorarch}/Cyrus/IMAP
%{perl_vendorarch}/Cyrus/IMAP.pm
%dir %{perl_vendorarch}/auto/Cyrus
%{perl_vendorarch}/auto/Cyrus/IMAP
%{_mandir}/man3/Cyrus::IMAP*

%files -n perl-Cyrus-Annotator
%defattr(-, root, root)
%dir %{perl_vendorlib}/Cyrus
%dir %{perl_vendorlib}/Cyrus/Annotator
%{perl_vendorlib}/Cyrus/Annotator/*.pm
%{_mandir}/man3/Cyrus::Annotator*

%files -n perl-Cyrus-SIEVE-managesieve
%defattr(-, root, root)
%{_bindir}/installsieve
%{_bindir}/sieveshell
%{_mandir}/man1/installsieve.1%{ext_man}
%{_mandir}/man1/sieveshell.1%{ext_man}
%dir %{perl_vendorarch}/Cyrus
%{perl_vendorarch}/Cyrus/SIEVE
%dir %{perl_vendorarch}/auto/Cyrus
%{perl_vendorarch}/auto/Cyrus/SIEVE
%{_mandir}/man3/Cyrus::SIEVE::managesieve.3pm%{ext_man}

%files devel
%defattr(-, root, root)
%dir %{_includedir}/cyrus
%dir %{_includedir}/cyrus/sieve
%{_includedir}/cyrus/*.h
%{_includedir}/cyrus/sieve/*.h
%{_libdir}/libcyrus*.so
%{_libdir}/pkgconfig/*.pc

%files -n libcyrus%{?_sover}
%defattr(-, root, root)
%{_libdir}/libcyrus*.so.*

%changelog
openSUSE Build Service is sponsored by