From 8e028ee7c88aa47317066ad0d09d3de9567ebddd Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Fri, 6 Apr 2012 15:55:14 -0400 Subject: [PATCH] Add support for -fmtproc and -nofmtproc switches to repl. --- h/prototypes.h | 2 +- man/repl.man | 11 ++++++++++- uip/repl.c | 17 ++++++++++++++++- uip/replsbr.c | 30 +++++++++++++++++++++++++----- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/h/prototypes.h b/h/prototypes.h index b0c0997..e74f327 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -153,7 +153,7 @@ int mhl(int, char **); int mhlsbr(int, char **, FILE *(*)(char *)); int distout (char *, char *, char *); void replout (FILE *, char *, char *, struct msgs *, int, - int, char *, char *, char *); + int, char *, char *, char *, int); void set_endian(void); int sc_hardcopy(void); int sc_length(void); diff --git a/man/repl.man b/man/repl.man index 261ee60..9e0ba5d 100644 --- a/man/repl.man +++ b/man/repl.man @@ -41,6 +41,9 @@ all/to/cc/me] .RB [ \-nowhatnowproc ] .RB [ \-atfile ] .RB [ \-noatfile ] +.RB [ \-fmtproc +.IR program ] +.RB [ \-nofmtproc ] .RB [ \-build ] .RB [ \-file .IR msgfile ] @@ -325,7 +328,13 @@ body:component=\*(lq>\*(rq,\|nowrap,\|format .PP See the .BR mhl(1) -documentation for more information. +documentation for more information. The format program can be changed by +the +.B \-fmtproc +.I program +and +.B \-nofmtproc +switches. .PP To use the MIME rules for encapsulation, specify the .B \-mime diff --git a/uip/repl.c b/uip/repl.c index 97178b1..f88d0c3 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -74,6 +74,10 @@ static struct swit switches[] = { { "atfile", 0 }, #define NOATFILESW 30 { "noatfile", 0 }, +#define FMTPROCSW 31 + { "fmtproc program", 0 }, +#define NFMTPROCSW 32 + { "nofmtproc", 0 }, { NULL, 0 } }; @@ -139,6 +143,7 @@ main (int argc, char **argv) int anot = 0, inplace = 1; int nedit = 0, nwhat = 0; int atfile = 1; + int fmtproc = -1; char *cp, *cwd, *dp, *maildir, *file = NULL; char *folder = NULL, *msg = NULL, *dfolder = NULL; char *dmsg = NULL, *ed = NULL, drft[BUFSIZ], buf[BUFSIZ]; @@ -316,6 +321,15 @@ main (int argc, char **argv) case NOATFILESW: atfile = 0; continue; + + case FMTPROCSW: + if (!(formatproc = *argp++) || *formatproc == '-') + adios (NULL, "missing argument to %s", argp[-2]); + fmtproc = 1; + continue; + case NFMTPROCSW: + fmtproc = 0; + continue; } } if (*cp == '+' || *cp == '@') { @@ -431,7 +445,8 @@ try_it_again: form = etcpath (replcomps); } - replout (in, msg, drft, mp, outputlinelen, mime, form, filter, fcc); + replout (in, msg, drft, mp, outputlinelen, mime, form, filter, + fcc, fmtproc); fclose (in); if (nwhat) diff --git a/uip/replsbr.c b/uip/replsbr.c index 613b3d9..83f6ee8 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -64,12 +64,12 @@ static char *addrcomps[] = { * 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) { NMH_UNUSED (msg); @@ -254,7 +254,7 @@ finished: 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)); @@ -447,11 +447,12 @@ insert (struct mailname *np) */ 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; @@ -473,7 +474,26 @@ replfilter (FILE *in, FILE *out, char *filter) 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)); -- 1.7.10.4