##
##  milter-mopher.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         milter-mopher
Summary:      Mail Filter
URL:          http://mopher.org/
Vendor:       ?
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      Open Source
Version:      0.5.3
Release:      20150308

#   package options
%option       with_fsl  yes

#   list of sources
Source0:      http://mopher.org/download/mopher-%{version}.tar.gz
Source1:      rc.milter-mopher
Source2:      mopherd.conf
Source3:      mopherd.acl
Patch0:       milter-mopher.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, bison, flex, gcc
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  milter, openssl, libidn, libiconv, db, db::with_compat = yes
PreReq:       milter, openssl, libidn, libiconv, db, db::with_compat = yes
%if "%{with_fsl}" == "yes"
BuildPreReq:  fsl
PreReq:       fsl
%endif

%description
    Mopher is a mail filter application that implements Sendmails
    Milter API with the main purpose of filtering spam. Design goals
    are scalability combined with a lightweight and modular code base.
    The filter configuration format aims to feel like a firewall
    configuration. Current set of features are: Greylisting, Tarpitting,
    Database storage and Automatic whitelisting.

%track
    prog milter-mopher = {
        version   = %{version}
        url       = http://mopher.org/download/
        regex     = mopher-(\d+(\.\d+)+)\.tar\.gz
    }

%prep
    %setup -q -n mopher-%{version}
    %patch -p0

%build
    #   configure program
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O} %{l_cppflags libidn .}" \
    CPPFLAGS="%{l_cppflags libidn .}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-liconv -ldb" \
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/milter-mopher \
        --libdir=%{l_prefix}/lib/milter-mopher \
        --mandir=%{l_prefix}/man \
        --with-bdb \
        --without-mysql \
        --without-spf2

    #   build program
    %{l_make} %{l_mflags -O}

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl \
        $RPM_BUILD_ROOT%{l_prefix}/var/milter-mopher/milter-mopher.db

    #   install program
    %{l_make} %{l_mflags} install DESTDIR="$RPM_BUILD_ROOT"

    #   install default configuration
    rm -f $RPM_BUILD_ROOT%{l_prefix}/etc/milter-mopher/*.example
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE mopherd.acl} \
        %{SOURCE mopherd.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/milter-mopher/

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.milter-mopher} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/fsl/*' \
        '%config %{l_prefix}/etc/milter-mopher/*' \
        '%attr(755,%{l_rusr},%{l_mgrp}) %{l_prefix}/var/milter-mopher/*' \
        '%attr(755,%{l_rusr},%{l_mgrp}) %{l_prefix}/var/milter-mopher'

%files -f files

%clean

%post
    #   after upgrade, restart service
    if [ $1 -eq 2 ]; then
        eval `%{l_rc} milter-mopher status 2>/dev/null`
        [ ".$milter_mopher_active" = .yes ] && %{l_rc} milter-mopher restart
    fi
    exit 0

%preun
    #   before erase, stop service and remove log files
    if [ $1 -eq 0 ]; then
        %{l_rc} milter-mopher stop 2>/dev/null
        rm -f $RPM_INSTALL_PREFIX/var/milter-mopher/milter-mopher.log  >/dev/null 2>&1 || true
        rm -f $RPM_INSTALL_PREFIX/var/milter-mopher/milter-mopher.pid  >/dev/null 2>&1 || true
        rm -f $RPM_INSTALL_PREFIX/var/milter-mopher/milter-mopher.db/* >/dev/null 2>&1 || true
    fi
    exit 0

