## mailfront

# Plugin: lua

This plugin allows for extending mailfront using Lua. All actions in the mailfront plugin API are exposed through calls to functions of the same name in the script, with the exception of the "`init`" function. For this function, the return from the script itself is used. The functions are passed the same parameters as described in the API. The return value from these functions is a numeric SMTP response code followed by a message. If the number is zero or `nil`, it is treated as an NULL response. If the message is missing, the script wrapper provides a simple one based on the response code.

## Configuration

`$LUA_SCRIPT`
  The file name of the Lua script to load. If not set, this plugin does nothing.

## Library

The plugin registers some mailfront functions for script use:

`getenv(...)`
  Returns the (string) value of each of the named session environment variables.
`getnum(name, default)`
  Returns the named session number, or `default` if it is not set.
`getstr(...)`
  Returns the (string) value of each of the named session strings.
`msg(...)`
  Outputs one message line (into the logs) for each parameter. The script is responsible for formatting.
`putenv(...)`
  Puts the given environment strings into the session environment. The strings must be in the form "`NAME=VALUE`"
`setenv(name, value, overwrite)`
  Sets a session environment variable which may be used by other plugins to modify their behavior. Does not return any values. Raises an error if any problems occur.
`setnum(name, value)`
  Sets the named session number. These numbers may be used by other plugins to modify their behavior. For example, the counters plugin uses the minimum value of the session environment variable `$DATABYTES` and the session number `maxdatabytes` for the maximum message size.
`setstr(name, value)`
  Sets the named session string. These strings may be used by other plugins to modify their behavior. For example, the add-received plugin uses the `helo_domain` string in the header(s) it generates.