#24 Template for Notify::Sender messages

open
None
5
2014-08-15
2002-10-09
No

This patch, issued against amavis-ng from CVS on
2002-10-09,
allows specification of a template file for the notify
message issued by the module Notify::Sender.

This patch adds a new option under the [Notify] config
section:

[Notify]
sender template =
/usr/local/amavis-ng/etc/sender-notify-message

A sample sender template, based on original Amavis'
message:

$ cat /usr/local/amavis-ng/etc/sender-notify-message
Subject: Virus in mail from you.

Our virus checker has found potentially malicious
code in a mail by
you. Delivery has been stopped. For further
questions, please contact
$cfg_sender.

Similar method could be used for Notify::Recipient.

This patch requires further testing, but for now I'm
particularly interested about the design of the
patch. Is it acceptable?

*** Sender.pm.orig Thu Oct 3 18:52:25 2002
--- Sender.pm Thu Oct 3 19:17:41 2002
***************
*** 10,15 ****
--- 10,16 ----

use vars qw(
$cfg_sender
+ $cfg_notify_template
);

sub init {
***************
*** 18,23 ****
--- 19,29 ----
writelog($args,LOG_DEBUG,__PACKAGE__." initialized.");
$cfg_sender = $AMAVIS::cfg->val('Notify', 'mail from');
$cfg_sender = 'postmaster' unless defined($cfg_sender);
+
+ $cfg_notify_template = load_notify_template($args);
+ return 0 unless defined($cfg_notify_template);
+ writelog($args, LOG_DEBUG, __PACKAGE__.': Notify
template loaded.');
+
# Return successfully
return 1;
}
***************
*** 44,55 ****
my $message = <<"EOF";
From: $cfg_sender
To: $recipient
! Subject: Virus in mail from you.

! Our virus checker has found potentially malicious
code in a mail by
! you. Delivery has been stopped. For further
questions, please contact
! $cfg_sender.

The recipient(s) for this message were:
EOF

--- 50,64 ----
my $message = <<"EOF";
From: $cfg_sender
To: $recipient
! EOF

! my $notify_message;
! eval '$notify_message = "$cfg_notify_template";';

+ $message .= $notify_message;
+
+ $message.= << "EOF";
+
The recipient(s) for this message were:
EOF

***************
*** 78,81 ****
--- 87,115 ----
return 1;
}

+ sub load_notify_template {
+ my $self = shift;
+ my $args = shift;
+
+ my $template_file = $AMAVIS::cfg->val('Notify',
'sender template');
+
+ if (!defined($template_file)) {
+ writelog($args,LOG_WARNING, "Missing 'sender
template' definition under [Notify]");
+ return undef;
+ }
+
+ local *IN;
+ if (!open(IN, "<$template_file")) {
+ writelog($args,LOG_WARNING, "Can't open sender
template file for reading: $template_file: $!");
+ return undef;
+ }
+
+ my @template_message = <IN>;
+
+ close(IN) || writelog($args,LOG_WARNING, "Failure
closing sender template file: $template_file: $!");
+
+ join('', @template_message);
+ }
+
1;
+

Discussion

  • Lars Hecking
    Lars Hecking
    2002-10-10

    • assigned_to: nobody --> bengen
     
  • Logged In: YES
    user_id=2126

    Have amavis-ng included a better mechanism to perform
    localization of notification messages?

    To modify hard-coded messages is inconvenient.

     
  • Hilko Bengen
    Hilko Bengen
    2005-01-06

    • assigned_to: bengen --> braeucup