-
-/*
- * slocal.c -- asynchronously filter and deliver new mail
+/* slocal.c -- asynchronously filter and deliver new mail
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
#include <h/tws.h>
#include <h/mts.h>
#include <h/utils.h>
+#include "../sbr/lock_file.h"
+#include "../sbr/m_mktemp.h"
#include <pwd.h>
#include <sys/ioctl.h>
if (*buffer == '#' || *buffer == '\n')
continue;
- TrimSuffixC(buffer, '\n');
+ trim_suffix_c(buffer, '\n');
/* split buffer into fields */
vecp = split (buffer, vec);
* do this - else fall through
*/
if (!next)
- continue; /* else fall */
+ continue;
+ /* FALLTHRU */
case '?':
/*
* consider delivered if action is successful.
*/
if (won)
- continue; /* else fall */
+ continue;
+ /* FALLTHRU */
case 'A':
case 'a':
if (won)
continue;
break;
- } /* else fall */
+ }
+ /* FALLTHRU */
default:
/* parse message and build lookup table */
case 'q':
/* deliver to quoted pipe */
if (strcasecmp (action, "qpipe"))
- continue; /* else fall */
+ continue;
+ /* FALLTHRU */
case '^':
expand (tmpbuf, string, fd);
if (split (tmpbuf, vec) < 1)
case 'p':
/* deliver to pipe */
if (strcasecmp (action, "pipe"))
- continue; /* else fall */
+ continue;
+ /* FALLTHRU */
case '|':
vec[2] = "sh";
vec[3] = "-c";
}
/* deliver to nmh folder */
else if (strcasecmp (action, "folder"))
- continue; /* else fall */
+ continue;
+ /* FALLTHRU */
case '+':
status = usr_folder (fd, string);
break;
}
/* mbox format */
else if (strcasecmp (action, "mbox"))
- continue; /* else fall */
+ continue;
+ /* FALLTHRU */
case '>':
/* mbox format */
int i, state;
int fd1;
char *cp, *dp, *lp;
- char name[NAMESZ], field[BUFSIZ];
+ char name[NAMESZ], field[NMH_BUFSIZ];
struct pair *p, *q;
FILE *in;
m_getfld_state_t gstate = 0;
case LENERR:
case FMTERR:
- advise (NULL, "format error in message");
+ inform("format error in message");
break;
default:
- advise (NULL, "internal error in m_getfld");
+ inform("internal error in m_getfld");
fclose (in);
return -1;
}
static int
usr_file (int fd, char *mailbox, int mbx_style)
{
- int md, mapping;
-
- if (verbose)
- verbose_printf ("delivering to file \"%s\"", mailbox);
+ int md;
- if (mbx_style == MBOX_FORMAT) {
- if (verbose)
- verbose_printf (" (mbox style)");
- mapping = 0;
- } else {
- if (verbose)
- verbose_printf (" (mmdf style)");
- mapping = 1;
+ if (verbose) {
+ verbose_printf("delivering to file \"%s\" (%s style)", mailbox,
+ mbx_style == MBOX_FORMAT ? "mbox" : "mmdf");
}
/* open and lock the file */
return -1;
}
- lseek (fd, (off_t) 0, SEEK_SET);
+ lseek(fd, 0, SEEK_SET);
/* append message to file */
- if (mbx_copy (mailbox, mbx_style, md, fd, mapping, NULL, verbose) == -1) {
+ if (mbx_copy (mailbox, mbx_style, md, fd, NULL) == -1) {
if (verbose)
adorn ("", "error writing to:");
return -1;
if (verbose && !suppress)
verbose_printf ("delivering to pipe \"%s\"", cmd);
- lseek (fd, (off_t) 0, SEEK_SET);
+ lseek(fd, 0, SEEK_SET);
for (i = 0; (child_id = fork()) == -1 && i < 5; i++)
sleep (5);
setpgid ((pid_t) 0, getpid ()); /* put in own process group */
*environ = NULL;
- m_putenv ("USER", pw->pw_name);
- m_putenv ("HOME", pw->pw_dir);
- m_putenv ("SHELL", pw->pw_shell);
+ setenv("USER", pw->pw_name, 1);
+ setenv("HOME", pw->pw_dir, 1);
+ setenv("SHELL", pw->pw_shell, 1);
execvp (pgm, vec);
_exit (-1);
}
if (i == -1)
goto you_lose;
- lseek (fd1, (off_t) 0, SEEK_SET);
+ lseek(fd1, 0, SEEK_SET);
return fd1;
}
while (fgets (buffer, sizeof(buffer), qfp)) {
if (first) {
first = 0;
- if (HasPrefix(buffer, "From ")) {
+ if (has_prefix(buffer, "From ")) {
/* get copy of envelope information ("From " line) */
envelope = mh_xstrdup(buffer);
return -1;
}
fclose (qfp);
- lseek (fd1, (off_t) 0, SEEK_SET);
+ lseek(fd1, 0, SEEK_SET);
return fd1;
suppress_duplicates (int fd, char *file)
{
int fd1, lockfd, state, result;
- char *cp, buf[BUFSIZ], name[NAMESZ];
+ char *cp, buf[NMH_BUFSIZ], name[NAMESZ];
datum key, value;
DBM *db;
FILE *in;