xref: /titanic_44/usr/src/cmd/mailx/init.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998 by Sun Microsystems, Inc.
28*7c478bd9Sstevel@tonic-gate  * All rights reserved.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*
32*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
33*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
34*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
37*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
38*7c478bd9Sstevel@tonic-gate  * contributors.
39*7c478bd9Sstevel@tonic-gate  */
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate  * mailx -- a modified version of a University of California at Berkeley
45*7c478bd9Sstevel@tonic-gate  *	mail program
46*7c478bd9Sstevel@tonic-gate  *
47*7c478bd9Sstevel@tonic-gate  * A bunch of global variable declarations lie herein.
48*7c478bd9Sstevel@tonic-gate  *
49*7c478bd9Sstevel@tonic-gate  * All global externs are declared in def.h. All variables are initialized
50*7c478bd9Sstevel@tonic-gate  * here!
51*7c478bd9Sstevel@tonic-gate  *
52*7c478bd9Sstevel@tonic-gate  * !!!!!IF YOU CHANGE (OR ADD) IT HERE, DO IT THERE ALSO !!!!!!!!
53*7c478bd9Sstevel@tonic-gate  *
54*7c478bd9Sstevel@tonic-gate  */
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate #include	"def.h"
57*7c478bd9Sstevel@tonic-gate #include	<grp.h>
58*7c478bd9Sstevel@tonic-gate #include	<pwd.h>
59*7c478bd9Sstevel@tonic-gate #include	<sys/utsname.h>
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate int	Fflag = 0;			/* -F option (followup) */
62*7c478bd9Sstevel@tonic-gate int	Hflag = 0;			/* print headers and exit */
63*7c478bd9Sstevel@tonic-gate char	*Tflag;				/* -T temp file for netnews */
64*7c478bd9Sstevel@tonic-gate int	UnUUCP = 0;			/* -U flag */
65*7c478bd9Sstevel@tonic-gate char	**altnames;			/* List of alternate names for user */
66*7c478bd9Sstevel@tonic-gate int	askme;
67*7c478bd9Sstevel@tonic-gate int	baud;				/* Output baud rate */
68*7c478bd9Sstevel@tonic-gate char	*bflag;				/* Bcc given from non tty */
69*7c478bd9Sstevel@tonic-gate char	*binmsg = "*** Message content is not printable: pipe to command or save to a file ***";
70*7c478bd9Sstevel@tonic-gate char	*cflag;				/* Cc given from non tty */
71*7c478bd9Sstevel@tonic-gate int	cond;				/* Current state of conditional exc. */
72*7c478bd9Sstevel@tonic-gate NODE	*curptr = NOFP;
73*7c478bd9Sstevel@tonic-gate int	debug;				/* Debug flag set */
74*7c478bd9Sstevel@tonic-gate struct	message	*dot;			/* Pointer to current message */
75*7c478bd9Sstevel@tonic-gate int	edit;				/* Indicates editing a file */
76*7c478bd9Sstevel@tonic-gate char	*editfile;			/* Name of file being edited */
77*7c478bd9Sstevel@tonic-gate int	exitflg = 0;			/* -e for mail test */
78*7c478bd9Sstevel@tonic-gate NODE	*fplist = NOFP;
79*7c478bd9Sstevel@tonic-gate struct	grouphead	*groups[HSHSIZE];/* Pointer to active groups */
80*7c478bd9Sstevel@tonic-gate int	hflag;				/* Sequence number for network -h */
81*7c478bd9Sstevel@tonic-gate char	homedir[PATHSIZE];		/* Name of home directory */
82*7c478bd9Sstevel@tonic-gate struct	ignore		*ignore[HSHSIZE];/* Pointer to ignored fields */
83*7c478bd9Sstevel@tonic-gate int	image;				/* File descriptor for image of msg */
84*7c478bd9Sstevel@tonic-gate FILE	*input;				/* Current command input file */
85*7c478bd9Sstevel@tonic-gate int	intty;				/* True if standard input a tty */
86*7c478bd9Sstevel@tonic-gate int	issysmbox;			/* mailname is a system mailbox */
87*7c478bd9Sstevel@tonic-gate FILE	*itf;				/* Input temp file buffer */
88*7c478bd9Sstevel@tonic-gate int	lexnumber;			/* Number of TNUMBER from scan() */
89*7c478bd9Sstevel@tonic-gate char	lexstring[STRINGLEN];		/* String from TSTRING, scan() */
90*7c478bd9Sstevel@tonic-gate int	loading;			/* Loading user definitions */
91*7c478bd9Sstevel@tonic-gate char	*lockname;			/* named used for locking in /var/mail */
92*7c478bd9Sstevel@tonic-gate #ifdef	USR_SPOOL_MAIL
93*7c478bd9Sstevel@tonic-gate char	*maildir = "/usr/spool/mail/";	/* directory for mail files */
94*7c478bd9Sstevel@tonic-gate #else
95*7c478bd9Sstevel@tonic-gate # ifdef preSVr4
96*7c478bd9Sstevel@tonic-gate char	*maildir = "/usr/mail/";	/* directory for mail files */
97*7c478bd9Sstevel@tonic-gate # else
98*7c478bd9Sstevel@tonic-gate char	*maildir = "/var/mail/";	/* directory for mail files */
99*7c478bd9Sstevel@tonic-gate # endif
100*7c478bd9Sstevel@tonic-gate #endif
101*7c478bd9Sstevel@tonic-gate char	mailname[PATHSIZE];		/* Name of /var/mail system mailbox */
102*7c478bd9Sstevel@tonic-gate off_t	mailsize;			/* Size of system mailbox */
103*7c478bd9Sstevel@tonic-gate int	maxfiles;			/* Maximum number of open files */
104*7c478bd9Sstevel@tonic-gate struct	message	*message;		/* The actual message structure */
105*7c478bd9Sstevel@tonic-gate int	msgCount;			/* Count of messages read in */
106*7c478bd9Sstevel@tonic-gate gid_t	myegid;
107*7c478bd9Sstevel@tonic-gate uid_t	myeuid;
108*7c478bd9Sstevel@tonic-gate char	myname[PATHSIZE];		/* My login id */
109*7c478bd9Sstevel@tonic-gate pid_t	mypid;				/* Current process id */
110*7c478bd9Sstevel@tonic-gate gid_t	myrgid;
111*7c478bd9Sstevel@tonic-gate uid_t	myruid;
112*7c478bd9Sstevel@tonic-gate int	newsflg = 0;			/* -I option for netnews */
113*7c478bd9Sstevel@tonic-gate char	noheader;			/* Suprress initial header listing */
114*7c478bd9Sstevel@tonic-gate int	noreset;			/* String resets suspended */
115*7c478bd9Sstevel@tonic-gate char	nosrc;				/* Don't source /etc/mail/mailx.rc */
116*7c478bd9Sstevel@tonic-gate int	nretained;			/* Number of retained fields */
117*7c478bd9Sstevel@tonic-gate int	numberstack[REGDEP];		/* Stack of regretted numbers */
118*7c478bd9Sstevel@tonic-gate char	origname[PATHSIZE];		/* Name of mailfile before expansion */
119*7c478bd9Sstevel@tonic-gate FILE	*otf;				/* Output temp file buffer */
120*7c478bd9Sstevel@tonic-gate int	outtty;				/* True if standard output a tty */
121*7c478bd9Sstevel@tonic-gate FILE	*pipef;				/* Pipe file we have opened */
122*7c478bd9Sstevel@tonic-gate char	*progname;			/* program name (argv[0]) */
123*7c478bd9Sstevel@tonic-gate char	*prompt = NOSTR;		/* prompt string */
124*7c478bd9Sstevel@tonic-gate int	rcvmode;			/* True if receiving mail */
125*7c478bd9Sstevel@tonic-gate int	readonly;			/* Will be unable to rewrite file */
126*7c478bd9Sstevel@tonic-gate int	regretp;			/* Pointer to TOS of regret tokens */
127*7c478bd9Sstevel@tonic-gate int	regretstack[REGDEP];		/* Stack of regretted tokens */
128*7c478bd9Sstevel@tonic-gate struct	ignore		*retain[HSHSIZE];/* Pointer to retained fields */
129*7c478bd9Sstevel@tonic-gate char	*rflag;				/* -r address for network */
130*7c478bd9Sstevel@tonic-gate int	rmail;				/* Being called as rmail */
131*7c478bd9Sstevel@tonic-gate int	sawcom;				/* Set after first command */
132*7c478bd9Sstevel@tonic-gate int	selfsent;			/* User sent self something */
133*7c478bd9Sstevel@tonic-gate int	senderr;			/* An error while checking */
134*7c478bd9Sstevel@tonic-gate int	rpterr;				/* An error msg was sent to stderr */
135*7c478bd9Sstevel@tonic-gate char	*sflag;				/* Subject given from non tty */
136*7c478bd9Sstevel@tonic-gate int	sourcing;			/* Currently reading variant file */
137*7c478bd9Sstevel@tonic-gate int	space;				/* Current maximum number of messages */
138*7c478bd9Sstevel@tonic-gate jmp_buf	srbuf;
139*7c478bd9Sstevel@tonic-gate int	tflag;				/* Read headers from text */
140*7c478bd9Sstevel@tonic-gate /*
141*7c478bd9Sstevel@tonic-gate  * The pointers for the string allocation routines,
142*7c478bd9Sstevel@tonic-gate  * there are NSPACE independent areas.
143*7c478bd9Sstevel@tonic-gate  * The first holds STRINGSIZE bytes, the next
144*7c478bd9Sstevel@tonic-gate  * twice as much, and so on.
145*7c478bd9Sstevel@tonic-gate  */
146*7c478bd9Sstevel@tonic-gate struct strings stringdope[NSPACE];
147*7c478bd9Sstevel@tonic-gate char	*stringstack[REGDEP];		/* Stack of regretted strings */
148*7c478bd9Sstevel@tonic-gate char	tempEdit[TMPSIZ];
149*7c478bd9Sstevel@tonic-gate char	tempMail[TMPSIZ];
150*7c478bd9Sstevel@tonic-gate char	tempMesg[TMPSIZ];
151*7c478bd9Sstevel@tonic-gate char	tempQuit[TMPSIZ];
152*7c478bd9Sstevel@tonic-gate char	tempResid[PATHSIZE];		/* temp file in :saved */
153*7c478bd9Sstevel@tonic-gate char	tempZedit[TMPSIZ];
154*7c478bd9Sstevel@tonic-gate uid_t	uid;				/* The invoker's user id */
155*7c478bd9Sstevel@tonic-gate static struct utimbuf	utimeb;
156*7c478bd9Sstevel@tonic-gate struct utimbuf	*utimep = &utimeb;
157*7c478bd9Sstevel@tonic-gate struct	var	*variables[HSHSIZE];	/* Pointer to active var list */
158*7c478bd9Sstevel@tonic-gate int	receipt_flg = 0;		/* Flag for return receipt */
159