*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
char *cp, *mdlvr = NULL, buf[BUFSIZ];
char mailbox[BUFSIZ], tmpfil[BUFSIZ];
char **argp, **arguments;
char *cp, *mdlvr = NULL, buf[BUFSIZ];
char mailbox[BUFSIZ], tmpfil[BUFSIZ];
char **argp, **arguments;
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (*argv, '/');
-
- /* foil search of user profile/context */
- if (context_foil (NULL) == -1)
- done (1);
+ if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
arguments = getarguments (invo_name, argc, argv, 0);
argp = arguments;
arguments = getarguments (invo_name, argc, argv, 0);
argp = arguments;
if ((pw = getpwnam (user)) == NULL)
adios (NULL, "no such local user as %s", user);
if (chdir (pw->pw_dir) == -1)
if ((pw = getpwnam (user)) == NULL)
adios (NULL, "no such local user as %s", user);
if (chdir (pw->pw_dir) == -1)
if (debug)
debug_printf ("retrieving message from file \"%s\"\n", file);
if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
if (debug)
debug_printf ("retrieving message from file \"%s\"\n", file);
if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
close (tempfd);
} else {
/* getting message from stdin */
if (debug)
debug_printf ("retrieving message from stdin\n");
if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
close (tempfd);
} else {
/* getting message from stdin */
if (debug)
debug_printf ("retrieving message from stdin\n");
if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
thing would be to delay this unlink() until later if debug == 1, but I'll
leave that for someone who cares about the temp-file-accessing
functionality (they'll have to watch out for cases where we adios()). */
thing would be to delay this unlink() until later if debug == 1, but I'll
leave that for someone who cares about the temp-file-accessing
functionality (they'll have to watch out for cases where we adios()). */
if (!(fp = fdopen (fd, "r+")))
adios (NULL, "unable to access temporary file");
if (!(fp = fdopen (fd, "r+")))
adios (NULL, "unable to access temporary file");
int i, accept, status=1, won, vecp, next;
char *field, *pattern, *action, *result, *string;
char buffer[BUFSIZ], tmpbuf[BUFSIZ];
int i, accept, status=1, won, vecp, next;
char *field, *pattern, *action, *result, *string;
char buffer[BUFSIZ], tmpbuf[BUFSIZ];
/* split buffer into fields */
vecp = split (buffer, vec);
/* split buffer into fields */
vecp = split (buffer, vec);
case '^':
expand (tmpbuf, string, fd);
if (split (tmpbuf, vec) < 1)
case '^':
expand (tmpbuf, string, fd);
if (split (tmpbuf, vec) < 1)
status = usr_file (fd, string, MBOX_FORMAT);
break;
}
/* deliver to nmh folder */
status = usr_file (fd, string, MBOX_FORMAT);
break;
}
/* deliver to nmh folder */
- for (i = 0, state = FLD;;) {
- switch (state = m_getfld (state, name, field, sizeof(field), in)) {
+ gstate = m_getfld_state_init(in);
+ for (i = 0;;) {
+ int fieldsz = sizeof field;
+ switch (state = m_getfld2(&gstate, name, field, &fieldsz)) {
- state = m_getfld (state, name, field, sizeof(field), in);
+ fieldsz = sizeof field;
+ state = m_getfld2(&gstate, name, field, &fieldsz);
if ((p = lookup (vars, "size"))) {
snprintf (buffer, sizeof(buffer), "%d",
fstat (fd, &st) != -1 ? (int) st.st_size : 0);
if ((p = lookup (vars, "size"))) {
snprintf (buffer, sizeof(buffer), "%d",
fstat (fd, &st) != -1 ? (int) st.st_size : 0);
}
if ((p = lookup (vars, "info")))
p->p_value = getcpy (info);
}
if ((p = lookup (vars, "info")))
p->p_value = getcpy (info);
lookup (struct pair *pairs, char *key)
{
for (; pairs->p_name; pairs++)
lookup (struct pair *pairs, char *key)
{
for (; pairs->p_name; pairs++)
- if (verbose)
- verbose_printf ("delivering to file \"%s\"", mailbox);
-
- 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");
- if (mbx_copy (mailbox, mbx_style, md, fd, mapping, NULL, verbose) == -1) {
+ if (mbx_copy (mailbox, mbx_style, md, fd, NULL) == -1) {
-usr_pipe (int fd, char *cmd, char *pgm, char **vec, int suppress)
+usr_pipe (int fd_arg, char *cmd, char *pgm, char **vec, int suppress)
pid_t child_id;
int i, bytes, seconds, status;
struct stat st;
pid_t child_id;
int i, bytes, seconds, status;
struct stat st;
if (verbose && !suppress)
verbose_printf ("delivering to pipe \"%s\"", cmd);
if (verbose && !suppress)
verbose_printf ("delivering to pipe \"%s\"", cmd);
- freopen ("/dev/null", "w", stdout);
- freopen ("/dev/null", "w", stderr);
+ if (freopen ("/dev/null", "w", stdout) == NULL) {
+ advise ("stdout", "freopen");
+ }
+ if (freopen ("/dev/null", "w", stderr) == NULL) {
+ advise ("stderr", "freopen");
+ }
- 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);
- else
- if ((status & 0xff00) == 0xff00)
- verbose_printf (", system error\n");
- else
- pidstatus (status, stdout, ", failed");
+ else if ((status & 0xff00) == 0xff00)
+ verbose_printf (", system error\n");
+ else
+ pidstatus (status, stdout, ", failed");
- } else {
- /*
- * Ruthlessly kill the child and anything
- * else in its process group.
- */
- killpg(child_id, SIGKILL);
- if (verbose)
- verbose_printf (", timed-out; terminated\n");
- return -1;
+ /*
+ * Ruthlessly kill the child and anything
+ * else in its process group.
+ */
+ killpg(child_id, SIGKILL);
+ if (verbose)
+ verbose_printf (", timed-out; terminated\n");
+ return -1;
strncpy (buffer, envelope + i, sizeof(buffer));
if ((cp = strchr(buffer, '\n'))) {
*cp = 0;
strncpy (buffer, envelope + i, sizeof(buffer));
if ((cp = strchr(buffer, '\n'))) {
*cp = 0;
tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
if (tfile == NULL) return -1;
tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
if (tfile == NULL) return -1;
suppress_duplicates (int fd, char *file)
{
int fd1, lockfd, state, result;
suppress_duplicates (int fd, char *file)
{
int fd1, lockfd, state, result;
- for (state = FLD;;) {
- state = m_getfld (state, name, buf, sizeof(buf), in);
+ gstate = m_getfld_state_init(in);
+ for (;;) {
+ int failed_to_lock = 0;
+ int bufsz = sizeof buf;
+ state = m_getfld2(&gstate, name, buf, &bufsz);
- if (mh_strcasecmp (name, "Message-ID")) {
- while (state == FLDPLUS)
- state = m_getfld (state, name, buf, sizeof(buf), in);
+ if (strcasecmp (name, "Message-ID")) {
+ while (state == FLDPLUS) {
+ bufsz = sizeof buf;
+ state = m_getfld2(&gstate, name, buf, &bufsz);
+ }
- state = m_getfld (state, name, buf, sizeof(buf), in);
+ bufsz = sizeof buf;
+ state = m_getfld2(&gstate, name, buf, &bufsz);
- if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) {
+ if ((lockfd = lkopendata(file, O_RDWR, 0, &failed_to_lock))
+ == -1) {