Skip to content

Commit

Permalink
mail: -f usage forbids extra args (#870)
Browse files Browse the repository at this point in the history
* If mail command is invoked with arguments it assumes those are addresses to send mail to, but running "mail -f mbox" is not compatible
* Raise an error and print usage string, as done in OpenBSD version
* Also use catfile() when constructing a default value for mailbox path
  • Loading branch information
mknos authored Dec 9, 2024
1 parent ff93712 commit a85b1bf
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions bin/mail
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,13 @@ EDLOOP: {
package main;

use File::Basename qw(basename);
use File::Spec;
use File::Temp;
use Getopt::Std;

use vars qw($opt_f $opt_s $opt_c $opt_b $opt_v);

our $VERSION = '0.04';
our $VERSION = '0.05';
our $ROWS = 23; # Screen Dimensions. Yeah, this sucks.
our $COLS = 80;
our $BUFFERL = 2; # Lines needed for "fluff"
Expand Down Expand Up @@ -1044,27 +1045,30 @@ sub VERSION_MESSAGE {
exit;
}

getopts("f:s:c:b:v") || die <<USAGE;
usage: $Program [-s subject] [-c cc-addrs] [-b bcc-addrs] to-addr [..toaddr..]
or: $Program [-f mailbox]
USAGE
sub usage {
warn "usage: $Program [-s subject] [-c cc-addrs] [-b bcc-addrs] " .
"to-addr ...\n $Program [-f mailbox]\n";
exit 1;

if (@ARGV) { # Assume batch-mode
}

getopts('f:s:c:b:v') or usage();
if (@ARGV) {
if (defined $opt_f) {
warn "$Program: to-addr may not be specified with a mailbox\n";
usage();
}
Batch(@ARGV);
} else {
my $mbox = 'mbox';
if (defined $opt_f) {
Interactive($opt_f);
} else {
if (exists $ENV{MAIL}) {
Interactive($ENV{MAIL});
} else {
if (! exists $ENV{HOME}) {
Interactive("mbox");
} else {
Interactive($ENV{HOME} . "/mbox");
}
}
$mbox = $opt_f;
} elsif (exists $ENV{'MAIL'}) {
$mbox = $ENV{'MAIL'};
} elsif (exists $ENV{'HOME'}) {
$mbox = File::Spec->catfile($ENV{'HOME'}, 'mbox');
}
Interactive($mbox);
}

=pod
Expand Down

0 comments on commit a85b1bf

Please sign in to comment.