5. Policy banks

Policy banks are used to provide policy switching between different sources of mail. The most important thing you need to know about them is that configuration variables which are part of policy banks should be accessed using the c (to access a scalar), cr (to obtain a reference to the value) or ca (to access an array, returning a reference) functions to access configuration variables which are part of policy banks, instead of accessing the global variables directly.

In addition, you should load the MYNETS policy bank if the client MTA has a local IP address and MYUSERS if the sender has a local address. This is determined using the mynetworks_maps and local_domains_maps settings respectively. The code looks like this:

my($cl_ip) = $msginfo->client_addr;  my($sender) = $msginfo->sender;
    if ($cl_ip ne '' && defined $policy_bank{'MYNETS'}
        && lookup_ip_acl($cl_ip,@{ca('mynetworks_maps')}) ) {
      Amavis::load_policy_bank('MYNETS'); $policy_changed = 1;
    }
    if ($sender ne '' && defined $policy_bank{'MYUSERS'}
        && lookup(0,$sender,@{ca('local_domains_maps')})) {
      Amavis::load_policy_bank('MYUSERS'); $policy_changed = 1;
    }

Before changing the policy bank, you need to save a copy of the %current_policy_bank hash. After mail processing is completed, you need to restore this hash to its original value. (Is this strictly necessary?)

You should also enable debugging if the sender matches debug_sender_maps, by doing debug_oneshot(1) if lookup(0, $sender, @{ca('debug_sender_maps')}); (after loading relevant policy banks).