1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2001-03-25 04:57:05 +00:00
|
|
|
#if 0
|
2001-12-18 20:52:09 +00:00
|
|
|
static char sccsid[] = "@(#)fio.c 8.2 (Berkeley) 4/20/95";
|
2001-03-25 04:57:05 +00:00
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$FreeBSD$";
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "rcv.h"
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mail -- a mail program
|
|
|
|
*
|
|
|
|
* File I/O.
|
|
|
|
*/
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
extern int wait_status;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Set up the input pointers while copying the mail file into /tmp.
|
|
|
|
*/
|
|
|
|
void
|
2001-12-18 20:52:09 +00:00
|
|
|
setptr(ibuf, offset)
|
2001-05-27 20:26:22 +00:00
|
|
|
FILE *ibuf;
|
2001-12-18 20:52:09 +00:00
|
|
|
off_t offset;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int c, count;
|
|
|
|
char *cp, *cp2;
|
1994-05-27 12:33:43 +00:00
|
|
|
struct message this;
|
|
|
|
FILE *mestmp;
|
|
|
|
int maybe, inhead;
|
2001-03-25 04:57:05 +00:00
|
|
|
char linebuf[LINESIZE], pathbuf[PATHSIZE];
|
2001-12-18 20:52:09 +00:00
|
|
|
int omsgCount;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/* Get temporary file. */
|
2001-03-25 04:57:05 +00:00
|
|
|
(void)snprintf(pathbuf, sizeof(pathbuf), "%s/mail.XXXXXXXXXX", tmpdir);
|
|
|
|
if ((c = mkstemp(pathbuf)) == -1 || (mestmp = Fdopen(c, "r+")) == NULL)
|
|
|
|
err(1, "can't open %s", pathbuf);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)rm(pathbuf);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-12-18 20:52:09 +00:00
|
|
|
if (offset == 0) {
|
|
|
|
msgCount = 0;
|
|
|
|
} else {
|
|
|
|
/* Seek into the file to get to the new messages */
|
|
|
|
(void)fseek(ibuf, offset, SEEK_SET);
|
|
|
|
/*
|
|
|
|
* We need to make "offset" a pointer to the end of
|
|
|
|
* the temp file that has the copy of the mail file.
|
|
|
|
* If any messages have been edited, this will be
|
|
|
|
* different from the offset into the mail file.
|
|
|
|
*/
|
|
|
|
(void)fseek(otf, 0L, SEEK_END);
|
|
|
|
offset = ftell(otf);
|
|
|
|
}
|
|
|
|
omsgCount = msgCount;
|
1994-05-27 12:33:43 +00:00
|
|
|
maybe = 1;
|
|
|
|
inhead = 0;
|
|
|
|
this.m_flag = MUSED|MNEW;
|
|
|
|
this.m_size = 0;
|
|
|
|
this.m_lines = 0;
|
|
|
|
this.m_block = 0;
|
|
|
|
this.m_offset = 0;
|
|
|
|
for (;;) {
|
2001-03-25 04:57:05 +00:00
|
|
|
if (fgets(linebuf, sizeof(linebuf), ibuf) == NULL) {
|
|
|
|
if (append(&this, mestmp))
|
|
|
|
errx(1, "temporary file");
|
2001-12-18 20:52:09 +00:00
|
|
|
makemessage(mestmp, omsgCount);
|
1994-05-27 12:33:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
count = strlen(linebuf);
|
2001-05-11 03:07:11 +00:00
|
|
|
/*
|
|
|
|
* Transforms lines ending in <CR><LF> to just <LF>.
|
|
|
|
* This allows mail to be able to read Eudora mailboxes.
|
|
|
|
*/
|
|
|
|
if (count >= 2 && linebuf[count - 1] == '\n' &&
|
|
|
|
linebuf[count - 2] == '\r') {
|
|
|
|
count--;
|
|
|
|
linebuf[count - 1] = '\n';
|
|
|
|
}
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fwrite(linebuf, sizeof(*linebuf), count, otf);
|
2001-03-25 04:57:05 +00:00
|
|
|
if (ferror(otf))
|
|
|
|
errx(1, "/tmp");
|
|
|
|
if (count)
|
|
|
|
linebuf[count - 1] = '\0';
|
1994-05-27 12:33:43 +00:00
|
|
|
if (maybe && linebuf[0] == 'F' && ishead(linebuf)) {
|
|
|
|
msgCount++;
|
2001-03-25 04:57:05 +00:00
|
|
|
if (append(&this, mestmp))
|
|
|
|
errx(1, "temporary file");
|
1994-05-27 12:33:43 +00:00
|
|
|
this.m_flag = MUSED|MNEW;
|
|
|
|
this.m_size = 0;
|
|
|
|
this.m_lines = 0;
|
|
|
|
this.m_block = blockof(offset);
|
2000-10-24 13:54:31 +00:00
|
|
|
this.m_offset = boffsetof(offset);
|
1994-05-27 12:33:43 +00:00
|
|
|
inhead = 1;
|
|
|
|
} else if (linebuf[0] == 0) {
|
|
|
|
inhead = 0;
|
|
|
|
} else if (inhead) {
|
|
|
|
for (cp = linebuf, cp2 = "status";; cp++) {
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((c = *cp2++) == '\0') {
|
1994-05-27 12:33:43 +00:00
|
|
|
while (isspace(*cp++))
|
|
|
|
;
|
|
|
|
if (cp[-1] != ':')
|
|
|
|
break;
|
2001-05-27 20:26:22 +00:00
|
|
|
while ((c = *cp++) != '\0')
|
1994-05-27 12:33:43 +00:00
|
|
|
if (c == 'R')
|
|
|
|
this.m_flag |= MREAD;
|
|
|
|
else if (c == 'O')
|
|
|
|
this.m_flag &= ~MNEW;
|
|
|
|
inhead = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*cp != c && *cp != toupper(c))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += count;
|
|
|
|
this.m_size += count;
|
|
|
|
this.m_lines++;
|
|
|
|
maybe = linebuf[0] == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drop the passed line onto the passed output buffer.
|
|
|
|
* If a write error occurs, return -1, else the count of
|
2001-12-18 20:52:09 +00:00
|
|
|
* characters written, including the newline if requested.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-12-18 20:52:09 +00:00
|
|
|
putline(obuf, linebuf, outlf)
|
1994-05-27 12:33:43 +00:00
|
|
|
FILE *obuf;
|
|
|
|
char *linebuf;
|
2001-12-18 20:52:09 +00:00
|
|
|
int outlf;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int c;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
c = strlen(linebuf);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fwrite(linebuf, sizeof(*linebuf), c, obuf);
|
2001-12-18 20:52:09 +00:00
|
|
|
if (outlf) {
|
|
|
|
fprintf(obuf, "\n");
|
|
|
|
c++;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
if (ferror(obuf))
|
|
|
|
return (-1);
|
2001-12-18 20:52:09 +00:00
|
|
|
return (c);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read up a line from the specified input into the line
|
|
|
|
* buffer. Return the number of characters read. Do not
|
2001-05-11 03:07:11 +00:00
|
|
|
* include the newline (or carriage return) at the end.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
readline(ibuf, linebuf, linesize)
|
|
|
|
FILE *ibuf;
|
|
|
|
char *linebuf;
|
|
|
|
int linesize;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int n;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
clearerr(ibuf);
|
|
|
|
if (fgets(linebuf, linesize, ibuf) == NULL)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
n = strlen(linebuf);
|
|
|
|
if (n > 0 && linebuf[n - 1] == '\n')
|
|
|
|
linebuf[--n] = '\0';
|
2001-05-11 03:07:11 +00:00
|
|
|
if (n > 0 && linebuf[n - 1] == '\r')
|
|
|
|
linebuf[--n] = '\0';
|
2001-05-27 20:26:22 +00:00
|
|
|
return (n);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a file buffer all ready to read up the
|
|
|
|
* passed message pointer.
|
|
|
|
*/
|
|
|
|
FILE *
|
|
|
|
setinput(mp)
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(otf);
|
2001-09-02 14:40:51 +00:00
|
|
|
if (fseeko(itf,
|
|
|
|
positionof(mp->m_block, mp->m_offset), SEEK_SET) < 0)
|
2001-03-25 04:57:05 +00:00
|
|
|
err(1, "fseek");
|
1994-05-27 12:33:43 +00:00
|
|
|
return (itf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take the data out of the passed ghost file and toss it into
|
|
|
|
* a dynamically allocated message structure.
|
|
|
|
*/
|
|
|
|
void
|
2001-12-18 20:52:09 +00:00
|
|
|
makemessage(f, omsgCount)
|
1994-05-27 12:33:43 +00:00
|
|
|
FILE *f;
|
2001-12-18 20:52:09 +00:00
|
|
|
int omsgCount;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-12-18 20:52:09 +00:00
|
|
|
size_t size;
|
|
|
|
struct message *nmessage;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-12-18 20:52:09 +00:00
|
|
|
size = (msgCount + 1) * sizeof(struct message);
|
|
|
|
nmessage = (struct message *)realloc(message, size);
|
|
|
|
if (nmessage == NULL)
|
|
|
|
errx(1, "Insufficient memory for %d messages\n",
|
|
|
|
msgCount);
|
|
|
|
if (omsgCount == 0 || message == NULL)
|
|
|
|
dot = nmessage;
|
|
|
|
else
|
|
|
|
dot = nmessage + (dot - message);
|
|
|
|
message = nmessage;
|
|
|
|
size -= (omsgCount + 1) * sizeof(struct message);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)fflush(f);
|
|
|
|
(void)lseek(fileno(f), (off_t)sizeof(*message), 0);
|
2001-12-18 20:52:09 +00:00
|
|
|
if (read(fileno(f), (char *)&message[omsgCount], size) != size)
|
2001-03-25 04:57:05 +00:00
|
|
|
errx(1, "Message temporary file corrupted");
|
1994-05-27 12:33:43 +00:00
|
|
|
message[msgCount].m_size = 0;
|
|
|
|
message[msgCount].m_lines = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)Fclose(f);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append the passed message descriptor onto the temp file.
|
|
|
|
* If the write fails, return 1, else 0
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
append(mp, f)
|
|
|
|
struct message *mp;
|
|
|
|
FILE *f;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
return (fwrite((char *)mp, sizeof(*mp), 1, f) != 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete a file, but only if the file is a plain file.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
rm(name)
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
if (stat(name, &sb) < 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (!S_ISREG(sb.st_mode)) {
|
|
|
|
errno = EISDIR;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (unlink(name));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sigdepth; /* depth of holdsigs() */
|
2001-12-18 20:52:09 +00:00
|
|
|
static sigset_t nset, oset;
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Hold signals SIGHUP, SIGINT, and SIGQUIT.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
holdsigs()
|
|
|
|
{
|
|
|
|
|
2001-12-18 20:52:09 +00:00
|
|
|
if (sigdepth++ == 0) {
|
|
|
|
(void)sigemptyset(&nset);
|
|
|
|
(void)sigaddset(&nset, SIGHUP);
|
|
|
|
(void)sigaddset(&nset, SIGINT);
|
|
|
|
(void)sigaddset(&nset, SIGQUIT);
|
|
|
|
(void)sigprocmask(SIG_BLOCK, &nset, &oset);
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release signals SIGHUP, SIGINT, and SIGQUIT.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
relsesigs()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (--sigdepth == 0)
|
2001-12-18 20:52:09 +00:00
|
|
|
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the size of the file possessed by
|
|
|
|
* the passed buffer.
|
|
|
|
*/
|
|
|
|
off_t
|
|
|
|
fsize(iob)
|
|
|
|
FILE *iob;
|
|
|
|
{
|
|
|
|
struct stat sbuf;
|
|
|
|
|
|
|
|
if (fstat(fileno(iob), &sbuf) < 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
|
|
|
return (sbuf.st_size);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Evaluate the string given as a new mailbox name.
|
|
|
|
* Supported meta characters:
|
|
|
|
* % for my system mail box
|
|
|
|
* %user for user's system mail box
|
|
|
|
* # for previous file
|
|
|
|
* & invoker's mbox file
|
|
|
|
* +file file in folder directory
|
|
|
|
* any shell meta character
|
|
|
|
* Return the file name as a dynamic string.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
expand(name)
|
2001-05-27 20:26:22 +00:00
|
|
|
char *name;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char xname[PATHSIZE];
|
|
|
|
char cmdbuf[PATHSIZE]; /* also used for file names */
|
2001-05-27 20:26:22 +00:00
|
|
|
int pid, l;
|
|
|
|
char *cp, *sh;
|
1994-05-27 12:33:43 +00:00
|
|
|
int pivec[2];
|
|
|
|
struct stat sbuf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The order of evaluation is "%" and "#" expand into constants.
|
|
|
|
* "&" can expand into "+". "+" can expand into shell meta characters.
|
|
|
|
* Shell meta characters expand into constants.
|
|
|
|
* This way, we make no recursive expansion.
|
|
|
|
*/
|
|
|
|
switch (*name) {
|
|
|
|
case '%':
|
2001-03-25 04:57:05 +00:00
|
|
|
findmail(name[1] ? name + 1 : myname, xname, sizeof(xname));
|
2001-05-27 20:26:22 +00:00
|
|
|
return (savestr(xname));
|
1994-05-27 12:33:43 +00:00
|
|
|
case '#':
|
|
|
|
if (name[1] != 0)
|
|
|
|
break;
|
|
|
|
if (prevfile[0] == 0) {
|
|
|
|
printf("No previous file\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (savestr(prevfile));
|
1994-05-27 12:33:43 +00:00
|
|
|
case '&':
|
2001-05-27 20:26:22 +00:00
|
|
|
if (name[1] == 0 && (name = value("MBOX")) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
name = "~/mbox";
|
|
|
|
/* fall through */
|
|
|
|
}
|
2001-03-25 04:57:05 +00:00
|
|
|
if (name[0] == '+' && getfold(cmdbuf, sizeof(cmdbuf)) >= 0) {
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)snprintf(xname, sizeof(xname), "%s/%s", cmdbuf, name + 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
name = savestr(xname);
|
|
|
|
}
|
|
|
|
/* catch the most common shell meta character */
|
2001-03-25 04:57:05 +00:00
|
|
|
if (name[0] == '~' && homedir != NULL &&
|
|
|
|
(name[1] == '/' || name[1] == '\0')) {
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)snprintf(xname, sizeof(xname), "%s%s", homedir, name + 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
name = savestr(xname);
|
|
|
|
}
|
2001-03-25 04:57:05 +00:00
|
|
|
if (!strpbrk(name, "~{[*?$`'\"\\"))
|
2001-05-27 20:26:22 +00:00
|
|
|
return (name);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (pipe(pivec) < 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("pipe");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (name);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)snprintf(cmdbuf, sizeof(cmdbuf), "echo %s", name);
|
|
|
|
if ((sh = value("SHELL")) == NULL)
|
|
|
|
sh = _PATH_CSHELL;
|
|
|
|
pid = start_command(sh, 0, -1, pivec[1], "-c", cmdbuf, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (pid < 0) {
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)close(pivec[0]);
|
|
|
|
(void)close(pivec[1]);
|
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)close(pivec[1]);
|
1994-05-27 12:33:43 +00:00
|
|
|
l = read(pivec[0], xname, BUFSIZ);
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)close(pivec[0]);
|
|
|
|
if (wait_child(pid) < 0 && WIFSIGNALED(wait_status) &&
|
|
|
|
WTERMSIG(wait_status) != SIGPIPE) {
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(stderr, "\"%s\": Expansion failed.\n", name);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (l < 0) {
|
2001-03-25 04:57:05 +00:00
|
|
|
warn("read");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (l == 0) {
|
|
|
|
fprintf(stderr, "\"%s\": No match.\n", name);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (l == BUFSIZ) {
|
|
|
|
fprintf(stderr, "\"%s\": Expansion buffer overflow.\n", name);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-03-25 04:57:05 +00:00
|
|
|
xname[l] = '\0';
|
1994-05-27 12:33:43 +00:00
|
|
|
for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--)
|
|
|
|
;
|
|
|
|
cp[1] = '\0';
|
2001-03-25 04:57:05 +00:00
|
|
|
if (strchr(xname, ' ') && stat(xname, &sbuf) < 0) {
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(stderr, "\"%s\": Ambiguous.\n", name);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (savestr(xname));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the current folder directory name.
|
|
|
|
*/
|
|
|
|
int
|
2001-03-25 04:57:05 +00:00
|
|
|
getfold(name, namelen)
|
1994-05-27 12:33:43 +00:00
|
|
|
char *name;
|
2001-03-25 04:57:05 +00:00
|
|
|
int namelen;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
char *folder;
|
2001-03-25 04:57:05 +00:00
|
|
|
int copylen;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((folder = value("folder")) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
return (-1);
|
|
|
|
if (*folder == '/')
|
2001-03-25 04:57:05 +00:00
|
|
|
copylen = strlcpy(name, folder, namelen);
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
2001-05-27 20:26:22 +00:00
|
|
|
copylen = snprintf(name, namelen, "%s/%s",
|
|
|
|
homedir ? homedir : ".", folder);
|
2001-08-20 14:46:40 +00:00
|
|
|
return (copylen < 0 || copylen >= namelen ? (-1) : (0));
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the name of the dead.letter file.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
getdeadletter()
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((cp = value("DEAD")) == NULL || (cp = expand(cp)) == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
cp = expand("~/dead.letter");
|
|
|
|
else if (*cp != '/') {
|
|
|
|
char buf[PATHSIZE];
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
(void)snprintf(buf, sizeof(buf), "~/%s", cp);
|
1994-05-27 12:33:43 +00:00
|
|
|
cp = expand(buf);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (cp);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|