Accéder au contenu.
Menu Sympa

fr - [sympa-fr] Proposition de contribution

Objet : Pour les administrateurs de serveurs de listes utilisant le logiciel Sympa

Archives de la liste

Chronologique Discussions  
  • From: Bruno Cornec <adresse@cachée>
  • To: sympa-fr <adresse@cachée>
  • Subject: [sympa-fr] Proposition de contribution
  • Date: Thu, 26 Mar 2009 17:37:15 +0100

Bonjour,

Je viens de recevoir l'autorisation de notre Open Source Review Board de
soumettre une petite contribution au projet Sympa.

Pour notre besoin interne au sein d'HP, nous avons eu à développer un
script permettant de renvoyer du mail vers des mailling lists à partir
d'archives, dans le cas où un problème de diffusion est apparu,
empêchant l'envoi correct originellement, mais permettant l'archivage.

J'ai vu qu'il y avait un répertoire de contrib pour Sympa, donc je me
permets de proposer ce script en espérant qu'il sera utile à d'autres
que nous. Il est fourni sous GPLv2.

Voici le man:
RESEND-MAIL(1) User Contributed Perl Documentation RESEND-MAIL(1)



NAME
resend-mail.pl

DESCRIPTION
Tool to resend mail from Sympa archives, in case a problem in the SMTP
sending has occured

SYNOPSIS
resend-mail.pl -g ML1,ML2,ML3,... -s StarDate -e EndDate

OPTIONS
-g|--groups
mailing lists to consider eparated by coma

-s|--startdate
Date of begining of lost mails (Fmt: YYYY-MM-DD HH:mm:ss TZ)

-e|--enddate
Date of end of lost mails (Fmt: YYYY-MM-DD HH:mm:ss TZ)

-n|--noaction
Doesn't execute the resend, just prints what it does

-d|--debug
Debug mode

AUTHORS
Bruno Cornec <mailto:adresse@cachée>.

COPYRIGHT
Project-Builder.org is distributed under the GPL v2.0 license



perl v5.10.0 2009-03-26 RESEND-MAIL(1)


Script attaché.
Cordialement,
Bruno.
--
Linux Profession Lead EMEA / Open Source Ambassador \ EMEA CME Sol. Center
http://www.mondorescue.org / HP/Intel Solution Center \ http://hpintelco.net
Des infos sur Linux? http://www.HyPer-Linux.org http://www.hp.com/linux
La musique ancienne? http://www.musique-ancienne.org http://www.medieval.org
#!/usr/bin/perl -w
#
# (C) 2009 Bruno Cornec, Hewlett-Packard
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2as published
# by the # Free Software Foundation
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <http://www.gnu.org/licenses>.

#
# The following is needed on the sympa server:
# sudo apt-get install libdate-manip-perl
# or yum install perl-Date-Manip or urpmi perl-Date-Manip
# depending on your distribution

use strict 'vars';
use Getopt::Long qw(:config auto_abbrev no_ignore_case);
use Data::Dumper;
use English;
use Date::Manip;
#use Mail::Sendmail;
use Mail::Header;

# Global variables
my %opts; # CLI Options

=pod

=head1 NAME

resend-mail.pl

=head1 DESCRIPTION

Tool to resend mail from Sympa archives, in case a problem in the SMTP
sending has occured

=head1 SYNOPSIS

resend-mail.pl -g ML1,ML2,ML3,... -s StarDate -e EndDate

=head1 OPTIONS

=over 4

=item B<-g|--groups>

mailing lists to consider eparated by coma

=item B<-s|--startdate>

Date of begining of lost mails (Fmt: YYYY-MM-DD HH:mm:ss TZ)

=item B<-e|--enddate>

Date of end of lost mails (Fmt: YYYY-MM-DD HH:mm:ss TZ)

=item B<-n|--noaction>

Doesn't execute the resend, just prints what it does

=item B<-d|--debug>

Debug mode

=back

=head1 AUTHORS

Bruno Cornec L<mailto:adresse@cachée>.

=head1 COPYRIGHT

Project-Builder.org is distributed under the GPL v2.0 license

=cut

# Global var to be adapted if needed
my $sympadir = "/home/sympa/arc";
my $sympaname = "lists.hp.com";


# get params from CLI
GetOptions(
"groups|g=s" => \$opts{'g'},
"startdate|s=s" => \$opts{'s'},
"enddate|e=s" => \$opts{'e'},
"noaction|n" => \$opts{'n'},
"debug|d" => \$opts{'d'},
) || syntax();

if ((not defined $opts{'g'}) || (not defined $opts{'s'}) || (not defined
$opts{'e'})) {
syntax();
}

# Get DateManip dates
my $dates = ParseDate($opts{'s'});
if (! $dates) {
print "ERROR in start date\n";
}
my $datee = ParseDate($opts{'e'});
if (! $datee) {
print "ERROR in end date\n";
}

# Extract Year and month for start and end dates
my $years = &UnixDate($dates,"%Y");
my $months = &UnixDate($dates,"%m");
my $yeare = &UnixDate($datee,"%Y");
my $monthe = &UnixDate($datee,"%m");
my $cpt = 0;

# Do we have to do something
my $process = "false";

# for each maililng list...
foreach my $ml (split(/,/,$opts{'g'})) {
my $dir = "$sympadir/$ml\@$sympaname";
print "Handling list $ml under $dir...\n";
my $cptml = 0;
if (not opendir(DIR,"$dir")) {
print "EROR: Unable to open directory $dir\n";
next;
}
# It contains dir with YYYY-MM format - get them in order
foreach my $d (sort(readdir(DIR))) {
next if ($d =~ /^\./);
# Get DateManip date for this dir
my $datef = ParseDate($d."-01");
if (! $datef) {
print "ERROR in date for $d\n";
next;
}
my $yearf = &UnixDate($datef,"%Y");
my $monthf = &UnixDate($datef,"%m");

# Skipping messages out of the period in consideration
print "DEBUG Considering date $datef wrt to $dates\n" if
(defined $opts{'d'});
next if ($years ne $yearf);
next if ($months lt $monthf);
print "DEBUG Still Considering date $datef wrt $datee\n" if
(defined $opts{'d'});
next if ($yeare ne $yearf);
next if ($monthe gt $monthf);

# Good to process
print "Working on messages of $d\n";
my %msg;

# Creates a hash of all messages with dates
foreach my $m (sort(<$dir/$d/arctxt/*>)) {
if (not open(F,$m)) {
print "ERROR: Unable to open file $m\n";
next;
}
my $head = new Mail::Header \*F, Modify => 0;
my $h = $head->header_hashref();

my $hd = $h->{'Date'}[0];
close(F);
chomp($hd);
$datef = ParseDate($hd);
print "DEBUG Storing msg $m as date $datef\n" if
(defined $opts{'d'});
$msg{$datef} = $m;
}
foreach my $d (sort keys %msg) {
print "DEBUG Considering header date $d wrt to
$dates\n" if (defined $opts{'d'});
next if (Date_Cmp($d,$dates) <= 0);
print "DEBUG Still Considering header date $d wrt
$datee\n" if (defined $opts{'d'});
next if (Date_Cmp($d,$datee) >= 0);
print "Processing $msg{$d} ($d)...\n";
$cptml++;
system("formail -f -A 'X-Resent-By: resend-mail.pl'
-s /usr/sbin/sendmail $ml\@$sympaname < $msg{$d}") if (not defined
$opts{'n'});
}
}
closedir(DIR);
print "$cptml messages resent for list $ml\n";
$cpt += $cptml;
$cptml = 0;
}
print "$cpt messages resent in total\n";



sub syntax {
die "Syntax: resend-mail.pl [-n|-d] -g ML1,ML2,... -s 'Date::Manip
startdate' -e 'Date::Manip enddate'";
}


  • [sympa-fr] Proposition de contribution, Bruno Cornec, 26/03/2009

Archives gérées par MHonArc 2.6.19+.

Haut de le page