webgui_newsletter/sbin/newsletter-transport.pl
2010-05-20 16:52:19 +02:00

58 lines
1.6 KiB
Perl
Executable file

#!/data/wre/prereqs/bin/perl
BEGIN {
unshift @INC, qw(
/data/custom/webgui_newsletter/lib
/data/WebGUI/lib
);
}
use strict;
use Mail::DeliveryStatus::BounceParser;
use WebGUI::Mailing::Email;
use List::MoreUtils qw{ any };
my $NO_SUCH_USER = 67;
my $webguiRoot = '/data/WebGUI';
my %configs = (
'martintwee.oqapi.nl' => 'martintwee.oqapi.nl.conf',
);
#---------------------------------------------------------------
my ( $domain, $user ) = @ARGV;
my ( $mailId, $command ) = $user =~ m{^(.+)-([^-]+)$}i;
my $configFile = $configs{ $domain };
my $validCommand = any { $command eq $_ } qw{ subscribe unsubscribe bounce confirm };
unless ( $configFile && $validCommand ) {
# system "/usr/sbin/sendmail -G -i $user\@$domain";
exit(0);
}
else {
my $session = WebGUI::Session->open($webguiRoot,$configFile);
my $email = WebGUI::Mailing::Email->new( $session, $session->id->fromHex( $mailId ) );
if ($email) {
my $dsr = Mail::DeliveryStatus::BounceParser->new( \*STDIN );
my $report = ( $dsr->reports )[0];
my $reason = $report->get( 'std_reason' );
my $message = $report->get( 'reason' );
$message =~ s{\s+}{ }g;
$email->registerBounced( $reason, $message );
}
else {
$session->log->error( "Cannot process bounced email because it cannot be located in the db [$mailId]" );
}
$session->close;
exit (0);
}
exit $NO_SUCH_USER unless any { $command eq $_ } qw{ subscribe unsubscribe bounces confirm };