# Author: Nigel Kukard  <nkukard@lbsd.net>

Support for custom policy change function

diff -ru amavisd-new-2.6.1/amavisd amavisd-new-2.6.1_policyd-200807052230/amavisd
--- amavisd-new-2.6.1/amavisd	2008-06-29 00:37:58.000000000 +0000
+++ amavisd-new-2.6.1_policyd-200807052230/amavisd	2008-07-05 22:29:52.000000000 +0000
@@ -8030,6 +8030,7 @@
 sub before_send { my($self,$conn,$msginfo)  = @_; undef }
 sub after_send  { my($self,$conn,$msginfo)  = @_; undef }
 sub mail_done   { my($self,$conn,$msginfo)  = @_; undef }
+sub process_policy   { my($self,$conn,$msginfo,$pbn)  = @_; return $pbn }
 
 1;
 
@@ -9705,6 +9706,20 @@
         $r->bypass_spam_checks($bypassed_s);
       }
     }
+
+    # Check if we need to do last minute policy changes
+    if (ref $custom_object) {
+      $which_section = "custom-process_policy";
+      eval {
+        my $new_policy_bank = $custom_object->process_policy($conn,$msginfo,\%current_policy_bank); 1;
+	%current_policy_bank = %{ $new_policy_bank };
+      } or do {
+        my($eval_stat) = $@ ne '' ? $@ : "errno=$!";  chomp $eval_stat;
+        do_log(-1,"custom process_policy error: %s", $eval_stat);
+      };
+      section_time($which_section);
+    }
+
     # update message count and mesage size snmp-like counters
     snmp_count('InMsgs');
     snmp_count('InMsgsNullRPath')  if $sender eq '';
