Double magic with '\&$x'
[p5sagit/p5-mst-13.2.git] / utils / perlbug.PL
index 97f8d86..49792f1 100644 (file)
@@ -30,22 +30,26 @@ open PATCH_LEVEL, "<" . catfile(updir, "patchlevel.h")
 my $patchlevel_date = (stat PATCH_LEVEL)[9];
 
 while (<PATCH_LEVEL>) {
-    last if $_ =~ /^\s*static\s+char.*?local_patches\[\]\s*=\s*{\s*$/;
+    last if $_ =~ /^\s*static\s+(?:const\s+)?char.*?local_patches\[\]\s*=\s*{\s*$/;
+}
+
+if (! defined($_)) {
+    warn "Warning: local_patches section not found in patchlevel.h\n";
 }
 
 my @patches;
 while (<PATCH_LEVEL>) {
     last if /^\s*}/;
     chomp;
-    s/^\s+,?"?//;
-    s/"?,?$//;
+    s/^\s+,?\s*"?//;
+    s/"?\s*,?$//;
     s/(['\\])/\\$1/g;
     push @patches, $_ unless $_ eq 'NULL';
 }
 my $patch_desc = "'" . join("',\n    '", @patches) . "'";
 my $patch_tags = join "", map /(\S+)/ ? "+$1 " : (), @patches;
 
-close PATCH_LEVEL;
+close(PATCH_LEVEL) or die "Error closing patchlevel.h: $!";
 
 # TO DO (prehaps): store/embed $Config::config_sh into perlbug. When perlbug is
 # used, compare $Config::config_sh with the stored version. If they differ then
@@ -57,7 +61,7 @@ print "Extracting $file (with variable substitutions)\n";
 # In this section, perl variables will be expanded during extraction.
 # You can use $Config{...} to use Configure variables.
 
-my $extract_version = sprintf("v%v", $^V);
+my $extract_version = sprintf("%vd", $^V);
 
 print OUT <<"!GROK!THIS!";
 $Config{startperl}
@@ -77,10 +81,11 @@ my \@patches = (
 
 print OUT <<'!NO!SUBS!';
 
+use strict;
 use Config;
 use File::Spec;                # keep perlbug Perl 5.005 compatible
 use Getopt::Std;
-use strict;
+use File::Basename 'basename';
 
 sub paraprint;
 
@@ -89,9 +94,14 @@ BEGIN {
     $::HaveSend = ($@ eq "");
     eval "use Mail::Util;";
     $::HaveUtil = ($@ eq "");
+    # use secure tempfiles wherever possible
+    eval "require File::Temp;";
+    $::HaveTemp = ($@ eq "");
+    eval { require Module::CoreList; };
+    $::HaveCoreList = ($@ eq "");
 };
 
-my $Version = "1.27";
+my $Version = "1.36";
 
 # Changed in 1.06 to skip Mail::Send and Mail::Util if not available.
 # Changed in 1.07 to see more sendmail execs, and added pipe output.
@@ -123,17 +133,27 @@ my $Version = "1.27";
 # Changed in 1.25 Warn on failure to open save file. HVDS 98-07-12
 # Changed in 1.26 Don't require -t STDIN for -ok. HVDS 98-07-15
 # Changed in 1.27 Added Mac OS and File::Spec support CNANDOR 99-07-27
+# Changed in 1.28 Additional questions for Perlbugtron RFOLEY 20.03.2000
+# Changed in 1.29 Perlbug(tron): auto(-ok), short prompts RFOLEY 05-05-2000
+# Changed in 1.30 Added warnings on failure to open files MSTEVENS 13-07-2000
+# Changed in 1.31 Add checks on close().Fix my $var unless. TJENNESS 26-07-2000
+# Changed in 1.32 Use File::Spec->tmpdir TJENNESS 20-08-2000
+# Changed in 1.33 Don't require -t STDOUT for -ok.
+# Changed in 1.34 Added Message-Id RFOLEY 18-06-2002 
+# Changed in 1.35 Use File::Temp (patch from Solar Designer) NWCLARK 28-02-2004
+# Changed in 1.36 Initial Module::CoreList support Alexandr Ciornii 11-07-2007
 
 # TODO: - Allow the user to re-name the file on mail failure, and
 #       make sure failure (transmission-wise) of Mail::Send is
 #       accounted for.
 #       - Test -b option
 
-my( $file, $usefile, $cc, $address, $perlbug, $testaddress, $filename,
-    $subject, $from, $verbose, $ed, $outfile, $Is_MacOS,
-    $fh, $me, $Is_MSWin32, $Is_VMS, $msg, $body, $andcc, %REP, $ok);
+my( $file, $usefile, $cc, $address, $bugaddress, $testaddress, $thanksaddress,
+    $filename, $messageid, $domain, $subject, $from, $verbose, $ed, $outfile,
+    $Is_MacOS, $category, $severity, $fh, $me, $Is_MSWin32, $Is_Linux, $Is_VMS,
+    $msg, $body, $andcc, %REP, $ok, $thanks, $Is_OpenBSD, $progname);
 
-my $perl_version = $^V ? sprintf("v%v", $^V) : $];
+my $perl_version = $^V ? sprintf("%vd", $^V) : $];
 
 my $config_tag2 = "$perl_version - $Config{cf_time}";
 
@@ -142,13 +162,12 @@ Init();
 if ($::opt_h) { Help(); exit; }
 if ($::opt_d) { Dump(*STDOUT); exit; }
 if (!-t STDIN && !($ok and not $::opt_n)) {
-    paraprint <<EOF;
-Please use perlbug interactively. If you want to
+    paraprint <<"EOF";
+Please use $progname interactively. If you want to
 include a file, you can use the -f switch.
 EOF
     die "\n";
 }
-if (!-t STDOUT && !$outfile) { Dump(*STDOUT); exit; }
 
 Query();
 Edit() unless $usefile || ($ok and not $::opt_n);
@@ -157,18 +176,66 @@ Send();
 
 exit;
 
+sub ask_for_alternatives { # (category|severity)
+    my $name = shift;
+    my %alts = (
+       'category' => {
+           'default' => 'core',
+           'ok'      => 'install',
+           # Inevitably some of these will end up in RT whatever we do:
+           'thanks'  => 'thanks',
+           'opts'    => [qw(core docs install library utilities)], # patch, notabug
+       },
+       'severity' => {
+           'default' => 'low',
+           'ok'      => 'none',
+           'thanks'  => 'none',
+           'opts'    => [qw(critical high medium low wishlist none)], # zero
+       },
+    );
+    die "Invalid alternative($name) requested\n" unless grep(/^$name$/, keys %alts);
+    my $alt = "";
+    my $what = $ok || $thanks;
+    if ($what) {
+       $alt = $alts{$name}{$what};
+    } else {
+       my @alts = @{$alts{$name}{'opts'}};
+       paraprint <<EOF;
+Please pick a \u$name from the following:
+
+    @alts
+
+EOF
+       my $err = 0;
+       do {
+           if ($err++ > 5) {
+               die "Invalid $name: aborting.\n";
+           }
+           print "Please enter a \u$name [$alts{$name}{'default'}]: ";
+           $alt = <>;
+           chomp $alt;
+           if ($alt =~ /^\s*$/) {
+               $alt = $alts{$name}{'default'};
+           }
+       } while !((($alt) = grep(/^$alt/i, @alts)));
+    }
+    lc $alt;
+}
+
 sub Init {
     # -------- Setup --------
 
     $Is_MSWin32 = $^O eq 'MSWin32';
     $Is_VMS = $^O eq 'VMS';
+    $Is_Linux = lc($^O) eq 'linux';
+    $Is_OpenBSD = lc($^O) eq 'openbsd';
     $Is_MacOS = $^O eq 'MacOS';
 
     @ARGV = split m/\s+/,
         MacPerl::Ask('Provide command-line args here (-h for help):')
         if $Is_MacOS && $MacPerl::Version =~ /App/;
 
-    if (!getopts("dhva:s:b:f:F:r:e:SCc:to:n:")) { Help(); exit; };
+    if (!getopts("Adhva:s:b:f:F:r:e:SCc:to:n:T")) { Help(); exit; };
 
     # This comment is needed to notify metaconfig that we are
     # using the $perladmin, $cf_by, and $cf_time definitions.
@@ -176,13 +243,28 @@ sub Init {
     # -------- Configuration ---------
 
     # perlbug address
-    $perlbug = 'perlbug@perl.com';
+    $bugaddress = 'perlbug@perl.org';
 
     # Test address
-    $testaddress = 'perlbug-test@perl.com';
+    $testaddress = 'perlbug-test@perl.org';
+
+    # Thanks address
+    $thanksaddress = 'perl-thanks@perl.org';
 
+    if (basename ($0) =~ /^perlthanks/i) {
+       # invoked as perlthanks
+       $::opt_T = 1;
+       $::opt_C = 1; # don't send a copy to the local admin
+    }
+
+    if ($::opt_T) {
+       $thanks = 'thanks';
+    }
+    
+    $progname = $thanks ? 'perlthanks' : 'perlbug';
     # Target address
-    $address = $::opt_a || ($::opt_t ? $testaddress : $perlbug);
+    $address = $::opt_a || ($::opt_t ? $testaddress
+                           : $thanks ? $thanksaddress : $bugaddress);
 
     # Users address, used in message and in Reply-To header
     $from = $::opt_r || "";
@@ -204,7 +286,7 @@ sub Init {
 
     # Body of report
     $body = $::opt_b || "";
-
+       
     # Editor
     $ed = $::opt_e || $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
        || ($Is_VMS && "edit/tpu")
@@ -223,7 +305,7 @@ sub Init {
     }
 
     # OK - send "OK" report for build on this system
-    $ok = 0;
+    $ok = '';
     if ($::opt_o) {
        if ($::opt_o eq 'k' or $::opt_o eq 'kay') {
            my $age = time - $patchlevel_date;
@@ -248,7 +330,7 @@ EOF
            $subject = ($::opt_n ? 'Not ' : '')
                    . "OK: perl $perl_version ${patch_tags}on"
                    ." $::Config{'archname'} $::Config{'osvers'} $subject";
-           $ok = 1;
+           $ok = 'ok';
        } else {
            Help();
            exit();
@@ -266,6 +348,18 @@ EOF
        || $::Config{'cf_email'} || $::Config{'cf_by'}
     );
 
+    if ($::HaveUtil) {
+               $domain = Mail::Util::maildomain();
+    } elsif ($Is_MSWin32) {
+               $domain = $ENV{'USERDOMAIN'};
+    } else {
+               require Sys::Hostname;
+               $domain = Sys::Hostname::hostname();
+    }
+
+    # Message-Id - rjsf
+    $messageid = "<$::Config{'version'}_${$}_".time."\@$domain>"; 
+
     # My username
     $me = $Is_MSWin32 ? $ENV{'USERNAME'}
            : $^O eq 'os2' ? $ENV{'USER'} || $ENV{'LOGNAME'}
@@ -280,7 +374,16 @@ EOF
 sub Query {
     # Explain what perlbug is
     unless ($ok) {
-       paraprint <<EOF;
+       if ($thanks) {
+           paraprint <<'EOF';
+This program provides an easy way to send a thank-you message back to the
+authors and maintainers of perl.
+
+If you wish to submit a bug report, please run it without the -T flag
+(or run the program perlbug rather than perlthanks)
+EOF
+       } else {
+           paraprint <<"EOF";
 This program provides an easy way to create a message reporting a bug
 in perl, and e-mail it to $address.  It is *NOT* intended for
 sending test messages or simply verifying that perl works, *NOR* is it
@@ -291,29 +394,44 @@ and any solutions to such problems, to the people who maintain perl.
 If you're just looking for help with perl, try posting to the Usenet
 newsgroup comp.lang.perl.misc.  If you're looking for help with using
 perl with CGI, try posting to comp.infosystems.www.programming.cgi.
+
+When invoked as perlthanks (or with the -T option) it can be used to
+send a thank-you message to $thanksaddress.
 EOF
+       }
     }
 
     # Prompt for subject of message, if needed
+    
+    if (TrivialSubject($subject)) {
+       $subject = '';
+    }
+
     unless ($subject) {
-       paraprint <<EOF;
+       if ($thanks) {
+           paraprint "First of all, please provide a subject for the message.\n";
+       } else {
+           paraprint <<EOF;
 First of all, please provide a subject for the
 message. It should be a concise description of
 the bug or problem. "perl bug" or "perl problem"
 is not a concise description.
 EOF
-       print "Subject: ";
-       $subject = <>;
+       }
 
        my $err = 0;
-       while ($subject !~ /\S/) {
-           print "\nPlease enter a subject: ";
+       do {
+           print "Subject: ";
            $subject = <>;
-           if ($err++ > 5) {
-               die "Aborting.\n";
+           chomp $subject;
+           if ($err++ == 5) {
+               if ($thanks) {
+                   $subject = 'Thanks for Perl';
+               } else {
+                   die "Aborting.\n";
+               }
            }
-       }
-       chop $subject;
+       } while (TrivialSubject($subject));
     }
 
     # Prompt for return address, if needed
@@ -330,16 +448,8 @@ EOF
         }
 
        unless ($guess) {
-           my $domain;
-           if ($::HaveUtil) {
-               $domain = Mail::Util::maildomain();
-           } elsif ($Is_MSWin32) {
-               $domain = $ENV{'USERDOMAIN'};
-           } else {
-               require Sys::Hostname;
-               $domain = Sys::Hostname::hostname();
-           }
-           if ($domain) {
+               # move $domain to where we can use it elsewhere 
+        if ($domain) {
                if ($Is_VMS && !$::Config{'d_socket'}) {
                    $guess = "$domain\:\:$me";
                } else {
@@ -369,7 +479,7 @@ EOF
            # verify it
            print "Your address [$guess]: ";
            $from = <>;
-           chop $from;
+           chomp $from;
            $from = $guess if $from eq '';
        }
     }
@@ -389,7 +499,7 @@ a copy.
 EOF
        print "Local perl administrator [$cc]: ";
        my $entry = scalar <>;
-       chop $entry;
+       chomp $entry;
 
        if ($entry ne "") {
            $cc = $entry;
@@ -403,7 +513,30 @@ EOF
     # Prompt for editor, if no override is given
 editor:
     unless ($::opt_e || $::opt_f || $::opt_b) {
-       paraprint <<EOF;
+       chomp (my $common_end = <<"EOF");
+
+You will probably want to use an editor to enter
+the report. If "$ed" is the editor you want
+to use, then just press Enter, otherwise type in
+the name of the editor you would like to use.
+
+If you would like to use a prepared file, type
+"file", and you will be asked for the filename.
+EOF
+
+       if ($thanks) {
+           paraprint <<"EOF";
+Now you need to supply your thank-you message.
+
+Some information about your local perl configuration
+will automatically be included at the end of the message,
+because we're curious about the different ways that people
+build perl, but you're welcome to delete it if you wish.
+
+$common_end
+EOF
+       } else {
+           paraprint <<"EOF";
 Now you need to supply the bug report. Try to make
 the report concise but descriptive. Include any
 relevant detail. If you are reporting something
@@ -417,17 +550,13 @@ at the end of the report. If you are using any
 unusual version of perl, please try and confirm
 exactly which versions are relevant.
 
-You will probably want to use an editor to enter
-the report. If "$ed" is the editor you want
-to use, then just press Enter, otherwise type in
-the name of the editor you would like to use.
-
-If you would like to use a prepared file, type
-"file", and you will be asked for the filename.
+$common_end
 EOF
+       }
+
        print "Editor [$ed]: ";
        my $entry =scalar <>;
-       chop $entry;
+       chomp $entry;
 
        $usefile = 0;
        if ($entry eq "file") {
@@ -436,6 +565,35 @@ EOF
            $ed = $entry;
        }
     }
+    my $report_about_module = '';
+    if ($::HaveCoreList && !$ok && !$thanks) {
+       paraprint <<EOF;
+Is your report about a Perl module? If yes, enter its name. If not, skip.
+EOF
+       print "Module []: ";
+       my $entry = scalar <>;
+       $entry =~ s/^\s+//s;
+       $entry =~ s/\s+$//s;
+       if ($entry ne q{}) {
+           $category ||= 'library';
+           $report_about_module = $entry;
+           my $first_release = Module::CoreList->first_release($entry);
+           unless ($first_release) {
+               paraprint <<EOF;
+Module $entry is not a core module. Please check that
+you entered its name correctly. If it is correct,
+abort this program, try searching for $entry on
+search.cpan.org, and report it there.
+EOF
+           }
+       }
+    }
+
+    # Prompt for category of bug
+    $category ||= ask_for_alternatives('category');
+
+    # Prompt for severity of bug
+    $severity ||= ask_for_alternatives('severity');
 
     # Generate scratch file to edit report in
     $filename = filename();
@@ -448,7 +606,7 @@ What is the name of the file that contains your report?
 EOF
        print "Filename: ";
        my $entry = scalar <>;
-       chop $entry;
+       chomp $entry;
 
        if ($entry eq "") {
            paraprint <<EOF;
@@ -459,7 +617,7 @@ EOF
 
        unless (-f $entry and -r $entry) {
            paraprint <<EOF;
-I'm sorry, but I can't read from `$entry'. Maybe you mistyped the name of
+I'm sorry, but I can't read from '$entry'. Maybe you mistyped the name of
 the file? If you don't want to send a file, just enter a blank line and you
 can get back to the editor selection.
 EOF
@@ -469,8 +627,9 @@ EOF
     }
 
     # Generate report
-    open(REP,">$filename");
-    my $reptype = !$ok ? "bug" : $::opt_n ? "build failure" : "success";
+    open(REP,">$filename") or die "Unable to create report file '$filename': $!\n";
+    my $reptype = !$ok ? ($thanks ? 'thank-you' : 'bug')
+       : $::opt_n ? "build failure" : "success";
 
     print REP <<EOF;
 This is a $reptype report for perl from $from,
@@ -482,13 +641,25 @@ EOF
        print REP $body;
     } elsif ($usefile) {
        open(F, "<$file")
-               or die "Unable to read report file from `$file': $!\n";
+               or die "Unable to read report file from '$file': $!\n";
        while (<F>) {
            print REP $_
        }
-       close(F);
+       close(F) or die "Error closing '$file': $!";
     } else {
-       print REP <<EOF;
+       if ($thanks) {
+           print REP <<'EOF';
+
+-----------------------------------------------------------------
+[Please enter your thank you message here]
+
+
+
+[You're welcome to delete anything below this line if you prefer]
+-----------------------------------------------------------------
+EOF
+       } else {
+           print REP <<'EOF';
 
 -----------------------------------------------------------------
 [Please enter your report here]
@@ -498,26 +669,40 @@ EOF
 [Please do not change anything below this line]
 -----------------------------------------------------------------
 EOF
+       }
     }
     Dump(*REP);
-    close(REP);
+    close(REP) or die "Error closing report file: $!";
 
     # read in the report template once so that
     # we can track whether the user does any editing.
     # yes, *all* whitespace is ignored.
-    open(REP, "<$filename");
+    open(REP, "<$filename") or die "Unable to open report file '$filename': $!\n";
     while (<REP>) {
        s/\s+//g;
        $REP{$_}++;
     }
-    close(REP);
+    close(REP) or die "Error closing report file '$filename': $!";
 } # sub Query
 
 sub Dump {
     local(*OUT) = @_;
 
-    print REP "\n---\n";
-    print REP "This perlbug was built using Perl $config_tag1\n",
+    print OUT <<EFF;
+---
+Flags:
+    category=$category
+    severity=$severity
+EFF
+    if ($::opt_A) {
+       print OUT <<EFF;
+    ack=no
+EFF
+    }
+    print OUT <<EFF;
+---
+EFF
+    print OUT "This perlbug was built using Perl $config_tag1\n",
            "It is being executed now by  Perl $config_tag2.\n\n"
        if $config_tag2 ne $config_tag1;
 
@@ -552,7 +737,7 @@ EOF
     my @env =
         qw(PATH LD_LIBRARY_PATH LANG PERL_BADLANG SHELL HOME LOGDIR LANGUAGE);
     push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
-    push @env, grep /^(?:PERL|LC_|LANG)/, keys %ENV;
+    push @env, grep /^(?:PERL|LC_|LANG|CYGWIN)/, keys %ENV;
     my %env;
     @env{@env} = @env;
     for my $env (sort keys %env) {
@@ -579,12 +764,13 @@ Please make sure that the name of the editor you want to use is correct.
 EOF
        print "Editor [$ed]: ";
        my $entry =scalar <>;
-       chop $entry;
+       chomp $entry;
        $ed = $entry unless $entry eq '';
     }
 
 tryagain:
-    my $sts = system("$ed $filename") unless $Is_MacOS;
+    my $sts;
+    $sts = system("$ed $filename") unless $Is_MacOS;
     if ($Is_MacOS) {
         require ExtUtils::MakeMaker;
         ExtUtils::MM_MacOS::launch_file($filename);
@@ -595,13 +781,13 @@ EOF
     }
     if ($sts) {
        paraprint <<EOF;
-The editor you chose (`$ed') could apparently not be run!
+The editor you chose ('$ed') could apparently not be run!
 Did you mistype the name of your editor? If so, please
 correct it here, otherwise just press Enter.
 EOF
        print "Editor [$ed]: ";
        my $entry =scalar <>;
-       chop $entry;
+       chomp $entry;
 
        if ($entry ne "") {
            $ed = $entry;
@@ -618,7 +804,7 @@ EOF
     # Check that we have a report that has some, eh, report in it.
     my $unseen = 0;
 
-    open(REP, "<$filename");
+    open(REP, "<$filename") or die "Couldn't open '$filename': $!\n";
     # a strange way to check whether any significant editing
     # have been done: check whether any new non-empty lines
     # have been added. Yes, the below code ignores *any* space
@@ -655,46 +841,62 @@ sub NowWhat {
            paraprint <<EOF;
 Now that you have completed your report, would you like to send
 the message to $address$andcc, display the message on
-the screen, re-edit it, or cancel without sending anything?
+the screen, re-edit it, display/change the subject,
+or cancel without sending anything?
 You may also save the message as a file to mail at another time.
 EOF
       retry:
-           print "Action (Send/Display/Edit/Cancel/Save to File): ";
+           print "Action (Send/Display/Edit/Subject/Save to File): ";
            my $action = scalar <>;
-           chop $action;
+           chomp $action;
 
            if ($action =~ /^(f|sa)/i) { # <F>ile/<Sa>ve
-               print "\n\nName of file to save message in [perlbug.rep]: ";
+               my $file_save = $outfile || "$progname.rep";
+               print "\n\nName of file to save message in [$file_save]: ";
                my $file = scalar <>;
-               chop $file;
-               $file = "perlbug.rep" if $file eq "";
+               chomp $file;
+               $file = $file_save if $file eq "";
 
                unless (open(FILE, ">$file")) {
                    print "\nError opening $file: $!\n\n";
                    goto retry;
                }
-               open(REP, "<$filename");
+               open(REP, "<$filename") or die "Couldn't open file '$filename': $!\n";
                print FILE "To: $address\nSubject: $subject\n";
                print FILE "Cc: $cc\n" if $cc;
                print FILE "Reply-To: $from\n" if $from;
+               print FILE "Message-Id: $messageid\n" if $messageid;
                print FILE "\n";
                while (<REP>) { print FILE }
-               close(REP);
-               close(FILE);
+               close(REP) or die "Error closing report file '$filename': $!";
+               close(FILE) or die "Error closing $file: $!";
 
-               print "\nMessage saved in `$file'.\n";
+               print "\nMessage saved in '$file'.\n";
                exit;
            } elsif ($action =~ /^(d|l|sh)/i ) { # <D>isplay, <L>ist, <Sh>ow
                # Display the message
-               open(REP, "<$filename");
+               open(REP, "<$filename") or die "Couldn't open file '$filename': $!\n";
                while (<REP>) { print $_ }
-               close(REP);
+               close(REP) or die "Error closing report file '$filename': $!";
+           } elsif ($action =~ /^su/i) { # <Su>bject
+               print "Subject: $subject\n";
+               print "If the above subject is fine, just press Enter.\n";
+               print "If not, type in the new subject.\n";
+               print "Subject: ";
+               my $reply = scalar <STDIN>;
+               chomp $reply;
+               if ($reply ne '') {
+                   unless (TrivialSubject($reply)) {
+                       $subject = $reply;
+                       print "Subject: $subject\n";
+                   }
+               }
            } elsif ($action =~ /^se/i) { # <S>end
                # Send the message
                print "Are you certain you want to send this message?\n"
                    . 'Please type "yes" if you are: ';
                my $reply = scalar <STDIN>;
-               chop $reply;
+               chomp $reply;
                if ($reply eq "yes") {
                    last;
                } else {
@@ -709,7 +911,7 @@ EOF
                Edit();
            } elsif ($action =~ /^[qc]/i) { # <C>ancel, <Q>uit
                Cancel();
-           } elsif ($action =~ /^s/) {
+           } elsif ($action =~ /^s/i) {
                paraprint <<EOF;
 I'm sorry, but I didn't understand that. Please type "send" or "save".
 EOF
@@ -718,21 +920,38 @@ EOF
     }
 } # sub NowWhat
 
+sub TrivialSubject {
+    my $subject = shift;
+    if ($subject =~
+       /^(y(es)?|no?|help|perl( (bug|problem))?|bug|problem)$/i ||
+       length($subject) < 4 ||
+       $subject !~ /\s/) {
+       print "\nThat doesn't look like a good subject.  Please be more verbose.\n\n";
+        return 1;
+    } else {
+       return 0;
+    }
+}
+
 sub Send {
     # Message has been accepted for transmission -- Send the message
     if ($outfile) {
        open SENDMAIL, ">$outfile" or die "Couldn't open '$outfile': $!\n";
        goto sendout;
     }
-    if ($::HaveSend) {
+
+    # on linux certain mail implementations won't accept the subject
+    # as "~s subject" and thus the Subject header will be corrupted
+    # so don't use Mail::Send to be safe
+    if ($::HaveSend && !$Is_Linux && !$Is_OpenBSD) {
        $msg = new Mail::Send Subject => $subject, To => $address;
        $msg->cc($cc) if $cc;
        $msg->add("Reply-To",$from) if $from;
 
        $fh = $msg->open;
-       open(REP, "<$filename");
+       open(REP, "<$filename") or die "Couldn't open '$filename': $!\n";
        while (<REP>) { print $fh $_ }
-       close(REP);
+       close(REP) or die "Error closing $filename: $!";
        $fh->close;
 
        print "\nMessage sent.\n";
@@ -775,18 +994,19 @@ the perl package Mail::Send has not been installed, so I can't send your bug
 report. We apologize for the inconvenience.
 
 So you may attempt to find some way of sending your message, it has
-been left in the file `$filename'.
+been left in the file '$filename'.
 EOF
-       open(SENDMAIL, "|$sendmail -t") || die "'|$sendmail -t' failed: $!";
+       open(SENDMAIL, "|$sendmail -t -oi") || die "'|$sendmail -t -oi' failed: $!";
 sendout:
        print SENDMAIL "To: $address\n";
        print SENDMAIL "Subject: $subject\n";
        print SENDMAIL "Cc: $cc\n" if $cc;
        print SENDMAIL "Reply-To: $from\n" if $from;
+       print SENDMAIL "Message-Id: $messageid\n" if $messageid;
        print SENDMAIL "\n\n";
-       open(REP, "<$filename");
+       open(REP, "<$filename") or die "Couldn't open '$filename': $!\n";
        while (<REP>) { print SENDMAIL $_ }
-       close(REP);
+       close(REP) or die "Error closing $filename: $!";
 
        if (close(SENDMAIL)) {
            printf "\nMessage %s.\n", $outfile ? "saved" : "sent";
@@ -807,7 +1027,7 @@ be needed.
 Usage:
 $0  [-v] [-a address] [-s subject] [-b body | -f inpufile ] [ -F outputfile ]
     [-r returnaddress] [-e editor] [-c adminaddress | -C] [-S] [-t] [-h]
-$0  [-v] [-r returnaddress] [-ok | -okay | -nok | -nokay]
+$0  [-v] [-r returnaddress] [-A] [-ok | -okay | -nok | -nokay]
 
 Simplest usage:  run "$0", and follow the prompts.
 
@@ -818,8 +1038,8 @@ Options:
         quickly send a prepared message.
   -F    File to output the resulting mail message to, instead of mailing.
   -S    Send without asking for confirmation.
-  -a    Address to send the report to. Defaults to `$address'.
-  -c    Address to send copy of report to. Defaults to `$cc'.
+  -a    Address to send the report to. Defaults to '$address'.
+  -c    Address to send copy of report to. Defaults to '$cc'.
   -C    Don't send copy to administrator.
   -s    Subject to include with the message. You will be prompted
         if you don't supply one on the command line.
@@ -828,10 +1048,11 @@ Options:
   -r    Your return address. The program will ask you to confirm
         this if you don't give it here.
   -e    Editor to use.
-  -t    Test mode. The target address defaults to `$testaddress'.
-  -d    Data mode (the default if you redirect or pipe output.)
-        This prints out your configuration data, without mailing
+  -t    Test mode. The target address defaults to '$testaddress'.
+  -T    Thank-you mode. The target address defaults to '$thanksaddress'.
+  -d    Data mode.  This prints out your configuration data, without mailing
         anything. You can use this with -v to get more complete data.
+  -A    Don't send a bug received acknowledgement to the return address.
   -ok   Report successful build on this system to perl porters
         (use alone or with -v). Only use -ok if *everything* was ok:
         if there were *any* problems at all, use -nok.
@@ -846,14 +1067,18 @@ EOF
 }
 
 sub filename {
-    my $dir = $Is_VMS ? 'sys$scratch:'
-       : ($Is_MSWin32 && $ENV{'TEMP'}) ? $ENV{'TEMP'}
-        : $Is_MacOS ? $ENV{'TMPDIR'}
-       : '/tmp';
-    $filename = "bugrep0$$";
-#    $dir .= "\\" if $Is_MSWin32 and $dir !~ m|[\\/]$|;
-    $filename++ while -e File::Spec->catfile($dir, $filename);
-    $filename = File::Spec->catfile($dir, $filename);
+    if ($::HaveTemp) {
+       # Good. Use a secure temp file
+       my ($fh, $filename) = File::Temp::tempfile(UNLINK => 1);
+       close($fh);
+       return $filename;
+    } else {
+       # Bah. Fall back to doing things less securely.
+       my $dir = File::Spec->tmpdir();
+       $filename = "bugrep0$$";
+       $filename++ while -e File::Spec->catfile($dir, $filename);
+       $filename = File::Spec->catfile($dir, $filename);
+    }
 }
 
 sub paraprint {
@@ -883,10 +1108,10 @@ B<perlbug> S<[ B<-v> ]> S<[ B<-a> I<address> ]> S<[ B<-s> I<subject> ]>
 S<[ B<-b> I<body> | B<-f> I<inputfile> ]> S<[ B<-F> I<outputfile> ]>
 S<[ B<-r> I<returnaddress> ]>
 S<[ B<-e> I<editor> ]> S<[ B<-c> I<adminaddress> | B<-C> ]>
-S<[ B<-S> ]> S<[ B<-t> ]>  S<[ B<-d> ]>  S<[ B<-h> ]>
+S<[ B<-S> ]> S<[ B<-t> ]>  S<[ B<-d> ]>  S<[ B<-A> ]>  S<[ B<-h> ]>
 
 B<perlbug> S<[ B<-v> ]> S<[ B<-r> I<returnaddress> ]>
-S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
+ S<[ B<-A> ]> S<[ B<-ok> | B<-okay> | B<-nok> | B<-nokay> ]>
 
 =head1 DESCRIPTION
 
@@ -904,7 +1129,7 @@ will be needed.  Simply run it, and follow the prompts.
 
 If you are unable to run B<perlbug> (most likely because you don't have
 a working setup to send mail that perlbug recognizes), you may have to
-compose your own report, and email it to B<perlbug@perl.com>.  You might
+compose your own report, and email it to B<perlbug@perl.org>.  You might
 find the B<-d> option useful to get summary information in that case.
 
 In any case, when reporting a bug, please make sure you have run through
@@ -982,7 +1207,7 @@ definitely be fixed.  Use the C<diff> program to generate your patches
 (C<diff> is being maintained by the GNU folks as part of the B<diffutils>
 package, so you should be able to get it from any of the GNU software
 repositories).  If you do submit a patch, the cool-dude counter at
-perlbug@perl.com will register you as a savior of the world.  Your
+perlbug@perl.org will register you as a savior of the world.  Your
 patch may be returned with requests for changes, or requests for more
 detailed explanations about your fix.
 
@@ -1002,7 +1227,7 @@ B<perlbug> will, amongst other things, ensure your report includes
 crucial information about your version of perl.  If C<perlbug> is unable
 to mail your report after you have typed it in, you may have to compose
 the message yourself, add the output produced by C<perlbug -d> and email
-it to B<perlbug@perl.com>.  If, for some reason, you cannot run
+it to B<perlbug@perl.org>.  If, for some reason, you cannot run
 C<perlbug> at all on your system, be sure to include the entire output
 produced by running C<perl -V> (note the uppercase V).
 
@@ -1029,7 +1254,14 @@ version of perl comes out and your bug is still present.
 
 =item B<-a>
 
-Address to send the report to.  Defaults to `perlbug@perl.com'.
+Address to send the report to.  Defaults to B<perlbug@perl.org>.
+
+=item B<-A>
+
+Don't send a bug received acknowledgement to the reply address.
+Generally it is only a sensible to use this option if you are a
+perl maintainer actively watching perl porters for your message to
+arrive.
 
 =item B<-b>
 
@@ -1114,7 +1346,7 @@ supply one on the command line.
 
 =item B<-t>
 
-Test mode.  The target address defaults to `perlbug-test@perl.com'.
+Test mode.  The target address defaults to B<perlbug-test@perl.org>.
 
 =item B<-v>
 
@@ -1129,9 +1361,10 @@ by Gurusamy Sarathy (E<lt>gsar@activestate.comE<gt>), Tom Christiansen
 (E<lt>tchrist@perl.comE<gt>), Nathan Torkington (E<lt>gnat@frii.comE<gt>),
 Charles F. Randall (E<lt>cfr@pobox.comE<gt>), Mike Guy
 (E<lt>mjtg@cam.a.ukE<gt>), Dominic Dunlop (E<lt>domo@computer.orgE<gt>),
-Hugo van der Sanden (E<lt>hv@crypt0.demon.co.ukE<gt>),
-Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), hris Nandor
-(E<lt>pudge@pobox.comE<gt>), and Jon Orwant (E<lt>orwant@media.mit.eduE<gt>).
+Hugo van der Sanden (E<lt>hv@crypt.org<gt>),
+Jarkko Hietaniemi (E<lt>jhi@iki.fiE<gt>), Chris Nandor
+(E<lt>pudge@pobox.comE<gt>), Jon Orwant (E<lt>orwant@media.mit.eduE<gt>,
+and Richard Foley (E<lt>richard@rfi.netE<gt>).
 
 =head1 SEE ALSO