/*
* replsbr.c -- routines to help repl along...
*
- * $Id$
- *
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
static char *badaddrs = NULL;
static char *dfhost = NULL;
-static struct mailname mq = { NULL };
+static struct mailname mq;
+static int nodupcheck = 0; /* If set, no check for duplicates */
/*
* Buffer size for content part of header fields.
* static prototypes
*/
static int insert (struct mailname *);
-static void replfilter (FILE *, FILE *, char *);
+static void replfilter (FILE *, FILE *, char *, int);
void
replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen,
- int mime, char *form, char *filter, char *fcc)
+ int mime, char *form, char *filter, char *fcc, int fmtproc)
{
register int state, i;
register struct comp *cptr;
char name[NAMESZ], *scanl;
unsigned char *cp;
FILE *out;
+ NMH_UNUSED (msg);
mask = umask(~m_gmprot());
if ((out = fopen (drft, "w")) == NULL)
if (!mh_strcasecmp(name, cptr->c_name)) {
char_read += msg_count;
if (! cptr->c_text) {
- i = strlen(cptr->c_text = tmpbuf) - 1;
- if (tmpbuf[i] == '\n')
- tmpbuf[i] = '\0';
+ cptr->c_text = tmpbuf;
*--savecomp = cptr;
tmpbuf = *nxtbuf++;
} else {
if (ferror (out))
adios (drft, "error writing");
- replfilter (inb, out, filter);
+ replfilter (inb, out, filter, fmtproc);
} else if (mime && mp) {
fprintf (out, "#forw [original message] +%s %s\n",
mp->foldpath, m_name (mp->lowsel));
}
+/*
+ * fmt_scan will call this routine if the user includes the function
+ * "(concataddr {component})" in a format string. This behaves exactly
+ * like formataddr, except that it does NOT suppress duplicate addresses
+ * between calls.
+ *
+ * As an implementation detail: I thought about splitting out formataddr()
+ * into the generic part and duplicate-suppressing part, but the call to
+ * insert() was buried deep within a couple of loops and I didn't see a
+ * way to do it easily. So instead we simply set a special flag to stop
+ * the duplicate check and call formataddr().
+ */
+char *
+concataddr(char *orig, char *str)
+{
+ char *cp;
+
+ nodupcheck = 1;
+ cp = formataddr(orig, str);
+ nodupcheck = 0;
+ return cp;
+}
+
static int
insert (struct mailname *np)
{
char buffer[BUFSIZ];
register struct mailname *mp;
+ if (nodupcheck)
+ return 1;
+
if (np->m_mbox == NULL)
return 0;
*/
static void
-replfilter (FILE *in, FILE *out, char *filter)
+replfilter (FILE *in, FILE *out, char *filter, int fmtproc)
{
int pid;
char *mhl;
char *errstr;
+ char *arglist[7];
if (filter == NULL)
return;
rewind (in);
lseek (fileno(in), (off_t) 0, SEEK_SET);
- switch (pid = vfork ()) {
+ switch (pid = vfork()) {
case NOTOK:
adios ("fork", "unable to");
dup2 (fileno (out), fileno (stdout));
closefds (3);
- execlp (mhlproc, mhl, "-form", filter, "-noclear", NULL);
+ arglist[0] = mhl;
+ arglist[1] = "-form";
+ arglist[2] = filter;
+ arglist[3] = "-noclear";
+
+ switch (fmtproc) {
+ case 1:
+ arglist[4] = "-fmtproc";
+ arglist[5] = formatproc;
+ arglist[6] = NULL;
+ break;
+ case 0:
+ arglist[4] = "-nofmtproc";
+ arglist[5] = NULL;
+ break;
+ default:
+ arglist[4] = NULL;
+ }
+
+ execvp (mhlproc, arglist);
errstr = strerror(errno);
write(2, "unable to exec ", 15);
write(2, mhlproc, strlen(mhlproc));