public abstract class AMilterHandlerAdapter extends Object implements IMilterHandler
IMilterHandler
interface so subclasses may override only those methods
they desire.Modifier and Type | Field and Description |
---|---|
protected IMilterStatus |
DEFAULT_ACCEPT |
protected IMilterStatus |
DEFAULT_CONTINUE |
protected IMilterStatus |
DEFAULT_DISCARD |
protected IMilterStatus |
DEFAULT_REJECT |
protected IMilterStatus |
DEFAULT_TEMPFAIL |
Constructor and Description |
---|
AMilterHandlerAdapter() |
Modifier and Type | Method and Description |
---|---|
IMilterStatus |
abort()
Handle the current message being aborted.
|
IMilterStatus |
body(ByteBuffer bodyp)
Handle a piece of a message's body.
|
IMilterStatus |
close()
The current connection is being closed.
|
IMilterStatus |
connect(String hostname,
InetAddress hostaddr,
Properties properties)
Called once at the start of each SMTP connection.
|
IMilterStatus |
data(Properties properties)
Handle the DATA command.
|
IMilterStatus |
envfrom(byte[][] argv,
Properties properties)
Handle the envelope FROM command.
|
IMilterStatus |
envrcpt(byte[][] argv,
Properties properties)
Handle the envelope RCPT command.
|
IMilterStatus |
eoh(IMilterActions eomActions,
Properties properties)
End of a headers.
|
IMilterStatus |
eom(IMilterActions eomActions,
Properties properties)
End of a message.
|
int |
getActionFlags()
Get the Milter Action flags as to what this milter uses.
|
Map<Integer,Set<String>> |
getMacros()
Get desired macros during negotiation.
|
int |
getProtocolFlags()
Get the list of calls the MTA should not await replies for.
|
IMilterStatus |
header(byte[] name,
byte[] value)
Handle a message header.
|
IMilterStatus |
helo(String helohost,
Properties properties)
Handle the HELO/EHLO command.
|
int |
negotiateVersion(int mtaVersion,
int actionFlags,
int protocolFlags)
Prepares for protocol version negotiation.
|
void |
reset()
Called when receiving a
MilterConstants.SMFIC_QUIT_NC command from the MTA. |
IMilterStatus |
unknown(byte[] command,
Properties properties)
Handle an unknown SMTP command.
|
protected final IMilterStatus DEFAULT_CONTINUE
protected final IMilterStatus DEFAULT_ACCEPT
protected final IMilterStatus DEFAULT_DISCARD
protected final IMilterStatus DEFAULT_REJECT
protected final IMilterStatus DEFAULT_TEMPFAIL
public IMilterStatus connect(String hostname, InetAddress hostaddr, Properties properties)
IMilterHandler
connect
in interface IMilterHandler
hostname
- The host name of the message sender, as determined by a reverse lookup on the host address.hostaddr
- The host address, as determined by a getpeername()
call on the SMTP socket.properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
. NOTE: The MTA will currently ignore
any custom values (values other than SMFIS_
values). Specifically, values created with
CustomMilterStatus.CustomMilterStatus(java.lang.String, java.lang.String, java.lang.String[])
will not be honored.public IMilterStatus helo(String helohost, Properties properties)
IMilterHandler
helo
in interface IMilterHandler
helohost
- Value passed to HELO/EHLO command, which should be the domain name of the sending host (but is,
in practice, anything the sending host wants to send).properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
.public IMilterStatus envfrom(byte[][] argv, Properties properties)
IMilterHandler
envrcpt
.envfrom
in interface IMilterHandler
argv
- An array of SMTP command arguments. argv[0]
is guaranteed to be the sender address.
Later arguments are the ESMTP arguments. While the default encoding should be presumed to be ASCII, the value
decoding is left to the user. Often simply the default String.String(byte[])
constructor is enough.properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
.public IMilterStatus envrcpt(byte[][] argv, Properties properties)
IMilterHandler
IMilterHandler.envfrom(byte[][], java.util.Properties)
.envrcpt
in interface IMilterHandler
argv
- An array of SMTP command arguments. argv[0]
is guaranteed to be the recipient address.
Later arguments are the ESMTP arguments. While the default encoding should be presumed to be ASCII, the value
decoding is left to the user. Often simply the default String.String(byte[])
constructor is enough.properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
.public IMilterStatus header(byte[] name, byte[] value)
IMilterHandler
IMilterHandler.envrcpt(byte[][], java.util.Properties)
and IMilterHandler.eoh(com.sendmail.milter.IMilterActions, java.util.Properties)
, once per message
header.header
in interface IMilterHandler
name
- Header field name.value
- Header field value. The content of the header may include folded white space (i.e. multiple lines
with following white space). The trailing line terminator (CR/LF) is removed.
While the default encoding should be presumed to be ASCII, the value decoding is left to the user. Often simply
the default String.String(byte[])
constructor is enough. String.String(byte[])
constructor is
enough.
SMFIS_
return codes from IMilterStatus
.public IMilterStatus body(ByteBuffer bodyp)
IMilterHandler
IMilterHandler.eoh(com.sendmail.milter.IMilterActions, java.util.Properties)
and IMilterHandler.eom(com.sendmail.milter.IMilterActions, java.util.Properties)
.body
in interface IMilterHandler
bodyp
- This block of body data.SMFIS_
return codes from IMilterStatus
.public IMilterStatus eoh(IMilterActions eomActions, Properties properties)
IMilterHandler
IMilterHandler.header(byte[], byte[])
for a given message.eoh
in interface IMilterHandler
eomActions
- Interface for effecting message changes.properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
.public IMilterStatus eom(IMilterActions eomActions, Properties properties)
IMilterHandler
IMilterHandler.body(java.nio.ByteBuffer)
for a given message.eom
in interface IMilterHandler
eomActions
- Interface for effecting message changes.properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
.public IMilterStatus unknown(byte[] command, Properties properties)
IMilterHandler
unknown
in interface IMilterHandler
command
- the incoming command.properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
.public IMilterStatus data(Properties properties)
IMilterHandler
IMilterHandler.eoh(com.sendmail.milter.IMilterActions, java.util.Properties)
and IMilterHandler.body(java.nio.ByteBuffer)
commands.data
in interface IMilterHandler
properties
- Any properties (macros) received from the MTA.SMFIS_
return codes from IMilterStatus
.public IMilterStatus abort()
IMilterHandler
IMilterHandler.eom(com.sendmail.milter.IMilterActions, java.util.Properties)
).abort
in interface IMilterHandler
SMFIS_
return codes from IMilterStatus
.public IMilterStatus close()
IMilterHandler
close
in interface IMilterHandler
SMFIS_
return codes from IMilterStatus
.public int getActionFlags()
IMilterHandler
getActionFlags
in interface IMilterHandler
MilterConstants.SMFIF_ADDHDRS
,
MilterConstants.SMFIF_CHGBODY
, MilterConstants.SMFIF_ADDRCPT
,
MilterConstants.SMFIF_DELRCPT
, MilterConstants.SMFIF_CHGHDRS
,
MilterConstants.SMFIF_QUARANTINE
, MilterConstants.SMFIF_CHGFROM
,
MilterConstants.SMFIF_ADDRCPT_PAR
, MilterConstants.SMFIF_SETSYMLIST
constants.public int getProtocolFlags()
IMilterHandler
getProtocolFlags
in interface IMilterHandler
MilterConstants.SMFIP_NOCONNECT
, MilterConstants.SMFIP_NOHELO
,
MilterConstants.SMFIP_NOMAIL
, MilterConstants.SMFIP_NORCPT
,
MilterConstants.SMFIP_NOBODY
, MilterConstants.SMFIP_NOHDRS
,
MilterConstants.SMFIP_NOEOH
, MilterConstants.SMFIP_NOUNKNOWN
,
MilterConstants.SMFIP_NODATA
, MilterConstants.SMFIP_SKIP
, MilterConstants.SMFIP_RCPT_REJ
,
MilterConstants.SMFIP_NR_HDR
, MilterConstants.SMFIP_NR_CONN
,
MilterConstants.SMFIP_NR_HELO
, MilterConstants.SMFIP_NR_MAIL
,
MilterConstants.SMFIP_NR_RCPT
, MilterConstants.SMFIP_NR_DATA
,
MilterConstants.SMFIP_NR_UNKN
, MilterConstants.SMFIP_NR_EOH
,
MilterConstants.SMFIP_NR_BODY
, MilterConstants.SMFIP_HDR_LEADSPC
or 0.public int negotiateVersion(int mtaVersion, int actionFlags, int protocolFlags)
IMilterHandler
IMilterHandler.getActionFlags()
, IMilterHandler.getProtocolFlags()
and
IMilterHandler.getMacros()
are subsequently called and verified.
If IMilterHandler.getActionFlags()
requires flags not supported by the MTA, the negotiation will fail and the
connection will be terminated with a IMilterStatus.SMFIS_TEMPFAIL
response.
If IMilterHandler.getProtocolFlags()
requires flags not supported by the MTA, other than SMFIP_NR_
flags,
the negotiation will fail and the connection will be terminated with a IMilterStatus.SMFIS_TEMPFAIL
response.
If IMilterHandler.getProtocolFlags()
requires SMFIP_NR_ flags not supported by the MTA, the Milter server will emulate
them by sending IMilterStatus.SMFIS_CONTINUE
responses.
Normally your filter's flags should be constant, but here we give you a chance to turn some features off or do workarounds. Note that your implemented handler functions are always called if a packet arrives for them, even if you report that you don't use them. Sendmail accepts the results and complains in the logs that your filter is a liar.
negotiateVersion
in interface IMilterHandler
mtaVersion
- Milter Protocol version of the Mail Transport Agent.actionFlags
- Actions flags for actions supported by the MTA. Prefixed with SMFIF_ in
MilterConstants
.protocolFlags
- Protocol flags supported by the MTA. Prefixed with SMFIP_ in MilterConstants
.public void reset()
IMilterHandler
MilterConstants.SMFIC_QUIT_NC
command from the MTA. A stateful Milter must reset
itself to the same state it was in before the IMilterHandler.connect(java.lang.String, java.net.InetAddress, java.util.Properties)
call, or after the calls to
IMilterHandler.negotiateVersion(int, int, int)
, IMilterHandler.getActionFlags()
, IMilterHandler.getProtocolFlags()
and
IMilterHandler.getMacros()
, because it will be reused.reset
in interface IMilterHandler
public Map<Integer,Set<String>> getMacros()
IMilterHandler
The macros themselves are available scattered with no particular grouping or order, with little to no description in the Sendmail documentation and some of them, but with proper description in the Postfix Milter documents.
getMacros
in interface IMilterHandler
MilterConstants.Macros
.Copyright © 2016. All rights reserved.