=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/main.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- src/usr.bin/mail/main.c 2014/11/24 20:01:43 1.24 +++ src/usr.bin/mail/main.c 2014/11/24 20:03:33 1.25 @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.24 2014/11/24 20:01:43 millert Exp $ */ +/* $OpenBSD: main.c,v 1.25 2014/11/24 20:03:33 millert Exp $ */ /* $NetBSD: main.c,v 1.7 1997/05/13 06:15:57 mikel Exp $ */ /* @@ -111,16 +111,10 @@ /* * 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. + * We read his mbox file unless another file + * is specified after the arguments. */ - if ((argv[optind]) && (argv[optind][0] != '-')) - ef = argv[optind++]; - else - ef = "&"; + ef = "&"; break; case 'n': /* @@ -169,17 +163,24 @@ /*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. */