Permalink
Browse files

convert mail-sending to use Email::Sender

this means (a) we can use Email::MIME, so later ::Kit but for now,
more importantly, it means that (b) we can *test* the mail we send
trivially
  • Loading branch information...
1 parent ad735c0 commit ebc51a564db17cc287ec2df1c73c7c70da70f055 @rjbs rjbs committed Aug 13, 2011
Showing with 63 additions and 20 deletions.
  1. +0 −1 lib/PAUSE.pm
  2. +18 −8 lib/PAUSE/dist.pm
  3. +17 −9 lib/PAUSE/mldistwatch.pm
  4. +0 −1 t/lib/PAUSE/TestPAUSE.pm
  5. +1 −1 t/lib/PAUSE/TestPAUSE/Result.pm
  6. +27 −0 t/mldistwatch.t
View
@@ -81,7 +81,6 @@ $PAUSE::Config ||=
MLROOT => '/home/ftp/pub/PAUSE/authors/id/', # originally module list root
ML_CHOWN_USER => qq{UNSAFE},
ML_CHOWN_GROUP => qq{UNSAFE},
- ML_MAILER => 'sendmail',
ML_MIN_INDEX_LINES => 1_000, # 02packages must be this long
ML_MIN_FILES => 20_000, # must be this many files to run mldistwatch
MOD_DATA_SOURCE_NAME => "dbi:mysql:mod",
View
@@ -2,6 +2,8 @@ use strict;
use warnings;
package PAUSE::dist;
use vars qw(%CHECKSUMDONE $AUTOLOAD $YAML_MODULE);
+
+use Email::Sender::Simple qw(sendmail);
use File::Copy ();
use List::MoreUtils ();
use PAUSE::mldistwatch::Constants;
@@ -502,15 +504,23 @@ sub mail_summary {
if ($status_over_all ne "OK") {
$failed = "Failed: ";
}
- my($msg) = Mail::Send
- ->new(
- To => $to,
- Subject => $failed."PAUSE indexer report $substrdistro",
+
+ my $email = Email::MIME->create(
+ header_str => [
+ To => $to,
+ Subject => $failed."PAUSE indexer report $substrdistro",
+ From => "PAUSE <$PAUSE::Config->{UPLOAD}>",
+ ],
+ attributes => {
+ charset => 'utf-8',
+ content_type => 'text/plain',
+ encoding => 'quoted-printable',
+ },
+ body_str => join( ($, // q{}) , @m),
);
- $msg->add("From", "PAUSE <$PAUSE::Config->{UPLOAD}>");
- my $fh = $msg->open($PAUSE::Config->{ML_MAILER});
- print $fh @m;
- $fh->close;
+
+ sendmail($email);
+
$self->verbose(1,"Sent \"indexer report\" mail about $substrdistro\n");
}
}
View
@@ -13,6 +13,8 @@ use Data::Dumper ();
use DirHandle ();
use Dumpvalue ();
use DynaLoader ();
+use Email::MIME;
+use Email::Sender::Simple qw(sendmail);
use Exporter ();
use ExtUtils::MakeMaker ();
use ExtUtils::Manifest;
@@ -27,7 +29,6 @@ use IPC::Cmd ();
use JSON ();
use List::Util ();
use List::MoreUtils ();
-use Mail::Send ();
use PAUSE ();
use PAUSE::dist ();
use PAUSE::pmfile ();
@@ -471,14 +472,21 @@ sub checkfornew {
if ($PAUSE::Config->{TESTHOST} || $self->{OPT}{testhost}) {
} else {
our $Id;
- my($msg) = Mail::Send->new(
- To => $PAUSE::Config->{ADMIN},
- Subject => "Upload Permission or Version mismatch"
- );
- $msg->add("From", "PAUSE <$PAUSE::Config->{UPLOAD}>");
- my $fh = $msg->open($PAUSE::Config->{ML_MAILER});
- print $fh "Not indexed.\n\t$Id\n\n", $alert;
- $fh->close;
+ my $email = Email::MIME->create(
+ header_str => [
+ To => $PAUSE::Config->{ADMIN},
+ Subject => "Upload Permission or Version mismatch",
+ From => "PAUSE <$PAUSE::Config->{UPLOAD}>",
+ ],
+ attributes => {
+ charset => 'utf-8',
+ content_type => 'text/plain',
+ encoding => 'quoted-printable',
+ },
+ body_str => join(qq{\n\n}, "Not indexed.\n\t$Id", $alert),
+ );
+
+ sendmail($email);
}
}
}
View
@@ -61,7 +61,6 @@ sub test_reindex {
MLROOT => File::Spec->catdir($ml_root),
ML_CHOWN_GROUP => +(getgrgid($)))[0],
ML_CHOWN_USER => +(getpwuid($>))[0],
- ML_MAILER => 'testfile',
ML_MIN_FILES => 1,
ML_MIN_INDEX_LINES => 1,
MOD_DATA_SOURCE_NAME => "$dsnbase/mod.sqlite",
@@ -21,7 +21,7 @@ sub tmpdir {
has config_overrides => (
reader => '_config_overrides',
- isa => 'HashRef[Str]',
+ isa => 'HashRef',
required => 1,
);
View
@@ -3,6 +3,9 @@ use warnings;
use lib 't/lib';
+use Email::Sender::Transport::Test;
+$ENV{EMAIL_SENDER_TRANSPORT} = 'Test';
+
use File::Spec;
use PAUSE;
use PAUSE::TestPAUSE;
@@ -51,4 +54,28 @@ subtest "tests with the parsed 02packages data" => sub {
);
};
+# PAUSE indexer report OPRIME/Bug-Gold-9.001.tar.gz
+# PAUSE indexer report OPRIME/XForm-Rollout-1.00.tar.gz
+# PAUSE indexer report XYZZY/Hall-MtKing-0.01.tar.gz
+# PAUSE indexer report XYZZY/Y-2.tar.gz
+
+subtest "tests for the emails we sent out" => sub {
+ my @deliveries = sort {
+ $a->{email}->get_header('Subject') cmp $b->{email}->get_header('Subject')
+ } Email::Sender::Simple->default_transport->deliveries;
+
+ my @subj_want = (
+ 'PAUSE indexer report OPRIME/Bug-Gold-9.001.tar.gz',
+ 'PAUSE indexer report OPRIME/XForm-Rollout-1.00.tar.gz',
+ 'PAUSE indexer report XYZZY/Hall-MtKing-0.01.tar.gz',
+ 'PAUSE indexer report XYZZY/Y-2.tar.gz',
+ );
+
+ is_deeply(
+ [ map {; $_->{email}->get_header('Subject') } @deliveries ],
+ \@subj_want,
+ "we sent mail with the right subjects",
+ );
+};
+
done_testing;

0 comments on commit ebc51a5

Please sign in to comment.