diff options
author | Niko Tyni <ntyni@debian.org> | 2016-04-28 18:50:17 +0300 |
---|---|---|
committer | Aaron Crane <arc@cpan.org> | 2016-05-16 13:31:39 +0100 |
commit | bd18aea6d95681e1bd5c2cdfd894bd3706e4b819 (patch) | |
tree | 8c85c8d5c80f6641f2a38787b44f6faf4faa3bb3 /utils | |
parent | a3b4b767538d6cb0592a1428349ec55e219b81b3 (diff) | |
download | perl-bd18aea6d95681e1bd5c2cdfd894bd3706e4b819.tar.gz |
perlbug: Refactor duplicated file reading code
_send_message_mailsend() needs to build the message itself rather than
calling build_complete_message() like the other backends, but they can
still share the file reading code, and so can the 'display report' part.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/perlbug.PL | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/utils/perlbug.PL b/utils/perlbug.PL index f5f88f9faf..95e34fe051 100644 --- a/utils/perlbug.PL +++ b/utils/perlbug.PL @@ -835,10 +835,7 @@ EOF if ( SaveMessage() ) { exit } } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow # Display the message - open(REP, '<:raw', $filename) or die "Couldn't open file '$filename': $!\n"; - binmode(REP, ':raw :crlf') if $Is_MSWin32; - while (<REP>) { print $_ } - close(REP) or die "Error closing report file '$filename': $!"; + print _read_report($filename); if ($have_attachment) { print "\n\n---\nAttachment(s):\n"; for my $att (split /\s*,\s*/, $attachments) { print " $att\n"; } @@ -1082,13 +1079,20 @@ ATTACHMENT return $attach; } +sub _read_report { + my $fname = shift; + my $content; + open( REP, "<:raw", $fname ) or die "Couldn't open file '$fname': $!\n"; + binmode(REP, ':raw :crlf') if $Is_MSWin32; + while (<REP>) { $content .= $_; } + close(REP) or die "Error closing report file '$fname': $!"; + return $content; +} + sub build_complete_message { my $content = _build_header(%{_message_headers()}) . "\n\n"; $content .= _add_body_start() if $have_attachment; - open( REP, "<:raw", $filename ) or die "Couldn't open file '$filename': $!\n"; - binmode(REP, ':raw :crlf') if $Is_MSWin32; - while (<REP>) { $content .= $_; } - close(REP) or die "Error closing report file '$filename': $!"; + $content .= _read_report($filename); $content .= _add_attachments() if $have_attachment; return $content; } @@ -1139,10 +1143,7 @@ sub _send_message_mailsend { $fh = $msg->open; binmode($fh, ':raw'); print $fh _add_body_start() if $have_attachment; - open(REP, "<:raw", $filename) or die "Couldn't open '$filename': $!\n"; - binmode(REP, ':raw :crlf') if $Is_MSWin32; - while (<REP>) { print $fh $_ } - close(REP) or die "Error closing $filename: $!"; + print $fh _read_report($filename); print $fh _add_attachments() if $have_attachment; $fh->close or die "Error sending mail: $!"; |