1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 2.1 */ 27*0Sstevel@tonic-gate #include "mail.h" 28*0Sstevel@tonic-gate /* 29*0Sstevel@tonic-gate Parse the command line. 30*0Sstevel@tonic-gate Return index of first non-option field (i.e. user) 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate parse(argc, argv) 33*0Sstevel@tonic-gate int argc; 34*0Sstevel@tonic-gate char **argv; 35*0Sstevel@tonic-gate { 36*0Sstevel@tonic-gate register int c; 37*0Sstevel@tonic-gate register char *tmailsurr; 38*0Sstevel@tonic-gate static char pn[] = "parse"; 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate /* 41*0Sstevel@tonic-gate "mail +" means to print in reverse order and is 42*0Sstevel@tonic-gate equivalent to "mail -r" 43*0Sstevel@tonic-gate */ 44*0Sstevel@tonic-gate if ((argc > 1) && (argv[1][0] == '+')) { 45*0Sstevel@tonic-gate if (ismail) { 46*0Sstevel@tonic-gate argv[1] = "-r"; 47*0Sstevel@tonic-gate } else { 48*0Sstevel@tonic-gate goerr++; 49*0Sstevel@tonic-gate } 50*0Sstevel@tonic-gate } 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate while ((c = getopt(argc, argv, "m:f:x:shrpPqeEdtT:w")) != EOF) { 53*0Sstevel@tonic-gate switch(c) { 54*0Sstevel@tonic-gate /* 55*0Sstevel@tonic-gate Set debugging level... 56*0Sstevel@tonic-gate */ 57*0Sstevel@tonic-gate case 'x': 58*0Sstevel@tonic-gate debug = atoi(optarg); 59*0Sstevel@tonic-gate orig_dbglvl = debug; 60*0Sstevel@tonic-gate if (debug < 0) { 61*0Sstevel@tonic-gate /* Keep trace file even if successful */ 62*0Sstevel@tonic-gate keepdbgfile = -1; 63*0Sstevel@tonic-gate debug = -debug; 64*0Sstevel@tonic-gate } 65*0Sstevel@tonic-gate break; 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate /* 68*0Sstevel@tonic-gate for backwards compatability with mailx... 69*0Sstevel@tonic-gate */ 70*0Sstevel@tonic-gate case 's': 71*0Sstevel@tonic-gate /* ignore this option */ 72*0Sstevel@tonic-gate break; 73*0Sstevel@tonic-gate /* 74*0Sstevel@tonic-gate * Deliver directly to a mailbox. Do Not go to sendmail 75*0Sstevel@tonic-gate */ 76*0Sstevel@tonic-gate case 'd': 77*0Sstevel@tonic-gate deliverflag = TRUE; 78*0Sstevel@tonic-gate break; 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate /* 81*0Sstevel@tonic-gate do not print mail 82*0Sstevel@tonic-gate */ 83*0Sstevel@tonic-gate case 'e': 84*0Sstevel@tonic-gate if (ismail) { 85*0Sstevel@tonic-gate flge = 1; 86*0Sstevel@tonic-gate } else { 87*0Sstevel@tonic-gate goerr++; 88*0Sstevel@tonic-gate } 89*0Sstevel@tonic-gate optcnt++; 90*0Sstevel@tonic-gate break; 91*0Sstevel@tonic-gate /* 92*0Sstevel@tonic-gate do not print mail 93*0Sstevel@tonic-gate */ 94*0Sstevel@tonic-gate case 'E': 95*0Sstevel@tonic-gate if (ismail) { 96*0Sstevel@tonic-gate flgE = 1; 97*0Sstevel@tonic-gate } else { 98*0Sstevel@tonic-gate goerr++; 99*0Sstevel@tonic-gate } 100*0Sstevel@tonic-gate optcnt++; 101*0Sstevel@tonic-gate break; 102*0Sstevel@tonic-gate /* 103*0Sstevel@tonic-gate * use alternate file as mailfile, when reading mail 104*0Sstevel@tonic-gate * use this from user when sending mail. 105*0Sstevel@tonic-gate */ 106*0Sstevel@tonic-gate case 'f': 107*0Sstevel@tonic-gate flgf = 1; 108*0Sstevel@tonic-gate fromflag = TRUE; 109*0Sstevel@tonic-gate mailfile = optarg; 110*0Sstevel@tonic-gate strncpy(from_user, optarg, sizeof (from_user)); 111*0Sstevel@tonic-gate from_user[sizeof (from_user) - 1] = '\0'; 112*0Sstevel@tonic-gate optcnt++; 113*0Sstevel@tonic-gate break; 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate /* 116*0Sstevel@tonic-gate Print headers first 117*0Sstevel@tonic-gate */ 118*0Sstevel@tonic-gate case 'h': 119*0Sstevel@tonic-gate if (ismail) { 120*0Sstevel@tonic-gate flgh = 1; 121*0Sstevel@tonic-gate } else { 122*0Sstevel@tonic-gate goerr++; 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate optcnt++; 125*0Sstevel@tonic-gate break; 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate /* 128*0Sstevel@tonic-gate print without prompting 129*0Sstevel@tonic-gate */ 130*0Sstevel@tonic-gate case 'p': 131*0Sstevel@tonic-gate if (ismail) { 132*0Sstevel@tonic-gate flgp++; 133*0Sstevel@tonic-gate } else { 134*0Sstevel@tonic-gate goerr++; 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate optcnt++; 137*0Sstevel@tonic-gate break; 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate /* 140*0Sstevel@tonic-gate override selective display default setting 141*0Sstevel@tonic-gate when reading mail... 142*0Sstevel@tonic-gate */ 143*0Sstevel@tonic-gate case 'P': 144*0Sstevel@tonic-gate if (ismail) { 145*0Sstevel@tonic-gate flgP++; 146*0Sstevel@tonic-gate } 147*0Sstevel@tonic-gate optcnt++; 148*0Sstevel@tonic-gate break; 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate /* 151*0Sstevel@tonic-gate terminate on deletes 152*0Sstevel@tonic-gate */ 153*0Sstevel@tonic-gate case 'q': 154*0Sstevel@tonic-gate if (ismail) { 155*0Sstevel@tonic-gate delflg = 0; 156*0Sstevel@tonic-gate } else { 157*0Sstevel@tonic-gate goerr++; 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate optcnt++; 160*0Sstevel@tonic-gate break; 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate /* 163*0Sstevel@tonic-gate print by first in, first out order 164*0Sstevel@tonic-gate */ 165*0Sstevel@tonic-gate case 'r': 166*0Sstevel@tonic-gate if (ismail) { 167*0Sstevel@tonic-gate flgr = 1; 168*0Sstevel@tonic-gate } else { 169*0Sstevel@tonic-gate goerr++; 170*0Sstevel@tonic-gate } 171*0Sstevel@tonic-gate optcnt++; 172*0Sstevel@tonic-gate break; 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate /* 175*0Sstevel@tonic-gate add To: line to letters 176*0Sstevel@tonic-gate */ 177*0Sstevel@tonic-gate case 't': 178*0Sstevel@tonic-gate flgt = 1; 179*0Sstevel@tonic-gate optcnt++; 180*0Sstevel@tonic-gate break; 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate /* 183*0Sstevel@tonic-gate don't wait on sends 184*0Sstevel@tonic-gate */ 185*0Sstevel@tonic-gate case 'w': 186*0Sstevel@tonic-gate flgw = 1; 187*0Sstevel@tonic-gate break; 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate /* 190*0Sstevel@tonic-gate set message-type: 191*0Sstevel@tonic-gate */ 192*0Sstevel@tonic-gate case 'm': 193*0Sstevel@tonic-gate msgtype = optarg; 194*0Sstevel@tonic-gate if (msgtype[0] == '\0' || msgtype[0] == '-') { 195*0Sstevel@tonic-gate goerr++; 196*0Sstevel@tonic-gate } else { 197*0Sstevel@tonic-gate flgm = 1; 198*0Sstevel@tonic-gate } 199*0Sstevel@tonic-gate break; 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate /* 202*0Sstevel@tonic-gate bad option 203*0Sstevel@tonic-gate */ 204*0Sstevel@tonic-gate case '?': 205*0Sstevel@tonic-gate goerr++; 206*0Sstevel@tonic-gate break; 207*0Sstevel@tonic-gate } 208*0Sstevel@tonic-gate } 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate if (argc == optind) { 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate if (flgm) { 215*0Sstevel@tonic-gate errmsg(E_SYNTAX, 216*0Sstevel@tonic-gate "-m option used but no recipient(s) specified."); 217*0Sstevel@tonic-gate goerr++; 218*0Sstevel@tonic-gate } 219*0Sstevel@tonic-gate if (flgt) { 220*0Sstevel@tonic-gate errmsg(E_SYNTAX, 221*0Sstevel@tonic-gate "-t option used but no recipient(s) specified."); 222*0Sstevel@tonic-gate goerr++; 223*0Sstevel@tonic-gate } 224*0Sstevel@tonic-gate if (flgw) { 225*0Sstevel@tonic-gate errmsg(E_SYNTAX, 226*0Sstevel@tonic-gate "-w option used but no recipient(s) specified."); 227*0Sstevel@tonic-gate goerr++; 228*0Sstevel@tonic-gate } 229*0Sstevel@tonic-gate if (flgf) { 230*0Sstevel@tonic-gate if (mailfile[0] == '-') { 231*0Sstevel@tonic-gate errmsg(E_SYNTAX, 232*0Sstevel@tonic-gate "Files names must not begin with '-'"); 233*0Sstevel@tonic-gate done(0); 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate if (!ismail) 236*0Sstevel@tonic-gate goerr++; 237*0Sstevel@tonic-gate } 238*0Sstevel@tonic-gate } 239*0Sstevel@tonic-gate 240*0Sstevel@tonic-gate if (ismail && (goerr > 0)) { 241*0Sstevel@tonic-gate errmsg(E_SYNTAX,"Usage: [-ehpPqr] [-f file] [-x debuglevel]"); 242*0Sstevel@tonic-gate (void) fprintf (stderr, "or\t[-tw] [-m message_type] [-T file] [-x debuglevel] persons\n"); 243*0Sstevel@tonic-gate (void) fprintf (stderr, "or\t[-x debuglevel]\n"); 244*0Sstevel@tonic-gate done(0); 245*0Sstevel@tonic-gate } 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate return (optind); 248*0Sstevel@tonic-gate } 249