The handling of the -f option is a hack. Instead of fooling around with argv behind getopt()'s back we can just treat the remainder of argv[] after option processing as the file name for -f. It is not possible to use -f in sending mode so there is no ambiguity. Index: usr.bin/mail/main.c =================================================================== --- usr.bin/mail/main.c.orig +++ usr.bin/mail/main.c @@ -111,16 +111,10 @@ main(int argc, char **argv) /* * User is specifying file to "edit" with Mail, * as opposed to reading system mailbox. - * If no argument is given after -f, we read his - * mbox file. - * - * getopt() can't handle optional arguments, so here - * is an ugly hack to get around it. - */ - if ((argv[optind]) && (argv[optind][0] != '-')) - ef = argv[optind++]; - else - ef = "&"; + * We read his mbox file unless another file + * is specified after the arguments. + */ + ef = "&"; break; case 'n': /* @@ -169,17 +163,24 @@ main(int argc, char **argv) /*NOTREACHED*/ } } - for (i = optind; (argv[i]) && (*argv[i] != '-'); i++) - to = cat(to, nalloc(argv[i], GTO)); - for (; argv[i]; i++) - smopts = cat(smopts, nalloc(argv[i], 0)); + if (ef != NULL) { + /* Check for optional mailbox file name. */ + if (optind < argc) { + ef = argv[optind++]; + if (optind < argc) + errx(1, "Cannot give -f and people to send to"); + } + } else { + for (i = optind; (argv[i]) && (*argv[i] != '-'); i++) + to = cat(to, nalloc(argv[i], GTO)); + for (; argv[i]; i++) + smopts = cat(smopts, nalloc(argv[i], 0)); + } /* * Check for inconsistent arguments. */ if (to == NULL && (subject != NULL || cc != NULL || bcc != NULL)) errx(1, "You must specify direct recipients with -s, -c, or -b"); - if (ef != NULL && to != NULL) - errx(1, "Cannot give -f and people to send to"); /* * Block SIGINT except where we install an explicit handler for it. */ Index: usr.bin/mail/mail.1 =================================================================== --- usr.bin/mail/mail.1.orig +++ usr.bin/mail/mail.1 @@ -79,11 +79,14 @@ to output all sorts of information usefu .Nm mail . .It Fl E Don't send messages with an empty body. -.It Fl f Op Ar file -Read in the contents of your mailbox -(or the specified -.Ar file ) -for processing; when you quit, +.It Fl f +Use an alternate mailbox. +Defaults to the user's +.Ar mbox +if no +.Ar file +is specified. +When quit, .Nm mail writes undeleted messages back to this .Ar file .