{ "Resent-From", NULL, P_ADR },
{ "Resent-Sender", NULL, P_ADR },
{ "Resent-To", NULL, P_ADR },
- { "Resent-cc", NULL, P_ADR },
+ { "Resent-Cc", NULL, P_ADR },
{ NULL, NULL, 0 }
};
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
- invo_name = r1bindex(*argv, '/');
+ invo_name = mhbasename(*argv);
/* foil search of user profile/context */
if (context_foil(NULL) == -1)
while ((cp = *argp++)) {
if (*cp == '-') {
switch (smatch(++cp, switches)) {
- case AMBIGSW:
- ambigsw(cp, switches);
- done(1);
- case UNKWNSW:
- adios(NULL, "-%s unknown", cp);
-
- case HELPSW:
- snprintf(buf, sizeof(buf), "%s [switches] [address info sender]", invo_name);
- print_help(buf, switches, 0);
- done(1);
- case VERSIONSW:
- print_version(invo_name);
- done(1);
-
- case ADDRSW:
- if (!(addr = *argp++))
- /* allow -xyz arguments */
- adios(NULL, "missing argument to %s", argp[-2]);
- continue;
- case INFOSW:
- if (!(info = *argp++))
- /* allow -xyz arguments */
- adios(NULL, "missing argument to %s", argp[-2]);
- continue;
- case USERSW:
- if (!(user = *argp++))
- /* allow -xyz arguments */
- adios(NULL, "missing argument to %s", argp[-2]);
- continue;
- case FILESW:
- if (!(file = *argp++) || *file == '-')
- adios(NULL, "missing argument to %s", argp[-2]);
- continue;
- case SENDERSW:
- if (!(sender = *argp++))
- /* allow -xyz arguments */
- adios(NULL, "missing argument to %s", argp[-2]);
- continue;
- case MAILBOXSW:
- if (!(mbox = *argp++) || *mbox == '-')
- adios(NULL, "missing argument to %s", argp[-2]);
- continue;
- case HOMESW:
- if (!(home = *argp++) || *home == '-')
- adios(NULL, "missing argument to %s", argp[-2]);
- continue;
+ case AMBIGSW:
+ ambigsw(cp, switches);
+ done(1);
+ case UNKWNSW:
+ adios(NULL, "-%s unknown", cp);
+
+ case HELPSW:
+ snprintf(buf, sizeof(buf), "%s [switches] [address info sender]", invo_name);
+ print_help(buf, switches, 0);
+ done(1);
+ case VERSIONSW:
+ print_version(invo_name);
+ done(1);
+
+ case ADDRSW:
+ if (!(addr = *argp++))
+ /* allow -xyz arguments */
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+ case INFOSW:
+ if (!(info = *argp++))
+ /* allow -xyz arguments */
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+ case USERSW:
+ if (!(user = *argp++))
+ /* allow -xyz arguments */
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+ case FILESW:
+ if (!(file = *argp++) || *file == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+ case SENDERSW:
+ if (!(sender = *argp++))
+ /* allow -xyz arguments */
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+ case MAILBOXSW:
+ if (!(mbox = *argp++) || *mbox == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
+ case HOMESW:
+ if (!(home = *argp++) || *home == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ continue;
- case MAILSW:
- if (!(cp = *argp++) || *cp == '-')
- adios(NULL, "missing argument to %s", argp[-2]);
- if (mdlvr)
- adios(NULL, "only one maildelivery file at a time!");
- mdlvr = cp;
- continue;
+ case MAILSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ if (mdlvr)
+ adios(NULL, "only one maildelivery file at a time!");
+ mdlvr = cp;
+ continue;
- case VERBSW:
- verbose++;
- continue;
- case NVERBSW:
- verbose = 0;
- continue;
+ case VERBSW:
+ verbose++;
+ continue;
+ case NVERBSW:
+ verbose = 0;
+ continue;
- case SUPPRESSDUP:
- suppressdup++;
- continue;
- case NSUPPRESSDUP:
- suppressdup = 0;
- continue;
- case DEBUGSW:
- debug++;
- continue;
+ case SUPPRESSDUP:
+ suppressdup++;
+ continue;
+ case NSUPPRESSDUP:
+ suppressdup = 0;
+ continue;
+ case DEBUGSW:
+ debug++;
+ continue;
}
}
switch (argp - (argv + 1)) {
- case 1:
- addr = cp;
- break;
-
- case 2:
- info = cp;
- break;
-
- case 3:
- sender = cp;
- break;
+ case 1:
+ addr = cp;
+ break;
+ case 2:
+ info = cp;
+ break;
+ case 3:
+ sender = cp;
+ break;
}
}
/* find out how to perform the action */
switch (result[0]) {
- case 'N':
- case 'n':
- /*
- ** If previous condition failed, don't
- ** do this - else fall through
- */
- if (!next)
- continue; /* else fall */
+ case 'N':
+ case 'n':
+ /*
+ ** If previous condition failed, don't
+ ** do this - else fall through
+ */
+ if (!next)
+ continue; /* else fall */
- case '?':
- /*
- ** If already delivered, skip this action.
- ** Else consider delivered if action is
- ** successful.
- */
- if (won)
- continue; /* else fall */
+ case '?':
+ /*
+ ** If already delivered, skip this action.
+ ** Else consider delivered if action is
+ ** successful.
+ */
+ if (won)
+ continue; /* else fall */
- case 'A':
- case 'a':
- /*
- ** Take action, and consider delivered if
- ** action is successful.
- */
- accept = 1;
- break;
+ case 'A':
+ case 'a':
+ /*
+ ** Take action, and consider delivered if
+ ** action is successful.
+ */
+ accept = 1;
+ break;
- case 'R':
- case 'r':
- default:
- /*
- ** Take action, but don't consider delivered,
- ** even if action is successful
- */
- accept = 0;
- break;
+ case 'R':
+ case 'r':
+ default:
+ /*
+ ** Take action, but don't consider delivered,
+ ** even if action is successful
+ */
+ accept = 0;
+ break;
}
if (vecp > 5) {
/* check if the field matches */
switch (*field) {
- case '*':
- /* always matches */
+ case '*':
+ /* always matches */
+ break;
+
+ case 'd':
+ /*
+ ** "default" matches only if the message hasn't
+ ** been delivered yet.
+ */
+ if (!mh_strcasecmp(field, "default")) {
+ if (won)
+ continue;
break;
+ } /* else fall */
- case 'd':
+ default:
+ /* parse message and build lookup table */
+ if (!parsed && parse(fd) == -1) {
+ fclose(fp);
+ return -1;
+ }
/*
- ** "default" matches only if the message hasn't
- ** been delivered yet.
+ ** find header field in lookup table, and
+ ** see if the pattern matches.
*/
- if (!mh_strcasecmp(field, "default")) {
- if (won)
- continue;
- break;
- } /* else fall */
-
- default:
- /* parse message and build lookup table */
- if (!parsed && parse(fd) == -1) {
- fclose(fp);
- return -1;
- }
- /*
- ** find header field in lookup table, and
- ** see if the pattern matches.
- */
- if ((p = lookup(hdrs, field)) &&
- (p->p_value != NULL) &&
- matches(p->p_value, pattern)
- ) {
- next = 1;
- } else {
- next = 0;
- continue;
- }
- break;
+ if ((p = lookup(hdrs, field)) && (p->p_value != NULL)
+ && matches(p->p_value, pattern)) {
+ next = 1;
+ } else {
+ next = 0;
+ continue;
+ }
+ break;
}
/* find out the action to perform */
switch (*action) {
- case 'q':
- /* deliver to quoted pipe */
- if (mh_strcasecmp(action, "qpipe"))
- continue; /* else fall */
- case '^':
- expand(tmpbuf, string, fd);
- if (split(tmpbuf, vec) < 1)
- continue;
- status = usr_pipe(fd, tmpbuf, vec[0], vec, 0);
- break;
+ case 'q':
+ /* deliver to quoted pipe */
+ if (mh_strcasecmp(action, "qpipe"))
+ continue; /* else fall */
+ case '^':
+ expand(tmpbuf, string, fd);
+ if (split(tmpbuf, vec) < 1)
+ continue;
+ status = usr_pipe(fd, tmpbuf, vec[0], vec, 0);
+ break;
- case 'p':
- /* deliver to pipe */
- if (mh_strcasecmp(action, "pipe"))
- continue; /* else fall */
- case '|':
- vec[2] = "sh";
- vec[3] = "-c";
- expand(tmpbuf, string, fd);
- vec[4] = tmpbuf;
- vec[5] = NULL;
- status = usr_pipe(fd, tmpbuf, "/bin/sh",
- vec + 2, 0);
- break;
+ case 'p':
+ /* deliver to pipe */
+ if (mh_strcasecmp(action, "pipe"))
+ continue; /* else fall */
+ case '|':
+ vec[2] = "sh";
+ vec[3] = "-c";
+ expand(tmpbuf, string, fd);
+ vec[4] = tmpbuf;
+ vec[5] = NULL;
+ status = usr_pipe(fd, tmpbuf, "/bin/sh",
+ vec + 2, 0);
+ break;
- case 'f':
- /* mbox format */
- if (!mh_strcasecmp(action, "file")) {
- status = usr_file(fd, string,
- MBOX_FORMAT);
- break;
- }
- /* deliver to nmh folder */
- else if (mh_strcasecmp(action, "folder"))
- continue; /* else fall */
- case '+':
- status = usr_folder(fd, string);
+ case 'f':
+ /* mbox format */
+ if (!mh_strcasecmp(action, "file")) {
+ status = usr_file(fd, string,
+ MBOX_FORMAT);
break;
+ }
+ /* deliver to nmh folder */
+ else if (mh_strcasecmp(action, "folder"))
+ continue; /* else fall */
+ case '+':
+ status = usr_folder(fd, string);
+ break;
- case 'm':
- /* mmdf format */
- if (!mh_strcasecmp(action, "mmdf")) {
- status = usr_file(fd, string,
- MMDF_FORMAT);
- break;
- }
- /* mbox format */
- else if (mh_strcasecmp(action, "mbox"))
- continue; /* else fall */
-
- case '>':
- /* mbox format */
- status = usr_file(fd, string, MBOX_FORMAT);
+ case 'm':
+ /* mmdf format */
+ if (!mh_strcasecmp(action, "mmdf")) {
+ status = usr_file(fd, string,
+ MMDF_FORMAT);
break;
+ }
+ /* mbox format */
+ else if (mh_strcasecmp(action, "mbox"))
+ continue; /* else fall */
- case 'd':
- /* ignore message */
- if (mh_strcasecmp(action, "destroy"))
- continue;
- status = 0;
- break;
+ case '>':
+ /* mbox format */
+ status = usr_file(fd, string, MBOX_FORMAT);
+ break;
+
+ case 'd':
+ /* ignore message */
+ if (mh_strcasecmp(action, "destroy"))
+ continue;
+ status = 0;
+ break;
}
if (status)
for (i = 0, state = FLD;;) {
switch (state = m_getfld(state, name, field, sizeof(field),
in)) {
- case FLD:
- case FLDEOF:
- case FLDPLUS:
- lp = add(field, NULL);
- while (state == FLDPLUS) {
- state = m_getfld(state, name, field,
- sizeof(field), in);
- lp = add(field, lp);
- }
- for (p = hdrs; p->p_name; p++) {
- if (!mh_strcasecmp(p->p_name, name)) {
- if (!(p->p_flags & P_HID)) {
- if ((cp = p->p_value)) {
- if (p->p_flags & P_ADR) {
- dp = cp + strlen(cp) - 1;
- if (*dp == '\n')
- *dp = 0;
- cp = add(",\n\t", cp);
- } else {
- cp = add("\t", cp);
- }
+ case FLD:
+ case FLDEOF:
+ case FLDPLUS:
+ lp = getcpy(field);
+ while (state == FLDPLUS) {
+ state = m_getfld(state, name, field,
+ sizeof(field), in);
+ lp = add(field, lp);
+ }
+ for (p = hdrs; p->p_name; p++) {
+ if (!mh_strcasecmp(p->p_name, name)) {
+ if (!(p->p_flags & P_HID)) {
+ if ((cp = p->p_value)) {
+ if (p->p_flags & P_ADR) {
+ dp = cp + strlen(cp) - 1;
+ if (*dp == '\n')
+ *dp = 0;
+ cp = add(",\n\t", cp);
+ } else {
+ cp = add("\t", cp);
}
- p->p_value = add(lp, cp);
}
- free(lp);
- break;
+ p->p_value = add(lp, cp);
}
+ free(lp);
+ break;
}
- if (p->p_name == NULL && i < NVEC) {
- p->p_name = getcpy(name);
- p->p_value = lp;
- p->p_flags = P_NIL;
- p++, i++;
- p->p_name = NULL;
- }
- if (state != FLDEOF)
- continue;
- break;
+ }
+ if (p->p_name == NULL && i < NVEC) {
+ p->p_name = getcpy(name);
+ p->p_value = lp;
+ p->p_flags = P_NIL;
+ p++, i++;
+ p->p_name = NULL;
+ }
+ if (state != FLDEOF)
+ continue;
+ break;
- case BODY:
- case BODYEOF:
- case FILEEOF:
- break;
+ case BODY:
+ case BODYEOF:
+ case FILEEOF:
+ break;
- case LENERR:
- case FMTERR:
- advise(NULL, "format error in message");
- break;
+ case LENERR:
+ case FMTERR:
+ advise(NULL, "format error in message");
+ break;
- default:
- advise(NULL, "internal error in m_getfld");
- fclose(in);
- return -1;
+ default:
+ advise(NULL, "internal error in m_getfld");
+ fclose(in);
+ return -1;
}
break;
}
if (debug) {
for (p = hdrs; p->p_name; p++)
debug_printf("hdrs[%d]: name=\"%s\" value=\"%s\"\n",
- p - hdrs, p->p_name, p->p_value ? trim(p->p_value) : "");
+ p - hdrs, p->p_name,
+ p->p_value ? trim(p->p_value) : "");
}
return 0;
sleep(5);
switch (child_id) {
- case -1:
- /* fork error */
- if (verbose)
- adorn("fork", "unable to");
- return -1;
+ case -1:
+ /* fork error */
+ if (verbose)
+ adorn("fork", "unable to");
+ return -1;
- case 0:
- /* child process */
- if (fd != 0)
- dup2(fd, 0);
- freopen("/dev/null", "w", stdout);
- freopen("/dev/null", "w", stderr);
- if (fd != 3)
- dup2(fd, 3);
- closefds(4);
+ case 0:
+ /* child process */
+ if (fd != 0)
+ dup2(fd, 0);
+ freopen("/dev/null", "w", stdout);
+ freopen("/dev/null", "w", stderr);
+ if (fd != 3)
+ dup2(fd, 3);
+ closefds(4);
#ifdef TIOCNOTTY
- if ((fd = open("/dev/tty", O_RDWR)) != -1) {
- ioctl(fd, TIOCNOTTY, NULL);
- close(fd);
- }
+ if ((fd = open("/dev/tty", O_RDWR)) != -1) {
+ ioctl(fd, TIOCNOTTY, NULL);
+ close(fd);
+ }
#endif /* TIOCNOTTY */
- /* put in own process group */
- setpgid((pid_t) 0, getpid());
+ /* put in own process group */
+ setpgid((pid_t) 0, getpid());
- *environ = NULL;
- m_putenv("USER", pw->pw_name);
- m_putenv("HOME", pw->pw_dir);
- m_putenv("SHELL", pw->pw_shell);
+ *environ = NULL;
+ m_putenv("USER", pw->pw_name);
+ m_putenv("HOME", pw->pw_dir);
+ m_putenv("SHELL", pw->pw_shell);
- execvp(pgm, vec);
- _exit(-1);
+ execvp(pgm, vec);
+ _exit(-1);
- default:
- /* parent process */
- if (!setjmp(myctx)) {
- SIGNAL(SIGALRM, alrmser);
- bytes = fstat(fd, &st) != -1 ?
- (int) st.st_size : 100;
-
- /*
- ** amount of time to wait depends on
- ** message size
- */
- if (bytes <= 100) {
- /* give at least 5 minutes */
- seconds = 300;
- } else if (bytes >= 90000) {
- /* a half hour is long enough */
- seconds = 1800;
- } else {
- seconds = (bytes / 60) + 300;
- }
- alarm((unsigned int) seconds);
- status = pidwait(child_id, 0);
- alarm(0);
+ default:
+ /* parent process */
+ if (!setjmp(myctx)) {
+ SIGNAL(SIGALRM, alrmser);
+ bytes = fstat(fd, &st) != -1 ?
+ (int) st.st_size : 100;
- if (verbose) {
- if (status == 0)
- verbose_printf(", success.\n");
- else
- if ((status & 0xff00) == 0xff00)
- verbose_printf(", system error\n");
- else
- pidstatus(status, stdout, ", failed");
- }
- return (status == 0 ? 0 : -1);
+ /*
+ ** amount of time to wait depends on
+ ** message size
+ */
+ if (bytes <= 100) {
+ /* give at least 5 minutes */
+ seconds = 300;
+ } else if (bytes >= 90000) {
+ /* a half hour is long enough */
+ seconds = 1800;
} 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;
+ seconds = (bytes / 60) + 300;
}
+ alarm((unsigned int) seconds);
+ status = pidwait(child_id, 0);
+ alarm(0);
+
+ if (verbose) {
+ if (status == 0)
+ verbose_printf(", success.\n");
+ else
+ if ((status & 0xff00) == 0xff00)
+ verbose_printf(", system error\n");
+ else
+ pidstatus(status, stdout, ", failed");
+ }
+ return (status == 0 ? 0 : -1);
+ } 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;
+ }
}
}
while (fgets(buffer, sizeof(buffer), qfp)) {
if (first) {
first = 0;
- if (!strncmp(buffer, "From ", i)) {
+ if (strncmp(buffer, "From ", i)==0) {
#ifdef RPATHS
char *fp, *cp, *hp, *ep;
#endif
for (state = FLD;;) {
state = m_getfld(state, name, buf, sizeof(buf), in);
switch (state) {
- case FLD:
- case FLDPLUS:
- case FLDEOF:
- /* Search for the message ID */
- if (mh_strcasecmp(name, "Message-ID")) {
- while (state == FLDPLUS)
- state = m_getfld(state, name, buf, sizeof(buf), in);
- continue;
- }
+ case FLD:
+ case FLDPLUS:
+ case FLDEOF:
+ /* Search for the message ID */
+ if (mh_strcasecmp(name, "Message-ID")) {
+ while (state == FLDPLUS)
+ state = m_getfld(state, name, buf,
+ sizeof(buf), in);
+ continue;
+ }
- cp = add(buf, NULL);
- while (state == FLDPLUS) {
- state = m_getfld(state, name, buf, sizeof(buf), in);
- cp = add(buf, cp);
- }
- key.dptr = trimcpy(cp);
- key.dsize = strlen(key.dptr) + 1;
- free(cp);
- cp = key.dptr;
-
- if (!(db = dbm_open(file, O_RDWR | O_CREAT,
- 0600))) {
- advise(file, "unable to perform dbm_open on");
- free(cp);
- fclose(in);
- return -1;
- }
- /*
- ** Since it is difficult to portable
- ** lock a ndbm file, we will open and
- ** lock the Maildelivery file instead.
- ** This will fail if your Maildelivery
- ** file doesn't exist.
- */
- if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) {
- advise(file, "unable to perform file locking on");
- free(cp);
- fclose(in);
- return -1;
- }
- value = dbm_fetch(db, key);
- if (value.dptr) {
- if (verbose)
- verbose_printf("Message-ID: %s\n already received on %s", cp, value.dptr);
- result = DONE;
- } else {
- value.dptr = ddate + sizeof("Delivery-Date:");
- value.dsize = strlen(value.dptr) + 1;
- if (dbm_store(db, key, value, DBM_INSERT))
- advise(file, "possibly corrupt file");
- result = 0;
- }
+ cp = getcpy(buf);
+ while (state == FLDPLUS) {
+ state = m_getfld(state, name, buf,
+ sizeof(buf), in);
+ cp = add(buf, cp);
+ }
+ key.dptr = trimcpy(cp);
+ key.dsize = strlen(key.dptr) + 1;
+ free(cp);
+ cp = key.dptr;
- dbm_close(db);
- lkclose(lockfd, file);
+ if (!(db = dbm_open(file, O_RDWR | O_CREAT, 0600))) {
+ advise(file, "unable to perform dbm_open on");
free(cp);
fclose(in);
- return result;
- break;
+ return -1;
+ }
+ /*
+ ** Since it is difficult to portable lock a ndbm
+ ** file, we will open and lock the Maildelivery
+ ** file instead. This will fail if your Maildelivery
+ ** file doesn't exist.
+ */
+ if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) {
+ advise(file, "unable to perform file locking on");
+ free(cp);
+ fclose(in);
+ return -1;
+ }
+ value = dbm_fetch(db, key);
+ if (value.dptr) {
+ if (verbose)
+ verbose_printf("Message-ID: %s\n already received on %s", cp, value.dptr);
+ result = DONE;
+ } else {
+ value.dptr = ddate + sizeof("Delivery-Date:");
+ value.dsize = strlen(value.dptr) + 1;
+ if (dbm_store(db, key, value, DBM_INSERT))
+ advise(file, "possibly corrupt file");
+ result = 0;
+ }
- case BODY:
- case BODYEOF:
- case FILEEOF:
- break;
+ dbm_close(db);
+ lkclose(lockfd, file);
+ free(cp);
+ fclose(in);
+ return result;
+ break;
- case LENERR:
- case FMTERR:
- default:
- break;
+ case BODY:
+ case BODYEOF:
+ case FILEEOF:
+ break;
+
+ case LENERR:
+ case FMTERR:
+ default:
+ break;
}
break;