Home | History | Annotate | Line # | Download | only in mail
fio.c revision 1.21
      1  1.21      ross /*	$NetBSD: fio.c,v 1.21 2002/03/29 15:07:52 ross Exp $	*/
      2   1.5  christos 
      3   1.1       cgd /*
      4   1.4   deraadt  * Copyright (c) 1980, 1993
      5   1.4   deraadt  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.10     lukem #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38   1.5  christos #if 0
     39   1.6       tls static char sccsid[] = "@(#)fio.c	8.2 (Berkeley) 4/20/95";
     40   1.5  christos #else
     41  1.21      ross __RCSID("$NetBSD: fio.c,v 1.21 2002/03/29 15:07:52 ross Exp $");
     42   1.5  christos #endif
     43   1.1       cgd #endif /* not lint */
     44   1.1       cgd 
     45   1.1       cgd #include "rcv.h"
     46   1.4   deraadt #include "extern.h"
     47   1.1       cgd 
     48   1.1       cgd /*
     49   1.1       cgd  * Mail -- a mail program
     50   1.1       cgd  *
     51   1.1       cgd  * File I/O.
     52   1.1       cgd  */
     53  1.13  christos extern int wait_status;
     54  1.13  christos extern char *tmpdir;
     55   1.1       cgd 
     56   1.1       cgd /*
     57   1.1       cgd  * Set up the input pointers while copying the mail file into /tmp.
     58   1.1       cgd  */
     59   1.4   deraadt void
     60  1.15       wiz setptr(FILE *ibuf, off_t offset)
     61   1.1       cgd {
     62  1.16       wiz 	int c, len;
     63  1.10     lukem 	char *cp, *cp2;
     64   1.1       cgd 	struct message this;
     65   1.1       cgd 	FILE *mestmp;
     66   1.1       cgd 	int maybe, inhead;
     67   1.1       cgd 	char linebuf[LINESIZE];
     68   1.6       tls 	int omsgCount;
     69   1.1       cgd 
     70   1.1       cgd 	/* Get temporary file. */
     71   1.7     mikel 	(void)snprintf(linebuf, LINESIZE, "%s/mail.XXXXXX", tmpdir);
     72   1.1       cgd 	if ((c = mkstemp(linebuf)) == -1 ||
     73   1.1       cgd 	    (mestmp = Fdopen(c, "r+")) == NULL) {
     74   1.1       cgd 		(void)fprintf(stderr, "mail: can't open %s\n", linebuf);
     75   1.1       cgd 		exit(1);
     76   1.1       cgd 	}
     77   1.1       cgd 	(void)unlink(linebuf);
     78   1.1       cgd 
     79   1.6       tls 	if (offset == 0) {
     80   1.6       tls 		 msgCount = 0;
     81   1.6       tls 	} else {
     82   1.6       tls 		/* Seek into the file to get to the new messages */
     83  1.19       wiz 		(void)fseek(ibuf, offset, 0);
     84   1.6       tls 		/*
     85   1.6       tls 		 * We need to make "offset" a pointer to the end of
     86   1.6       tls 		 * the temp file that has the copy of the mail file.
     87   1.6       tls 		 * If any messages have been edited, this will be
     88   1.6       tls 		 * different from the offset into the mail file.
     89   1.6       tls 		 */
     90  1.19       wiz 		(void)fseek(otf, 0L, 2);
     91   1.6       tls 		offset = ftell(otf);
     92   1.6       tls 	}
     93   1.6       tls 	omsgCount = msgCount;
     94   1.1       cgd 	maybe = 1;
     95   1.1       cgd 	inhead = 0;
     96   1.1       cgd 	this.m_flag = MUSED|MNEW;
     97   1.1       cgd 	this.m_size = 0;
     98   1.1       cgd 	this.m_lines = 0;
     99  1.21      ross 	this.m_blines = 0;
    100   1.1       cgd 	this.m_block = 0;
    101   1.1       cgd 	this.m_offset = 0;
    102   1.1       cgd 	for (;;) {
    103   1.1       cgd 		if (fgets(linebuf, LINESIZE, ibuf) == NULL) {
    104   1.1       cgd 			if (append(&this, mestmp)) {
    105  1.20       wiz 				warn("temporary file");
    106   1.1       cgd 				exit(1);
    107   1.1       cgd 			}
    108   1.6       tls 			makemessage(mestmp, omsgCount);
    109   1.1       cgd 			return;
    110   1.1       cgd 		}
    111  1.16       wiz 		len = strlen(linebuf);
    112   1.9      matt 		/*
    113   1.9      matt 		 * Transforms lines ending in <CR><LF> to just <LF>.
    114   1.9      matt 		 * This allows mail to be able to read Eudora mailboxes
    115   1.9      matt 		 * that reside on a DOS partition.
    116   1.9      matt 		 */
    117  1.16       wiz 		if (len >= 2 && linebuf[len-1] == '\n' && linebuf[len-2] == '\r') {
    118  1.16       wiz 			linebuf[len-2] = '\n';
    119  1.16       wiz 			len--;
    120   1.9      matt 		}
    121  1.19       wiz 		(void)fwrite(linebuf, sizeof *linebuf, len, otf);
    122   1.1       cgd 		if (ferror(otf)) {
    123  1.20       wiz 			warn("/tmp");
    124   1.1       cgd 			exit(1);
    125   1.1       cgd 		}
    126  1.16       wiz 		if(len)
    127  1.16       wiz 			linebuf[len - 1] = 0;
    128   1.1       cgd 		if (maybe && linebuf[0] == 'F' && ishead(linebuf)) {
    129   1.1       cgd 			msgCount++;
    130   1.1       cgd 			if (append(&this, mestmp)) {
    131  1.20       wiz 				warn("temporary file");
    132   1.1       cgd 				exit(1);
    133   1.1       cgd 			}
    134   1.1       cgd 			this.m_flag = MUSED|MNEW;
    135   1.1       cgd 			this.m_size = 0;
    136   1.1       cgd 			this.m_lines = 0;
    137  1.21      ross 			this.m_blines = 0;
    138   1.1       cgd 			this.m_block = blockof(offset);
    139   1.1       cgd 			this.m_offset = offsetof(offset);
    140   1.1       cgd 			inhead = 1;
    141   1.1       cgd 		} else if (linebuf[0] == 0) {
    142   1.1       cgd 			inhead = 0;
    143   1.1       cgd 		} else if (inhead) {
    144   1.1       cgd 			for (cp = linebuf, cp2 = "status";; cp++) {
    145   1.1       cgd 				if ((c = *cp2++) == 0) {
    146  1.12  christos 					while (isspace((unsigned char)*cp++))
    147   1.1       cgd 						;
    148   1.1       cgd 					if (cp[-1] != ':')
    149   1.1       cgd 						break;
    150   1.5  christos 					while ((c = *cp++) != '\0')
    151   1.1       cgd 						if (c == 'R')
    152   1.1       cgd 							this.m_flag |= MREAD;
    153   1.1       cgd 						else if (c == 'O')
    154   1.1       cgd 							this.m_flag &= ~MNEW;
    155   1.1       cgd 					inhead = 0;
    156   1.1       cgd 					break;
    157   1.1       cgd 				}
    158   1.1       cgd 				if (*cp != c && *cp != toupper(c))
    159   1.1       cgd 					break;
    160   1.1       cgd 			}
    161   1.1       cgd 		}
    162  1.16       wiz 		offset += len;
    163  1.16       wiz 		this.m_size += len;
    164   1.1       cgd 		this.m_lines++;
    165  1.21      ross 		if (!inhead) {
    166  1.21      ross 			int lines_plus_wraps = 1;
    167  1.21      ross 			int linelen = strlen(linebuf);
    168  1.21      ross 
    169  1.21      ross 			if (linelen > screenwidth) {
    170  1.21      ross 				lines_plus_wraps = linelen / screenwidth;
    171  1.21      ross 				if (linelen % screenwidth != 0)
    172  1.21      ross 					++lines_plus_wraps;
    173  1.21      ross 			}
    174  1.21      ross 			this.m_blines += lines_plus_wraps;
    175  1.21      ross 		}
    176   1.1       cgd 		maybe = linebuf[0] == 0;
    177   1.1       cgd 	}
    178   1.1       cgd }
    179   1.1       cgd 
    180   1.1       cgd /*
    181   1.1       cgd  * Drop the passed line onto the passed output buffer.
    182   1.1       cgd  * If a write error occurs, return -1, else the count of
    183   1.8      phil  * characters written, including the newline if requested.
    184   1.1       cgd  */
    185   1.4   deraadt int
    186  1.15       wiz putline(FILE *obuf, char *linebuf, int outlf)
    187   1.1       cgd {
    188  1.10     lukem 	int c;
    189   1.1       cgd 
    190   1.1       cgd 	c = strlen(linebuf);
    191  1.19       wiz 	(void)fwrite(linebuf, sizeof *linebuf, c, obuf);
    192   1.8      phil 	if (outlf) {
    193  1.19       wiz 		(void)putc('\n', obuf);
    194   1.8      phil 		c++;
    195   1.8      phil 	}
    196   1.1       cgd 	if (ferror(obuf))
    197   1.1       cgd 		return (-1);
    198   1.8      phil 	return (c);
    199   1.1       cgd }
    200   1.1       cgd 
    201   1.1       cgd /*
    202   1.1       cgd  * Read up a line from the specified input into the line
    203   1.1       cgd  * buffer.  Return the number of characters read.  Do not
    204   1.1       cgd  * include the newline at the end.
    205   1.1       cgd  */
    206   1.4   deraadt int
    207  1.15       wiz readline(FILE *ibuf, char *linebuf, int linesize)
    208   1.1       cgd {
    209  1.10     lukem 	int n;
    210   1.1       cgd 
    211   1.1       cgd 	clearerr(ibuf);
    212   1.1       cgd 	if (fgets(linebuf, linesize, ibuf) == NULL)
    213   1.1       cgd 		return -1;
    214   1.1       cgd 	n = strlen(linebuf);
    215   1.1       cgd 	if (n > 0 && linebuf[n - 1] == '\n')
    216   1.1       cgd 		linebuf[--n] = '\0';
    217   1.1       cgd 	return n;
    218   1.1       cgd }
    219   1.1       cgd 
    220   1.1       cgd /*
    221   1.1       cgd  * Return a file buffer all ready to read up the
    222   1.1       cgd  * passed message pointer.
    223   1.1       cgd  */
    224   1.1       cgd FILE *
    225  1.15       wiz setinput(struct message *mp)
    226   1.1       cgd {
    227   1.1       cgd 
    228   1.1       cgd 	fflush(otf);
    229  1.10     lukem 	if (fseek(itf, (long)positionof(mp->m_block, mp->m_offset), 0) < 0)
    230  1.10     lukem 		err(1, "fseek");
    231   1.1       cgd 	return (itf);
    232   1.1       cgd }
    233   1.1       cgd 
    234   1.1       cgd /*
    235   1.1       cgd  * Take the data out of the passed ghost file and toss it into
    236   1.1       cgd  * a dynamically allocated message structure.
    237   1.1       cgd  */
    238   1.4   deraadt void
    239  1.15       wiz makemessage(FILE *f, int omsgCount)
    240   1.1       cgd {
    241  1.10     lukem 	int size = (msgCount + 1) * sizeof (struct message);
    242  1.14  christos 	struct message *nmessage = realloc(message, size);
    243   1.1       cgd 
    244  1.14  christos 	if (nmessage == NULL)
    245  1.14  christos 		err(1, "Insufficient memory for %d messages", msgCount);
    246  1.14  christos 	if (omsgCount == 0 || message == NULL)
    247  1.14  christos 		dot = nmessage;
    248  1.14  christos 	else
    249  1.14  christos 		dot = nmessage + (dot - message);
    250  1.14  christos 	message = nmessage;
    251   1.6       tls 	size -= (omsgCount + 1) * sizeof (struct message);
    252   1.1       cgd 	fflush(f);
    253  1.19       wiz 	(void)lseek(fileno(f), (off_t)sizeof *message, 0);
    254   1.6       tls 	if (read(fileno(f), (char *) &message[omsgCount], size) != size)
    255  1.10     lukem 		errx(1, "Message temporary file corrupted");
    256   1.1       cgd 	message[msgCount].m_size = 0;
    257   1.1       cgd 	message[msgCount].m_lines = 0;
    258  1.21      ross 	message[msgCount].m_blines = 0;
    259   1.1       cgd 	Fclose(f);
    260   1.1       cgd }
    261   1.1       cgd 
    262   1.1       cgd /*
    263   1.1       cgd  * Append the passed message descriptor onto the temp file.
    264   1.1       cgd  * If the write fails, return 1, else 0
    265   1.1       cgd  */
    266   1.4   deraadt int
    267  1.15       wiz append(struct message *mp, FILE *f)
    268   1.1       cgd {
    269   1.1       cgd 	return fwrite((char *) mp, sizeof *mp, 1, f) != 1;
    270   1.1       cgd }
    271   1.1       cgd 
    272   1.1       cgd /*
    273   1.1       cgd  * Delete a file, but only if the file is a plain file.
    274   1.1       cgd  */
    275   1.4   deraadt int
    276  1.15       wiz rm(char *name)
    277   1.1       cgd {
    278   1.1       cgd 	struct stat sb;
    279   1.1       cgd 
    280   1.1       cgd 	if (stat(name, &sb) < 0)
    281   1.1       cgd 		return(-1);
    282   1.1       cgd 	if (!S_ISREG(sb.st_mode)) {
    283   1.1       cgd 		errno = EISDIR;
    284   1.1       cgd 		return(-1);
    285   1.1       cgd 	}
    286   1.1       cgd 	return(unlink(name));
    287   1.1       cgd }
    288   1.1       cgd 
    289   1.1       cgd static int sigdepth;		/* depth of holdsigs() */
    290   1.5  christos static sigset_t nset, oset;
    291   1.1       cgd /*
    292   1.1       cgd  * Hold signals SIGHUP, SIGINT, and SIGQUIT.
    293   1.1       cgd  */
    294   1.4   deraadt void
    295  1.15       wiz holdsigs(void)
    296   1.1       cgd {
    297   1.1       cgd 
    298   1.5  christos 	if (sigdepth++ == 0) {
    299   1.5  christos 		sigemptyset(&nset);
    300   1.5  christos 		sigaddset(&nset, SIGHUP);
    301   1.5  christos 		sigaddset(&nset, SIGINT);
    302   1.5  christos 		sigaddset(&nset, SIGQUIT);
    303   1.5  christos 		sigprocmask(SIG_BLOCK, &nset, &oset);
    304   1.5  christos 	}
    305   1.1       cgd }
    306   1.1       cgd 
    307   1.1       cgd /*
    308   1.1       cgd  * Release signals SIGHUP, SIGINT, and SIGQUIT.
    309   1.1       cgd  */
    310   1.4   deraadt void
    311  1.15       wiz relsesigs(void)
    312   1.1       cgd {
    313   1.1       cgd 
    314   1.1       cgd 	if (--sigdepth == 0)
    315   1.5  christos 		sigprocmask(SIG_SETMASK, &oset, NULL);
    316   1.1       cgd }
    317   1.1       cgd 
    318   1.1       cgd /*
    319   1.1       cgd  * Determine the size of the file possessed by
    320   1.1       cgd  * the passed buffer.
    321   1.1       cgd  */
    322   1.1       cgd off_t
    323  1.15       wiz fsize(FILE *iob)
    324   1.1       cgd {
    325   1.1       cgd 	struct stat sbuf;
    326   1.1       cgd 
    327   1.1       cgd 	if (fstat(fileno(iob), &sbuf) < 0)
    328   1.1       cgd 		return 0;
    329   1.1       cgd 	return sbuf.st_size;
    330   1.1       cgd }
    331   1.1       cgd 
    332   1.1       cgd /*
    333   1.1       cgd  * Evaluate the string given as a new mailbox name.
    334   1.1       cgd  * Supported meta characters:
    335   1.1       cgd  *	%	for my system mail box
    336   1.1       cgd  *	%user	for user's system mail box
    337   1.1       cgd  *	#	for previous file
    338   1.1       cgd  *	&	invoker's mbox file
    339   1.1       cgd  *	+file	file in folder directory
    340   1.1       cgd  *	any shell meta character
    341   1.1       cgd  * Return the file name as a dynamic string.
    342   1.1       cgd  */
    343   1.1       cgd char *
    344  1.15       wiz expand(char *name)
    345   1.1       cgd {
    346   1.1       cgd 	char xname[PATHSIZE];
    347   1.1       cgd 	char cmdbuf[PATHSIZE];		/* also used for file names */
    348  1.10     lukem 	int pid, l;
    349  1.16       wiz 	char *cp, *shellcmd;
    350   1.1       cgd 	int pivec[2];
    351   1.1       cgd 	struct stat sbuf;
    352   1.1       cgd 
    353   1.1       cgd 	/*
    354   1.1       cgd 	 * The order of evaluation is "%" and "#" expand into constants.
    355   1.1       cgd 	 * "&" can expand into "+".  "+" can expand into shell meta characters.
    356   1.1       cgd 	 * Shell meta characters expand into constants.
    357   1.1       cgd 	 * This way, we make no recursive expansion.
    358   1.1       cgd 	 */
    359   1.1       cgd 	switch (*name) {
    360   1.1       cgd 	case '%':
    361   1.1       cgd 		findmail(name[1] ? name + 1 : myname, xname);
    362   1.1       cgd 		return savestr(xname);
    363   1.1       cgd 	case '#':
    364   1.1       cgd 		if (name[1] != 0)
    365   1.1       cgd 			break;
    366   1.1       cgd 		if (prevfile[0] == 0) {
    367   1.1       cgd 			printf("No previous file\n");
    368  1.17       wiz 			return NULL;
    369   1.1       cgd 		}
    370   1.1       cgd 		return savestr(prevfile);
    371   1.1       cgd 	case '&':
    372  1.17       wiz 		if (name[1] == 0 && (name = value("MBOX")) == NULL)
    373   1.1       cgd 			name = "~/mbox";
    374   1.1       cgd 		/* fall through */
    375   1.1       cgd 	}
    376   1.1       cgd 	if (name[0] == '+' && getfold(cmdbuf) >= 0) {
    377   1.7     mikel 		snprintf(xname, PATHSIZE, "%s/%s", cmdbuf, name + 1);
    378   1.1       cgd 		name = savestr(xname);
    379   1.1       cgd 	}
    380   1.1       cgd 	/* catch the most common shell meta character */
    381   1.1       cgd 	if (name[0] == '~' && (name[1] == '/' || name[1] == '\0')) {
    382   1.7     mikel 		snprintf(xname, PATHSIZE, "%s%s", homedir, name + 1);
    383   1.1       cgd 		name = savestr(xname);
    384   1.1       cgd 	}
    385  1.18       wiz 	if (strpbrk(name, "~{[*?$`'\"\\") == NULL)
    386   1.1       cgd 		return name;
    387   1.1       cgd 	if (pipe(pivec) < 0) {
    388  1.20       wiz 		warn("pipe");
    389   1.1       cgd 		return name;
    390   1.1       cgd 	}
    391   1.7     mikel 	snprintf(cmdbuf, PATHSIZE, "echo %s", name);
    392  1.17       wiz 	if ((shellcmd = value("SHELL")) == NULL)
    393  1.16       wiz 		shellcmd = _PATH_CSHELL;
    394  1.17       wiz 	pid = start_command(shellcmd, 0, -1, pivec[1], "-c", cmdbuf, NULL);
    395   1.1       cgd 	if (pid < 0) {
    396   1.1       cgd 		close(pivec[0]);
    397   1.1       cgd 		close(pivec[1]);
    398  1.17       wiz 		return NULL;
    399   1.1       cgd 	}
    400   1.1       cgd 	close(pivec[1]);
    401   1.7     mikel 	l = read(pivec[0], xname, PATHSIZE);
    402   1.1       cgd 	close(pivec[0]);
    403  1.12  christos 	if (wait_child(pid) < 0 && WTERMSIG(wait_status) != SIGPIPE) {
    404   1.1       cgd 		fprintf(stderr, "\"%s\": Expansion failed.\n", name);
    405  1.17       wiz 		return NULL;
    406   1.1       cgd 	}
    407   1.1       cgd 	if (l < 0) {
    408  1.20       wiz 		warn("read");
    409  1.17       wiz 		return NULL;
    410   1.1       cgd 	}
    411   1.1       cgd 	if (l == 0) {
    412   1.1       cgd 		fprintf(stderr, "\"%s\": No match.\n", name);
    413  1.17       wiz 		return NULL;
    414   1.1       cgd 	}
    415   1.7     mikel 	if (l == PATHSIZE) {
    416   1.1       cgd 		fprintf(stderr, "\"%s\": Expansion buffer overflow.\n", name);
    417  1.17       wiz 		return NULL;
    418   1.1       cgd 	}
    419   1.7     mikel 	xname[l] = '\0';
    420   1.1       cgd 	for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--)
    421   1.1       cgd 		;
    422   1.1       cgd 	cp[1] = '\0';
    423  1.12  christos 	if (strchr(xname, ' ') && stat(xname, &sbuf) < 0) {
    424   1.1       cgd 		fprintf(stderr, "\"%s\": Ambiguous.\n", name);
    425  1.17       wiz 		return NULL;
    426   1.1       cgd 	}
    427   1.1       cgd 	return savestr(xname);
    428   1.1       cgd }
    429   1.1       cgd 
    430   1.1       cgd /*
    431   1.1       cgd  * Determine the current folder directory name.
    432   1.1       cgd  */
    433   1.4   deraadt int
    434  1.15       wiz getfold(char *name)
    435   1.1       cgd {
    436   1.1       cgd 	char *folder;
    437   1.1       cgd 
    438  1.17       wiz 	if ((folder = value("folder")) == NULL)
    439   1.1       cgd 		return (-1);
    440   1.7     mikel 	if (*folder == '/') {
    441   1.7     mikel 		strncpy(name, folder, PATHSIZE - 1);
    442   1.7     mikel 		name[PATHSIZE - 1] = '\0' ;
    443   1.7     mikel 	}
    444   1.1       cgd 	else
    445   1.7     mikel 		snprintf(name, PATHSIZE, "%s/%s", homedir, folder);
    446   1.1       cgd 	return (0);
    447   1.1       cgd }
    448   1.1       cgd 
    449   1.1       cgd /*
    450   1.1       cgd  * Return the name of the dead.letter file.
    451   1.1       cgd  */
    452   1.1       cgd char *
    453  1.15       wiz getdeadletter(void)
    454   1.1       cgd {
    455  1.10     lukem 	char *cp;
    456   1.1       cgd 
    457  1.17       wiz 	if ((cp = value("DEAD")) == NULL || (cp = expand(cp)) == NULL)
    458   1.1       cgd 		cp = expand("~/dead.letter");
    459   1.1       cgd 	else if (*cp != '/') {
    460   1.1       cgd 		char buf[PATHSIZE];
    461   1.1       cgd 
    462  1.19       wiz 		(void)snprintf(buf, PATHSIZE, "~/%s", cp);
    463   1.1       cgd 		cp = expand(buf);
    464   1.1       cgd 	}
    465   1.1       cgd 	return cp;
    466   1.1       cgd }
    467