17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 22*b7d62af5Sceastha /* 23*b7d62af5Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*b7d62af5Sceastha * Use is subject to license terms. 25*b7d62af5Sceastha */ 26*b7d62af5Sceastha 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 31*b7d62af5Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 32*b7d62af5Sceastha 337c478bd9Sstevel@tonic-gate #include "mail.h" 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate Parse the command line. 367c478bd9Sstevel@tonic-gate Return index of first non-option field (i.e. user) 377c478bd9Sstevel@tonic-gate */ 38*b7d62af5Sceastha int 39*b7d62af5Sceastha parse(int argc, char **argv) 407c478bd9Sstevel@tonic-gate { 41*b7d62af5Sceastha int c; 42*b7d62af5Sceastha char *tmailsurr; 437c478bd9Sstevel@tonic-gate static char pn[] = "parse"; 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate "mail +" means to print in reverse order and is 477c478bd9Sstevel@tonic-gate equivalent to "mail -r" 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate if ((argc > 1) && (argv[1][0] == '+')) { 507c478bd9Sstevel@tonic-gate if (ismail) { 517c478bd9Sstevel@tonic-gate argv[1] = "-r"; 527c478bd9Sstevel@tonic-gate } else { 537c478bd9Sstevel@tonic-gate goerr++; 547c478bd9Sstevel@tonic-gate } 557c478bd9Sstevel@tonic-gate } 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "m:f:x:shrpPqeEdtT:w")) != EOF) { 587c478bd9Sstevel@tonic-gate switch(c) { 597c478bd9Sstevel@tonic-gate /* 607c478bd9Sstevel@tonic-gate Set debugging level... 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate case 'x': 637c478bd9Sstevel@tonic-gate debug = atoi(optarg); 647c478bd9Sstevel@tonic-gate orig_dbglvl = debug; 657c478bd9Sstevel@tonic-gate if (debug < 0) { 667c478bd9Sstevel@tonic-gate /* Keep trace file even if successful */ 677c478bd9Sstevel@tonic-gate keepdbgfile = -1; 687c478bd9Sstevel@tonic-gate debug = -debug; 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate break; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate for backwards compatability with mailx... 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate case 's': 767c478bd9Sstevel@tonic-gate /* ignore this option */ 777c478bd9Sstevel@tonic-gate break; 787c478bd9Sstevel@tonic-gate /* 797c478bd9Sstevel@tonic-gate * Deliver directly to a mailbox. Do Not go to sendmail 807c478bd9Sstevel@tonic-gate */ 817c478bd9Sstevel@tonic-gate case 'd': 827c478bd9Sstevel@tonic-gate deliverflag = TRUE; 837c478bd9Sstevel@tonic-gate break; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* 867c478bd9Sstevel@tonic-gate do not print mail 877c478bd9Sstevel@tonic-gate */ 887c478bd9Sstevel@tonic-gate case 'e': 897c478bd9Sstevel@tonic-gate if (ismail) { 907c478bd9Sstevel@tonic-gate flge = 1; 917c478bd9Sstevel@tonic-gate } else { 927c478bd9Sstevel@tonic-gate goerr++; 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate optcnt++; 957c478bd9Sstevel@tonic-gate break; 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate do not print mail 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate case 'E': 1007c478bd9Sstevel@tonic-gate if (ismail) { 1017c478bd9Sstevel@tonic-gate flgE = 1; 1027c478bd9Sstevel@tonic-gate } else { 1037c478bd9Sstevel@tonic-gate goerr++; 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate optcnt++; 1067c478bd9Sstevel@tonic-gate break; 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * use alternate file as mailfile, when reading mail 1097c478bd9Sstevel@tonic-gate * use this from user when sending mail. 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate case 'f': 1127c478bd9Sstevel@tonic-gate flgf = 1; 1137c478bd9Sstevel@tonic-gate fromflag = TRUE; 1147c478bd9Sstevel@tonic-gate mailfile = optarg; 1157c478bd9Sstevel@tonic-gate strncpy(from_user, optarg, sizeof (from_user)); 1167c478bd9Sstevel@tonic-gate from_user[sizeof (from_user) - 1] = '\0'; 1177c478bd9Sstevel@tonic-gate optcnt++; 1187c478bd9Sstevel@tonic-gate break; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate Print headers first 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate case 'h': 1247c478bd9Sstevel@tonic-gate if (ismail) { 1257c478bd9Sstevel@tonic-gate flgh = 1; 1267c478bd9Sstevel@tonic-gate } else { 1277c478bd9Sstevel@tonic-gate goerr++; 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate optcnt++; 1307c478bd9Sstevel@tonic-gate break; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate /* 1337c478bd9Sstevel@tonic-gate print without prompting 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate case 'p': 1367c478bd9Sstevel@tonic-gate if (ismail) { 1377c478bd9Sstevel@tonic-gate flgp++; 1387c478bd9Sstevel@tonic-gate } else { 1397c478bd9Sstevel@tonic-gate goerr++; 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate optcnt++; 1427c478bd9Sstevel@tonic-gate break; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate override selective display default setting 1467c478bd9Sstevel@tonic-gate when reading mail... 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate case 'P': 1497c478bd9Sstevel@tonic-gate if (ismail) { 1507c478bd9Sstevel@tonic-gate flgP++; 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate optcnt++; 1537c478bd9Sstevel@tonic-gate break; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate /* 1567c478bd9Sstevel@tonic-gate terminate on deletes 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate case 'q': 1597c478bd9Sstevel@tonic-gate if (ismail) { 1607c478bd9Sstevel@tonic-gate delflg = 0; 1617c478bd9Sstevel@tonic-gate } else { 1627c478bd9Sstevel@tonic-gate goerr++; 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate optcnt++; 1657c478bd9Sstevel@tonic-gate break; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate print by first in, first out order 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate case 'r': 1717c478bd9Sstevel@tonic-gate if (ismail) { 1727c478bd9Sstevel@tonic-gate flgr = 1; 1737c478bd9Sstevel@tonic-gate } else { 1747c478bd9Sstevel@tonic-gate goerr++; 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate optcnt++; 1777c478bd9Sstevel@tonic-gate break; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate add To: line to letters 1817c478bd9Sstevel@tonic-gate */ 1827c478bd9Sstevel@tonic-gate case 't': 1837c478bd9Sstevel@tonic-gate flgt = 1; 1847c478bd9Sstevel@tonic-gate optcnt++; 1857c478bd9Sstevel@tonic-gate break; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* 1887c478bd9Sstevel@tonic-gate don't wait on sends 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate case 'w': 1917c478bd9Sstevel@tonic-gate flgw = 1; 1927c478bd9Sstevel@tonic-gate break; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate /* 1957c478bd9Sstevel@tonic-gate set message-type: 1967c478bd9Sstevel@tonic-gate */ 1977c478bd9Sstevel@tonic-gate case 'm': 1987c478bd9Sstevel@tonic-gate msgtype = optarg; 1997c478bd9Sstevel@tonic-gate if (msgtype[0] == '\0' || msgtype[0] == '-') { 2007c478bd9Sstevel@tonic-gate goerr++; 2017c478bd9Sstevel@tonic-gate } else { 2027c478bd9Sstevel@tonic-gate flgm = 1; 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate break; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate bad option 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate case '?': 2107c478bd9Sstevel@tonic-gate goerr++; 2117c478bd9Sstevel@tonic-gate break; 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate if (argc == optind) { 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate if (flgm) { 2207c478bd9Sstevel@tonic-gate errmsg(E_SYNTAX, 2217c478bd9Sstevel@tonic-gate "-m option used but no recipient(s) specified."); 2227c478bd9Sstevel@tonic-gate goerr++; 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate if (flgt) { 2257c478bd9Sstevel@tonic-gate errmsg(E_SYNTAX, 2267c478bd9Sstevel@tonic-gate "-t option used but no recipient(s) specified."); 2277c478bd9Sstevel@tonic-gate goerr++; 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate if (flgw) { 2307c478bd9Sstevel@tonic-gate errmsg(E_SYNTAX, 2317c478bd9Sstevel@tonic-gate "-w option used but no recipient(s) specified."); 2327c478bd9Sstevel@tonic-gate goerr++; 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate if (flgf) { 2357c478bd9Sstevel@tonic-gate if (mailfile[0] == '-') { 2367c478bd9Sstevel@tonic-gate errmsg(E_SYNTAX, 2377c478bd9Sstevel@tonic-gate "Files names must not begin with '-'"); 2387c478bd9Sstevel@tonic-gate done(0); 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate if (!ismail) 2417c478bd9Sstevel@tonic-gate goerr++; 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate if (ismail && (goerr > 0)) { 2467c478bd9Sstevel@tonic-gate errmsg(E_SYNTAX,"Usage: [-ehpPqr] [-f file] [-x debuglevel]"); 2477c478bd9Sstevel@tonic-gate (void) fprintf (stderr, "or\t[-tw] [-m message_type] [-T file] [-x debuglevel] persons\n"); 2487c478bd9Sstevel@tonic-gate (void) fprintf (stderr, "or\t[-x debuglevel]\n"); 2497c478bd9Sstevel@tonic-gate done(0); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate return (optind); 2537c478bd9Sstevel@tonic-gate } 254