##
##  milter-smc.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-smc
Summary:      Mail Filter for Anti-Spam Filtering
URL:          http://milter.sourceforge.net/
Vendor:       A. Djourik, S. Ivankin, P. Zhilin
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      GPL
Version:      2.2
Release:      20150428

#   package options
%option       with_fsl  yes

#   list of sources
Source0:      http://osdn.dl.sourceforge.net/milter/smc-milter-%{version}.tar.gz
Source1:      rc.milter-smc
Source2:      fsl.milter-smc
Source3:      milter-smc.conf
Patch0:       milter-smc.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  milter, openssl, libspf2
PreReq:       milter, openssl, libspf2
%if "%{with_fsl}" == "yes"
BuildPreReq:  fsl
PreReq:       fsl
%endif

%description
    This is an Anti-Spam filter based on the MILTER API of MTAs. It uses
    greylisting and SPF techniques to stops the junk-mail and a set of
    dynamic auto "whitelists" for unknown, but legitimate senders.

%track
    prog milter-smc = {
        version   = %{version}
        url       = http://sourceforge.net/projects/milter/files/
        regex     = smc-milter-(\d+(\.\d+)+)\.tar\.gz
    }

%prep
    %setup -q -n smc-milter-%{version}
    %patch -p0

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags} %{l_fsl_ldflags}" \
    LIBS="-lssl -lcrypto %{l_fsl_libs}" \
    ./configure \
        --prefix=%{l_prefix} \
        --sysconfdir=%{l_prefix}/etc/milter-smc \
        --localstatedir=%{l_prefix}/var/milter-smc \
        --with-spf2-lib=%{l_prefix}
    %{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}/etc/milter-smc \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/var/milter-smc

    #   install program
    %{l_shtool} install -c -s -m 755 \
        smc-milter $RPM_BUILD_ROOT%{l_prefix}/sbin/milter-smc

    #   install default configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE milter-smc.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/milter-smc/
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        smc-milter.hosts $RPM_BUILD_ROOT%{l_prefix}/etc/milter-smc/milter-smc.hosts
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        smc-milter.users $RPM_BUILD_ROOT%{l_prefix}/etc/milter-smc/milter-smc.users

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

    #   install OSSP fsl configuration
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.milter-smc} $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/

    #   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-smc/*' \
        '%attr(755,%{l_rusr},%{l_mgrp}) %{l_prefix}/var/milter-smc'

%files -f files

%clean

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

%preun
    #   before erase, stop service and remove log files
    if [ $1 -eq 0 ]; then
        %{l_rc} milter-smc stop 2>/dev/null
    fi
    exit 0

