Home | History | Annotate | Line # | Download | only in mail
fio.c revision 1.10
      1  1.10     lukem /*	$NetBSD: fio.c,v 1.10 1997/10/19 05:03:22 lukem 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.10     lukem __RCSID("$NetBSD: fio.c,v 1.10 1997/10/19 05:03:22 lukem 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.1       cgd 
     54   1.1       cgd /*
     55   1.1       cgd  * Set up the input pointers while copying the mail file into /tmp.
     56   1.1       cgd  */
     57   1.4   deraadt void
     58   1.6       tls setptr(ibuf, offset)
     59  1.10     lukem 	FILE *ibuf;
     60   1.6       tls 	off_t offset;
     61   1.1       cgd {
     62   1.4   deraadt 	extern char *tmpdir;
     63  1.10     lukem 	int c, count;
     64  1.10     lukem 	char *cp, *cp2;
     65   1.1       cgd 	struct message this;
     66   1.1       cgd 	FILE *mestmp;
     67   1.1       cgd 	int maybe, inhead;
     68   1.1       cgd 	char linebuf[LINESIZE];
     69   1.6       tls 	int omsgCount;
     70   1.1       cgd 
     71   1.1       cgd 	/* Get temporary file. */
     72   1.7     mikel 	(void)snprintf(linebuf, LINESIZE, "%s/mail.XXXXXX", tmpdir);
     73   1.1       cgd 	if ((c = mkstemp(linebuf)) == -1 ||
     74   1.1       cgd 	    (mestmp = Fdopen(c, "r+")) == NULL) {
     75   1.1       cgd 		(void)fprintf(stderr, "mail: can't open %s\n", linebuf);
     76   1.1       cgd 		exit(1);
     77   1.1       cgd 	}
     78   1.1       cgd 	(void)unlink(linebuf);
     79   1.1       cgd 
     80   1.6       tls 	if (offset == 0) {
     81   1.6       tls 		 msgCount = 0;
     82   1.6       tls 	} else {
     83   1.6       tls 		/* Seek into the file to get to the new messages */
     84   1.6       tls 		(void) fseek(ibuf, offset, 0);
     85   1.6       tls 		/*
     86   1.6       tls 		 * We need to make "offset" a pointer to the end of
     87   1.6       tls 		 * the temp file that has the copy of the mail file.
     88   1.6       tls 		 * If any messages have been edited, this will be
     89   1.6       tls 		 * different from the offset into the mail file.
     90   1.6       tls 		 */
     91   1.6       tls 		(void) fseek(otf, 0L, 2);
     92   1.6       tls 		offset = ftell(otf);
     93   1.6       tls 	}
     94   1.6       tls 	omsgCount = msgCount;
     95   1.1       cgd 	maybe = 1;
     96   1.1       cgd 	inhead = 0;
     97   1.1       cgd 	this.m_flag = MUSED|MNEW;
     98   1.1       cgd 	this.m_size = 0;
     99   1.1       cgd 	this.m_lines = 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.1       cgd 				perror("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.1       cgd 		count = 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.9      matt 		if (count >= 2 && linebuf[count-1] == '\n' && linebuf[count-2] == '\r') {
    118   1.9      matt 			linebuf[count-2] = '\n';
    119   1.9      matt 			count--;
    120   1.9      matt 		}
    121   1.1       cgd 		(void) fwrite(linebuf, sizeof *linebuf, count, otf);
    122   1.1       cgd 		if (ferror(otf)) {
    123   1.1       cgd 			perror("/tmp");
    124   1.1       cgd 			exit(1);
    125   1.1       cgd 		}
    126   1.1       cgd 		linebuf[count - 1] = 0;
    127   1.1       cgd 		if (maybe && linebuf[0] == 'F' && ishead(linebuf)) {
    128   1.1       cgd 			msgCount++;
    129   1.1       cgd 			if (append(&this, mestmp)) {
    130   1.1       cgd 				perror("temporary file");
    131   1.1       cgd 				exit(1);
    132   1.1       cgd 			}
    133   1.1       cgd 			this.m_flag = MUSED|MNEW;
    134   1.1       cgd 			this.m_size = 0;
    135   1.1       cgd 			this.m_lines = 0;
    136   1.1       cgd 			this.m_block = blockof(offset);
    137   1.1       cgd 			this.m_offset = offsetof(offset);
    138   1.1       cgd 			inhead = 1;
    139   1.1       cgd 		} else if (linebuf[0] == 0) {
    140   1.1       cgd 			inhead = 0;
    141   1.1       cgd 		} else if (inhead) {
    142   1.1       cgd 			for (cp = linebuf, cp2 = "status";; cp++) {
    143   1.1       cgd 				if ((c = *cp2++) == 0) {
    144   1.1       cgd 					while (isspace(*cp++))
    145   1.1       cgd 						;
    146   1.1       cgd 					if (cp[-1] != ':')
    147   1.1       cgd 						break;
    148   1.5  christos 					while ((c = *cp++) != '\0')
    149   1.1       cgd 						if (c == 'R')
    150   1.1       cgd 							this.m_flag |= MREAD;
    151   1.1       cgd 						else if (c == 'O')
    152   1.1       cgd 							this.m_flag &= ~MNEW;
    153   1.1       cgd 					inhead = 0;
    154   1.1       cgd 					break;
    155   1.1       cgd 				}
    156   1.1       cgd 				if (*cp != c && *cp != toupper(c))
    157   1.1       cgd 					break;
    158   1.1       cgd 			}
    159   1.1       cgd 		}
    160   1.1       cgd 		offset += count;
    161   1.1       cgd 		this.m_size += count;
    162   1.1       cgd 		this.m_lines++;
    163   1.1       cgd 		maybe = linebuf[0] == 0;
    164   1.1       cgd 	}
    165   1.1       cgd }
    166   1.1       cgd 
    167   1.1       cgd /*
    168   1.1       cgd  * Drop the passed line onto the passed output buffer.
    169   1.1       cgd  * If a write error occurs, return -1, else the count of
    170   1.8      phil  * characters written, including the newline if requested.
    171   1.1       cgd  */
    172   1.4   deraadt int
    173   1.8      phil putline(obuf, linebuf, outlf)
    174   1.1       cgd 	FILE *obuf;
    175   1.1       cgd 	char *linebuf;
    176   1.8      phil 	int   outlf;
    177   1.1       cgd {
    178  1.10     lukem 	int c;
    179   1.1       cgd 
    180   1.1       cgd 	c = strlen(linebuf);
    181   1.1       cgd 	(void) fwrite(linebuf, sizeof *linebuf, c, obuf);
    182   1.8      phil 	if (outlf) {
    183   1.8      phil 		(void) putc('\n', obuf);
    184   1.8      phil 		c++;
    185   1.8      phil 	}
    186   1.1       cgd 	if (ferror(obuf))
    187   1.1       cgd 		return (-1);
    188   1.8      phil 	return (c);
    189   1.1       cgd }
    190   1.1       cgd 
    191   1.1       cgd /*
    192   1.1       cgd  * Read up a line from the specified input into the line
    193   1.1       cgd  * buffer.  Return the number of characters read.  Do not
    194   1.1       cgd  * include the newline at the end.
    195   1.1       cgd  */
    196   1.4   deraadt int
    197   1.1       cgd readline(ibuf, linebuf, linesize)
    198   1.1       cgd 	FILE *ibuf;
    199   1.1       cgd 	char *linebuf;
    200   1.4   deraadt 	int linesize;
    201   1.1       cgd {
    202  1.10     lukem 	int n;
    203   1.1       cgd 
    204   1.1       cgd 	clearerr(ibuf);
    205   1.1       cgd 	if (fgets(linebuf, linesize, ibuf) == NULL)
    206   1.1       cgd 		return -1;
    207   1.1       cgd 	n = strlen(linebuf);
    208   1.1       cgd 	if (n > 0 && linebuf[n - 1] == '\n')
    209   1.1       cgd 		linebuf[--n] = '\0';
    210   1.1       cgd 	return n;
    211   1.1       cgd }
    212   1.1       cgd 
    213   1.1       cgd /*
    214   1.1       cgd  * Return a file buffer all ready to read up the
    215   1.1       cgd  * passed message pointer.
    216   1.1       cgd  */
    217   1.1       cgd FILE *
    218   1.1       cgd setinput(mp)
    219  1.10     lukem 	struct message *mp;
    220   1.1       cgd {
    221   1.1       cgd 
    222   1.1       cgd 	fflush(otf);
    223  1.10     lukem 	if (fseek(itf, (long)positionof(mp->m_block, mp->m_offset), 0) < 0)
    224  1.10     lukem 		err(1, "fseek");
    225   1.1       cgd 	return (itf);
    226   1.1       cgd }
    227   1.1       cgd 
    228   1.1       cgd /*
    229   1.1       cgd  * Take the data out of the passed ghost file and toss it into
    230   1.1       cgd  * a dynamically allocated message structure.
    231   1.1       cgd  */
    232   1.4   deraadt void
    233   1.6       tls makemessage(f, omsgCount)
    234   1.1       cgd 	FILE *f;
    235   1.6       tls 	int omsgCount;
    236   1.1       cgd {
    237  1.10     lukem 	int size = (msgCount + 1) * sizeof (struct message);
    238   1.1       cgd 
    239   1.6       tls 	if (omsgCount) {
    240   1.6       tls 		message = (struct message *)realloc(message, (unsigned) size);
    241   1.6       tls 		if (message == 0)
    242  1.10     lukem 			errx(1, "Insufficient memory for %d messages\n",
    243   1.6       tls 			      msgCount);
    244   1.6       tls 	} else {
    245   1.6       tls 		if (message != 0)
    246   1.6       tls 			free((char *) message);
    247   1.6       tls 		if ((message = (struct message *) malloc((unsigned) size)) == 0)
    248  1.10     lukem 			errx(1, "Insufficient memory for %d messages",
    249  1.10     lukem 			    msgCount);
    250   1.6       tls 		dot = message;
    251   1.6       tls 	}
    252   1.6       tls 	size -= (omsgCount + 1) * sizeof (struct message);
    253   1.1       cgd 	fflush(f);
    254   1.4   deraadt 	(void) lseek(fileno(f), (off_t)sizeof *message, 0);
    255   1.6       tls 	if (read(fileno(f), (char *) &message[omsgCount], size) != size)
    256  1.10     lukem 		errx(1, "Message temporary file corrupted");
    257   1.1       cgd 	message[msgCount].m_size = 0;
    258   1.1       cgd 	message[msgCount].m_lines = 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.1       cgd append(mp, f)
    268   1.1       cgd 	struct message *mp;
    269   1.1       cgd 	FILE *f;
    270   1.1       cgd {
    271   1.1       cgd 	return fwrite((char *) mp, sizeof *mp, 1, f) != 1;
    272   1.1       cgd }
    273   1.1       cgd 
    274   1.1       cgd /*
    275   1.1       cgd  * Delete a file, but only if the file is a plain file.
    276   1.1       cgd  */
    277   1.4   deraadt int
    278   1.1       cgd rm(name)
    279   1.1       cgd 	char *name;
    280   1.1       cgd {
    281   1.1       cgd 	struct stat sb;
    282   1.1       cgd 
    283   1.1       cgd 	if (stat(name, &sb) < 0)
    284   1.1       cgd 		return(-1);
    285   1.1       cgd 	if (!S_ISREG(sb.st_mode)) {
    286   1.1       cgd 		errno = EISDIR;
    287   1.1       cgd 		return(-1);
    288   1.1       cgd 	}
    289   1.1       cgd 	return(unlink(name));
    290   1.1       cgd }
    291   1.1       cgd 
    292   1.1       cgd static int sigdepth;		/* depth of holdsigs() */
    293   1.5  christos static sigset_t nset, oset;
    294   1.1       cgd /*
    295   1.1       cgd  * Hold signals SIGHUP, SIGINT, and SIGQUIT.
    296   1.1       cgd  */
    297   1.4   deraadt void
    298   1.1       cgd holdsigs()
    299   1.1       cgd {
    300   1.1       cgd 
    301   1.5  christos 	if (sigdepth++ == 0) {
    302   1.5  christos 		sigemptyset(&nset);
    303   1.5  christos 		sigaddset(&nset, SIGHUP);
    304   1.5  christos 		sigaddset(&nset, SIGINT);
    305   1.5  christos 		sigaddset(&nset, SIGQUIT);
    306   1.5  christos 		sigprocmask(SIG_BLOCK, &nset, &oset);
    307   1.5  christos 	}
    308   1.1       cgd }
    309   1.1       cgd 
    310   1.1       cgd /*
    311   1.1       cgd  * Release signals SIGHUP, SIGINT, and SIGQUIT.
    312   1.1       cgd  */
    313   1.4   deraadt void
    314   1.1       cgd relsesigs()
    315   1.1       cgd {
    316   1.1       cgd 
    317   1.1       cgd 	if (--sigdepth == 0)
    318   1.5  christos 		sigprocmask(SIG_SETMASK, &oset, NULL);
    319   1.1       cgd }
    320   1.1       cgd 
    321   1.1       cgd /*
    322   1.1       cgd  * Determine the size of the file possessed by
    323   1.1       cgd  * the passed buffer.
    324   1.1       cgd  */
    325   1.1       cgd off_t
    326   1.1       cgd fsize(iob)
    327   1.1       cgd 	FILE *iob;
    328   1.1       cgd {
    329   1.1       cgd 	struct stat sbuf;
    330   1.1       cgd 
    331   1.1       cgd 	if (fstat(fileno(iob), &sbuf) < 0)
    332   1.1       cgd 		return 0;
    333   1.1       cgd 	return sbuf.st_size;
    334   1.1       cgd }
    335   1.1       cgd 
    336   1.1       cgd /*
    337   1.1       cgd  * Evaluate the string given as a new mailbox name.
    338   1.1       cgd  * Supported meta characters:
    339   1.1       cgd  *	%	for my system mail box
    340   1.1       cgd  *	%user	for user's system mail box
    341   1.1       cgd  *	#	for previous file
    342   1.1       cgd  *	&	invoker's mbox file
    343   1.1       cgd  *	+file	file in folder directory
    344   1.1       cgd  *	any shell meta character
    345   1.1       cgd  * Return the file name as a dynamic string.
    346   1.1       cgd  */
    347   1.1       cgd char *
    348   1.1       cgd expand(name)
    349  1.10     lukem 	char *name;
    350   1.1       cgd {
    351   1.1       cgd 	char xname[PATHSIZE];
    352   1.1       cgd 	char cmdbuf[PATHSIZE];		/* also used for file names */
    353  1.10     lukem 	int pid, l;
    354  1.10     lukem 	char *cp, *shell;
    355   1.1       cgd 	int pivec[2];
    356   1.1       cgd 	struct stat sbuf;
    357   1.1       cgd 	extern union wait wait_status;
    358   1.1       cgd 
    359   1.1       cgd 	/*
    360   1.1       cgd 	 * The order of evaluation is "%" and "#" expand into constants.
    361   1.1       cgd 	 * "&" can expand into "+".  "+" can expand into shell meta characters.
    362   1.1       cgd 	 * Shell meta characters expand into constants.
    363   1.1       cgd 	 * This way, we make no recursive expansion.
    364   1.1       cgd 	 */
    365   1.1       cgd 	switch (*name) {
    366   1.1       cgd 	case '%':
    367   1.1       cgd 		findmail(name[1] ? name + 1 : myname, xname);
    368   1.1       cgd 		return savestr(xname);
    369   1.1       cgd 	case '#':
    370   1.1       cgd 		if (name[1] != 0)
    371   1.1       cgd 			break;
    372   1.1       cgd 		if (prevfile[0] == 0) {
    373   1.1       cgd 			printf("No previous file\n");
    374   1.1       cgd 			return NOSTR;
    375   1.1       cgd 		}
    376   1.1       cgd 		return savestr(prevfile);
    377   1.1       cgd 	case '&':
    378   1.1       cgd 		if (name[1] == 0 && (name = value("MBOX")) == NOSTR)
    379   1.1       cgd 			name = "~/mbox";
    380   1.1       cgd 		/* fall through */
    381   1.1       cgd 	}
    382   1.1       cgd 	if (name[0] == '+' && getfold(cmdbuf) >= 0) {
    383   1.7     mikel 		snprintf(xname, PATHSIZE, "%s/%s", cmdbuf, name + 1);
    384   1.1       cgd 		name = savestr(xname);
    385   1.1       cgd 	}
    386   1.1       cgd 	/* catch the most common shell meta character */
    387   1.1       cgd 	if (name[0] == '~' && (name[1] == '/' || name[1] == '\0')) {
    388   1.7     mikel 		snprintf(xname, PATHSIZE, "%s%s", homedir, name + 1);
    389   1.1       cgd 		name = savestr(xname);
    390   1.1       cgd 	}
    391   1.1       cgd 	if (!anyof(name, "~{[*?$`'\"\\"))
    392   1.1       cgd 		return name;
    393   1.1       cgd 	if (pipe(pivec) < 0) {
    394   1.1       cgd 		perror("pipe");
    395   1.1       cgd 		return name;
    396   1.1       cgd 	}
    397   1.7     mikel 	snprintf(cmdbuf, PATHSIZE, "echo %s", name);
    398   1.1       cgd 	if ((shell = value("SHELL")) == NOSTR)
    399   1.1       cgd 		shell = _PATH_CSHELL;
    400   1.1       cgd 	pid = start_command(shell, 0, -1, pivec[1], "-c", cmdbuf, NOSTR);
    401   1.1       cgd 	if (pid < 0) {
    402   1.1       cgd 		close(pivec[0]);
    403   1.1       cgd 		close(pivec[1]);
    404   1.1       cgd 		return NOSTR;
    405   1.1       cgd 	}
    406   1.1       cgd 	close(pivec[1]);
    407   1.7     mikel 	l = read(pivec[0], xname, PATHSIZE);
    408   1.1       cgd 	close(pivec[0]);
    409   1.1       cgd 	if (wait_child(pid) < 0 && wait_status.w_termsig != SIGPIPE) {
    410   1.1       cgd 		fprintf(stderr, "\"%s\": Expansion failed.\n", name);
    411   1.1       cgd 		return NOSTR;
    412   1.1       cgd 	}
    413   1.1       cgd 	if (l < 0) {
    414   1.1       cgd 		perror("read");
    415   1.1       cgd 		return NOSTR;
    416   1.1       cgd 	}
    417   1.1       cgd 	if (l == 0) {
    418   1.1       cgd 		fprintf(stderr, "\"%s\": No match.\n", name);
    419   1.1       cgd 		return NOSTR;
    420   1.1       cgd 	}
    421   1.7     mikel 	if (l == PATHSIZE) {
    422   1.1       cgd 		fprintf(stderr, "\"%s\": Expansion buffer overflow.\n", name);
    423   1.1       cgd 		return NOSTR;
    424   1.1       cgd 	}
    425   1.7     mikel 	xname[l] = '\0';
    426   1.1       cgd 	for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--)
    427   1.1       cgd 		;
    428   1.1       cgd 	cp[1] = '\0';
    429   1.1       cgd 	if (index(xname, ' ') && stat(xname, &sbuf) < 0) {
    430   1.1       cgd 		fprintf(stderr, "\"%s\": Ambiguous.\n", name);
    431   1.1       cgd 		return NOSTR;
    432   1.1       cgd 	}
    433   1.1       cgd 	return savestr(xname);
    434   1.1       cgd }
    435   1.1       cgd 
    436   1.1       cgd /*
    437   1.1       cgd  * Determine the current folder directory name.
    438   1.1       cgd  */
    439   1.4   deraadt int
    440   1.1       cgd getfold(name)
    441   1.1       cgd 	char *name;
    442   1.1       cgd {
    443   1.1       cgd 	char *folder;
    444   1.1       cgd 
    445   1.1       cgd 	if ((folder = value("folder")) == NOSTR)
    446   1.1       cgd 		return (-1);
    447   1.7     mikel 	if (*folder == '/') {
    448   1.7     mikel 		strncpy(name, folder, PATHSIZE - 1);
    449   1.7     mikel 		name[PATHSIZE - 1] = '\0' ;
    450   1.7     mikel 	}
    451   1.1       cgd 	else
    452   1.7     mikel 		snprintf(name, PATHSIZE, "%s/%s", homedir, folder);
    453   1.1       cgd 	return (0);
    454   1.1       cgd }
    455   1.1       cgd 
    456   1.1       cgd /*
    457   1.1       cgd  * Return the name of the dead.letter file.
    458   1.1       cgd  */
    459   1.1       cgd char *
    460   1.1       cgd getdeadletter()
    461   1.1       cgd {
    462  1.10     lukem 	char *cp;
    463   1.1       cgd 
    464   1.1       cgd 	if ((cp = value("DEAD")) == NOSTR || (cp = expand(cp)) == NOSTR)
    465   1.1       cgd 		cp = expand("~/dead.letter");
    466   1.1       cgd 	else if (*cp != '/') {
    467   1.1       cgd 		char buf[PATHSIZE];
    468   1.1       cgd 
    469   1.7     mikel 		(void) snprintf(buf, PATHSIZE, "~/%s", cp);
    470   1.1       cgd 		cp = expand(buf);
    471   1.1       cgd 	}
    472   1.1       cgd 	return cp;
    473   1.1       cgd }
    474