%global real_name filter-rspamd

Summary:	OpenSMTPD filter integration for Rspamd
Name:		opensmtpd-%{real_name}
Version:	0.1.8
Release:	1%{?dist}

License:	ISC
URL:		https://github.com/poolpOrg/filter-rspamd

Source0:	https://github.com/poolpOrg/filter-rspamd/archive/v%{version}/%{name}-%{version}.tar.gz

#Patch0:     opensmtpd-filter-rspamd-fix-go-sys-version.patch

BuildRequires:	golang
%if 0%{?rhel} >= 7
BuildRequires:  golang(golang.org/x/sys/cpu)
%else
BuildRequires:  golang-github-golang-sys-devel
%endif
%if 0%{?rhel} == 7
BuildRequires: pkgconfig(openssl) < 3.0
%else
BuildRequires:  pkgconfig(openssl) >= 3.0
%endif


Requires: opensmtpd
Requires: rspamd

%description
This filter implements the Rspamd protocol and allows OpenSMTPD to request an
Rspamd analysis of an SMTP transaction before a message is committed to queue.
The filter currently supports:
* greylisting
* adding X-Spam related headers to a message
* rewriting Subject headers
* DKIM-signing messages
* using Rspamd-provided SMTP replies
* allowing Rspamd to add and remove headers

%prep
%autosetup -p1 -n %{real_name}-%{version}

%build

export CGO_CPPFLAGS="${CPPFLAGS}"
export CGO_CFLAGS="${CFLAGS}"
%if 0%{?rhel} <= 8
export CGO_CFLAGS="-I%{_includedir}/openssl3 ${CGO_CFLAGS}"
%endif
export CGO_CXXFLAGS="${CXXFLAGS}"
export CGO_LDFLAGS="${LDFLAGS}"
export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
export GOCODE=".:%{_datadir}/gocode"
go env -w GO111MODULE=off
go build -v -ldflags "-linkmode external" -o %{real_name}


%install
mkdir -p %{buildroot}/{%{_libexecdir}/opensmtpd,%{_mandir}/man8}
install -D %{real_name} -t %{buildroot}/%{_libexecdir}/opensmtpd
install %{real_name}.8 %{buildroot}%{_mandir}/man8


%files
%doc README.md
%if 0%{?rhel} >= 8
%license LICENSE
%else
%doc LICENSE
%endif
%{_libexecdir}/opensmtpd/%{real_name}
%{_mandir}/man8/%{real_name}.8*


%changelog
* Wed Oct 4 2023 Raven <raven@sysadmins.ws> - 0.1.8-1
- Initial release
