Previous: , Up: Special handlers   [Contents][Index]


4.15.3 Action Hook

Action hook handler is run implicitly before executing each reply action, such as accept, reject, etc. See reply actions, for a discussion of reply action statements.

Upon invocation, the handler is passed four arguments:

  1. Identifier of the action which is about to be performed. Each action is assigned a numeric identifier. The status module defines the following symbolic names for action identifiers:
    ACCEPT_ACTION
    CONTINUE_ACTION
    DISCARD_ACTION
    REJECT_ACTION
    TEMPFAIL_ACTION

    To convert these to textual action names, use the milter_action_name function (see milter_action_name).

  2. SMTP code of the reply
  3. Extended reply code
  4. Textual message passed to the action.

The last three arguments are meaningful only for reject and tempfail actions. For the remaining three actions (accept, discard, and continue), empty strings are passed.

The action hook handler is useful mainly for logging and accounting purposes. For example, the code fragment below assumes that the openmetrics module is used (see mfmod_openmetrics in mfmod_openmetrics reference). It increases the corresponding metrics before taking the action. Additionally, for reject and tempfail actions, the metrics ‘reject_code’ and ‘tempfail_code’ are increased, where code is the three-digit SMTP status code being sent to the server.

prog action
do
  openmetrics_incr(milter_action_name($1))
  switch $1
  do
  case REJECT_ACTION:
     openmetrics_incr("reject_" . $2)
  case TEMPFAIL_ACTION:
     openmetrics_incr("tempfail_" . $2)
  done
done