Here is a patch to allow admins to customize the blocking SMTP response reason in a config variable. It is particularly useful for people using amavisd-new in milter and proxy contexts that want to customize their reject messages. (Especially adding a contact address).
The implementation adds the config hash %smtp_reason_by_ccat, a mapping of CC_ => 'reason string' to use when amavisd-new blocks content. The reason strings are subject to template-style expansion, so all the builtins work normally (%T, %d, etc). In order to access the original reason amavisd-new would have used for the given ccat, I've added a builtin 'x', available only in this context. (I have no idea what letter to use and chose x more or less arbitrarily) One important detail of the implementation is that: %smtp_reason_by_ccat = ( CC_VIRUS, '%x' ); will NOT give you the original behavior, for that you need: %smtp_reason_by_ccat = ( CC_VIRUS, 'id=%n, %x' ); The rationale being that if people want to customize their reason, they might also want to customize the id format. (We did.) Incorporating %x into SMTP reasons is usually good because amavisd places message specific data there, such as virus name, banning reason, blacklist status, etc. The patch uses the same sanity checking on the length of custom, expanded SMTP reason strings that is used on the default messages. This patch does not do any changing of the SMTP response status (eg "554 5.7.0"). It seems like this is pretty commonly requested functionality. The "customize the code" approach does not work for us, as we wanted to have the ability to easily change SMTP responses on a scheduled basis. (i'm a lot more comfortable with a script writing out a config file and reloading amavisd, rather than a script that modifies the code and reloads...) --- amavisd-new-2.6.3/amavisd 2009-04-21 17:24:12.000000000 -0700 +++ amavisd-new-2.6.3/mavisd 2009-04-25 00:05:31.000000000 -0700 @@ -347,6 +347,7 @@ %admin_maps_by_ccat %warnrecip_maps_by_ccat %always_bcc_by_ccat %dsn_bcc_by_ccat %addr_extension_maps_by_ccat %addr_rewrite_maps_by_ccat + %smtp_reason_by_ccat )], 'confvars' => # global settings (not per-policy, not per-recipient) [qw( @@ -11050,10 +11051,24 @@ local($1,$2); $status =~ s{^5(\d\d) 5(\.\d\.\d)\z}{250 2$2}; # 5xx -> 250 } + # get the custom smtp response reason text + my ($smtp_reason) = setting_by_given_contents_category( + $blocking_ccat, cr('smtp_reason_by_ccat') + ); + # use smtp response reason text (by ccat) override + if ($smtp_reason ne '') { + my(%mybuiltins) = %builtins; # make a local copy + # provide the default reason by ccat (%x) for use in template + $mybuiltins{'x'} = $reason; + # finish preparing custom reason template + $smtp_reason = expand(\$smtp_reason, \%mybuiltins); + $smtp_reason = !ref($smtp_reason) ? '' : ${$smtp_reason}; + $smtp_reason = substr($smtp_reason,0,100)."..." if length($smtp_reason) > 100+3; + } my($response) = $status . ' ' . ($final_destiny == D_PASS ? "Ok" : $final_destiny == D_DISCARD ? "Ok, discarded" : "Reject") . - ", id=$am_id - $reason"; + ($smtp_reason ne '' ? ", $smtp_reason" : ", id=$am_id - $reason"); ll(4) && do_log(4, "blocking ccat=%s, SMTP response: %s", $blocking_ccat,$response); $r->recip_smtp_response($response); ------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp as they present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com _______________________________________________ AMaViS-user mailing list AMaViS-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amavis-user AMaViS-FAQ:http://www.amavis.org/amavis-faq.php3 AMaViS-HowTos:http://www.amavis.org/howto/