smfi_setmlreply Function

Purpose

The smfi_setmlreply function sets the default simple mail transfer protocol (SMTP) error reply code to a multi-line response. The smfi_setmlreply function accepts only 4XX and 5XX replies.

Syntax

#include <libmilter/mfapi.h>
int smfi_setmlreply(
SMFICTX *ctx,
char *rcode,
char *xcode,
...
);

Description

The smfi_setmlreply function is called from any of the xxfi_callback functions, except for xxfi_connect function. The smfi_setmlreply function provides SMTP error reply code for the connections mentioned below the xcode. The list of arguments must be null-terminated. This code is used for subsequent error replies resulting from actions taken by this filter.

The values passed to the smfi_setmlreply function are not checked for standards compliance.

The message parameter must contain only printable characters, other characters can lead to undefined behavior. For example, characters like CR or LF causes the call to fail, single '%' characters causes the text to be ignored.
Note: If a '%' string is required in the message parameter use '%%' string similarly like printf(3) string is used.

For reply codes and their meanings, see RFC 821 or 2821 and RFC 1893 or 2034.

If the rcode is set as 4XX but, the SMFI_REJECT value is used for the message, the custom reply is not used.

If the rcode is set as 5XX but, the SMFI_TEMPFAIL value is used for the message, the custom reply is not used.
Note: In the above two cases an error is returned to the milter parameter, and the Libmilter parameter ignores the error.

If the milter parameter returns the SMFI_TEMPFAIL value and sets the reply code to 421, the SMTP server terminates the SMTP session with an 421 error code.

Arguments

Table 1. Arguments
Item Description
ctx The opaque context structure is maintained in the libmilter parameter.
rcode The three-digit ( RFC 821 or 2821) SMTP reply code, as a null-terminated string. The rcode argument cannot be NULL, and must be a valid 4XX or 5XX reply code.
xcode The extended ( RFC 1893 or 2034) reply code. If xcode is NULL, no extended code is used. Otherwise, xcode must conform to RFC 1893 or 2034
... The remainder of the arguments is single lines of text, up to 32 arguments, which is used as text part of the SMTP reply. The list must be null-terminated.

Return values

The smfi_setmlreply function returns the MI_FAILURE value in the following cases. Otherwise, the function returns MI_SUCCESS.
  • The rcode or xcode argument is invalid.
  • A memory-allocation failure occurs.
  • The text line contains a carriage return or line feed.
  • The length of any text line is more than MAXREPLYLEN(980).
  • The text replies exceeds more than 32 lines.

Example

ret = smfi_setmlreply(ctx, "550", "5.7.0",
"Spammer access rejected",
"Please see our policy at:",
 "http://www.example.com/spampolicy.html",
NULL);
The previous example results in the following :
550-5.7.0 Spammer access rejected
550-5.7.0 Please see our policy at:
550 5.7.0 http://www.example.com/spampolicy.html

Related information

libmilter_xxfi_connect.html