Skip to content

Commit

Permalink
indexer: in one place, use proper email header formatting
Browse files Browse the repository at this point in the history
This is a test run for things to come.  In most places, we only use the
user email address, not their name.  But in some places, most especially
in paused, we use their name.

There were two problems there:

1. we were using the ASCII name, which we really don't need to do
2. we were not escaping any quotes (or anything else) in the name field,
   which could cause problems if someone puts a double quote in their
   fullname

It wasn't trivial to test and fix those locations because we don't
(yet!) have any tests for paused.  This introduces the use of fullname
to mldistwatch, using the new form: get the PAUSE::MailAddress for the
user, then use its ->email_object method to create a
Email::MIME::Header::AddressList.  We'll switch all the mailing to use
this, soon.
  • Loading branch information
rjbs committed Apr 30, 2024
1 parent ffc5a3a commit 7ba8f86
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/PAUSE/dist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use warnings;
package PAUSE::dist;
use vars qw(%CHECKSUMDONE $AUTOLOAD);

use Email::Address::XS;
use Email::MIME::Header::AddressList;
use Email::Sender::Simple qw(sendmail);
use File::Copy ();
use List::MoreUtils ();
Expand Down Expand Up @@ -616,15 +618,19 @@ sub mail_summary {
warn "Unsent Report [@m]";
}
} else {
my $to = sprintf "%s, %s", $pma->address, $PAUSE::Config->{ADMIN};
my $to_list = Email::MIME::Header::AddressList->new(
$pma->email_object,
Email::Address::XS->new("PAUSE Admin", $PAUSE::Config->{ADMIN}),
);

my $failed = "";
if ($status_over_all ne "OK") {
$failed = "Failed: ";
}

my $email = Email::MIME->create(
header_str => [
To => $to,
To => $to_list,
Subject => $failed."PAUSE indexer report $substrdistro",
From => "PAUSE <$PAUSE::Config->{UPLOAD}>",
],
Expand Down
32 changes: 32 additions & 0 deletions t/mldistwatch-misc.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use strict;
use warnings;

use utf8;

use 5.10.1;
use lib 't/lib';
use lib 't/privatelib'; # Stub PrivatePAUSE
Expand Down Expand Up @@ -581,6 +583,36 @@ subtest "do not index dists without META file" => sub {
);
};

subtest "quotes in username" => sub {
my $pause = PAUSE::TestPAUSE->init_new;

my $initial_result = $pause->test_reindex;

my $dbh = $initial_result->connect_mod_db;

$dbh->do(
"INSERT INTO users (userid, email, fullname, asciiname)
VALUES (?, ?, ?, ?)",
undef,
'PERSON', '[email protected]', q{R★S"'<xmp>}, q{R*S"'<xmp>},
);

$pause->upload_author_fake(PERSON => 'Not-Very-Meta-1.234.tar.gz', {
omitted_files => [ qw( META.yml META.json ) ],
});

my $result = $pause->test_reindex;

my ($to) = ($result->deliveries)[0]->{email}->object->header_as_obj('To');
my @addresses = $to->addresses;

is($addresses[0]->address, q{[email protected]}, "first address is right");
is($addresses[0]->phrase, q{R★S"'<xmp>}, "first name is right");

is($addresses[1]->address, q{[email protected]}, "second address is right");
is($addresses[1]->phrase, q{PAUSE Admin}, "second name is right");
};

done_testing;

# Local Variables:
Expand Down

0 comments on commit 7ba8f86

Please sign in to comment.