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*18Srobbin
23*18Srobbin /*
24*18Srobbin * Copyright 1999 Sun Microsystems, Inc. All rights reserved.
25*18Srobbin * Use is subject to license terms.
26*18Srobbin */
27*18Srobbin
280Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
290Sstevel@tonic-gate /* All Rights Reserved */
300Sstevel@tonic-gate
31*18Srobbin #pragma ident "%Z%%M% %I% %E% SMI"
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include "rcv.h"
340Sstevel@tonic-gate #include <locale.h>
350Sstevel@tonic-gate #include <wordexp.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate * mailx -- a modified version of a University of California at Berkeley
390Sstevel@tonic-gate * mail program
400Sstevel@tonic-gate *
410Sstevel@tonic-gate * File I/O.
420Sstevel@tonic-gate */
430Sstevel@tonic-gate
440Sstevel@tonic-gate static int getln(char *line, int max, FILE *f);
450Sstevel@tonic-gate static int linecount(char *lp, long size);
460Sstevel@tonic-gate
470Sstevel@tonic-gate /*
480Sstevel@tonic-gate * Set up the input pointers while copying the mail file into
490Sstevel@tonic-gate * /tmp.
500Sstevel@tonic-gate */
510Sstevel@tonic-gate
520Sstevel@tonic-gate void
setptr(register FILE * ibuf)530Sstevel@tonic-gate setptr(register FILE *ibuf)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate int n, newline = 1, blankline = 1;
560Sstevel@tonic-gate int StartNewMsg = TRUE;
570Sstevel@tonic-gate int ToldUser = FALSE;
580Sstevel@tonic-gate long clen = -1L;
590Sstevel@tonic-gate int hdr = 0;
600Sstevel@tonic-gate int cflg = 0; /* found Content-length in header */
610Sstevel@tonic-gate register char *cp;
620Sstevel@tonic-gate register int l;
630Sstevel@tonic-gate register long s;
640Sstevel@tonic-gate off_t offset;
650Sstevel@tonic-gate char linebuf[LINESIZE];
660Sstevel@tonic-gate int inhead, newmail, Odot;
670Sstevel@tonic-gate short flag;
680Sstevel@tonic-gate
690Sstevel@tonic-gate if (!space) {
700Sstevel@tonic-gate msgCount = 0;
710Sstevel@tonic-gate offset = 0;
720Sstevel@tonic-gate space = 32;
730Sstevel@tonic-gate newmail = 0;
740Sstevel@tonic-gate message =
750Sstevel@tonic-gate (struct message *)calloc(space, sizeof (struct message));
760Sstevel@tonic-gate if (message == NULL) {
770Sstevel@tonic-gate fprintf(stderr, gettext(
780Sstevel@tonic-gate "calloc: insufficient memory for %d messages\n"),
790Sstevel@tonic-gate space);
800Sstevel@tonic-gate exit(1);
810Sstevel@tonic-gate /* NOTREACHED */
820Sstevel@tonic-gate }
830Sstevel@tonic-gate dot = message;
840Sstevel@tonic-gate } else {
850Sstevel@tonic-gate newmail = 1;
860Sstevel@tonic-gate offset = fsize(otf);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate s = 0L;
890Sstevel@tonic-gate l = 0;
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate * Set default flags. When reading from
920Sstevel@tonic-gate * a folder, assume the message has been
930Sstevel@tonic-gate * previously read.
940Sstevel@tonic-gate */
950Sstevel@tonic-gate if (edit)
960Sstevel@tonic-gate flag = MUSED|MREAD;
970Sstevel@tonic-gate else
980Sstevel@tonic-gate flag = MUSED|MNEW;
990Sstevel@tonic-gate
1000Sstevel@tonic-gate inhead = 0;
1010Sstevel@tonic-gate while ((n = getln(linebuf, sizeof (linebuf), ibuf)) > 0) {
1020Sstevel@tonic-gate if (!newline) {
1030Sstevel@tonic-gate goto putout;
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate top:
1060Sstevel@tonic-gate hdr = inhead && (headerp(linebuf) ||
1070Sstevel@tonic-gate (linebuf[0] == ' ' || linebuf[0] == '\t'));
1080Sstevel@tonic-gate if (!hdr && cflg) { /* nonheader, Content-length seen */
1090Sstevel@tonic-gate if (clen > 0 && clen < n) { /* read too much */
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate * NB: this only can happen if there is a
1120Sstevel@tonic-gate * small content that is NOT \n terminated
1130Sstevel@tonic-gate * and has no leading blank line, i.e., never.
1140Sstevel@tonic-gate */
1150Sstevel@tonic-gate if (fwrite(linebuf, 1, (int)clen, otf) !=
1160Sstevel@tonic-gate clen) {
1170Sstevel@tonic-gate fclose(ibuf);
1180Sstevel@tonic-gate fflush(otf);
1190Sstevel@tonic-gate } else {
1200Sstevel@tonic-gate l += linecount(linebuf, clen);
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate offset += clen;
1230Sstevel@tonic-gate s += clen;
1240Sstevel@tonic-gate n -= (int)clen;
1250Sstevel@tonic-gate /* shift line to the left, copy null as well */
1260Sstevel@tonic-gate memcpy(linebuf, linebuf+clen, n+1);
1270Sstevel@tonic-gate cflg = 0;
1280Sstevel@tonic-gate message[msgCount-1].m_clen = clen + 1;
1290Sstevel@tonic-gate blankline = 1;
1300Sstevel@tonic-gate StartNewMsg = TRUE;
1310Sstevel@tonic-gate goto top;
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate /* here, clen == 0 or clen >= n */
1340Sstevel@tonic-gate if (n == 1 && linebuf[0] == '\n') {
1350Sstevel@tonic-gate /* leading empty line */
1360Sstevel@tonic-gate clen++; /* cheat */
1370Sstevel@tonic-gate inhead = 0;
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate offset += clen;
1400Sstevel@tonic-gate s += (long)clen;
1410Sstevel@tonic-gate message[msgCount-1].m_clen = clen;
1420Sstevel@tonic-gate for (;;) {
1430Sstevel@tonic-gate if (fwrite(linebuf, 1, n, otf) != n) {
1440Sstevel@tonic-gate fclose(ibuf);
1450Sstevel@tonic-gate fflush(otf);
1460Sstevel@tonic-gate } else {
1470Sstevel@tonic-gate l += linecount(linebuf, n);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate clen -= n;
1500Sstevel@tonic-gate if (clen <= 0) {
1510Sstevel@tonic-gate break;
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate n = clen < sizeof (linebuf) ?
1540Sstevel@tonic-gate (int)clen : (int)sizeof (linebuf);
1550Sstevel@tonic-gate if ((n = fread(linebuf, 1, n, ibuf)) <= 0) {
1560Sstevel@tonic-gate fprintf(stderr, gettext(
1570Sstevel@tonic-gate "%s:\tYour mailfile was found to be corrupted.\n"),
1580Sstevel@tonic-gate progname);
1590Sstevel@tonic-gate fprintf(stderr, gettext(
1600Sstevel@tonic-gate "\t(Unexpected end-of-file).\n"));
1610Sstevel@tonic-gate fprintf(stderr, gettext(
1620Sstevel@tonic-gate "\tMessage #%d may be truncated.\n\n"),
1630Sstevel@tonic-gate msgCount);
1640Sstevel@tonic-gate offset -= clen;
1650Sstevel@tonic-gate s -= clen;
1660Sstevel@tonic-gate clen = 0; /* stop the loop */
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate /* All done, go to top for next message */
1700Sstevel@tonic-gate cflg = 0;
1710Sstevel@tonic-gate blankline = 1;
1720Sstevel@tonic-gate StartNewMsg = TRUE;
1730Sstevel@tonic-gate continue;
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate /* Look for a From line that starts a new message */
1770Sstevel@tonic-gate if (blankline && linebuf[0] == 'F' && ishead(linebuf)) {
1780Sstevel@tonic-gate if (msgCount > 0 && !newmail) {
1790Sstevel@tonic-gate message[msgCount-1].m_size = s;
1800Sstevel@tonic-gate message[msgCount-1].m_lines = l;
1810Sstevel@tonic-gate message[msgCount-1].m_flag = flag;
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate if (msgCount >= space) {
1840Sstevel@tonic-gate /*
1850Sstevel@tonic-gate * Limit the speed at which the
1860Sstevel@tonic-gate * allocated space grows.
1870Sstevel@tonic-gate */
1880Sstevel@tonic-gate if (space < 512)
1890Sstevel@tonic-gate space = space*2;
1900Sstevel@tonic-gate else
1910Sstevel@tonic-gate space += 512;
1920Sstevel@tonic-gate errno = 0;
1930Sstevel@tonic-gate Odot = dot - &(message[0]);
1940Sstevel@tonic-gate message = (struct message *)
1950Sstevel@tonic-gate realloc(message,
1960Sstevel@tonic-gate space*(sizeof (struct message)));
1970Sstevel@tonic-gate if (message == NULL) {
1980Sstevel@tonic-gate perror("realloc failed");
1990Sstevel@tonic-gate fprintf(stderr, gettext(
2000Sstevel@tonic-gate "realloc: insufficient memory for %d messages\n"),
2010Sstevel@tonic-gate space);
2020Sstevel@tonic-gate exit(1);
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate dot = &message[Odot];
2050Sstevel@tonic-gate }
2060Sstevel@tonic-gate message[msgCount].m_offset = offset;
2070Sstevel@tonic-gate message[msgCount].m_text = TRUE;
2080Sstevel@tonic-gate message[msgCount].m_clen = 0;
2090Sstevel@tonic-gate newmail = 0;
2100Sstevel@tonic-gate msgCount++;
2110Sstevel@tonic-gate if (edit)
2120Sstevel@tonic-gate flag = MUSED|MREAD;
2130Sstevel@tonic-gate else
2140Sstevel@tonic-gate flag = MUSED|MNEW;
2150Sstevel@tonic-gate inhead = 1;
2160Sstevel@tonic-gate s = 0L;
2170Sstevel@tonic-gate l = 0;
2180Sstevel@tonic-gate StartNewMsg = FALSE;
2190Sstevel@tonic-gate ToldUser = FALSE;
2200Sstevel@tonic-gate goto putout;
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate /* if didn't get a header line, we're no longer in the header */
2240Sstevel@tonic-gate if (!hdr)
2250Sstevel@tonic-gate inhead = 0;
2260Sstevel@tonic-gate if (!inhead)
2270Sstevel@tonic-gate goto putout;
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate /*
2300Sstevel@tonic-gate * Look for Status: line. Do quick check for second character,
2310Sstevel@tonic-gate * many headers start with "S" but few have "t" as second char.
2320Sstevel@tonic-gate */
2330Sstevel@tonic-gate if ((linebuf[1] == 't' || linebuf[1] == 'T') &&
2340Sstevel@tonic-gate ishfield(linebuf, "status")) {
2350Sstevel@tonic-gate cp = hcontents(linebuf);
2360Sstevel@tonic-gate flag = MUSED|MNEW;
2370Sstevel@tonic-gate if (strchr(cp, 'R'))
2380Sstevel@tonic-gate flag |= MREAD;
2390Sstevel@tonic-gate if (strchr(cp, 'O'))
2400Sstevel@tonic-gate flag &= ~MNEW;
2410Sstevel@tonic-gate }
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate * Look for Content-Length and Content-Type headers. Like
2440Sstevel@tonic-gate * above, do a quick check for the "-", which is rare.
2450Sstevel@tonic-gate */
2460Sstevel@tonic-gate if (linebuf[7] == '-') {
2470Sstevel@tonic-gate if (ishfield(linebuf, "content-length")) {
2480Sstevel@tonic-gate if (!cflg) {
2490Sstevel@tonic-gate clen = atol(hcontents(linebuf));
2500Sstevel@tonic-gate cflg = clen >= 0;
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate } else if (ishfield(linebuf, "content-type")) {
2530Sstevel@tonic-gate char word[LINESIZE];
2540Sstevel@tonic-gate char *cp2;
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate cp = hcontents(linebuf);
2570Sstevel@tonic-gate cp2 = word;
2580Sstevel@tonic-gate while (!isspace(*cp))
2590Sstevel@tonic-gate *cp2++ = *cp++;
2600Sstevel@tonic-gate *cp2 = '\0';
2610Sstevel@tonic-gate if (icequal(word, "binary"))
2620Sstevel@tonic-gate message[msgCount-1].m_text = FALSE;
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate putout:
2660Sstevel@tonic-gate offset += n;
2670Sstevel@tonic-gate s += (long)n;
2680Sstevel@tonic-gate if (fwrite(linebuf, 1, n, otf) != n) {
2690Sstevel@tonic-gate fclose(ibuf);
2700Sstevel@tonic-gate fflush(otf);
2710Sstevel@tonic-gate } else {
2720Sstevel@tonic-gate l++;
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate if (ferror(otf)) {
2750Sstevel@tonic-gate perror("/tmp");
2760Sstevel@tonic-gate exit(1);
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate if (msgCount == 0) {
2790Sstevel@tonic-gate fclose(ibuf);
2800Sstevel@tonic-gate fflush(otf);
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate if (linebuf[n-1] == '\n') {
2830Sstevel@tonic-gate blankline = newline && n == 1;
2840Sstevel@tonic-gate newline = 1;
2850Sstevel@tonic-gate if (n == 1) {
2860Sstevel@tonic-gate /* Blank line. Skip StartNewMsg check below */
2870Sstevel@tonic-gate continue;
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate } else {
2900Sstevel@tonic-gate newline = 0;
2910Sstevel@tonic-gate }
2920Sstevel@tonic-gate if (StartNewMsg && !ToldUser) {
2930Sstevel@tonic-gate fprintf(stderr, gettext(
2940Sstevel@tonic-gate "%s:\tYour mailfile was found to be corrupted\n"),
2950Sstevel@tonic-gate progname);
2960Sstevel@tonic-gate fprintf(stderr,
2970Sstevel@tonic-gate gettext("\t(Content-length mismatch).\n"));
2980Sstevel@tonic-gate fprintf(stderr, gettext(
2990Sstevel@tonic-gate "\tMessage #%d may be truncated,\n"), msgCount);
3000Sstevel@tonic-gate fprintf(stderr, gettext(
3010Sstevel@tonic-gate "\twith another message concatenated to it.\n\n"));
3020Sstevel@tonic-gate ToldUser = TRUE;
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate }
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate if (n == 0) {
3070Sstevel@tonic-gate fflush(otf);
3080Sstevel@tonic-gate if (fferror(otf)) {
3090Sstevel@tonic-gate perror("/tmp");
3100Sstevel@tonic-gate exit(1);
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate if (msgCount) {
3130Sstevel@tonic-gate message[msgCount-1].m_size = s;
3140Sstevel@tonic-gate message[msgCount-1].m_lines = l;
3150Sstevel@tonic-gate message[msgCount-1].m_flag = flag;
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate fclose(ibuf);
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate /*
3220Sstevel@tonic-gate * Compute the content length of a message and set it into m_clen.
3230Sstevel@tonic-gate */
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate void
setclen(register struct message * mp)3260Sstevel@tonic-gate setclen(register struct message *mp)
3270Sstevel@tonic-gate {
3280Sstevel@tonic-gate long c;
3290Sstevel@tonic-gate FILE *ibuf;
3300Sstevel@tonic-gate char line[LINESIZE];
3310Sstevel@tonic-gate int fline, nread;
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate ibuf = setinput(mp);
3340Sstevel@tonic-gate c = mp->m_size;
3350Sstevel@tonic-gate fline = 1;
3360Sstevel@tonic-gate while (c > 0L) {
3370Sstevel@tonic-gate nread = getln(line, sizeof (line), ibuf);
3380Sstevel@tonic-gate c -= nread;
3390Sstevel@tonic-gate /*
3400Sstevel@tonic-gate * First line is the From line, so no headers
3410Sstevel@tonic-gate * there to worry about.
3420Sstevel@tonic-gate */
3430Sstevel@tonic-gate if (fline) {
3440Sstevel@tonic-gate fline = 0;
3450Sstevel@tonic-gate continue;
3460Sstevel@tonic-gate }
3470Sstevel@tonic-gate /*
3480Sstevel@tonic-gate * If line is blank, we've reached end of headers.
3490Sstevel@tonic-gate */
3500Sstevel@tonic-gate if (line[0] == '\n')
3510Sstevel@tonic-gate break;
3520Sstevel@tonic-gate /*
3530Sstevel@tonic-gate * If this line is a continuation
3540Sstevel@tonic-gate * of a previous header field, keep going.
3550Sstevel@tonic-gate */
3560Sstevel@tonic-gate if (isspace(line[0]))
3570Sstevel@tonic-gate continue;
3580Sstevel@tonic-gate /*
3590Sstevel@tonic-gate * If we are no longer looking at real
3600Sstevel@tonic-gate * header lines, we're done.
3610Sstevel@tonic-gate * This happens in uucp style mail where
3620Sstevel@tonic-gate * there are no headers at all.
3630Sstevel@tonic-gate */
3640Sstevel@tonic-gate if (!headerp(line)) {
3650Sstevel@tonic-gate c += nread;
3660Sstevel@tonic-gate break;
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate if (c == 0)
3700Sstevel@tonic-gate c = 1;
3710Sstevel@tonic-gate mp->m_clen = c;
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate static int
getln(char * line,int max,FILE * f)3750Sstevel@tonic-gate getln(char *line, int max, FILE *f)
3760Sstevel@tonic-gate {
3770Sstevel@tonic-gate register int c;
3780Sstevel@tonic-gate register char *cp, *ecp;
3790Sstevel@tonic-gate
3800Sstevel@tonic-gate cp = line;
3810Sstevel@tonic-gate ecp = cp + max - 1;
3820Sstevel@tonic-gate while (cp < ecp && (c = getc(f)) != EOF)
3830Sstevel@tonic-gate if ((*cp++ = (char)c) == '\n')
3840Sstevel@tonic-gate break;
3850Sstevel@tonic-gate *cp = '\0';
3860Sstevel@tonic-gate return (cp - line);
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate /*
3900Sstevel@tonic-gate * Read up a line from the specified input into the line
3910Sstevel@tonic-gate * buffer. Return the number of characters read. Do not
3920Sstevel@tonic-gate * include the newline at the end.
3930Sstevel@tonic-gate */
3940Sstevel@tonic-gate
395*18Srobbin int
readline(FILE * ibuf,char * linebuf)3960Sstevel@tonic-gate readline(FILE *ibuf, char *linebuf)
3970Sstevel@tonic-gate {
3980Sstevel@tonic-gate register char *cp;
3990Sstevel@tonic-gate register int c;
4000Sstevel@tonic-gate int seennulls = 0;
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate clearerr(ibuf);
4030Sstevel@tonic-gate c = getc(ibuf);
4040Sstevel@tonic-gate for (cp = linebuf; c != '\n' && c != EOF; c = getc(ibuf)) {
4050Sstevel@tonic-gate if (c == 0) {
4060Sstevel@tonic-gate if (!seennulls) {
4070Sstevel@tonic-gate fprintf(stderr,
4080Sstevel@tonic-gate gettext("mailx: NUL changed to @\n"));
4090Sstevel@tonic-gate seennulls++;
4100Sstevel@tonic-gate }
4110Sstevel@tonic-gate c = '@';
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate if (cp - linebuf < LINESIZE-2)
4140Sstevel@tonic-gate *cp++ = (char)c;
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate *cp = 0;
4170Sstevel@tonic-gate if (c == EOF && cp == linebuf)
4180Sstevel@tonic-gate return (0);
4190Sstevel@tonic-gate return (cp - linebuf + 1);
4200Sstevel@tonic-gate }
4210Sstevel@tonic-gate
4220Sstevel@tonic-gate /*
4230Sstevel@tonic-gate * linecount - determine the number of lines in a printable file.
4240Sstevel@tonic-gate */
4250Sstevel@tonic-gate
4260Sstevel@tonic-gate static int
linecount(char * lp,long size)4270Sstevel@tonic-gate linecount(char *lp, long size)
4280Sstevel@tonic-gate {
4290Sstevel@tonic-gate register char *cp, *ecp;
4300Sstevel@tonic-gate register int count;
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate count = 0;
4330Sstevel@tonic-gate cp = lp;
4340Sstevel@tonic-gate ecp = cp + size;
4350Sstevel@tonic-gate while (cp < ecp)
4360Sstevel@tonic-gate if (*cp++ == '\n')
4370Sstevel@tonic-gate count++;
4380Sstevel@tonic-gate return (count);
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate /*
4420Sstevel@tonic-gate * Return a file buffer all ready to read up the
4430Sstevel@tonic-gate * passed message pointer.
4440Sstevel@tonic-gate */
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate FILE *
setinput(register struct message * mp)4470Sstevel@tonic-gate setinput(register struct message *mp)
4480Sstevel@tonic-gate {
4490Sstevel@tonic-gate fflush(otf);
4500Sstevel@tonic-gate if (fseek(itf, mp->m_offset, 0) < 0) {
4510Sstevel@tonic-gate perror("fseek");
4520Sstevel@tonic-gate panic("temporary file seek");
4530Sstevel@tonic-gate }
4540Sstevel@tonic-gate return (itf);
4550Sstevel@tonic-gate }
4560Sstevel@tonic-gate
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate /*
4590Sstevel@tonic-gate * Delete a file, but only if the file is a plain file.
4600Sstevel@tonic-gate */
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate int
removefile(char name[])4630Sstevel@tonic-gate removefile(char name[])
4640Sstevel@tonic-gate {
4650Sstevel@tonic-gate struct stat statb;
4660Sstevel@tonic-gate extern int errno;
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate if (stat(name, &statb) < 0)
4690Sstevel@tonic-gate if (errno == ENOENT)
4700Sstevel@tonic-gate return (0); /* it's already gone, no error */
4710Sstevel@tonic-gate else
4720Sstevel@tonic-gate return (-1);
4730Sstevel@tonic-gate if ((statb.st_mode & S_IFMT) != S_IFREG) {
4740Sstevel@tonic-gate errno = EISDIR;
4750Sstevel@tonic-gate return (-1);
4760Sstevel@tonic-gate }
4770Sstevel@tonic-gate return (unlink(name));
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate /*
4810Sstevel@tonic-gate * Terminate an editing session by attempting to write out the user's
4820Sstevel@tonic-gate * file from the temporary. Save any new stuff appended to the file.
4830Sstevel@tonic-gate */
4840Sstevel@tonic-gate int
edstop(int noremove)4850Sstevel@tonic-gate edstop(
4860Sstevel@tonic-gate int noremove /* don't allow the file to be removed, trunc instead */
4870Sstevel@tonic-gate )
4880Sstevel@tonic-gate {
4890Sstevel@tonic-gate register int gotcha, c;
4900Sstevel@tonic-gate register struct message *mp;
4910Sstevel@tonic-gate FILE *obuf, *ibuf, *tbuf = 0, *readstat;
4920Sstevel@tonic-gate struct stat statb;
4930Sstevel@tonic-gate char tempname[STSIZ], *id;
4940Sstevel@tonic-gate int tmpfd = -1;
4950Sstevel@tonic-gate
4960Sstevel@tonic-gate if (readonly)
4970Sstevel@tonic-gate return (0);
4980Sstevel@tonic-gate holdsigs();
4990Sstevel@tonic-gate if (Tflag != NOSTR) {
5000Sstevel@tonic-gate if ((readstat = fopen(Tflag, "w")) == NULL)
5010Sstevel@tonic-gate Tflag = NOSTR;
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
5040Sstevel@tonic-gate if (mp->m_flag & MNEW) {
5050Sstevel@tonic-gate mp->m_flag &= ~MNEW;
5060Sstevel@tonic-gate mp->m_flag |= MSTATUS;
5070Sstevel@tonic-gate }
5080Sstevel@tonic-gate if (mp->m_flag & (MODIFY|MDELETED|MSTATUS))
5090Sstevel@tonic-gate gotcha++;
5100Sstevel@tonic-gate if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
5110Sstevel@tonic-gate if ((id = hfield("article-id", mp, addone)) != NOSTR)
5120Sstevel@tonic-gate fprintf(readstat, "%s\n", id);
5130Sstevel@tonic-gate }
5140Sstevel@tonic-gate }
5150Sstevel@tonic-gate if (Tflag != NOSTR)
5160Sstevel@tonic-gate fclose(readstat);
5170Sstevel@tonic-gate if (!gotcha || Tflag != NOSTR)
5180Sstevel@tonic-gate goto done;
5190Sstevel@tonic-gate if ((ibuf = fopen(editfile, "r+")) == NULL) {
5200Sstevel@tonic-gate perror(editfile);
5210Sstevel@tonic-gate relsesigs();
5220Sstevel@tonic-gate longjmp(srbuf, 1);
5230Sstevel@tonic-gate }
5240Sstevel@tonic-gate lock(ibuf, "r+", 1);
5250Sstevel@tonic-gate if (fstat(fileno(ibuf), &statb) >= 0 && statb.st_size > mailsize) {
5260Sstevel@tonic-gate nstrcpy(tempname, STSIZ, "/tmp/mboxXXXXXX");
5270Sstevel@tonic-gate if ((tmpfd = mkstemp(tempname)) == -1) {
5280Sstevel@tonic-gate perror(tempname);
5290Sstevel@tonic-gate fclose(ibuf);
5300Sstevel@tonic-gate relsesigs();
5310Sstevel@tonic-gate longjmp(srbuf, 1);
5320Sstevel@tonic-gate }
5330Sstevel@tonic-gate if ((obuf = fdopen(tmpfd, "w")) == NULL) {
5340Sstevel@tonic-gate perror(tempname);
5350Sstevel@tonic-gate fclose(ibuf);
5360Sstevel@tonic-gate removefile(tempname);
5370Sstevel@tonic-gate relsesigs();
5380Sstevel@tonic-gate (void) close(tmpfd);
5390Sstevel@tonic-gate longjmp(srbuf, 1);
5400Sstevel@tonic-gate }
5410Sstevel@tonic-gate fseek(ibuf, mailsize, 0);
5420Sstevel@tonic-gate while ((c = getc(ibuf)) != EOF)
5430Sstevel@tonic-gate putc(c, obuf);
5440Sstevel@tonic-gate fclose(obuf);
5450Sstevel@tonic-gate if ((tbuf = fopen(tempname, "r")) == NULL) {
5460Sstevel@tonic-gate perror(tempname);
5470Sstevel@tonic-gate fclose(ibuf);
5480Sstevel@tonic-gate removefile(tempname);
5490Sstevel@tonic-gate relsesigs();
5500Sstevel@tonic-gate longjmp(srbuf, 1);
5510Sstevel@tonic-gate }
5520Sstevel@tonic-gate removefile(tempname);
5530Sstevel@tonic-gate }
5540Sstevel@tonic-gate if ((obuf = fopen(editfile, "r+")) == NULL) {
5550Sstevel@tonic-gate if ((obuf = fopen(editfile, "w")) == NULL) {
5560Sstevel@tonic-gate perror(editfile);
5570Sstevel@tonic-gate fclose(ibuf);
5580Sstevel@tonic-gate if (tbuf)
5590Sstevel@tonic-gate fclose(tbuf);
5600Sstevel@tonic-gate relsesigs();
5610Sstevel@tonic-gate longjmp(srbuf, 1);
5620Sstevel@tonic-gate }
5630Sstevel@tonic-gate }
5640Sstevel@tonic-gate printf("\"%s\" ", editfile);
5650Sstevel@tonic-gate flush();
5660Sstevel@tonic-gate c = 0;
5670Sstevel@tonic-gate for (mp = &message[0]; mp < &message[msgCount]; mp++) {
5680Sstevel@tonic-gate if ((mp->m_flag & MDELETED) != 0)
5690Sstevel@tonic-gate continue;
5700Sstevel@tonic-gate c++;
5710Sstevel@tonic-gate if (msend(mp, obuf, 0, fputs) < 0) {
5720Sstevel@tonic-gate perror(editfile);
5730Sstevel@tonic-gate fclose(ibuf);
5740Sstevel@tonic-gate fclose(obuf);
5750Sstevel@tonic-gate if (tbuf)
5760Sstevel@tonic-gate fclose(tbuf);
5770Sstevel@tonic-gate relsesigs();
5780Sstevel@tonic-gate longjmp(srbuf, 1);
5790Sstevel@tonic-gate }
5800Sstevel@tonic-gate }
5810Sstevel@tonic-gate gotcha = (c == 0 && tbuf == NULL);
5820Sstevel@tonic-gate if (tbuf != NULL) {
5830Sstevel@tonic-gate while ((c = getc(tbuf)) != EOF)
5840Sstevel@tonic-gate putc(c, obuf);
5850Sstevel@tonic-gate fclose(tbuf);
5860Sstevel@tonic-gate }
5870Sstevel@tonic-gate fflush(obuf);
5880Sstevel@tonic-gate if (fferror(obuf)) {
5890Sstevel@tonic-gate perror(editfile);
5900Sstevel@tonic-gate fclose(ibuf);
5910Sstevel@tonic-gate fclose(obuf);
5920Sstevel@tonic-gate relsesigs();
5930Sstevel@tonic-gate longjmp(srbuf, 1);
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate if (gotcha && !noremove && (value("keep") == NOSTR)) {
5960Sstevel@tonic-gate removefile(editfile);
5970Sstevel@tonic-gate printf(gettext("removed.\n"));
5980Sstevel@tonic-gate }
5990Sstevel@tonic-gate else
6000Sstevel@tonic-gate printf(gettext("updated.\n"));
6010Sstevel@tonic-gate fclose(ibuf);
6020Sstevel@tonic-gate trunc(obuf);
6030Sstevel@tonic-gate fclose(obuf);
6040Sstevel@tonic-gate flush();
6050Sstevel@tonic-gate
6060Sstevel@tonic-gate done:
6070Sstevel@tonic-gate relsesigs();
6080Sstevel@tonic-gate return (1);
6090Sstevel@tonic-gate }
6100Sstevel@tonic-gate
6110Sstevel@tonic-gate #ifndef OLD_BSD_SIGS
6120Sstevel@tonic-gate static int sigdepth = 0; /* depth of holdsigs() */
6130Sstevel@tonic-gate #ifdef VMUNIX
6140Sstevel@tonic-gate static int omask = 0;
6150Sstevel@tonic-gate #else
6160Sstevel@tonic-gate static sigset_t mask, omask;
6170Sstevel@tonic-gate #endif
6180Sstevel@tonic-gate #endif
6190Sstevel@tonic-gate /*
6200Sstevel@tonic-gate * Hold signals SIGHUP - SIGQUIT.
6210Sstevel@tonic-gate */
6220Sstevel@tonic-gate void
holdsigs(void)6230Sstevel@tonic-gate holdsigs(void)
6240Sstevel@tonic-gate {
6250Sstevel@tonic-gate #ifndef OLD_BSD_SIGS
6260Sstevel@tonic-gate if (sigdepth++ == 0) {
6270Sstevel@tonic-gate #ifdef VMUNIX
6280Sstevel@tonic-gate omask = sigblock(sigmask(SIGHUP) |
6290Sstevel@tonic-gate sigmask(SIGINT)|sigmask(SIGQUIT));
6300Sstevel@tonic-gate #else
6310Sstevel@tonic-gate sigemptyset(&mask);
6320Sstevel@tonic-gate sigaddset(&mask, SIGHUP);
6330Sstevel@tonic-gate sigaddset(&mask, SIGINT);
6340Sstevel@tonic-gate sigaddset(&mask, SIGQUIT);
6350Sstevel@tonic-gate sigprocmask(SIG_BLOCK, &mask, &omask);
6360Sstevel@tonic-gate #endif
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate #else
6390Sstevel@tonic-gate sighold(SIGHUP);
6400Sstevel@tonic-gate sighold(SIGINT);
6410Sstevel@tonic-gate sighold(SIGQUIT);
6420Sstevel@tonic-gate #endif
6430Sstevel@tonic-gate }
6440Sstevel@tonic-gate
6450Sstevel@tonic-gate /*
6460Sstevel@tonic-gate * Release signals SIGHUP - SIGQUIT
6470Sstevel@tonic-gate */
6480Sstevel@tonic-gate void
relsesigs(void)6490Sstevel@tonic-gate relsesigs(void)
6500Sstevel@tonic-gate {
6510Sstevel@tonic-gate #ifndef OLD_BSD_SIGS
6520Sstevel@tonic-gate if (--sigdepth == 0)
6530Sstevel@tonic-gate #ifdef VMUNIX
6540Sstevel@tonic-gate sigsetmask(omask);
6550Sstevel@tonic-gate #else
6560Sstevel@tonic-gate sigprocmask(SIG_SETMASK, &omask, NULL);
6570Sstevel@tonic-gate #endif
6580Sstevel@tonic-gate #else
6590Sstevel@tonic-gate sigrelse(SIGHUP);
6600Sstevel@tonic-gate sigrelse(SIGINT);
6610Sstevel@tonic-gate sigrelse(SIGQUIT);
6620Sstevel@tonic-gate #endif
6630Sstevel@tonic-gate }
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate #if !defined(OLD_BSD_SIGS) && !defined(VMUNIX)
6660Sstevel@tonic-gate void
sigset(int sig,void (* act)(int))6670Sstevel@tonic-gate (*sigset(int sig, void (*act)(int)))(int)
6680Sstevel@tonic-gate {
6690Sstevel@tonic-gate struct sigaction sa, osa;
6700Sstevel@tonic-gate
6710Sstevel@tonic-gate sa.sa_handler = (void (*)())act;
6720Sstevel@tonic-gate sigemptyset(&sa.sa_mask);
6730Sstevel@tonic-gate sa.sa_flags = SA_RESTART;
6740Sstevel@tonic-gate if (sigaction(sig, &sa, &osa) < 0)
6750Sstevel@tonic-gate return ((void (*)(int))-1);
6760Sstevel@tonic-gate return ((void (*)(int))osa.sa_handler);
6770Sstevel@tonic-gate }
6780Sstevel@tonic-gate #endif
6790Sstevel@tonic-gate
6800Sstevel@tonic-gate /*
6810Sstevel@tonic-gate * Flush the standard output.
6820Sstevel@tonic-gate */
6830Sstevel@tonic-gate
6840Sstevel@tonic-gate void
flush(void)6850Sstevel@tonic-gate flush(void)
6860Sstevel@tonic-gate {
6870Sstevel@tonic-gate fflush(stdout);
6880Sstevel@tonic-gate fflush(stderr);
6890Sstevel@tonic-gate }
6900Sstevel@tonic-gate
6910Sstevel@tonic-gate /*
6920Sstevel@tonic-gate * Determine the size of the file possessed by
6930Sstevel@tonic-gate * the passed buffer.
6940Sstevel@tonic-gate */
6950Sstevel@tonic-gate
6960Sstevel@tonic-gate off_t
fsize(FILE * iob)6970Sstevel@tonic-gate fsize(FILE *iob)
6980Sstevel@tonic-gate {
6990Sstevel@tonic-gate register int f;
7000Sstevel@tonic-gate struct stat sbuf;
7010Sstevel@tonic-gate
7020Sstevel@tonic-gate f = fileno(iob);
7030Sstevel@tonic-gate if (fstat(f, &sbuf) < 0)
7040Sstevel@tonic-gate return (0);
7050Sstevel@tonic-gate return (sbuf.st_size);
7060Sstevel@tonic-gate }
7070Sstevel@tonic-gate
7080Sstevel@tonic-gate /*
7090Sstevel@tonic-gate * Check for either a stdio recognized error, or
7100Sstevel@tonic-gate * a possibly delayed write error (in case it's
7110Sstevel@tonic-gate * an NFS file, for instance).
7120Sstevel@tonic-gate */
7130Sstevel@tonic-gate
7140Sstevel@tonic-gate int
fferror(FILE * iob)7150Sstevel@tonic-gate fferror(FILE *iob)
7160Sstevel@tonic-gate {
7170Sstevel@tonic-gate return (ferror(iob) || fsync(fileno(iob)) < 0);
7180Sstevel@tonic-gate }
7190Sstevel@tonic-gate
7200Sstevel@tonic-gate /*
7210Sstevel@tonic-gate * Take a file name, possibly with shell meta characters
7220Sstevel@tonic-gate * in it and expand it by using wordexp().
7230Sstevel@tonic-gate * Return the file name as a dynamic string.
7240Sstevel@tonic-gate * If the name cannot be expanded (for whatever reason)
7250Sstevel@tonic-gate * return NULL.
7260Sstevel@tonic-gate */
7270Sstevel@tonic-gate
7280Sstevel@tonic-gate char *
expand(char * name)7290Sstevel@tonic-gate expand(char *name)
7300Sstevel@tonic-gate {
7310Sstevel@tonic-gate char xname[BUFSIZ];
7320Sstevel@tonic-gate char foldbuf[BUFSIZ];
7330Sstevel@tonic-gate register char *cp;
7340Sstevel@tonic-gate register int l;
7350Sstevel@tonic-gate wordexp_t wrdexp_buf;
7360Sstevel@tonic-gate
7370Sstevel@tonic-gate if (debug) fprintf(stderr, "expand(%s)=", name);
7380Sstevel@tonic-gate cp = strchr(name, '\0') - 1; /* pointer to last char of name */
7390Sstevel@tonic-gate if (isspace(*cp)) {
7400Sstevel@tonic-gate /* strip off trailing blanks */
7410Sstevel@tonic-gate while (cp > name && isspace(*cp))
7420Sstevel@tonic-gate cp--;
7430Sstevel@tonic-gate l = *++cp; /* save char */
7440Sstevel@tonic-gate *cp = '\0';
7450Sstevel@tonic-gate name = savestr(name);
7460Sstevel@tonic-gate *cp = (char)l; /* restore char */
7470Sstevel@tonic-gate }
7480Sstevel@tonic-gate if (name[0] == '+' && getfold(foldbuf) >= 0) {
7490Sstevel@tonic-gate snprintf(xname, sizeof (xname), "%s/%s", foldbuf, name + 1);
7500Sstevel@tonic-gate cp = safeexpand(savestr(xname));
7510Sstevel@tonic-gate if (debug) fprintf(stderr, "%s\n", cp);
7520Sstevel@tonic-gate return (cp);
7530Sstevel@tonic-gate }
7540Sstevel@tonic-gate if (!anyof(name, "~{[*?$`'\"\\")) {
7550Sstevel@tonic-gate if (debug) fprintf(stderr, "%s\n", name);
7560Sstevel@tonic-gate return (name);
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate if (wordexp(name, &wrdexp_buf, 0) != 0) {
7590Sstevel@tonic-gate fprintf(stderr, gettext("Syntax error in \"%s\"\n"), name);
7600Sstevel@tonic-gate fflush(stderr);
7610Sstevel@tonic-gate return (NOSTR);
7620Sstevel@tonic-gate }
7630Sstevel@tonic-gate if (wrdexp_buf.we_wordc > 1) {
7640Sstevel@tonic-gate fprintf(stderr, gettext("\"%s\": Ambiguous\n"), name);
7650Sstevel@tonic-gate fflush(stderr);
7660Sstevel@tonic-gate return (NOSTR);
7670Sstevel@tonic-gate }
7680Sstevel@tonic-gate if (debug) fprintf(stderr, "%s\n", wrdexp_buf.we_wordv[0]);
7690Sstevel@tonic-gate return (savestr(wrdexp_buf.we_wordv[0]));
7700Sstevel@tonic-gate }
7710Sstevel@tonic-gate
7720Sstevel@tonic-gate /*
7730Sstevel@tonic-gate * Take a file name, possibly with shell meta characters
7740Sstevel@tonic-gate * in it and expand it by using "sh -c echo filename"
7750Sstevel@tonic-gate * Return the file name as a dynamic string.
7760Sstevel@tonic-gate * If the name cannot be expanded (for whatever reason)
7770Sstevel@tonic-gate * return the original file name.
7780Sstevel@tonic-gate */
7790Sstevel@tonic-gate
7800Sstevel@tonic-gate char *
safeexpand(char name[])7810Sstevel@tonic-gate safeexpand(char name[])
7820Sstevel@tonic-gate {
7830Sstevel@tonic-gate char *t = expand(name);
7840Sstevel@tonic-gate return (t) ? t : savestr(name);
7850Sstevel@tonic-gate }
7860Sstevel@tonic-gate
7870Sstevel@tonic-gate /*
7880Sstevel@tonic-gate * Determine the current folder directory name.
7890Sstevel@tonic-gate */
790*18Srobbin int
getfold(char * name)7910Sstevel@tonic-gate getfold(char *name)
7920Sstevel@tonic-gate {
7930Sstevel@tonic-gate char *folder;
7940Sstevel@tonic-gate
7950Sstevel@tonic-gate if ((folder = value("folder")) == NOSTR || *folder == '\0')
7960Sstevel@tonic-gate return (-1);
7970Sstevel@tonic-gate /*
7980Sstevel@tonic-gate * If name looks like a folder name, don't try
7990Sstevel@tonic-gate * to expand it, to prevent infinite recursion.
8000Sstevel@tonic-gate */
8010Sstevel@tonic-gate if (*folder != '+' && (folder = expand(folder)) == NOSTR ||
8020Sstevel@tonic-gate *folder == '\0')
8030Sstevel@tonic-gate return (-1);
8040Sstevel@tonic-gate if (*folder == '/') {
8050Sstevel@tonic-gate nstrcpy(name, BUFSIZ, folder);
8060Sstevel@tonic-gate } else
8070Sstevel@tonic-gate snprintf(name, BUFSIZ, "%s/%s", homedir, folder);
8080Sstevel@tonic-gate return (0);
8090Sstevel@tonic-gate }
8100Sstevel@tonic-gate
8110Sstevel@tonic-gate /*
8120Sstevel@tonic-gate * A nicer version of Fdopen, which allows us to fclose
8130Sstevel@tonic-gate * without losing the open file.
8140Sstevel@tonic-gate */
8150Sstevel@tonic-gate
8160Sstevel@tonic-gate FILE *
Fdopen(int fildes,char * mode)8170Sstevel@tonic-gate Fdopen(int fildes, char *mode)
8180Sstevel@tonic-gate {
8190Sstevel@tonic-gate register int f;
8200Sstevel@tonic-gate
8210Sstevel@tonic-gate f = dup(fildes);
8220Sstevel@tonic-gate if (f < 0) {
8230Sstevel@tonic-gate perror("dup");
8240Sstevel@tonic-gate return (NULL);
8250Sstevel@tonic-gate }
8260Sstevel@tonic-gate return (fdopen(f, mode));
8270Sstevel@tonic-gate }
8280Sstevel@tonic-gate
8290Sstevel@tonic-gate /*
8300Sstevel@tonic-gate * return the filename associated with "s". This function always
8310Sstevel@tonic-gate * returns a non-null string (no error checking is done on the receiving end)
8320Sstevel@tonic-gate */
8330Sstevel@tonic-gate char *
Getf(register char * s)8340Sstevel@tonic-gate Getf(register char *s)
8350Sstevel@tonic-gate {
8360Sstevel@tonic-gate register char *cp;
8370Sstevel@tonic-gate static char defbuf[PATHSIZE];
8380Sstevel@tonic-gate
8390Sstevel@tonic-gate if (((cp = value(s)) != 0) && *cp) {
8400Sstevel@tonic-gate return (safeexpand(cp));
8410Sstevel@tonic-gate } else if (strcmp(s, "MBOX") == 0) {
8420Sstevel@tonic-gate snprintf(defbuf, sizeof (defbuf), "%s/%s", Getf("HOME"),
8430Sstevel@tonic-gate "mbox");
8440Sstevel@tonic-gate return (defbuf);
8450Sstevel@tonic-gate } else if (strcmp(s, "DEAD") == 0) {
8460Sstevel@tonic-gate snprintf(defbuf, sizeof (defbuf), "%s/%s", Getf("HOME"),
8470Sstevel@tonic-gate "dead.letter");
8480Sstevel@tonic-gate return (defbuf);
8490Sstevel@tonic-gate } else if (strcmp(s, "MAILRC") == 0) {
8500Sstevel@tonic-gate snprintf(defbuf, sizeof (defbuf), "%s/%s", Getf("HOME"),
8510Sstevel@tonic-gate ".mailrc");
8520Sstevel@tonic-gate return (defbuf);
8530Sstevel@tonic-gate } else if (strcmp(s, "HOME") == 0) {
8540Sstevel@tonic-gate /* no recursion allowed! */
8550Sstevel@tonic-gate return (".");
8560Sstevel@tonic-gate }
8570Sstevel@tonic-gate return ("DEAD"); /* "cannot happen" */
8580Sstevel@tonic-gate }
859