SMTP Policies

Advanced Configuration of Axigen

Basic structure

The language is structured in blocks of two types: events and methods. The events are predefined blocks that will be executed at specific moments by the server. The methods are custom defined blocks that will be called from the language. Thus the basic structure of a language file is:

 

Comments inside the script file are allowed using the syntax: #comment until the end of line.

 

Methods

Beside the custom methods, a number of predefined methods are also available. They are called in the same way and have a predefined behavior. The currently available predefined methods are:

  • checkSPF
  • checkReverseDNS
  • addHeader
  • addIfNotExistsHeader
  • removeFirstHeader
  • removeHeader
  • modifyHeader
  • modifyIfExistsHeader
  • addRcpt
  • discardRcpt

A more comprehensive example of a script defined until now, can be:

 

 

Variables 

After methods and events, the next as level of importance are the variables. They act as input and output to functions and also act as actions to be taken by the SMTP engine. All variables are considered to be string or numbers and can be of three types: 

  • read-only variables (input variables);
  • read-write variables (input/output variables);
  • action variables - these variables can be either read-only or read-write but they are in this category because they can cause the SMTP engine to take an action or are involved in an action.

 

Variable behavior is context-dependent. If a variable is an input variable for the SMTP Incoming context it will be set only in that context and will be "" in the SMTP Outgoing context. Furthermore, a variable will be set only after that variable's value is known. For example, the MailFromDomain variable will be "" in the onConnect and onEhlo events and will be set only in onMailFrom event. 

Some variables are set/read by the engine but there are methods for reading/writing them from the code. The reading of a variable implies the comparing of the variable's value with another value or variable. This is done using test functions that form the test block of a conditional block.

 

Structures

Condition blocks

There are only block, sub-block, if and switch structures. The block structures were defined above. The ‘if’ structure has the following form:

 

 

The sub-blocks mentioned above are part of the "if" and "switch" structure and as in the case of blocks, start with a "{" and end with a "}". 

The switch structure has the following form: 

 

Both the "if" and the "switch" structures can imbricate a maximum of 16 levels of imbrication. The case statements are exclusive, that means that if a case is matched, after the execution of the block, the switch structure is exited. 

Conditions 

The conditions are Boolean functions that are used in the "if" and "switch" tests. They split into 2 types: single conditions and logical groups. 

The single conditions are as follows: 

  • is(variable,value) - matches for equality;
  • isCase(variable,value) - matches for equality and if strings, the match is case insensitive;
  • match(variable,regexp) - regular expression match;
  • lessThen(variable,value) - number comparison;
  • greaterThen(variable,value) - number comparison;
  • greaterOrEqual(variable, value) - number comparison;
  • lessOrEqual(variable, value) - number comparison;
  • iprange(variable, range) - matches if the variable's value is in range. If the variable is not an ipAddress, the function returns false. 

Example of how to define IP ranges: 

  • 192.168.1.1-192.168.1.10 (range)
  • 192.168.1.1/24 (cidr)
  • 192.168.1.1/255.255.255.0 (netmask) 

The logical groups are: 

  • not(condition) - negation of a condition;
  • allof(condition,condition,...) - similar to an AND between conditions;
  • anyof(condition,condition,...) - similar to an OR between conditions.

The logical groups allow a maximum of 16 levels of imbrication.

 

Functions

The functions can be looked at as keywords from other languages. They are the building blocks of the language and their behavior is hard-coded. The functions available are: 

  • all the Boolean functions described above;
  • call (method) - this executes a predefined of custom defined method. If the method is custom defined, it must be defined in the same script file as the call;
  • export (variable) - this function exports a variable name and value to be used in another context. If the variable is custom defined it must be defined in the same script file;
  • set (variable, value) - this sets the value of a RW variable;
  • return - this function ends the current event or method execution.