webgui_newsletter/lib/WebGUI/Mailing/Bounce.pm
2010-06-03 12:10:07 +02:00

74 lines
2.1 KiB
Perl

package WebGUI::Mailing::Bounce;
use strict;
use warnings;
use WebGUI::Mailing::Admin;
#----------------------------------------------------------------------------
sub bounceScoreOk {
my $self = shift;
my $address = shift;
my $setting = $self->session->setting;
my $threshold = $setting->get('newsletterBounceScoreThreshold');
return 1 unless $threshold;
return $self->getBounceScore( $address ) < $threshold;
}
#----------------------------------------------------------------------------
sub getBounceScore {
my $self = shift;
my $address = shift;
my $session = $self->session;
my $it = WebGUI::Mailing::Email->getAllIterator( $session, {
constraints => [
{ 'sentTo=?' => [ $address ] },
{ 'status<>?' => [ 'queued' ] },
],
orderBy => 'sendDate desc',
limit => 10,
} );
my $score = 0;
while ( my $email = $it->() ) {
$score += 1 if $email->get('status') eq 'bounced';
}
return $score;
}
#----------------------------------------------------------------------------
sub new {
my $class = shift;
my $session = shift;
bless { _session => $session }, $class;
}
#----------------------------------------------------------------------------
sub session {
return (shift)->{ _session };
}
#----------------------------------------------------------------------------
sub www_bounceReport {
my $self = shift;
my $session = $self->session;
my $i18n = WebGUI::International->new( $session, 'MailingManager' );
my $sth = $session->db->read( 'select distinct sentTo from Mailing_email where sentTo is not null' );
my $output = '<table><tr><th>'.$i18n->get('email').'</th><th>'.$i18n->get('bounce score').'</th></tr>';
while ( my ($email) = $sth->array ) {
my $score = $self->getBounceScore( $email );
$output .= "<tr><td>$email</td><td>$score</td></tr>";
}
$output .= '</table>';
return WebGUI::Mailing::Admin->new( $session )->getAdminConsole->render( $output, $i18n->get( 'bounce scores' ) );
}
1;