Wire Protocol Messages
Messages use a simple format, that starts with the same two fields (in network byte order, obviously):
unsigned long: message size (excluding this field, including command octet)char: A type value, see the message sections below for each type’s value.
The rest of the message, if there is any, is type-dependent and described in the relevant section below.
MTA Setup Commands
Negotiate
Sent by an MTA after connecting to the filter to indicate its accepted options and returned with modified options by the filter.
Optional symbol lists (macros) may be requested for each supported event. The event is
signaled with an unsigned long integer value that maps to an event message type but is
unrelated to the message’s identifier (char). Note that not all events can have macros
send with them. The symbols are delivered with a Macro message before the relevant
event message.
Stage |
Event Message |
|---|---|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
This message corresponds to the libmilter callback xxfi_negotiate registered with smfi_register.
Class: kilter.protocol.messages.Negotiate
Type Value: 'O'
Responses:
Negotiate
Data Structure:
struct {
unsigned long version;
unsigned long action_flags; /* bit-field */
unsigned long protocol_flags; /* bit-field */
struct {
unsigned long stage;
char symbols[]; /* NULL-terminated, space-separated names */
}[];
};
Macro
Transfer symbol (macro) values to a filter for the subsequent event
message. There is no response expected. The event is indicated with
a char type value.
Type Value: 'D'
Data Structure:
struct {
char event;
struct {
char symbol[]; /* NULL-terminated string */
char value[]; /* NULL-terminated string */
}[];
};
Event Messages
These messages are sent with event-appropriate data from the MTA to indicate an event occurring that the filter previously registered its interest in.
Connect
Sent when a client connects to the MTA.
This event corresponds to the libmilter callback xxfi_connect registered with smfi_register.
Class: kilter.protocol.messages.Connect
Type Value: 'C'
Responses:
Continue, Reject, Accept,
Temporary Failure
Data Structure:
struct {
char hostname[]; /* NULL-terminated string */
char addr_family;
union {
/* addr_family == Family.UNKNOWN */
struct {} unknown;
/* addr_family in {Family.INET, Family.INET6, Family.UNIX} */
struct {
unsigned short port;
char address[]; /* NULL-terminated string */
} known;
};
};
Helo
Sent when a client transfers a HELO or EHLO command.
This event corresponds to the libmilter callback xxfi_helo registered with smfi_register.
Class: kilter.protocol.messages.Helo
Type Value: 'H'
Responses:
Continue, Reject, Accept,
Temporary Failure, Reply Code
Data Structure:
char hostname[]; /* NULL-terminated string */
Envelope From
Sent when a client transfers a “MAIL FROM” command.
This event corresponds to the libmilter callback xxfi_envfrom registered with smfi_register.
Class: kilter.protocol.messages.EnvelopeFrom
Type Value: 'K'
Responses:
Continue, Reject, Discard, Accept,
Reply Code
Data Structure:
struct {
char sender[]; /* NULL-terminated string */
char argv[][]; /* Sequence of NULL-terminated strings */
}
Envelope Recipient
Sent when a client indicates a recipient with an “RCPT TO” command.
This event corresponds to the libmilter callback xxfi_envrcpt registered with smfi_register.
Class: kilter.protocol.messages.EnvelopeRecipient
Type Value: 'R'
Responses:
Continue, Reject, Discard, Accept,
Temporary Failure, Reply Code
Data Structure:
struct {
char sender[]; /* NULL-terminated string */
char argv[][]; /* Sequence of NULL-terminated strings */
}
Data
Sent when a client indicates it wants to send a message with the DATA command.
This would indicate the end of envelope recipients.
This event corresponds to the libmilter callback xxfi_data registered with smfi_register.
Class: kilter.protocol.messages.Data
Type Value: 'T'
Responses:
Continue, Reject, Discard, Accept,
Temporary Failure, Reply Code
Data Structure: None
Unknown
Sent when a client tries to use an SMTP command that is unknown to the MTA
This event corresponds to the libmilter callback xxfi_unknown registered with smfi_register.
Class: kilter.protocol.messages.Unknown
Type Value: 'U'
Responses:
Continue, Reject, Discard, Accept,
Temporary Failure, Reply Code
Data Structure:
char* contents; /* NULL-terminated string */
Header
Sent for each mail header that arrives in a message.
This event corresponds to the libmilter callback xxfi_header registered with smfi_register.
Class: kilter.protocol.messages.Header
Type Value: 'L'
Responses:
Continue, Reject, Discard, Accept,
Temporary Failure, Reply Code
Data Structure:
struct {
char name[]; /* NULL-terminated string */
char value[]; /* NULL-terminated string */
}
End of Headers
Sent once all message headers have been processed.
This event corresponds to the libmilter callback xxfi_eoh registered with smfi_register.
Class: kilter.protocol.messages.EndOfHeaders
Type Value: 'N'
Responses:
Continue, Reject, Discard, Accept,
Temporary Failure, Reply Code
Data Structure: None
Body
Transfer a chunk of a message body to a filter.
Although each SMTP message is transfered to the MTA in one continuous stream, it is passed as chunks in Body messages. This allows Skip (or any other non-Continue response) to be sent as a response once the filter has seen enough of the message body to satisfy its interest.
This event corresponds to the libmilter callback xxfi_body registered with smfi_register.
Class: kilter.protocol.messages.Body
Type Value: 'B'
Responses:
Continue, Reject, Discard, Accept,
Temporary Failure, Skip, Reply Code
Data Structure:
char *content; /* unterminated; xxfi_body requires a length argument */
End of Message
A.K.A. End of Body
Similar to Body although only for the final chunk. While its awaiting a response to this event, is the only time an MTA will accept modifications.
TODO What is sent if a Skip response is previously returned?
This event corresponds to the libmilter callback xxfi_eom registered with smfi_register.
Class: kilter.protocol.messages.EndOfMessage
Type Value: 'E'
Responses:
Continue, Reject, Discard, Accept,
Temporary Failure, Reply Code
Data Structure:
char *content; /* unterminated; xxfi_body requires a length argument */
Abort
Tell the filter the session has been aborted.
This event corresponds to the libmilter callback xxfi_abort registered with smfi_register.
Class: kilter.protocol.messages.Abort
Type Value: 'A'
Responses: None
Data Structure: None
Close
Sent when a client sends a QUIT command.
This event corresponds to the libmilter callback xxfi_close registered with smfi_register.
Class: kilter.protocol.messages.Close
Type Value: 'Q'
Responses: None
Data Structure: None
QUIT with New Connection
???
Type Value: 'K'
Response Messages
The messages are sent from the filter to indicate a response to an event, and are required before the MTA will send further events. After sending, no further messages may be sent by a filter until a new event is received from the MTA.
Continue
Continue processing a connection, message or recipient
Class: kilter.protocol.messages.Continue
Type Value: 'c'
Negotiated: no
Events:
Connect, Helo, Envelope-From,
Envelope-Recipient, Data, Unknown,
Header, End-of-Headers,
Body, End-of-Message, Abort, Close,
Negotiate
Reject
Reject a connection, message, or recipient
Class: kilter.protocol.messages.Reject
Type Value: 'r'
Negotiated: no
Events:
Connect, Helo, Envelope-From,
Envelope-Recipient, Data, Unknown,
Header, End-of-Headers,
Body, Negotiate
Discard
Tell the MTA to appear to accept a message or recipient, but reject it internally.
Class: kilter.protocol.messages.Discard
Type Value: 'd'
Negotiated: no
Events:
Envelope-From, Envelope-Recipient, Data,
Unknown, Header, End-of-Headers,
Body, End-of-Message, Abort
Accept
Accept a connection, message or recipient and skip further filtering.
Class: kilter.protocol.messages.Accept
Type Value: 'a'
Negotiated: no
Events:
Connect, Helo, Envelope-From,
Envelope-Recipient, Data, Unknown,
Header, End-of-Headers,
Body, End-of-Message, Abort, Negotiate
Temporary Failure
Similar to Reject, however an SMTP temporary failure code (4xx) will be returned.
Class: kilter.protocol.messages.TemporaryFailure
Type Value: 't'
Negotiated: no
Events:
Connect, Helo, Envelope-Recipient,
Data, Unknown, Header, End-of-Headers,
Body, End-of-Message, Abort, Negotiate
Skip
Used to skip further Body events if a filter has processed enough of a message body to make a decision and wants to move onto the End-of-Message event.
Class: kilter.protocol.messages.Skip
Type Value: 's'
Negotiated: yes
Events:
Body
Modification Messages
These messages are sent by the filter to request a modification of a message, and MAY ONLY be sent after receiving an End-of-Message event from the MTA, and before sending a response for that event. To be send they MUST have been enabled during filter registration.
Add Header
Add a header to the message
This command corresponds to the smfi_addheader function in libmilter
Class: kilter.protocol.messages.AddHeader
Type Value: 'h'
Data Structure:
struct {
char field[]; /* NULL-terminated string */
char value[]; /* NULL-terminated string */
};
Change Header
Change or delete an existing header in the message
This command corresponds to the smfi_chgheader function in libmilter
Class: kilter.protocol.messages.ChangeHeader
Type Value: 'm'
Data Structure:
struct {
unsigned long index;
char field[]; /* NULL-terminated string */
char value[]; /* NULL-terminated string */
};
Insert Header
Insert a header at a given position in the header list
This command corresponds to the smfi_insheader function in libmilter
Class: kilter.protocol.messages.InsertHeader
Type Value: 'i'
Data Structure:
struct {
unsigned long index;
char field[]; /* NULL-terminated string */
char value[]; /* NULL-terminated string */
};
Change Sender
Change the envelope sender address.
This command corresponds to the smfi_chgfrom function in libmilter
Class: kilter.protocol.messages.ChangeSender
Type Value: 'e'
Data Structure:
union {
struct {
char address[]; /* NULL-terminated RFC-6530 address */
} without_args;
struct {
char address[]; /* NULL-terminated RFC-6530 address */
char args[]; /* NULL-terminated string */
} with_args;
};
Add Recipient
Add a recipient to a message
This command corresponds to the smfi_addrcpt function in libmilter
Class: kilter.protocol.messages.AddRecipient
Type Value: '+'
Data Structure:
char address[]; /* NULL-terminated RFC-6530 address */
Add Recipient (with ESMTP arguments)
Add a recipient to a message with additional ESMTP arguments appended.
This command corresponds to the smfi_addrcpt_par function in libmilter
Class: kilter.protocol.messages.AddRecipientPar
Type Value: '2'
Data Structure:
struct {
char address[]; /* NULL-terminated RFC-6530 address */
char args[]; /* NULL-terminated string */
};
Remove Recipient
Remove a recipient from a message (similar to returning Discard in response to an Envelope-Recipient event).
This command corresponds to the smfi_delrcpt function in libmilter
Class: kilter.protocol.messages.RemoveRecipient
Type Value: '-'
Data Structure:
char address[]; /* NULL-terminated RFC-6530 address */
Replace Body
Replace the body of a message. The first message causes the original body to be truncated, and each replacement message is then appended to the message.
This command corresponds to the smfi_replacebody function in libmilter
Class: kilter.protocol.messages.ReplaceBody
Type Value: 'b'
Data Structure:
char *content; /* unterminated; smfi_replacebody requires a length argument */
Progress
Indicates that the filter is still processing a message, used to prevent an MTA from treating a filter as stuck.
This command corresponds to the smfi_progress function in libmilter
Class: kilter.protocol.messages.Progress
Type Value: 'p'
Data Structure: None
Quarantine
Request that the MTA quarantines a message, with a reason.
This command corresponds to the smfi_quarantine function in libmilter
Class: kilter.protocol.messages.Quarantine
Type Value: 'q'
Data Structure:
char reason[]; /* NULL-terminated free-form message */
Misc Messages
These messages appear to be unused or are internal to libmilter.
Shutdown
Type Value: '4'
Connection Fail
Cause a connection failure (between the MTA and client, presumably).
Type Value: 'f'
Set Symbol List
Change the requested symbol list to receive from the MTA?
Type Value: 'l'