====== Script Custom condition delai.pm ======
Pour personnaliser le message modifier
* à la ligne 3 "**package CustomCondition::delai**;" remplacer delai par le nom du script
* à la ligne 75 "**my $tpl = 'delai';**" \\ en remplaçant delai par le nom du fichier du message (avant **.tt2**)\\ dans ~sympa>/etc/[robot]/mail_tt2/ \\ Dans cet exemple le fichier du message sous mail_tt2 s'appelle delai.tt2
delai.pm
#!/usr/bin/perl
package CustomCondition::delai;
use strict;
use English qw(-no_match_vars);
use MIME::EncWords;
use Sympa::Log;
use Sympa::List;
use Exporter;
our @EXPORT_OK = qw(verify);
my $log = Sympa::Log->instance;
sub verify {
eval { require DateTime::Format::DateParse; };
if ($EVAL_ERROR) {
$log->syslog(
'err',
'Error requiring DateTime::Format::DateParse : %s (%s)',
"$EVAL_ERROR",
ref($EVAL_ERROR)
);
return 1;
}
# Get parameters
my $list_address = shift;
my $vacation_start = shift;
my $vacation_end = shift;
my $sender = shift;
my $subject = shift;
$subject = shift @$subject if ref $subject eq 'ARRAY';
$subject = MIME::EncWords::decode_mimewords($subject);
# Parse dates
my $dt_start = DateTime::Format::DateParse->parse_datetime($vacation_start);
my $dt_end = DateTime::Format::DateParse->parse_datetime($vacation_end);
unless($dt_start) {
$log->syslog(
'err',
'Unable to parse date "%s"',
$vacation_start
);
return 1;
}
unless($dt_end) {
$log->syslog(
'err',
'Unable to parse date "%s"',
$vacation_end
);
return 1;
}
$vacation_start = $dt_start->epoch();
$vacation_end = $dt_end->epoch();
# Check time range, return if not vacation
return 1 unless time >= $vacation_start and time <= $vacation_end;
# We are in vacation range, notify sender
# Retreive List object
my ($list_name, $robot) = split(/@/, $list_address);
my $list = Sympa::List->new($list_name, $robot);
# Send notification
my $tpl = 'delai';
unless (
Sympa::send_file(
$list,
$tpl,
$sender,
{
'auto_submitted' => 'auto-replied',
'vacation_start' => $vacation_start,
'vacation_end' => $vacation_end,
'subject' => $subject
}
)
) {
$log->syslog(
'notice',
'Unable to send template "%s" to %s',
$tpl,
$sender
);
}
return 1;
}
# Packages must return true
1;