##
##  milter-backscatter.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-backscatter
Summary:      Mail Filter for Backscatting
URL:          http://www.elandsys.com/scam/scam-backscatter/
Vendor:       Eland Systems
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      BSD-style
Version:      1.5.1
Release:      20100221

#   package options
%option       with_fsl  yes

#   list of sources
Source0:      http://www.elandsys.com/scam/scam-backscatter/scamback-%{version}.tgz
Source1:      rc.milter-backscatter
Source2:      fsl.milter-backscatter
Patch0:       milter-backscatter.patch

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

%description
    This is a MILTER which prevents backscatter (accept and bounce)
    on mail servers which don't host mailboxes locally. It validates
    mailboxes by verifying the recipient addresses hosted on a different
    mail server.

%track
    prog milter-backscatter = {
        version   = %{version}
        url       = http://www.elandsys.com/scam/scam-backscatter/
        regex     = scamback-(__VER__)\.tgz
    }

%prep
    %setup -q -n scamback
    %patch -p0

%build
    #   build program
    %{l_shtool} subst \
        -e 's;/var/spool/scam/scam-back.pid;%{l_prefix}/var/milter-backscatter/milter-backscatter.pid;' \
        -e 's;/etc/mail/scam.conf;%{l_prefix}/etc/milter-backscatter/milter-backscatter.conf;' \
        scam-back.c
    makefile="Makefile"
    case "%{l_platform -t}" in
        *-linux*   ) makefile="Makefile.linux"   ;;
        *-sunos*   ) makefile="Makefile.solaris" ;;
        *-freebsd* ) makefile="Makefile.freebsd" ;;
        *-*bsd*    ) makefile="Makefile.bsd"     ;;
    esac
    %{l_make} %{l_mflags} -f $makefile \
        CC="%{l_cc}" \
        CCFLAGS="%{l_cflags -O}" \
        CFLAGS="%{l_cppflags}" \
        LDFLAGS="%{l_ldflags} %{l_fsl_ldflags} %{l_fsl_libs}" \
        PROG="milter-backscatter"

%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-backscatter \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/var/milter-backscatter

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

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.milter-backscatter} $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-backscatter} $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/*' \
        '%attr(755,%{l_rusr},%{l_mgrp}) %{l_prefix}/var/milter-backscatter/*' \
        '%attr(755,%{l_rusr},%{l_mgrp}) %{l_prefix}/var/milter-backscatter'

%files -f files

%clean

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

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

