NAME
Mail::MIMEDefang::OpenSMTPD - helpers for the MIMEDefang OpenSMTPD filter
DESCRIPTION
This module holds the parts of filter-mimedefang.pl that do not need a
running smtpd(8): talking to mimedefang-multiplexor(8), parsing its answers
and the RESULTS file, and rewriting message headers. It is split out so
that it can be unit tested.
FUNCTIONS
split_addr($str)
Splits an smtpd(8) ip:port, [ipv6]:port or local string into
($ip, $port). The IP never has brackets.
relay_hostname($rdns, $ip)
Returns the host name the way MIMEDefang expects it: the reverse DNS name, or the IP address in square brackets when there is none.
encode_command(@args)
Percent-encodes each argument and joins them with spaces, like
mimedefang(8) does. Undefined and empty arguments become ?.
mx_request($socket_path, $timeout, $command)
Sends one newline-terminated command to the multiplexor and returns everything it answers, or undef on failure. A failed attempt is retried once.
parse_mx_reply($text)
Parses an ok N message code dsn delay answer to relayok, helook,
senderok or recipok. Returns a hashref with status (1 continue,
0 reject, -1 tempfail, 2 accept without further filtering, 3 discard),
message, code, dsn and delay, or undef if the text is not an
answer.
reply_to_decision($reply, $default_text)
Turns a parsed multiplexor answer into ($action, $text). $action is
one of proceed, reject, accept (stop filtering this session) or
discard; $text is a complete SMTP reply such as 550 5.7.1 go away
for reject.
build_commands(%args)
Returns the text of the COMMANDS file for mimedefang.pl. Arguments:
sender, recipients (array ref), msgid, qid, helo,
subject (already percent-encoded), relay_ip, mx_id and macros
(hash ref of Sendmail macro name to value, written as =name value).
Addresses are written inside angle brackets, as Sendmail does.
stuff_line($line) / unstuff_line($line)
Add or remove SMTP dot-stuffing on one line.
tls_macros($tls_string)
Converts the version:cipher:bits string reported by smtpd(8) into the
Sendmail macros that MIMEDefang filters expect.
parse_headers(\@lines)
Splits message lines (without the final .) into headers and body.
Returns (\@headers, $body_index). Each header is a hashref with name,
lc (lower-cased name) and lines, the raw physical lines including any
folded continuation lines. $body_index is the index of the blank line
that ends the headers, or the number of lines if there is none.
header_value($header)
The unfolded value of a header returned by parse_headers, without the
leading white space.
parse_results($text)
Parses the RESULTS file written by mimedefang.pl. Returns a hashref:
ops list of { type => H|N|I|J|M, name, idx, value } header changes
action first of 'reject', 'tempfail' or 'discard' found, if any
reply complete SMTP reply for reject and tempfail
newbody true if the body was replaced (NEWBODY)
unsupported list of { type => Q|R|S|f, value } requests that cannot be
done through smtpd-filters(7)
As in mimedefang(8), header changes are not to be applied when action
is set.
apply_header_ops(\@headers, \@ops)
Applies the header changes from parse_results to the headers from
parse_headers, in order, the way libmilter would, and returns the
resulting list of physical header lines. The input is not modified.
H add a header at the end
N insert a header so that it is header number idx (0 is the top)
I change the idx'th (1-based) header called name; add it if there is none
J delete the idx'th header called name
M replace Content-Type (and add MIME-Version if missing)
SEE ALSO
filter-mimedefang.pl(1), mimedefang-multiplexor(8), mimedefang-protocol(7), mimedefang.pl(8)