3 ###############################################################################
4 # UseVoteGer 4.13 Bounce-Verarbeitung
5 # (c) 2001-2022 Marc Langer <uv@marclanger.de>
7 # This script package is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Public License as published by the
9 # Free Software Foundation.
11 # Use this script to process bounce messages and generate a list of
12 # undeliverable voter adresses.
15 # - Ron Dippold (Usevote 3.0, 1993/94)
16 # - Frederik Ramm (German translation, 1994)
17 # - Wolfgang Behrens (UseVoteGer 3.1, based on Frederik's translation, 1998/99)
18 # - Cornell Binder for some good advice and code fragments
20 # This is a complete rewrite of UseVoteGer 3.1 in Perl (former versions were
21 # written in C). Not all functions of Usevote/UseVoteGer 3.x are implemented!
22 ###############################################################################
36 print STDERR "\n$usevote_version Bounce-Verarbeitung - (c) 2001-2005 Marc Langer\n\n";
38 # unknown parameters remain in @ARGV (for "help")
39 Getopt::Long::Configure(qw(pass_through bundling));
41 # Put known parameters in %opt_ctl
42 GetOptions(\%opt_ctl, qw(h|help f|file config-file=s c=s));
44 # Get name auf config file (default: usevote.cfg) and read it
45 my $cfgfile = $opt_ctl{'config-file'} || $opt_ctl{c} || "usevote.cfg";
46 UVconfig::read_config($cfgfile);
48 # check POP3 settings in usevote.cfg and combination with -f parameter
49 $pop3 = 1 if ($config{pop3} && !$opt_ctl{f});
51 # Additional parameters or invalid options? Show help and exit.
52 help() if ($opt_ctl{h} || !(@ARGV || $pop3));
55 if (-e $config{lockfile}) {
56 my $lockfile = $config{lockfile};
58 # don't delete lockfile in END block ;-)
59 $config{lockfile} = '';
62 die UVmessage::get("ERR_LOCK", (FILE=>$lockfile)) . "\n\n";
65 # safe exit (delete lockfile)
66 $SIG{QUIT} = 'sighandler';
67 $SIG{INT} = 'sighandler';
68 $SIG{KILL} = 'sighandler';
69 $SIG{TERM} = 'sighandler';
70 $SIG{HUP} = 'sighandler';
73 open (LOCKFILE, ">$config{lockfile}");
76 # read and process mails
77 # for each mail pass a reference to the sub to be called
80 unless (-d $config{archivedir}) {
81 mkdir ($config{archivedir}, 0700)
82 or die UVmessage::get("ERR_MKDIR", (DIR => $config{archivedir})) . "$!\n\n";
85 # mails are saved in file
86 # normally unixtime is sufficient for a unique file name, else append PID
89 opendir (ARCHIVE, $config{archivedir});
90 my @fertigfiles = readdir (ARCHIVE);
93 # append PID if file name already exists
94 $ext .= "-$$" if (grep (/$ext/, @fertigfiles));
96 my $file = "$config{archivedir}/bounces-" . $ext;
97 UVreadmail::process($file, \&process_bounce, 2); # 2 = POP3
100 foreach my $file (@ARGV) {
101 UVreadmail::process($file, \&process_bounce, 3); # 3 = existing file
105 my $template = UVtemplate->new();
107 foreach my $address (sort keys %bounces) {
108 my $name = $bounces{$address};
111 if ($name eq '***request***') {
113 $text = UVmessage::get ("BOUNCE_BALLOT") . "\n";
115 $text = UVmessage::get ("BOUNCE_ACKMAIL") . "\n";
117 $name = ' ' unless($name);
118 $template->addListItem('bounces', name=>$name, mail=>$address, bouncetext=>$text);
121 print $template->processTemplate($config{'tpl_bouncelist'});
125 ##############################################################################
126 # Evaluate a bounce #
127 # This sub is called from UVreadmail::process() for every mail #
128 # Parameters: voter address and name, date header (strings) #
129 # complete header and body (references to strings) #
130 ##############################################################################
133 # last element of @_ is the body, other stuff not needed here
135 my ($address, $name);
137 # search body for voter name and address
138 if ($$body =~ /$config{addresstext}\s+(\S+@\S+)/) {
140 if ($$body =~ /$config{nametext2}\s+(.*)$/m) {
142 $bounces{$address} = $name;
143 } elsif ($$body =~ /$config{nametext}/) {
144 # Text from this config option does only appear in ballots,
145 # not in acknowledge mails. So this has to be a bounced ballot request
146 $bounces{$address} = '***request***';
148 $bounces{$address} = '';
156 unlink $config{lockfile} if ($config{lockfile});
161 die "\n\nSIG$sig: deleting lockfile and exiting\n\n";
165 ##############################################################################
166 # Print help text (options and syntax) on -h or --help #
167 ##############################################################################
171 Usage: uvbounce.pl [-c config_file] [-f] DATEI1 [DATEI2 [...]]
174 Liest Bounces aus den uebergebenen Dateien oder aus einer POP3-Mailbox ein
175 (Verhalten haengt von usevote.cfg ab) und generiert eine Liste von
176 unzustellbaren Adressen, die an den 2. CfV oder das Result angehaengt
177 werden kann. Falls POP3 in usevote.cfg eingeschaltet und die Option -f
178 (siehe unten) nicht benutzt wurde, werden die uebergebenen Dateinamen
181 -c config_file liest die Konfiguration aus config_file
182 (usevote.cfg falls nicht angegeben)
184 -f, --file liest die Bounces aus den uebergebenen Dateien, auch
185 wenn in der Konfigurationsdatei POP3 eingeschaltet ist.
186 Diese Option wird benoetigt, falls zwar die Stimmzettel
187 per POP3 eingelesen werden sollen, nicht aber die Bounces.
189 -h, --help zeigt diesen Hilfetext an