[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.6.6 Modifying SMTP Commands

GNU Anubis is able to modify arguments of SMTP commands. To instruct it to do so, define a section named `SMTP'. Anubis will call this section each time it receives an SMTP command. This section can contain any statements allowed for `RULE' section, plus the following special flavor of the `modify' statement:

Command: modify [flags] command `['cmd`]' value

If the current SMTP command matches cmd, rewrite it by using value as its argument.

For example, this is how to force using `my.host.org' as the `EHLO' argument:

 
BEGIN SMTP
modify command [ehlo] "my.host.org"
END

Additionally, the ESMTP authentication settings (see section ESMTP Authentication Settings) can be used as actions in this section. To do so, you must first set esmtp-auth-delayed to `yes' in the `CONTROL' section (see section esmtp-auth-delayed). Changes in the settings take effect if they occur either before the `MAIL' SMTP command, or while handling this command.

Consider, for example, the following configuration:

 
BEGIN CONTROL
 mode transparent
 bind 25
 remote-mta mail.example.com
 esmtp-auth-delayed yes
END

BEGIN SMTP
if command ["mail from:"] "<smith(\+.*)?@example.net>"
  esmtp-auth-id smith
  esmtp-password guessme
else
  esmtp-auth no
fi
END

It delays ESMTP authentication until the receipt of the MAIL command from the client. Authentication is used only if the mail is being sent from smith@example.net or any additional mailbox of that user (e.g. smith+mbox@example.net). Otherwise, authentication is disabled.

The following points are worth mentioning:

  1. As usual, you may use conditional expressions to decide what to modify and how. For example, the code below replaces the domain part of each `MAIL FROM' command with `gnu.org':
     
    BEGIN SMTP
    if command ["mail from:"] "<(.*)@(.*)>(.*)"
      modify command ["mail from:"] "<\1@gnu.org>\2"
    fi
    END
    
  2. Each `modify command' statement applies only if the current command matches its cmd argument. In particular, this means that you cannot modify already transferred SMTP commands nor the commands to be transferred. For example, the following code will not work:
     
    BEGIN SMTP
    # Wrong!
    if command ["mail from:"] "<>(.*)"
      modify command [ehlo] "domain.net"
    fi
    END
    

    It is because by the time `MAIL FROM' is received, the `EHLO' command has already been processed and sent to the server.

The final point to notice is that you may use an alternative name for that section (if you really want to). To do so, define the new name via the `smtp-command-rule' option in the `CONTROL' section (see section smtp-command-rule).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on May, 24 2014 using texi2html 1.76.