xref: /illumos-gate/usr/src/cmd/mailx/cmd3.c (revision 55fea89d)
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  */
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
246c83d09fSrobbin  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
286c83d09fSrobbin /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
296c83d09fSrobbin /*	  All Rights Reserved  	*/
306c83d09fSrobbin 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
337c478bd9Sstevel@tonic-gate  * The Regents of the University of California
347c478bd9Sstevel@tonic-gate  * All Rights Reserved
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
377c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
387c478bd9Sstevel@tonic-gate  * contributors.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include "rcv.h"
427c478bd9Sstevel@tonic-gate #include <locale.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * mailx -- a modified version of a University of California at Berkeley
467c478bd9Sstevel@tonic-gate  *	mail program
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * Still more user commands.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate static int	bangexp(char *str);
527c478bd9Sstevel@tonic-gate static int	diction(const void *a, const void *b);
537c478bd9Sstevel@tonic-gate static char	*getfilename(char *name, int *aedit);
547c478bd9Sstevel@tonic-gate static int	resp1(int *msgvec, int useauthor);
557c478bd9Sstevel@tonic-gate static int	Resp1(int *msgvec, int useauthor);
567c478bd9Sstevel@tonic-gate static char	*reedit(char *subj);
577c478bd9Sstevel@tonic-gate static int	shell1(char *str);
587c478bd9Sstevel@tonic-gate static void	sort(char **list);
597c478bd9Sstevel@tonic-gate static char	*replyto(struct message *mp, char **f);
607c478bd9Sstevel@tonic-gate static int	reply2sender(void);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate static char	prevfile[PATHSIZE];
637c478bd9Sstevel@tonic-gate static char	origprevfile[PATHSIZE];
647c478bd9Sstevel@tonic-gate static char	lastbang[BUFSIZ];
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * Process a shell escape by saving signals, ignoring signals,
687c478bd9Sstevel@tonic-gate  * and forking a sh -c
697c478bd9Sstevel@tonic-gate  */
707c478bd9Sstevel@tonic-gate 
71*55fea89dSDan Cross int
shell(char * str)727c478bd9Sstevel@tonic-gate shell(char *str)
737c478bd9Sstevel@tonic-gate {
747c478bd9Sstevel@tonic-gate 	shell1(str);
757c478bd9Sstevel@tonic-gate 	printf("!\n");
767c478bd9Sstevel@tonic-gate 	return(0);
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate 
79*55fea89dSDan Cross static int
shell1(char * str)807c478bd9Sstevel@tonic-gate shell1(char *str)
817c478bd9Sstevel@tonic-gate {
827c478bd9Sstevel@tonic-gate 	void (*sig[2])(int);
8346d64c14SToomas Soome 	int t;
8446d64c14SToomas Soome 	pid_t p;
857c478bd9Sstevel@tonic-gate 	char *Shell;
867c478bd9Sstevel@tonic-gate 	char cmd[BUFSIZ];
87*55fea89dSDan Cross 
887c478bd9Sstevel@tonic-gate 	nstrcpy(cmd, sizeof (cmd), str);
897c478bd9Sstevel@tonic-gate 	if (bangexp(cmd) < 0)
907c478bd9Sstevel@tonic-gate 		return(-1);
917c478bd9Sstevel@tonic-gate 	if ((Shell = value("SHELL")) == NOSTR || *Shell=='\0')
927c478bd9Sstevel@tonic-gate 		Shell = SHELL;
937c478bd9Sstevel@tonic-gate 	for (t = SIGINT; t <= SIGQUIT; t++)
947c478bd9Sstevel@tonic-gate 		sig[t-SIGINT] = sigset(t, SIG_IGN);
957c478bd9Sstevel@tonic-gate 	p = vfork();
967c478bd9Sstevel@tonic-gate 	if (p == 0) {
977c478bd9Sstevel@tonic-gate 		setuid(getuid());
987c478bd9Sstevel@tonic-gate 		sigchild();
997c478bd9Sstevel@tonic-gate 		for (t = SIGINT; t <= SIGQUIT; t++)
1007c478bd9Sstevel@tonic-gate 			if (sig[t-SIGINT] != SIG_IGN)
1017c478bd9Sstevel@tonic-gate 				sigsys(t, SIG_DFL);
1027c478bd9Sstevel@tonic-gate 		execlp(Shell, Shell, "-c", cmd, (char *)0);
1037c478bd9Sstevel@tonic-gate 		perror(Shell);
1047c478bd9Sstevel@tonic-gate 		_exit(1);
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 	while (wait(0) != p)
1077c478bd9Sstevel@tonic-gate 		;
1087c478bd9Sstevel@tonic-gate 	if (p == (pid_t)-1)
1097c478bd9Sstevel@tonic-gate 		perror("fork");
1107c478bd9Sstevel@tonic-gate 	for (t = SIGINT; t <= SIGQUIT; t++)
1117c478bd9Sstevel@tonic-gate 		sigset(t, sig[t-SIGINT]);
1127c478bd9Sstevel@tonic-gate 	return(0);
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * Fork an interactive shell.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate 
119*55fea89dSDan Cross int
1207c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
dosh(char *)1217c478bd9Sstevel@tonic-gate dosh(char *)
1227c478bd9Sstevel@tonic-gate #else
1237c478bd9Sstevel@tonic-gate /* ARGSUSED */
1247c478bd9Sstevel@tonic-gate dosh(char *s)
1257c478bd9Sstevel@tonic-gate #endif
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	void (*sig[2])(int);
12846d64c14SToomas Soome 	int t;
12946d64c14SToomas Soome 	pid_t p;
1307c478bd9Sstevel@tonic-gate 	char *Shell;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	if ((Shell = value("SHELL")) == NOSTR || *Shell=='\0')
1337c478bd9Sstevel@tonic-gate 		Shell = SHELL;
1347c478bd9Sstevel@tonic-gate 	for (t = SIGINT; t <= SIGQUIT; t++)
1357c478bd9Sstevel@tonic-gate 		sig[t-SIGINT] = sigset(t, SIG_IGN);
1367c478bd9Sstevel@tonic-gate 	p = vfork();
1377c478bd9Sstevel@tonic-gate 	if (p == 0) {
1387c478bd9Sstevel@tonic-gate 		setuid(getuid());
1397c478bd9Sstevel@tonic-gate 		sigchild();
1407c478bd9Sstevel@tonic-gate 		for (t = SIGINT; t <= SIGQUIT; t++)
1417c478bd9Sstevel@tonic-gate 			if (sig[t-SIGINT] != SIG_IGN)
1427c478bd9Sstevel@tonic-gate 				sigset(t, SIG_DFL);
1437c478bd9Sstevel@tonic-gate 		execlp(Shell, Shell, (char *)0);
1447c478bd9Sstevel@tonic-gate 		perror(Shell);
1457c478bd9Sstevel@tonic-gate 		_exit(1);
1467c478bd9Sstevel@tonic-gate 	}
1477c478bd9Sstevel@tonic-gate 	while (wait(0) != p)
1487c478bd9Sstevel@tonic-gate 		;
1497c478bd9Sstevel@tonic-gate 	if (p == (pid_t)-1)
1507c478bd9Sstevel@tonic-gate 		perror("fork");
1517c478bd9Sstevel@tonic-gate 	for (t = SIGINT; t <= SIGQUIT; t++)
1527c478bd9Sstevel@tonic-gate 		sigset(t, sig[t-SIGINT]);
1537c478bd9Sstevel@tonic-gate 	putchar('\n');
1547c478bd9Sstevel@tonic-gate 	return(0);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * Expand the shell escape by expanding unescaped !'s into the
1597c478bd9Sstevel@tonic-gate  * last issued command where possible.
1607c478bd9Sstevel@tonic-gate  */
161*55fea89dSDan Cross static int
bangexp(char * str)1627c478bd9Sstevel@tonic-gate bangexp(char *str)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate 	char bangbuf[BUFSIZ];
16546d64c14SToomas Soome 	char *cp, *cp2;
16646d64c14SToomas Soome 	int n;
1677c478bd9Sstevel@tonic-gate 	int changed = 0;
1687c478bd9Sstevel@tonic-gate 	int bangit = (value("bang")!=NOSTR);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	cp = str;
1717c478bd9Sstevel@tonic-gate 	cp2 = bangbuf;
1727c478bd9Sstevel@tonic-gate 	n = BUFSIZ;
1737c478bd9Sstevel@tonic-gate 	while (*cp) {
1747c478bd9Sstevel@tonic-gate 		if (*cp=='!' && bangit) {
1757c478bd9Sstevel@tonic-gate 			if (n < (int)strlen(lastbang)) {
1767c478bd9Sstevel@tonic-gate overf:
1777c478bd9Sstevel@tonic-gate 				printf(gettext("Command buffer overflow\n"));
1787c478bd9Sstevel@tonic-gate 				return(-1);
1797c478bd9Sstevel@tonic-gate 			}
1807c478bd9Sstevel@tonic-gate 			changed++;
1817c478bd9Sstevel@tonic-gate 			strcpy(cp2, lastbang);
1827c478bd9Sstevel@tonic-gate 			cp2 += strlen(lastbang);
1837c478bd9Sstevel@tonic-gate 			n -= strlen(lastbang);
1847c478bd9Sstevel@tonic-gate 			cp++;
1857c478bd9Sstevel@tonic-gate 			continue;
1867c478bd9Sstevel@tonic-gate 		}
1877c478bd9Sstevel@tonic-gate 		if (*cp == '\\' && cp[1] == '!') {
1887c478bd9Sstevel@tonic-gate 			if (--n <= 1)
1897c478bd9Sstevel@tonic-gate 				goto overf;
1907c478bd9Sstevel@tonic-gate 			*cp2++ = '!';
1917c478bd9Sstevel@tonic-gate 			cp += 2;
1927c478bd9Sstevel@tonic-gate 			changed++;
1937c478bd9Sstevel@tonic-gate 		}
1947c478bd9Sstevel@tonic-gate 		if (--n <= 1)
1957c478bd9Sstevel@tonic-gate 			goto overf;
1967c478bd9Sstevel@tonic-gate 		*cp2++ = *cp++;
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 	*cp2 = 0;
1997c478bd9Sstevel@tonic-gate 	if (changed) {
2007c478bd9Sstevel@tonic-gate 		printf("!%s\n", bangbuf);
2017c478bd9Sstevel@tonic-gate 		fflush(stdout);
2027c478bd9Sstevel@tonic-gate 	}
2037c478bd9Sstevel@tonic-gate 	nstrcpy(str, BUFSIZ, bangbuf);
2047c478bd9Sstevel@tonic-gate 	nstrcpy(lastbang, sizeof (lastbang), bangbuf);
2057c478bd9Sstevel@tonic-gate 	return(0);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * Print out a nice help message from some file or another.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate 
212*55fea89dSDan Cross int
help(void)2137c478bd9Sstevel@tonic-gate help(void)
2147c478bd9Sstevel@tonic-gate {
2156c83d09fSrobbin 	int c;
21646d64c14SToomas Soome 	FILE *f;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	if ((f = fopen(HELPFILE, "r")) == NULL) {
2197c478bd9Sstevel@tonic-gate 		printf(gettext("No help just now.\n"));
2207c478bd9Sstevel@tonic-gate 		return(1);
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 	while ((c = getc(f)) != EOF)
2237c478bd9Sstevel@tonic-gate 		putchar(c);
2247c478bd9Sstevel@tonic-gate 	fclose(f);
2257c478bd9Sstevel@tonic-gate 	return(0);
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate /*
2297c478bd9Sstevel@tonic-gate  * Change user's working directory.
2307c478bd9Sstevel@tonic-gate  */
2317c478bd9Sstevel@tonic-gate 
232*55fea89dSDan Cross int
schdir(char * str)2337c478bd9Sstevel@tonic-gate schdir(char *str)
2347c478bd9Sstevel@tonic-gate {
23546d64c14SToomas Soome 	char *cp;
2367c478bd9Sstevel@tonic-gate 	char cwd[PATHSIZE], file[PATHSIZE];
2377c478bd9Sstevel@tonic-gate 	static char efile[PATHSIZE];
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	for (cp = str; *cp == ' '; cp++)
2407c478bd9Sstevel@tonic-gate 		;
2417c478bd9Sstevel@tonic-gate 	if (*cp == '\0')
2427c478bd9Sstevel@tonic-gate 		cp = homedir;
2437c478bd9Sstevel@tonic-gate 	else
2447c478bd9Sstevel@tonic-gate 		if ((cp = expand(cp)) == NOSTR)
2457c478bd9Sstevel@tonic-gate 			return(1);
2467c478bd9Sstevel@tonic-gate 	if (editfile != NOSTR && (*editfile != '/' || mailname[0] != '/')) {
2477c478bd9Sstevel@tonic-gate 		if (getcwd(cwd, (int)sizeof (cwd)) == 0) {
2487c478bd9Sstevel@tonic-gate 			fprintf(stderr,
2497c478bd9Sstevel@tonic-gate 			    gettext("Can't get current directory: %s\n"), cwd);
2507c478bd9Sstevel@tonic-gate 			return(1);
2517c478bd9Sstevel@tonic-gate 		}
2527c478bd9Sstevel@tonic-gate 	}
2537c478bd9Sstevel@tonic-gate 	if (chdir(cp) < 0) {
2547c478bd9Sstevel@tonic-gate 		perror(cp);
2557c478bd9Sstevel@tonic-gate 		return(1);
2567c478bd9Sstevel@tonic-gate 	}
2577c478bd9Sstevel@tonic-gate 	/*
2587c478bd9Sstevel@tonic-gate 	 * Convert previously relative names to absolute names.
2597c478bd9Sstevel@tonic-gate 	 */
2607c478bd9Sstevel@tonic-gate 	if (editfile != NOSTR && *editfile != '/') {
2617c478bd9Sstevel@tonic-gate 		snprintf(file, sizeof (file), "%s/%s", cwd, editfile);
2627c478bd9Sstevel@tonic-gate 		nstrcpy(efile, sizeof (efile), file);
2637c478bd9Sstevel@tonic-gate 		editfile = efile;
2647c478bd9Sstevel@tonic-gate 	}
2657c478bd9Sstevel@tonic-gate 	if (mailname[0] != '/') {
2667c478bd9Sstevel@tonic-gate 		snprintf(file, sizeof (file), "%s/%s", cwd, mailname);
2677c478bd9Sstevel@tonic-gate 		nstrcpy(mailname, PATHSIZE, file);
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 	return(0);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate /*
2737c478bd9Sstevel@tonic-gate  * Two versions of reply.  Reply to all names in message or reply
2747c478bd9Sstevel@tonic-gate  * to only sender of message, depending on setting of "replyall".
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate 
277*55fea89dSDan Cross int
respond(int * msgvec)2787c478bd9Sstevel@tonic-gate respond(int *msgvec)
2797c478bd9Sstevel@tonic-gate {
2807c478bd9Sstevel@tonic-gate 	if (reply2sender())
2817c478bd9Sstevel@tonic-gate 		return(resp1(msgvec, 0));
2827c478bd9Sstevel@tonic-gate 	else
2837c478bd9Sstevel@tonic-gate 		return(Resp1(msgvec, 0));
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
286*55fea89dSDan Cross int
followup(int * msgvec)2877c478bd9Sstevel@tonic-gate followup(int *msgvec)
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate 	if (reply2sender())
2907c478bd9Sstevel@tonic-gate 		return(resp1(msgvec, 1));
2917c478bd9Sstevel@tonic-gate 	else
2927c478bd9Sstevel@tonic-gate 		return(Resp1(msgvec, 1));
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
295*55fea89dSDan Cross int
replyall(int * msgvec)2967c478bd9Sstevel@tonic-gate replyall(int *msgvec)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	return(resp1(msgvec, 0));
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate 
301*55fea89dSDan Cross static int
resp1(int * msgvec,int useauthor)3027c478bd9Sstevel@tonic-gate resp1(int *msgvec, int useauthor)
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate 	struct message *mp;
3057c478bd9Sstevel@tonic-gate 	char *cp, *buf, *rcv, *skin_rcv, *reply2, **ap, *returnaddr;
3067c478bd9Sstevel@tonic-gate 	struct name *np;
3077c478bd9Sstevel@tonic-gate 	struct header head;
3087c478bd9Sstevel@tonic-gate 	char mylocalname[BUFSIZ], mydomname[BUFSIZ];
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	if (msgvec[1] != 0) {
3117c478bd9Sstevel@tonic-gate 		printf(gettext(
3127c478bd9Sstevel@tonic-gate 		    "Sorry, can't reply to multiple messages at once\n"));
3137c478bd9Sstevel@tonic-gate 		return(1);
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 	snprintf(mydomname, sizeof (mydomname), "%s@%s", myname, domain);
3167c478bd9Sstevel@tonic-gate 	snprintf(mylocalname, sizeof (mylocalname), "%s@%s", myname, host);
3177c478bd9Sstevel@tonic-gate 	returnaddr = value("returnaddr");
318*55fea89dSDan Cross 
3197c478bd9Sstevel@tonic-gate 	mp = &message[msgvec[0] - 1];
3207c478bd9Sstevel@tonic-gate 	dot = mp;
3217c478bd9Sstevel@tonic-gate 	reply2 = replyto(mp, &rcv);
3227c478bd9Sstevel@tonic-gate 	cp = skin(hfield("to", mp, addto));
3237c478bd9Sstevel@tonic-gate 	if (cp != NOSTR) {
3247c478bd9Sstevel@tonic-gate 		buf = (char *)salloc(strlen(reply2) + strlen(cp) + 2);
3257c478bd9Sstevel@tonic-gate 		strcpy(buf, reply2);
3267c478bd9Sstevel@tonic-gate 		strcat(buf, " ");
3277c478bd9Sstevel@tonic-gate 		strcat(buf, cp);
3287c478bd9Sstevel@tonic-gate 	} else
3297c478bd9Sstevel@tonic-gate 		buf = reply2;
3307c478bd9Sstevel@tonic-gate 	np = elide(extract(buf, GTO));
3317c478bd9Sstevel@tonic-gate #ifdef	OPTIM
3327c478bd9Sstevel@tonic-gate 	/* rcv = netrename(rcv); */
3337c478bd9Sstevel@tonic-gate #endif	/* OPTIM */
3347c478bd9Sstevel@tonic-gate 	/*
3357c478bd9Sstevel@tonic-gate 	 * Delete my name from the reply list,
3367c478bd9Sstevel@tonic-gate 	 * and with it, all my alternate names.
3377c478bd9Sstevel@tonic-gate 	 */
3387c478bd9Sstevel@tonic-gate 	skin_rcv = skin(rcv);
3397c478bd9Sstevel@tonic-gate 	mapf(np, skin_rcv);
3407c478bd9Sstevel@tonic-gate 	np = delname(np, myname);
3417c478bd9Sstevel@tonic-gate 	np = delname(np, mylocalname);
3427c478bd9Sstevel@tonic-gate 	np = delname(np, mydomname);
3437c478bd9Sstevel@tonic-gate 	if (returnaddr && *returnaddr)
3447c478bd9Sstevel@tonic-gate 		np = delname(np, returnaddr);
3457c478bd9Sstevel@tonic-gate 	if (altnames != 0)
3467c478bd9Sstevel@tonic-gate 		for (ap = altnames; *ap; ap++)
3477c478bd9Sstevel@tonic-gate 			np = delname(np, *ap);
3487c478bd9Sstevel@tonic-gate 	head.h_seq = 1;
3497c478bd9Sstevel@tonic-gate 	cp = detract(np, 0);
3507c478bd9Sstevel@tonic-gate 	if (cp == NOSTR) {
3517c478bd9Sstevel@tonic-gate 		if (reply2)
3527c478bd9Sstevel@tonic-gate 			cp = unuucp(reply2);
3537c478bd9Sstevel@tonic-gate 		else
3547c478bd9Sstevel@tonic-gate 			cp = unuucp(rcv);
3557c478bd9Sstevel@tonic-gate 	}
3567c478bd9Sstevel@tonic-gate 	head.h_to = cp;
3577c478bd9Sstevel@tonic-gate 	head.h_subject = hfield("subject", mp, addone);
3587c478bd9Sstevel@tonic-gate 	if (head.h_subject == NOSTR)
3597c478bd9Sstevel@tonic-gate 		head.h_subject = hfield("subj", mp, addone);
3607c478bd9Sstevel@tonic-gate 	head.h_subject = reedit(head.h_subject);
3617c478bd9Sstevel@tonic-gate 	head.h_cc = NOSTR;
3627c478bd9Sstevel@tonic-gate 	cp = skin(hfield("cc", mp, addto));
3637c478bd9Sstevel@tonic-gate 	if (cp != NOSTR) {
3647c478bd9Sstevel@tonic-gate 		np = elide(extract(cp, GCC));
3657c478bd9Sstevel@tonic-gate 		mapf(np, skin_rcv);
3667c478bd9Sstevel@tonic-gate 		np = delname(np, myname);
3677c478bd9Sstevel@tonic-gate 		np = delname(np, mylocalname);
3687c478bd9Sstevel@tonic-gate 		np = delname(np, mydomname);
3697c478bd9Sstevel@tonic-gate 		if (returnaddr && *returnaddr)
3707c478bd9Sstevel@tonic-gate 			np = delname(np, returnaddr);
3717c478bd9Sstevel@tonic-gate 		np = delname(np, skin_rcv);
3727c478bd9Sstevel@tonic-gate 		if (altnames != 0)
3737c478bd9Sstevel@tonic-gate 			for (ap = altnames; *ap; ap++)
3747c478bd9Sstevel@tonic-gate 				np = delname(np, *ap);
3757c478bd9Sstevel@tonic-gate 		head.h_cc = detract(np, 0);
3767c478bd9Sstevel@tonic-gate 	}
3777c478bd9Sstevel@tonic-gate 	head.h_bcc = NOSTR;
3787c478bd9Sstevel@tonic-gate 	head.h_defopt = NOSTR;
3797c478bd9Sstevel@tonic-gate 	head.h_others = NOSTRPTR;
3807c478bd9Sstevel@tonic-gate 	mail1(&head, useauthor, useauthor ? rcv : NOSTR);
3817c478bd9Sstevel@tonic-gate 	return(0);
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate 
384*55fea89dSDan Cross void
getrecf(char * buf,char * recfile,int useauthor,int sz_recfile)3857c478bd9Sstevel@tonic-gate getrecf(char *buf, char *recfile, int useauthor, int sz_recfile)
3867c478bd9Sstevel@tonic-gate {
38746d64c14SToomas Soome 	char *bp, *cp;
38846d64c14SToomas Soome 	char *recf = recfile;
38946d64c14SToomas Soome 	int folderize;
3907c478bd9Sstevel@tonic-gate 	char fldr[BUFSIZ];
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	folderize = (value("outfolder")!=NOSTR && getfold(fldr) == 0);
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 	if (useauthor) {
3957c478bd9Sstevel@tonic-gate 		if (folderize)
3967c478bd9Sstevel@tonic-gate 			*recf++ = '+';
3977c478bd9Sstevel@tonic-gate 		if (debug) fprintf(stderr, "buf='%s'\n", buf);
3987c478bd9Sstevel@tonic-gate 		for (bp=skin(buf), cp=recf; *bp && !any(*bp, ", "); bp++) {
3997c478bd9Sstevel@tonic-gate 			if (*bp=='!')
4007c478bd9Sstevel@tonic-gate 				cp = recf;
4017c478bd9Sstevel@tonic-gate 			else
4027c478bd9Sstevel@tonic-gate 				*cp++ = *bp;
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 			if (cp >= &recfile[sz_recfile - 1]) {
4057c478bd9Sstevel@tonic-gate 				printf(gettext("File name buffer overflow\n"));
4067c478bd9Sstevel@tonic-gate 				break;
4077c478bd9Sstevel@tonic-gate 			}
4087c478bd9Sstevel@tonic-gate 		}
4097c478bd9Sstevel@tonic-gate 		*cp = '\0';
4107c478bd9Sstevel@tonic-gate 		if (cp==recf)
4117c478bd9Sstevel@tonic-gate 			*recfile = '\0';
4127c478bd9Sstevel@tonic-gate 		/* now strip off any Internet host names */
4137c478bd9Sstevel@tonic-gate 		if ((cp = strchr(recf, '%')) == NOSTR)
4147c478bd9Sstevel@tonic-gate 			cp = strchr(recf, '@');
4157c478bd9Sstevel@tonic-gate 		if (cp != NOSTR)
4167c478bd9Sstevel@tonic-gate 			*cp = '\0';
4177c478bd9Sstevel@tonic-gate 	} else {
4187c478bd9Sstevel@tonic-gate 		if (cp = value("record")) {
4197c478bd9Sstevel@tonic-gate 			int sz = PATHSIZE;
4207c478bd9Sstevel@tonic-gate 			if (folderize && *cp!='+' && *cp!='/'
4217c478bd9Sstevel@tonic-gate 			 && *safeexpand(cp)!='/') {
4227c478bd9Sstevel@tonic-gate 				*recf++ = '+';
4237c478bd9Sstevel@tonic-gate 				sz--;
4247c478bd9Sstevel@tonic-gate 			}
4257c478bd9Sstevel@tonic-gate 			nstrcpy(recf, sz, cp);
4267c478bd9Sstevel@tonic-gate 		} else
4277c478bd9Sstevel@tonic-gate 			*recf = '\0';
4287c478bd9Sstevel@tonic-gate 	}
4297c478bd9Sstevel@tonic-gate 	if (debug) fprintf(stderr, "recfile='%s'\n", recfile);
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * Modify the subject we are replying to to begin with Re: if
4347c478bd9Sstevel@tonic-gate  * it does not already.
4357c478bd9Sstevel@tonic-gate  */
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate static char *
reedit(char * subj)4387c478bd9Sstevel@tonic-gate reedit(char *subj)
4397c478bd9Sstevel@tonic-gate {
4407c478bd9Sstevel@tonic-gate 	char sbuf[10];
44146d64c14SToomas Soome 	char *newsubj;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	if (subj == NOSTR)
4447c478bd9Sstevel@tonic-gate 		return(NOSTR);
4457c478bd9Sstevel@tonic-gate 	strncpy(sbuf, subj, 3);
4467c478bd9Sstevel@tonic-gate 	sbuf[3] = 0;
4477c478bd9Sstevel@tonic-gate 	if (icequal(sbuf, "re:"))
4487c478bd9Sstevel@tonic-gate 		return(subj);
4497c478bd9Sstevel@tonic-gate 	newsubj = (char *)salloc((unsigned)(strlen(subj) + 5));
4507c478bd9Sstevel@tonic-gate 	sprintf(newsubj, "Re: %s", subj);
4517c478bd9Sstevel@tonic-gate 	return(newsubj);
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate /*
4557c478bd9Sstevel@tonic-gate  * Preserve the named messages, so that they will be sent
4567c478bd9Sstevel@tonic-gate  * back to the system mailbox.
4577c478bd9Sstevel@tonic-gate  */
4587c478bd9Sstevel@tonic-gate 
459*55fea89dSDan Cross int
preserve(int * msgvec)4607c478bd9Sstevel@tonic-gate preserve(int *msgvec)
4617c478bd9Sstevel@tonic-gate {
46246d64c14SToomas Soome 	struct message *mp;
46346d64c14SToomas Soome 	int *ip, mesg;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	if (edit) {
4667c478bd9Sstevel@tonic-gate 		printf(gettext("Cannot \"preserve\" in edit mode\n"));
4677c478bd9Sstevel@tonic-gate 		return(1);
4687c478bd9Sstevel@tonic-gate 	}
46946d64c14SToomas Soome 	for (ip = msgvec; *ip != 0; ip++) {
4707c478bd9Sstevel@tonic-gate 		mesg = *ip;
4717c478bd9Sstevel@tonic-gate 		mp = &message[mesg-1];
4727c478bd9Sstevel@tonic-gate 		mp->m_flag |= MPRESERVE;
4737c478bd9Sstevel@tonic-gate 		mp->m_flag &= ~MBOX;
4747c478bd9Sstevel@tonic-gate 		dot = mp;
4757c478bd9Sstevel@tonic-gate 	}
4767c478bd9Sstevel@tonic-gate 	return(0);
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate /*
4807c478bd9Sstevel@tonic-gate  * Mark all given messages as unread.
4817c478bd9Sstevel@tonic-gate  */
482*55fea89dSDan Cross int
unread(int msgvec[])4837c478bd9Sstevel@tonic-gate unread(int msgvec[])
4847c478bd9Sstevel@tonic-gate {
48546d64c14SToomas Soome 	int *ip;
4867c478bd9Sstevel@tonic-gate 
48746d64c14SToomas Soome 	for (ip = msgvec; *ip != 0; ip++) {
4887c478bd9Sstevel@tonic-gate 		dot = &message[*ip-1];
4897c478bd9Sstevel@tonic-gate 		dot->m_flag &= ~(MREAD|MTOUCH);
4907c478bd9Sstevel@tonic-gate 		dot->m_flag |= MSTATUS;
4917c478bd9Sstevel@tonic-gate 	}
4927c478bd9Sstevel@tonic-gate 	return(0);
4937c478bd9Sstevel@tonic-gate }
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate /*
4967c478bd9Sstevel@tonic-gate  * Print the size of each message.
4977c478bd9Sstevel@tonic-gate  */
4987c478bd9Sstevel@tonic-gate 
499*55fea89dSDan Cross int
messize(int * msgvec)5007c478bd9Sstevel@tonic-gate messize(int *msgvec)
5017c478bd9Sstevel@tonic-gate {
50246d64c14SToomas Soome 	struct message *mp;
50346d64c14SToomas Soome 	int *ip, mesg;
5047c478bd9Sstevel@tonic-gate 
50546d64c14SToomas Soome 	for (ip = msgvec; *ip != 0; ip++) {
5067c478bd9Sstevel@tonic-gate 		mesg = *ip;
5077c478bd9Sstevel@tonic-gate 		mp = &message[mesg-1];
5087c478bd9Sstevel@tonic-gate 		dot = mp;
5097c478bd9Sstevel@tonic-gate 		printf("%d: %ld\n", mesg, mp->m_size);
5107c478bd9Sstevel@tonic-gate 	}
5117c478bd9Sstevel@tonic-gate 	return(0);
5127c478bd9Sstevel@tonic-gate }
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate /*
5157c478bd9Sstevel@tonic-gate  * Quit quickly.  If we are sourcing, just pop the input level
5167c478bd9Sstevel@tonic-gate  * by returning an error.
5177c478bd9Sstevel@tonic-gate  */
5187c478bd9Sstevel@tonic-gate 
519*55fea89dSDan Cross int
rexit(int e)5207c478bd9Sstevel@tonic-gate rexit(int e)
5217c478bd9Sstevel@tonic-gate {
5227c478bd9Sstevel@tonic-gate 	if (sourcing)
5237c478bd9Sstevel@tonic-gate 		return(1);
5247c478bd9Sstevel@tonic-gate 	if (Tflag != NOSTR)
5257c478bd9Sstevel@tonic-gate 		close(creat(Tflag, TEMPPERM));
5267c478bd9Sstevel@tonic-gate 	if (!edit)
5277c478bd9Sstevel@tonic-gate 		Verhogen();
5287c478bd9Sstevel@tonic-gate 	exit(e ? e : rpterr);
5297c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
5307c478bd9Sstevel@tonic-gate 	return (0);	/* shut up lint and CC */
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate /*
5347c478bd9Sstevel@tonic-gate  * Set or display a variable value.  Syntax is similar to that
5357c478bd9Sstevel@tonic-gate  * of csh.
5367c478bd9Sstevel@tonic-gate  */
5377c478bd9Sstevel@tonic-gate 
538*55fea89dSDan Cross int
set(char ** arglist)5397c478bd9Sstevel@tonic-gate set(char **arglist)
5407c478bd9Sstevel@tonic-gate {
54146d64c14SToomas Soome 	struct var *vp;
54246d64c14SToomas Soome 	char *cp, *cp2;
5437c478bd9Sstevel@tonic-gate 	char varbuf[BUFSIZ], **ap, **p;
5447c478bd9Sstevel@tonic-gate 	int errs, h, s;
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	if (argcount(arglist) == 0) {
5477c478bd9Sstevel@tonic-gate 		for (h = 0, s = 1; h < HSHSIZE; h++)
5487c478bd9Sstevel@tonic-gate 			for (vp = variables[h]; vp != NOVAR; vp = vp->v_link)
5497c478bd9Sstevel@tonic-gate 				s++;
5507c478bd9Sstevel@tonic-gate 		ap = (char **) salloc(s * sizeof *ap);
5517c478bd9Sstevel@tonic-gate 		for (h = 0, p = ap; h < HSHSIZE; h++)
5527c478bd9Sstevel@tonic-gate 			for (vp = variables[h]; vp != NOVAR; vp = vp->v_link)
5537c478bd9Sstevel@tonic-gate 				*p++ = vp->v_name;
5547c478bd9Sstevel@tonic-gate 		*p = NOSTR;
5557c478bd9Sstevel@tonic-gate 		sort(ap);
5567c478bd9Sstevel@tonic-gate 		for (p = ap; *p != NOSTR; p++)
5577c478bd9Sstevel@tonic-gate 			if (((cp = value(*p)) != 0) && *cp)
5587c478bd9Sstevel@tonic-gate 				printf("%s=\"%s\"\n", *p, cp);
5597c478bd9Sstevel@tonic-gate 			else
5607c478bd9Sstevel@tonic-gate 				printf("%s\n", *p);
5617c478bd9Sstevel@tonic-gate 		return(0);
5627c478bd9Sstevel@tonic-gate 	}
5637c478bd9Sstevel@tonic-gate 	errs = 0;
5647c478bd9Sstevel@tonic-gate 	for (ap = arglist; *ap != NOSTR; ap++) {
5657c478bd9Sstevel@tonic-gate 		cp = *ap;
5667c478bd9Sstevel@tonic-gate 		cp2 = varbuf;
5677c478bd9Sstevel@tonic-gate 		while (*cp != '=' && *cp != '\0')
5687c478bd9Sstevel@tonic-gate 			*cp2++ = *cp++;
5697c478bd9Sstevel@tonic-gate 		*cp2 = '\0';
5707c478bd9Sstevel@tonic-gate 		if (*cp == '\0')
5717c478bd9Sstevel@tonic-gate 			cp = "";
5727c478bd9Sstevel@tonic-gate 		else
5737c478bd9Sstevel@tonic-gate 			cp++;
5747c478bd9Sstevel@tonic-gate 		if (equal(varbuf, "")) {
5757c478bd9Sstevel@tonic-gate 			printf(gettext("Non-null variable name required\n"));
5767c478bd9Sstevel@tonic-gate 			errs++;
5777c478bd9Sstevel@tonic-gate 			continue;
5787c478bd9Sstevel@tonic-gate 		}
5797c478bd9Sstevel@tonic-gate 		assign(varbuf, cp);
5807c478bd9Sstevel@tonic-gate 	}
5817c478bd9Sstevel@tonic-gate 	return(errs);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate /*
5857c478bd9Sstevel@tonic-gate  * Unset a bunch of variable values.
5867c478bd9Sstevel@tonic-gate  */
5877c478bd9Sstevel@tonic-gate 
588*55fea89dSDan Cross int
unset(char ** arglist)5897c478bd9Sstevel@tonic-gate unset(char **arglist)
5907c478bd9Sstevel@tonic-gate {
59146d64c14SToomas Soome 	int errs;
59246d64c14SToomas Soome 	char **ap;
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	errs = 0;
5957c478bd9Sstevel@tonic-gate 	for (ap = arglist; *ap != NOSTR; ap++)
5967c478bd9Sstevel@tonic-gate 		errs += deassign(*ap);
5977c478bd9Sstevel@tonic-gate 	return(errs);
5987c478bd9Sstevel@tonic-gate }
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate  * Add users to a group.
6027c478bd9Sstevel@tonic-gate  */
6037c478bd9Sstevel@tonic-gate 
604*55fea89dSDan Cross int
group(char ** argv)6057c478bd9Sstevel@tonic-gate group(char **argv)
6067c478bd9Sstevel@tonic-gate {
60746d64c14SToomas Soome 	struct grouphead *gh;
60846d64c14SToomas Soome 	struct mgroup *gp;
60946d64c14SToomas Soome 	int h;
6107c478bd9Sstevel@tonic-gate 	int s;
6117c478bd9Sstevel@tonic-gate 	char **ap, *gname, **p;
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate 	if (argcount(argv) == 0) {
6147c478bd9Sstevel@tonic-gate 		for (h = 0, s = 1; h < HSHSIZE; h++)
6157c478bd9Sstevel@tonic-gate 			for (gh = groups[h]; gh != NOGRP; gh = gh->g_link)
6167c478bd9Sstevel@tonic-gate 				s++;
6177c478bd9Sstevel@tonic-gate 		ap = (char **) salloc(s * sizeof *ap);
6187c478bd9Sstevel@tonic-gate 		for (h = 0, p = ap; h < HSHSIZE; h++)
6197c478bd9Sstevel@tonic-gate 			for (gh = groups[h]; gh != NOGRP; gh = gh->g_link)
6207c478bd9Sstevel@tonic-gate 				*p++ = gh->g_name;
6217c478bd9Sstevel@tonic-gate 		*p = NOSTR;
6227c478bd9Sstevel@tonic-gate 		sort(ap);
6237c478bd9Sstevel@tonic-gate 		for (p = ap; *p != NOSTR; p++)
6247c478bd9Sstevel@tonic-gate 			printgroup(*p);
6257c478bd9Sstevel@tonic-gate 		return(0);
6267c478bd9Sstevel@tonic-gate 	}
6277c478bd9Sstevel@tonic-gate 	if (argcount(argv) == 1) {
6287c478bd9Sstevel@tonic-gate 		printgroup(*argv);
6297c478bd9Sstevel@tonic-gate 		return(0);
6307c478bd9Sstevel@tonic-gate 	}
6317c478bd9Sstevel@tonic-gate 	gname = *argv;
6327c478bd9Sstevel@tonic-gate 	h = hash(gname);
6337c478bd9Sstevel@tonic-gate 	if ((gh = findgroup(gname)) == NOGRP) {
6347c478bd9Sstevel@tonic-gate 		if ((gh = (struct grouphead *)
6357c478bd9Sstevel@tonic-gate 		    calloc(sizeof (*gh), 1)) == NULL) {
6367c478bd9Sstevel@tonic-gate 			panic("Failed to allocate memory for group");
6377c478bd9Sstevel@tonic-gate 	}
6387c478bd9Sstevel@tonic-gate 		gh->g_name = vcopy(gname);
6397c478bd9Sstevel@tonic-gate 		gh->g_list = NOGE;
6407c478bd9Sstevel@tonic-gate 		gh->g_link = groups[h];
6417c478bd9Sstevel@tonic-gate 		groups[h] = gh;
6427c478bd9Sstevel@tonic-gate 	}
6437c478bd9Sstevel@tonic-gate 
6447c478bd9Sstevel@tonic-gate 	/*
6457c478bd9Sstevel@tonic-gate 	 * Insert names from the command list into the group.
6467c478bd9Sstevel@tonic-gate 	 * Who cares if there are duplicates?  They get tossed
6477c478bd9Sstevel@tonic-gate 	 * later anyway.
6487c478bd9Sstevel@tonic-gate 	 */
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 	for (ap = argv+1; *ap != NOSTR; ap++) {
6517c478bd9Sstevel@tonic-gate 		if ((gp = (struct mgroup *)
6527c478bd9Sstevel@tonic-gate 		    calloc(sizeof (*gp), 1)) == NULL) {
6537c478bd9Sstevel@tonic-gate 			panic("Failed to allocate memory for group");
6547c478bd9Sstevel@tonic-gate 	}
6557c478bd9Sstevel@tonic-gate 	gp->ge_name = vcopy(*ap);
6567c478bd9Sstevel@tonic-gate 		gp->ge_link = gh->g_list;
6577c478bd9Sstevel@tonic-gate 		gh->g_list = gp;
6587c478bd9Sstevel@tonic-gate 	}
6597c478bd9Sstevel@tonic-gate 	return(0);
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate /*
6637c478bd9Sstevel@tonic-gate  * Remove users from a group.
6647c478bd9Sstevel@tonic-gate  */
6657c478bd9Sstevel@tonic-gate 
666*55fea89dSDan Cross int
ungroup(char ** argv)6677c478bd9Sstevel@tonic-gate ungroup(char **argv)
6687c478bd9Sstevel@tonic-gate {
66946d64c14SToomas Soome 	struct grouphead *gh, **ghp;
67046d64c14SToomas Soome 	struct mgroup *gp, *gpnext;
67146d64c14SToomas Soome 	int h;
6727c478bd9Sstevel@tonic-gate 	char **ap, *gname;
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	if (argcount(argv) == 0) {
6757c478bd9Sstevel@tonic-gate 		printf("Must specify alias or group to remove\n");
6767c478bd9Sstevel@tonic-gate 		return(1);
6777c478bd9Sstevel@tonic-gate 	}
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	/*
6807c478bd9Sstevel@tonic-gate 	 * Remove names on the command list from the group list.
6817c478bd9Sstevel@tonic-gate 	 */
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	for (ap = argv; *ap != NOSTR; ap++) {
6847c478bd9Sstevel@tonic-gate 		gname = *ap;
6857c478bd9Sstevel@tonic-gate 		h = hash(gname);
6867c478bd9Sstevel@tonic-gate 		for (ghp = &groups[h]; *ghp != NOGRP; ghp = &((*ghp)->g_link)) {
6877c478bd9Sstevel@tonic-gate 			gh = *ghp;
6887c478bd9Sstevel@tonic-gate 			if (equal(gh->g_name, gname)) {
6897c478bd9Sstevel@tonic-gate 				/* remove from list */
6907c478bd9Sstevel@tonic-gate 				*ghp = gh->g_link;
6917c478bd9Sstevel@tonic-gate 				/* free each member of gorup */
6927c478bd9Sstevel@tonic-gate 				for (gp = gh->g_list; gp != NOGE; gp = gpnext) {
6937c478bd9Sstevel@tonic-gate 					gpnext = gp->ge_link;
6947c478bd9Sstevel@tonic-gate 					vfree(gp->ge_name);
6957c478bd9Sstevel@tonic-gate 					free(gp);
6967c478bd9Sstevel@tonic-gate 				}
6977c478bd9Sstevel@tonic-gate 				vfree(gh->g_name);
6987c478bd9Sstevel@tonic-gate 				free(gh);
6997c478bd9Sstevel@tonic-gate 				break;
7007c478bd9Sstevel@tonic-gate 			}
7017c478bd9Sstevel@tonic-gate 		}
7027c478bd9Sstevel@tonic-gate 	}
7037c478bd9Sstevel@tonic-gate 	return(0);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate /*
7077c478bd9Sstevel@tonic-gate  * Sort the passed string vecotor into ascending dictionary
7087c478bd9Sstevel@tonic-gate  * order.
7097c478bd9Sstevel@tonic-gate  */
7107c478bd9Sstevel@tonic-gate 
711*55fea89dSDan Cross static void
sort(char ** list)7127c478bd9Sstevel@tonic-gate sort(char **list)
7137c478bd9Sstevel@tonic-gate {
71446d64c14SToomas Soome 	char **ap;
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 	for (ap = list; *ap != NOSTR; ap++)
7177c478bd9Sstevel@tonic-gate 		;
7187c478bd9Sstevel@tonic-gate 	if (ap-list < 2)
7197c478bd9Sstevel@tonic-gate 		return;
7207c478bd9Sstevel@tonic-gate 	qsort((char *) list, (unsigned) (ap-list), sizeof *list, diction);
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate /*
7247c478bd9Sstevel@tonic-gate  * Do a dictionary order comparison of the arguments from
7257c478bd9Sstevel@tonic-gate  * qsort.
7267c478bd9Sstevel@tonic-gate  */
727*55fea89dSDan Cross static int
diction(const void * a,const void * b)7287c478bd9Sstevel@tonic-gate diction(const void *a, const void *b)
7297c478bd9Sstevel@tonic-gate {
7307c478bd9Sstevel@tonic-gate 	return(strcmp(*(char **)a, *(char **)b));
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate /*
7347c478bd9Sstevel@tonic-gate  * The do nothing command for comments.
7357c478bd9Sstevel@tonic-gate  */
7367c478bd9Sstevel@tonic-gate 
737*55fea89dSDan Cross int
7387c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
null(char *)7397c478bd9Sstevel@tonic-gate null(char *)
7407c478bd9Sstevel@tonic-gate #else
7417c478bd9Sstevel@tonic-gate /* ARGSUSED */
7427c478bd9Sstevel@tonic-gate null(char *s)
7437c478bd9Sstevel@tonic-gate #endif
7447c478bd9Sstevel@tonic-gate {
7457c478bd9Sstevel@tonic-gate 	return(0);
7467c478bd9Sstevel@tonic-gate }
7477c478bd9Sstevel@tonic-gate 
7487c478bd9Sstevel@tonic-gate /*
7497c478bd9Sstevel@tonic-gate  * Print out the current edit file, if we are editing.
7507c478bd9Sstevel@tonic-gate  * Otherwise, print the name of the person who's mail
7517c478bd9Sstevel@tonic-gate  * we are reading.
7527c478bd9Sstevel@tonic-gate  */
753*55fea89dSDan Cross int
file(char ** argv)7547c478bd9Sstevel@tonic-gate file(char **argv)
7557c478bd9Sstevel@tonic-gate {
75646d64c14SToomas Soome 	char *cp;
7577c478bd9Sstevel@tonic-gate 	int editing, mdot;
7587c478bd9Sstevel@tonic-gate 
7597c478bd9Sstevel@tonic-gate 	if (argv[0] == NOSTR) {
7607c478bd9Sstevel@tonic-gate 		mdot = newfileinfo(1);
7617c478bd9Sstevel@tonic-gate 		dot = &message[mdot - 1];
7627c478bd9Sstevel@tonic-gate 		return(0);
7637c478bd9Sstevel@tonic-gate 	}
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate 	/*
7667c478bd9Sstevel@tonic-gate 	 * Acker's!  Must switch to the new file.
7677c478bd9Sstevel@tonic-gate 	 * We use a funny interpretation --
7687c478bd9Sstevel@tonic-gate 	 *	# -- gets the previous file
7697c478bd9Sstevel@tonic-gate 	 *	% -- gets the invoker's post office box
7707c478bd9Sstevel@tonic-gate 	 *	%user -- gets someone else's post office box
7717c478bd9Sstevel@tonic-gate 	 *	& -- gets invoker's mbox file
7727c478bd9Sstevel@tonic-gate 	 *	string -- reads the given file
7737c478bd9Sstevel@tonic-gate 	 */
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 	cp = getfilename(argv[0], &editing);
7767c478bd9Sstevel@tonic-gate 	if (cp == NOSTR)
7777c478bd9Sstevel@tonic-gate 		return(-1);
7787c478bd9Sstevel@tonic-gate 	if (setfile(cp, editing)) {
7797c478bd9Sstevel@tonic-gate 		nstrcpy(origname, PATHSIZE, origprevfile);
7807c478bd9Sstevel@tonic-gate 		return(-1);
7817c478bd9Sstevel@tonic-gate 	}
7827c478bd9Sstevel@tonic-gate 	mdot = newfileinfo(1);
7837c478bd9Sstevel@tonic-gate 	dot = &message[mdot - 1];
7847c478bd9Sstevel@tonic-gate 	return(0);
7857c478bd9Sstevel@tonic-gate }
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate /*
7887c478bd9Sstevel@tonic-gate  * Evaluate the string given as a new mailbox name.
7897c478bd9Sstevel@tonic-gate  * Ultimately, we want this to support a number of meta characters.
7907c478bd9Sstevel@tonic-gate  * Possibly:
7917c478bd9Sstevel@tonic-gate  *	% -- for my system mail box
7927c478bd9Sstevel@tonic-gate  *	%user -- for user's system mail box
7937c478bd9Sstevel@tonic-gate  *	# -- for previous file
7947c478bd9Sstevel@tonic-gate  *	& -- get's invoker's mbox file
7957c478bd9Sstevel@tonic-gate  *	file name -- for any other file
7967c478bd9Sstevel@tonic-gate  */
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate static char *
getfilename(char * name,int * aedit)7997c478bd9Sstevel@tonic-gate getfilename(char *name, int *aedit)
8007c478bd9Sstevel@tonic-gate {
80146d64c14SToomas Soome 	char *cp;
8027c478bd9Sstevel@tonic-gate 	char savename[BUFSIZ];
8037c478bd9Sstevel@tonic-gate 	char oldmailname[BUFSIZ];
8047c478bd9Sstevel@tonic-gate 	char tmp[BUFSIZ];
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate 	/*
8077c478bd9Sstevel@tonic-gate 	 * Assume we will be in "edit file" mode, until
8087c478bd9Sstevel@tonic-gate 	 * proven wrong.
8097c478bd9Sstevel@tonic-gate 	 */
8107c478bd9Sstevel@tonic-gate 	*aedit = 1;
8117c478bd9Sstevel@tonic-gate 	switch (*name) {
8127c478bd9Sstevel@tonic-gate 	case '%':
8137c478bd9Sstevel@tonic-gate 		*aedit = 0;
8147c478bd9Sstevel@tonic-gate 		nstrcpy(prevfile, sizeof (prevfile), editfile);
8157c478bd9Sstevel@tonic-gate 		nstrcpy(origprevfile, sizeof (origprevfile), origname);
8167c478bd9Sstevel@tonic-gate 		if (name[1] != 0) {
8177c478bd9Sstevel@tonic-gate 			nstrcpy(oldmailname, sizeof (oldmailname), mailname);
8187c478bd9Sstevel@tonic-gate 			findmail(name+1);
8197c478bd9Sstevel@tonic-gate 			cp = savestr(mailname);
8207c478bd9Sstevel@tonic-gate 			nstrcpy(origname, PATHSIZE, cp);
8217c478bd9Sstevel@tonic-gate 			nstrcpy(mailname, PATHSIZE, oldmailname);
8227c478bd9Sstevel@tonic-gate 			return(cp);
8237c478bd9Sstevel@tonic-gate 		}
8247c478bd9Sstevel@tonic-gate 		nstrcpy(oldmailname, sizeof (oldmailname), mailname);
8257c478bd9Sstevel@tonic-gate 		findmail(NULL);
8267c478bd9Sstevel@tonic-gate 		cp = savestr(mailname);
8277c478bd9Sstevel@tonic-gate 		nstrcpy(mailname, PATHSIZE, oldmailname);
8287c478bd9Sstevel@tonic-gate 		nstrcpy(origname, PATHSIZE, cp);
8297c478bd9Sstevel@tonic-gate 		return(cp);
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 	case '#':
8327c478bd9Sstevel@tonic-gate 		if (name[1] != 0)
8337c478bd9Sstevel@tonic-gate 			goto regular;
8347c478bd9Sstevel@tonic-gate 		if (prevfile[0] == 0) {
8357c478bd9Sstevel@tonic-gate 			printf(gettext("No previous file\n"));
8367c478bd9Sstevel@tonic-gate 			return(NOSTR);
8377c478bd9Sstevel@tonic-gate 		}
8387c478bd9Sstevel@tonic-gate 		cp = savestr(prevfile);
8397c478bd9Sstevel@tonic-gate 		nstrcpy(prevfile, sizeof (prevfile), editfile);
8407c478bd9Sstevel@tonic-gate 		nstrcpy(tmp, sizeof (tmp), origname);
8417c478bd9Sstevel@tonic-gate 		nstrcpy(origname, PATHSIZE, origprevfile);
8427c478bd9Sstevel@tonic-gate 		nstrcpy(origprevfile, sizeof (origprevfile), tmp);
8437c478bd9Sstevel@tonic-gate 		return(cp);
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 	case '&':
8467c478bd9Sstevel@tonic-gate 		nstrcpy(prevfile, sizeof (prevfile), editfile);
8477c478bd9Sstevel@tonic-gate 		nstrcpy(origprevfile, sizeof (origprevfile), origname);
8487c478bd9Sstevel@tonic-gate 		if (name[1] == 0) {
8497c478bd9Sstevel@tonic-gate 			cp=Getf("MBOX");
8507c478bd9Sstevel@tonic-gate 			nstrcpy(origname, PATHSIZE, cp);
8517c478bd9Sstevel@tonic-gate 			return(cp);
8527c478bd9Sstevel@tonic-gate 		}
8530c5b3cb4SToomas Soome 		/* FALLTHROUGH */
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 	default:
8567c478bd9Sstevel@tonic-gate regular:
8577c478bd9Sstevel@tonic-gate 		nstrcpy(prevfile, sizeof (prevfile), editfile);
8587c478bd9Sstevel@tonic-gate 		nstrcpy(origprevfile, sizeof (origprevfile), origname);
8597c478bd9Sstevel@tonic-gate 		cp = safeexpand(name);
8607c478bd9Sstevel@tonic-gate 		nstrcpy(origname, PATHSIZE, cp);
8617c478bd9Sstevel@tonic-gate 		if (cp[0] != '/') {
8627c478bd9Sstevel@tonic-gate 			name = getcwd(NOSTR, PATHSIZE);
8637c478bd9Sstevel@tonic-gate 			nstrcat(name, PATHSIZE, "/");
8647c478bd9Sstevel@tonic-gate 			nstrcat(name, PATHSIZE, cp);
8657c478bd9Sstevel@tonic-gate 			cp = name;
8667c478bd9Sstevel@tonic-gate 		}
8677c478bd9Sstevel@tonic-gate 		return(cp);
8687c478bd9Sstevel@tonic-gate 	}
8697c478bd9Sstevel@tonic-gate }
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate /*
8727c478bd9Sstevel@tonic-gate  * Expand file names like echo
8737c478bd9Sstevel@tonic-gate  */
8747c478bd9Sstevel@tonic-gate 
875*55fea89dSDan Cross int
echo(char ** argv)87646d64c14SToomas Soome echo(char **argv)
8777c478bd9Sstevel@tonic-gate {
87846d64c14SToomas Soome 	char *cp;
8797c478bd9Sstevel@tonic-gate 	int neednl = 0;
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate 	while (*argv != NOSTR) {
8827c478bd9Sstevel@tonic-gate 		cp = *argv++;
8837c478bd9Sstevel@tonic-gate 		if ((cp = expand(cp)) != NOSTR) {
8847c478bd9Sstevel@tonic-gate 			neednl++;
8857c478bd9Sstevel@tonic-gate 			printf("%s", cp);
8867c478bd9Sstevel@tonic-gate 			if (*argv!=NOSTR)
8877c478bd9Sstevel@tonic-gate 				putchar(' ');
8887c478bd9Sstevel@tonic-gate 		}
8897c478bd9Sstevel@tonic-gate 	}
8907c478bd9Sstevel@tonic-gate 	if (neednl)
8917c478bd9Sstevel@tonic-gate 		putchar('\n');
8927c478bd9Sstevel@tonic-gate 	return(0);
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate /*
8967c478bd9Sstevel@tonic-gate  * Reply to a series of messages by simply mailing to the senders
8977c478bd9Sstevel@tonic-gate  * and not messing around with the To: and Cc: lists as in normal
8987c478bd9Sstevel@tonic-gate  * reply.
8997c478bd9Sstevel@tonic-gate  */
9007c478bd9Sstevel@tonic-gate 
901*55fea89dSDan Cross int
Respond(int * msgvec)9027c478bd9Sstevel@tonic-gate Respond(int *msgvec)
9037c478bd9Sstevel@tonic-gate {
9047c478bd9Sstevel@tonic-gate 	if (reply2sender())
9057c478bd9Sstevel@tonic-gate 		return(Resp1(msgvec, 0));
9067c478bd9Sstevel@tonic-gate 	else
9077c478bd9Sstevel@tonic-gate 		return(resp1(msgvec, 0));
9087c478bd9Sstevel@tonic-gate }
9097c478bd9Sstevel@tonic-gate 
910*55fea89dSDan Cross int
Followup(int * msgvec)9117c478bd9Sstevel@tonic-gate Followup(int *msgvec)
9127c478bd9Sstevel@tonic-gate {
9137c478bd9Sstevel@tonic-gate 	if (reply2sender())
9147c478bd9Sstevel@tonic-gate 		return(Resp1(msgvec, 1));
9157c478bd9Sstevel@tonic-gate 	else
9167c478bd9Sstevel@tonic-gate 		return(resp1(msgvec, 1));
9177c478bd9Sstevel@tonic-gate }
9187c478bd9Sstevel@tonic-gate 
919*55fea89dSDan Cross int
replysender(int * msgvec)9207c478bd9Sstevel@tonic-gate replysender(int *msgvec)
9217c478bd9Sstevel@tonic-gate {
9227c478bd9Sstevel@tonic-gate 	return(Resp1(msgvec, 0));
9237c478bd9Sstevel@tonic-gate }
9247c478bd9Sstevel@tonic-gate 
925*55fea89dSDan Cross static int
Resp1(int * msgvec,int useauthor)9267c478bd9Sstevel@tonic-gate Resp1(int *msgvec, int useauthor)
9277c478bd9Sstevel@tonic-gate {
9287c478bd9Sstevel@tonic-gate 	struct header head;
9297c478bd9Sstevel@tonic-gate 	struct message *mp;
93046d64c14SToomas Soome 	int s, *ap;
93146d64c14SToomas Soome 	char *cp, *cp2, *subject;
9327c478bd9Sstevel@tonic-gate 
9337c478bd9Sstevel@tonic-gate 	for (s = 0, ap = msgvec; *ap != 0; ap++) {
9347c478bd9Sstevel@tonic-gate 		mp = &message[*ap - 1];
9357c478bd9Sstevel@tonic-gate 		dot = mp;
9367c478bd9Sstevel@tonic-gate 		cp = replyto(mp, NOSTRPTR);
9377c478bd9Sstevel@tonic-gate 		s += strlen(cp) + 1;
9387c478bd9Sstevel@tonic-gate 	}
9397c478bd9Sstevel@tonic-gate 	if (s == 0)
9407c478bd9Sstevel@tonic-gate 		return(0);
9417c478bd9Sstevel@tonic-gate 	cp = (char *)salloc(s + 2);
9427c478bd9Sstevel@tonic-gate 	head.h_to = cp;
9437c478bd9Sstevel@tonic-gate 	for (ap = msgvec; *ap != 0; ap++) {
9447c478bd9Sstevel@tonic-gate 		mp = &message[*ap - 1];
9457c478bd9Sstevel@tonic-gate 		cp2 = replyto(mp, NOSTRPTR);
9467c478bd9Sstevel@tonic-gate 		cp = copy(cp2, cp);
9477c478bd9Sstevel@tonic-gate 		*cp++ = ' ';
9487c478bd9Sstevel@tonic-gate 	}
9497c478bd9Sstevel@tonic-gate 	*--cp = 0;
9507c478bd9Sstevel@tonic-gate 	mp = &message[msgvec[0] - 1];
9517c478bd9Sstevel@tonic-gate 	subject = hfield("subject", mp, addone);
9527c478bd9Sstevel@tonic-gate 	head.h_seq = 1;
9537c478bd9Sstevel@tonic-gate 	if (subject == NOSTR)
9547c478bd9Sstevel@tonic-gate 		subject = hfield("subj", mp, addone);
9557c478bd9Sstevel@tonic-gate 	head.h_subject = reedit(subject);
9567c478bd9Sstevel@tonic-gate 	if (subject != NOSTR)
9577c478bd9Sstevel@tonic-gate 		head.h_seq++;
9587c478bd9Sstevel@tonic-gate 	head.h_cc = NOSTR;
9597c478bd9Sstevel@tonic-gate 	head.h_bcc = NOSTR;
9607c478bd9Sstevel@tonic-gate 	head.h_defopt = NOSTR;
9617c478bd9Sstevel@tonic-gate 	head.h_others = NOSTRPTR;
9627c478bd9Sstevel@tonic-gate 	mail1(&head, useauthor, NOSTR);
9637c478bd9Sstevel@tonic-gate 	return(0);
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate /*
9677c478bd9Sstevel@tonic-gate  * Conditional commands.  These allow one to parameterize one's
9687c478bd9Sstevel@tonic-gate  * .mailrc and do some things if sending, others if receiving.
9697c478bd9Sstevel@tonic-gate  */
9707c478bd9Sstevel@tonic-gate 
971*55fea89dSDan Cross int
ifcmd(char ** argv)9727c478bd9Sstevel@tonic-gate ifcmd(char **argv)
9737c478bd9Sstevel@tonic-gate {
97446d64c14SToomas Soome 	char *cp;
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	if (cond != CANY) {
9777c478bd9Sstevel@tonic-gate 		printf(gettext("Illegal nested \"if\"\n"));
9787c478bd9Sstevel@tonic-gate 		return(1);
9797c478bd9Sstevel@tonic-gate 	}
9807c478bd9Sstevel@tonic-gate 	cond = CANY;
9817c478bd9Sstevel@tonic-gate 	cp = argv[0];
9827c478bd9Sstevel@tonic-gate 	switch (*cp) {
9837c478bd9Sstevel@tonic-gate 	case 'r': case 'R':
9847c478bd9Sstevel@tonic-gate 		cond = CRCV;
9857c478bd9Sstevel@tonic-gate 		break;
9867c478bd9Sstevel@tonic-gate 
9877c478bd9Sstevel@tonic-gate 	case 's': case 'S':
9887c478bd9Sstevel@tonic-gate 		cond = CSEND;
9897c478bd9Sstevel@tonic-gate 		break;
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate 	case 't': case 'T':
9927c478bd9Sstevel@tonic-gate 		cond = CTTY;
9937c478bd9Sstevel@tonic-gate 		break;
9947c478bd9Sstevel@tonic-gate 
9957c478bd9Sstevel@tonic-gate 	default:
9967c478bd9Sstevel@tonic-gate 		printf(gettext("Unrecognized if-keyword: \"%s\"\n"), cp);
9977c478bd9Sstevel@tonic-gate 		return(1);
9987c478bd9Sstevel@tonic-gate 	}
9997c478bd9Sstevel@tonic-gate 	return(0);
10007c478bd9Sstevel@tonic-gate }
10017c478bd9Sstevel@tonic-gate 
10027c478bd9Sstevel@tonic-gate /*
10037c478bd9Sstevel@tonic-gate  * Implement 'else'.  This is pretty simple -- we just
10047c478bd9Sstevel@tonic-gate  * flip over the conditional flag.
10057c478bd9Sstevel@tonic-gate  */
10067c478bd9Sstevel@tonic-gate 
1007*55fea89dSDan Cross int
elsecmd(void)10087c478bd9Sstevel@tonic-gate elsecmd(void)
10097c478bd9Sstevel@tonic-gate {
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate 	switch (cond) {
10127c478bd9Sstevel@tonic-gate 	case CANY:
10137c478bd9Sstevel@tonic-gate 		printf(gettext("\"Else\" without matching \"if\"\n"));
10147c478bd9Sstevel@tonic-gate 		return(1);
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate 	case CSEND:
10177c478bd9Sstevel@tonic-gate 		cond = CRCV;
10187c478bd9Sstevel@tonic-gate 		break;
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate 	case CRCV:
10217c478bd9Sstevel@tonic-gate 		cond = CSEND;
10227c478bd9Sstevel@tonic-gate 		break;
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate 	case CTTY:
10257c478bd9Sstevel@tonic-gate 		cond = CNOTTY;
10267c478bd9Sstevel@tonic-gate 		break;
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 	case CNOTTY:
10297c478bd9Sstevel@tonic-gate 		cond = CTTY;
10307c478bd9Sstevel@tonic-gate 		break;
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate 	default:
10337c478bd9Sstevel@tonic-gate 		printf(gettext("invalid condition encountered\n"));
10347c478bd9Sstevel@tonic-gate 		cond = CANY;
10357c478bd9Sstevel@tonic-gate 		break;
10367c478bd9Sstevel@tonic-gate 	}
10377c478bd9Sstevel@tonic-gate 	return(0);
10387c478bd9Sstevel@tonic-gate }
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate /*
10417c478bd9Sstevel@tonic-gate  * End of if statement.  Just set cond back to anything.
10427c478bd9Sstevel@tonic-gate  */
10437c478bd9Sstevel@tonic-gate 
1044*55fea89dSDan Cross int
endifcmd(void)10457c478bd9Sstevel@tonic-gate endifcmd(void)
10467c478bd9Sstevel@tonic-gate {
10477c478bd9Sstevel@tonic-gate 
10487c478bd9Sstevel@tonic-gate 	if (cond == CANY) {
10497c478bd9Sstevel@tonic-gate 		printf(gettext("\"Endif\" without matching \"if\"\n"));
10507c478bd9Sstevel@tonic-gate 		return(1);
10517c478bd9Sstevel@tonic-gate 	}
10527c478bd9Sstevel@tonic-gate 	cond = CANY;
10537c478bd9Sstevel@tonic-gate 	return(0);
10547c478bd9Sstevel@tonic-gate }
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate /*
10577c478bd9Sstevel@tonic-gate  * Set the list of alternate names.
10587c478bd9Sstevel@tonic-gate  */
1059*55fea89dSDan Cross int
alternates(char ** namelist)10607c478bd9Sstevel@tonic-gate alternates(char **namelist)
10617c478bd9Sstevel@tonic-gate {
106246d64c14SToomas Soome 	int c;
106346d64c14SToomas Soome 	char **ap, **ap2, *cp;
10647c478bd9Sstevel@tonic-gate 
10657c478bd9Sstevel@tonic-gate 	c = argcount(namelist) + 1;
10667c478bd9Sstevel@tonic-gate 	if (c == 1) {
10677c478bd9Sstevel@tonic-gate 		if (altnames == 0)
10687c478bd9Sstevel@tonic-gate 			return(0);
10697c478bd9Sstevel@tonic-gate 		for (ap = altnames; *ap; ap++)
10707c478bd9Sstevel@tonic-gate 			printf("%s ", *ap);
10717c478bd9Sstevel@tonic-gate 		printf("\n");
10727c478bd9Sstevel@tonic-gate 		return (0);
10737c478bd9Sstevel@tonic-gate 	}
10747c478bd9Sstevel@tonic-gate 	if (altnames != 0)
10757c478bd9Sstevel@tonic-gate 		free((char *)altnames);
10767c478bd9Sstevel@tonic-gate 	if ((altnames = (char **)
10777c478bd9Sstevel@tonic-gate 	    calloc((unsigned)c, sizeof (char *))) == NULL)
10787c478bd9Sstevel@tonic-gate 		panic("Failed to allocate memory");
10797c478bd9Sstevel@tonic-gate 	for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) {
10807c478bd9Sstevel@tonic-gate 		if ((cp = (char *)
10817c478bd9Sstevel@tonic-gate 		    calloc((unsigned)strlen(*ap) + 1, sizeof (char))) == NULL)
10827c478bd9Sstevel@tonic-gate 			panic("Failed to allocate memory");
10837c478bd9Sstevel@tonic-gate 		strcpy(cp, *ap);
10847c478bd9Sstevel@tonic-gate 		*ap2 = cp;
10857c478bd9Sstevel@tonic-gate 	}
10867c478bd9Sstevel@tonic-gate 	*ap2 = 0;
10877c478bd9Sstevel@tonic-gate 	return(0);
10887c478bd9Sstevel@tonic-gate }
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate /*
10917c478bd9Sstevel@tonic-gate  * Figure out who to reply to.
10927c478bd9Sstevel@tonic-gate  * Return the real sender in *f.
10937c478bd9Sstevel@tonic-gate  */
10947c478bd9Sstevel@tonic-gate static char *
replyto(struct message * mp,char ** f)10957c478bd9Sstevel@tonic-gate replyto(struct message *mp, char **f)
10967c478bd9Sstevel@tonic-gate {
10977c478bd9Sstevel@tonic-gate 	char *r, *rf;
10987c478bd9Sstevel@tonic-gate 
10997c478bd9Sstevel@tonic-gate 	if ((rf = skin(hfield("from", mp, addto)))==NOSTR)
11007c478bd9Sstevel@tonic-gate 		rf = skin(addto(NOSTR, nameof(mp)));
11017c478bd9Sstevel@tonic-gate 	if ((r = skin(hfield("reply-to", mp, addto)))==NOSTR)
11027c478bd9Sstevel@tonic-gate 		r = rf;
11037c478bd9Sstevel@tonic-gate 	if (f)
11047c478bd9Sstevel@tonic-gate 		*f = rf;
11057c478bd9Sstevel@tonic-gate 	return (r);
11067c478bd9Sstevel@tonic-gate }
11077c478bd9Sstevel@tonic-gate 
1108*55fea89dSDan Cross /*
11097c478bd9Sstevel@tonic-gate  * reply2sender - determine whether a "reply" command should reply to the
11107c478bd9Sstevel@tonic-gate  *                sender of the messages, or to all the recipients of the
1111*55fea89dSDan Cross  *                message.
11127c478bd9Sstevel@tonic-gate  *
11137c478bd9Sstevel@tonic-gate  *                With the advent of POSIX.2 compliance, this has become
11147c478bd9Sstevel@tonic-gate  *                a bit more complicated, and so should be done in one
11157c478bd9Sstevel@tonic-gate  *                place, for all to use.
11167c478bd9Sstevel@tonic-gate  */
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate static int
reply2sender(void)11197c478bd9Sstevel@tonic-gate reply2sender (void)
11207c478bd9Sstevel@tonic-gate {
112146d64c14SToomas Soome 	int rep = (value("replyall") != NOSTR);
112246d64c14SToomas Soome 	int flp = (value("flipr") != NOSTR);
11237c478bd9Sstevel@tonic-gate 
11247c478bd9Sstevel@tonic-gate 	return((rep && !flp)|| (!rep && flp));
11257c478bd9Sstevel@tonic-gate }
1126