10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 22*373Sceastha /* 23*373Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*373Sceastha * Use is subject to license terms. 25*373Sceastha */ 26*373Sceastha 270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate 31*373Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 32*373Sceastha 330Sstevel@tonic-gate #include "mail.h" 340Sstevel@tonic-gate /* 350Sstevel@tonic-gate Parse the command line. 360Sstevel@tonic-gate Return index of first non-option field (i.e. user) 370Sstevel@tonic-gate */ 38*373Sceastha int 39*373Sceastha parse(int argc, char **argv) 400Sstevel@tonic-gate { 41*373Sceastha int c; 42*373Sceastha char *tmailsurr; 430Sstevel@tonic-gate static char pn[] = "parse"; 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate "mail +" means to print in reverse order and is 470Sstevel@tonic-gate equivalent to "mail -r" 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate if ((argc > 1) && (argv[1][0] == '+')) { 500Sstevel@tonic-gate if (ismail) { 510Sstevel@tonic-gate argv[1] = "-r"; 520Sstevel@tonic-gate } else { 530Sstevel@tonic-gate goerr++; 540Sstevel@tonic-gate } 550Sstevel@tonic-gate } 560Sstevel@tonic-gate 570Sstevel@tonic-gate while ((c = getopt(argc, argv, "m:f:x:shrpPqeEdtT:w")) != EOF) { 580Sstevel@tonic-gate switch(c) { 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate Set debugging level... 610Sstevel@tonic-gate */ 620Sstevel@tonic-gate case 'x': 630Sstevel@tonic-gate debug = atoi(optarg); 640Sstevel@tonic-gate orig_dbglvl = debug; 650Sstevel@tonic-gate if (debug < 0) { 660Sstevel@tonic-gate /* Keep trace file even if successful */ 670Sstevel@tonic-gate keepdbgfile = -1; 680Sstevel@tonic-gate debug = -debug; 690Sstevel@tonic-gate } 700Sstevel@tonic-gate break; 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate for backwards compatability with mailx... 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate case 's': 760Sstevel@tonic-gate /* ignore this option */ 770Sstevel@tonic-gate break; 780Sstevel@tonic-gate /* 790Sstevel@tonic-gate * Deliver directly to a mailbox. Do Not go to sendmail 800Sstevel@tonic-gate */ 810Sstevel@tonic-gate case 'd': 820Sstevel@tonic-gate deliverflag = TRUE; 830Sstevel@tonic-gate break; 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate do not print mail 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate case 'e': 890Sstevel@tonic-gate if (ismail) { 900Sstevel@tonic-gate flge = 1; 910Sstevel@tonic-gate } else { 920Sstevel@tonic-gate goerr++; 930Sstevel@tonic-gate } 940Sstevel@tonic-gate optcnt++; 950Sstevel@tonic-gate break; 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate do not print mail 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate case 'E': 1000Sstevel@tonic-gate if (ismail) { 1010Sstevel@tonic-gate flgE = 1; 1020Sstevel@tonic-gate } else { 1030Sstevel@tonic-gate goerr++; 1040Sstevel@tonic-gate } 1050Sstevel@tonic-gate optcnt++; 1060Sstevel@tonic-gate break; 1070Sstevel@tonic-gate /* 1080Sstevel@tonic-gate * use alternate file as mailfile, when reading mail 1090Sstevel@tonic-gate * use this from user when sending mail. 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate case 'f': 1120Sstevel@tonic-gate flgf = 1; 1130Sstevel@tonic-gate fromflag = TRUE; 1140Sstevel@tonic-gate mailfile = optarg; 1150Sstevel@tonic-gate strncpy(from_user, optarg, sizeof (from_user)); 1160Sstevel@tonic-gate from_user[sizeof (from_user) - 1] = '\0'; 1170Sstevel@tonic-gate optcnt++; 1180Sstevel@tonic-gate break; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* 1210Sstevel@tonic-gate Print headers first 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate case 'h': 1240Sstevel@tonic-gate if (ismail) { 1250Sstevel@tonic-gate flgh = 1; 1260Sstevel@tonic-gate } else { 1270Sstevel@tonic-gate goerr++; 1280Sstevel@tonic-gate } 1290Sstevel@tonic-gate optcnt++; 1300Sstevel@tonic-gate break; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate print without prompting 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate case 'p': 1360Sstevel@tonic-gate if (ismail) { 1370Sstevel@tonic-gate flgp++; 1380Sstevel@tonic-gate } else { 1390Sstevel@tonic-gate goerr++; 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate optcnt++; 1420Sstevel@tonic-gate break; 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* 1450Sstevel@tonic-gate override selective display default setting 1460Sstevel@tonic-gate when reading mail... 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate case 'P': 1490Sstevel@tonic-gate if (ismail) { 1500Sstevel@tonic-gate flgP++; 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate optcnt++; 1530Sstevel@tonic-gate break; 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate terminate on deletes 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate case 'q': 1590Sstevel@tonic-gate if (ismail) { 1600Sstevel@tonic-gate delflg = 0; 1610Sstevel@tonic-gate } else { 1620Sstevel@tonic-gate goerr++; 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate optcnt++; 1650Sstevel@tonic-gate break; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate print by first in, first out order 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate case 'r': 1710Sstevel@tonic-gate if (ismail) { 1720Sstevel@tonic-gate flgr = 1; 1730Sstevel@tonic-gate } else { 1740Sstevel@tonic-gate goerr++; 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate optcnt++; 1770Sstevel@tonic-gate break; 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate add To: line to letters 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate case 't': 1830Sstevel@tonic-gate flgt = 1; 1840Sstevel@tonic-gate optcnt++; 1850Sstevel@tonic-gate break; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate don't wait on sends 1890Sstevel@tonic-gate */ 1900Sstevel@tonic-gate case 'w': 1910Sstevel@tonic-gate flgw = 1; 1920Sstevel@tonic-gate break; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* 1950Sstevel@tonic-gate set message-type: 1960Sstevel@tonic-gate */ 1970Sstevel@tonic-gate case 'm': 1980Sstevel@tonic-gate msgtype = optarg; 1990Sstevel@tonic-gate if (msgtype[0] == '\0' || msgtype[0] == '-') { 2000Sstevel@tonic-gate goerr++; 2010Sstevel@tonic-gate } else { 2020Sstevel@tonic-gate flgm = 1; 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate break; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* 2070Sstevel@tonic-gate bad option 2080Sstevel@tonic-gate */ 2090Sstevel@tonic-gate case '?': 2100Sstevel@tonic-gate goerr++; 2110Sstevel@tonic-gate break; 2120Sstevel@tonic-gate } 2130Sstevel@tonic-gate } 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate if (argc == optind) { 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate if (flgm) { 2200Sstevel@tonic-gate errmsg(E_SYNTAX, 2210Sstevel@tonic-gate "-m option used but no recipient(s) specified."); 2220Sstevel@tonic-gate goerr++; 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate if (flgt) { 2250Sstevel@tonic-gate errmsg(E_SYNTAX, 2260Sstevel@tonic-gate "-t option used but no recipient(s) specified."); 2270Sstevel@tonic-gate goerr++; 2280Sstevel@tonic-gate } 2290Sstevel@tonic-gate if (flgw) { 2300Sstevel@tonic-gate errmsg(E_SYNTAX, 2310Sstevel@tonic-gate "-w option used but no recipient(s) specified."); 2320Sstevel@tonic-gate goerr++; 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate if (flgf) { 2350Sstevel@tonic-gate if (mailfile[0] == '-') { 2360Sstevel@tonic-gate errmsg(E_SYNTAX, 2370Sstevel@tonic-gate "Files names must not begin with '-'"); 2380Sstevel@tonic-gate done(0); 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate if (!ismail) 2410Sstevel@tonic-gate goerr++; 2420Sstevel@tonic-gate } 2430Sstevel@tonic-gate } 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate if (ismail && (goerr > 0)) { 2460Sstevel@tonic-gate errmsg(E_SYNTAX,"Usage: [-ehpPqr] [-f file] [-x debuglevel]"); 2470Sstevel@tonic-gate (void) fprintf (stderr, "or\t[-tw] [-m message_type] [-T file] [-x debuglevel] persons\n"); 2480Sstevel@tonic-gate (void) fprintf (stderr, "or\t[-x debuglevel]\n"); 2490Sstevel@tonic-gate done(0); 2500Sstevel@tonic-gate } 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate return (optind); 2530Sstevel@tonic-gate } 254