Don't die on error but exit with correct code.
This commit is contained in:
parent
14a1a03ba6
commit
de51152950
1 changed files with 18 additions and 13 deletions
|
|
@ -9,17 +9,20 @@ BEGIN {
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use 5.010;
|
||||
|
||||
#use Mail::DeliveryStatus::BounceParser;
|
||||
#use WebGUI::Mailing::Email;
|
||||
use WebGUI::MailCommand;
|
||||
use List::MoreUtils qw{ any };
|
||||
use WebGUI::Config;
|
||||
use Getopt::Long;
|
||||
use Readonly;
|
||||
|
||||
use 5.010;
|
||||
Readonly my $WRONG_USAGE => 64;
|
||||
Readonly my $DATA_ERROR => 65;
|
||||
Readonly my $NO_SUCH_USER => 67;
|
||||
Readonly my $UNKNOWN_HOST => 68;
|
||||
Readonly my $CONFIG_ERROR => 78;
|
||||
|
||||
my $NO_SUCH_USER = 67;
|
||||
my $webguiRoot = '/data/WebGUI';
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
|
@ -41,7 +44,9 @@ my $webguiRoot = '/data/WebGUI';
|
|||
closeSession( $session );
|
||||
}
|
||||
else {
|
||||
die "Not a valid command [$command].";
|
||||
warn "Not a valid command [$command].";
|
||||
exit( $NO_SUCH_USER );
|
||||
#die "Not a valid command [$command].";
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
|
@ -57,22 +62,22 @@ sub getCredentials {
|
|||
'sender=s' => \$sender,
|
||||
'senderIp=s'=> \$senderIp,
|
||||
);
|
||||
die "--domain parameter is required" unless $domain;
|
||||
die "--user parameter is required" unless $user;
|
||||
die "--sender parameter is required" unless $sender;
|
||||
die "--senderIp parameter is required" unless $senderIp;
|
||||
warn "--domain parameter is required" && exit( $WRONG_USAGE ) unless $domain;
|
||||
warn "--user parameter is required" && exit( $WRONG_USAGE ) unless $user;
|
||||
warn "--sender parameter is required" && exit( $WRONG_USAGE ) unless $sender;
|
||||
warn "--senderIp parameter is required" && exit( $WRONG_USAGE ) unless $senderIp;
|
||||
|
||||
my $dispatch = WebGUI::Config->new( $webguiRoot, 'mailing_dispatch.config' )
|
||||
|| die "Cannot open $webguiRoot/etc/mailing_dispatch.config";
|
||||
|| warn "Cannot open $webguiRoot/etc/mailing_dispatch.config" && exit( $CONFIG_ERROR );
|
||||
|
||||
my $configFile = $dispatch->get( $domain )
|
||||
|| die "Received mail for domain [$domain] which is not configured!";
|
||||
|| warn "Received mail for domain [$domain] which is not configured!" && exit( $UNKNOWN_HOST );
|
||||
|
||||
# Format is mailId-command
|
||||
my ( $id, $command ) = $user =~ m{ ^ (.+) - ([^-]+) $ }ix;
|
||||
|
||||
die "Received mail addressed to [$user\@$domain] which contains no id" unless $id;
|
||||
die "Received mail addressed to [$user\@$domain] which contains no command" unless $command;
|
||||
print "Received mail addressed to [$user\@$domain] which contains no id" && exit( $NO_SUCH_USER ) unless $id;
|
||||
print "Received mail addressed to [$user\@$domain] which contains no command" && exit( $NO_SUCH_USER ) unless $command;
|
||||
|
||||
|
||||
return ( $configFile, $command, $id, $sender, $senderIp );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue