Refactoring postfix transport script to allow pluggable commands.
This commit is contained in:
parent
a735068f25
commit
37120bafa8
4 changed files with 184 additions and 35 deletions
40
lib/WebGUI/MailCommand/Bounce.pm
Normal file
40
lib/WebGUI/MailCommand/Bounce.pm
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package WebGUI::MailCommand::Bounce;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use WebGUI::Mailing::Email;
|
||||
use Mail::DeliveryStatus::BounceParser;
|
||||
|
||||
use base 'WebGUI::MailCommand';
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
sub process {
|
||||
my $self = shift;
|
||||
my $hexId = shift;
|
||||
my $session = $self->session;
|
||||
my $log = $session->log;
|
||||
my $id = $session->id->fromHex( $hexId );
|
||||
|
||||
my $email = WebGUI::Mailing::Email->new( $session, $id );
|
||||
|
||||
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;
|
||||
|
||||
$log->warn( "Registering email [$id] as bounced." );
|
||||
$email->registerBounced( $reason, $message );
|
||||
}
|
||||
else {
|
||||
$log->error( "Cannot process bounced email [$id] because it cannot be located in the db." );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
27
lib/WebGUI/MailCommand/Subscribe.pm
Normal file
27
lib/WebGUI/MailCommand/Subscribe.pm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package WebGUI::MailCommand::Subscribe;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use WebGUI::AssetAspect::Subscriber;
|
||||
|
||||
use base 'WebGUI::MailCommand';
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
sub process {
|
||||
my $self = shift;
|
||||
my $listName= shift;
|
||||
my $session = $self->session;
|
||||
my $log = $session->log;
|
||||
|
||||
my $asset = WebGUI::AssetAspect::Subscriber::findAssetByListName( $session, $listName );
|
||||
|
||||
die "Invalid list name [$listName]" unless $asset;
|
||||
|
||||
$asset->subscribeThroughEmail( $fromAddress );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue