##
##  mimedefang.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:         mimedefang
Summary:      Mail Processing Filter for Sendmail
URL:          http://www.mimedefang.org/
Vendor:       Roaring Penguing Software
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      GPL
Version:      3.6
Release:      20250425

#   package options
%option       with_clamav    no

#   list of sources
Source0:      https://www.mimedefang.org/releases/mimedefang-%{version}.tar.gz
Source1:      rc.mimedefang

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, make, perl-openpkg
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  milter, perl, perl-mail, perl-crypto, perl-ds
PreReq:       milter, perl, perl-mail, perl-crypto, perl-ds
%if "%{with_clamav}" == "yes"
BuildPreReq:  clamav
PreReq:       clamav
%endif

%description
    MIMEDefang is a framework for filtering e-mail. It uses Sendmail's
    "Milter" API, some C glue code, and some Perl code to let you write
    high-performance mail filters in Perl.

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

%prep
    %setup -q

%build
    #   configure program
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags} %{l_cppflags}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --cache-file=./config.cache \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --sysconfdir=%{l_prefix}/etc/mimedefang \
        --with-confsubdir="" \
        --with-sendmail=%{l_prefix}/sbin/sendmail \
        --with-milterinc=%{l_prefix}/include \
        --with-milterlib=%{l_prefix}/lib \
        --with-spooldir=%{l_prefix}/var/mimedefang/spool \
        --with-quarantinedir=%{l_prefix}/var/mimedefang/quarantine \
        --with-user=%{l_rusr} \
%if "%{with_clamav}" == "yes"
        --enable-anti-virus \
        --enable-clamav \
        --enable-clamd \
        --disable-antivir \
        --disable-vexira\
        --disable-uvscan \
        --disable-bdc \
        --disable-sweep \
        --disable-trend \
        --disable-AvpLinux \
        --disable-aveclient \
        --disable-clamav \
        --disable-fsav \
        --disable-fprot \
        --disable-sophie \
        --disable-nvcc \
        --disable-trophie
%else
        --disable-anti-virus
%endif

    #   build program
    %{l_make} %{l_mflags}

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

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

    #   create run-time data directories
    %{l_shtool} mkdir -f -p -m 750 \
        $RPM_BUILD_ROOT%{l_prefix}/var/mimedefang \
        $RPM_BUILD_ROOT%{l_prefix}/var/mimedefang/spool \
        $RPM_BUILD_ROOT%{l_prefix}/var/mimedefang/quarantine

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/mimedefang/*' \
        '%attr(750,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/mimedefang' \
        '%attr(750,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/mimedefang/*'

%files -f files

%clean

