/* Cached SPF interface. Copyright (C) 2007-2020 Sergey Poznyakoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ module 'spf'. #pragma regex push +extended +icase const None 0 const Neutral 1 const Pass 2 const Fail 3 const SoftFail 4 const TempError 5 const PermError 6 func spf_status_string(number code) returns string do switch code do case None: return "None" case Neutral: return "Neutral" case Pass: return "Pass" case Fail: return "Fail" case SoftFail: return "SoftFail" case TempError: return "TempError" case PermError: return "PermError" done return "UNKNOWN (%code)" done static func __spf_msgid() returns string do if macro_defined("i") return getmacro("i") . ": " else return "" fi done static func __spf_log(number result, string ip, string domain, string sender) do string logmsg "SPF check_host(%ip, %domain, %sender) = " . spf_status_string(result) if spf_mechanism != "" set logmsg "%logmsg; matching mechanism \"%spf_mechanism\"" fi if spf_explanation != "" set logmsg "%logmsg; %spf_explanation" fi echo __spf_msgid() . logmsg done func check_host(string ip, string domain, string sender, string helo) returns number do set result spf_check_host(ip, domain, sender, helo, ehlo_domain) __spf_log(result, ip, domain, sender) return result done #pragma regex pop