From: Ken Hornstein Date: Mon, 20 Feb 2012 00:59:06 +0000 (-0500) Subject: Add support for "to", "cc", "from", and "fcc" components via command-line X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=907d56122e31657df15e9bc79460210deedaefd9;p=mmh Add support for "to", "cc", "from", and "fcc" components via command-line switches. --- diff --git a/etc/components b/etc/components index 95be90c..26d54c2 100644 --- a/etc/components +++ b/etc/components @@ -1,6 +1,6 @@ -From: %(localmbox) -To: -cc: -Fcc: +outbox +%<{from}%|%(void(localmbox))%>%(void(width))%(putaddr From: ) +%<{to}%(void(width))%(putaddr To: )%|To:%> +%<{cc}%(void(width))%(putaddr cc: )%|cc:%> +Fcc: %<{fcc}%(putstr)%|+outbox%> Subject: -------- diff --git a/man/comp.man b/man/comp.man index 643c056..251619b 100644 --- a/man/comp.man +++ b/man/comp.man @@ -23,6 +23,16 @@ comp \- compose a message .RB [ \-editor .IR editor ] .RB [ \-noedit ] +.RB [ \-width +.IR columns ] +.RB [ \-from +.IR address ] +.RB [ \-to +.IR address ] +.RB [ \-cc +.IR address ] +.RB [ \-fcc +.IR +folder ] .RB [ \-whatnowproc .IR program ] .RB [ \-nowhatnowproc ] @@ -37,11 +47,18 @@ the draft (unless .B \-noedit is given, in which case the initial edit is suppressed). .PP -The default message form contains the following elements: +The default message template \*(lqcomponents\*(rq will direct +.B comp +to construct the messgage draft as follows: .PP .RS 5 .nf -%components% +From: {from switch} or or +To: {to switch} or blank +cc: {cc switch} or blank +Fcc: {fcc switch} or +outbox +Subject: +-------- .fi .RE .PP @@ -107,6 +124,43 @@ or switchs will NOT be processed with .BR mh\-format (5). .PP +In addition to the standard +.BR mh\-format (5) +escapes, +.B comp +the following +.I component +escapes are either new or have an alternate meaning: +.PP +.RS 5 +.nf +.ta \w'Escape 'u +\w'Returns 'u +.I Escape Returns Description +fcc string Any folders specified with `\-fcc\ folder' +from string Any addresses specified with `\-from\ address' +to string Any addresses specified with `\-to\ address' +cc string Any addresses specified with `\-cc\ address' +.fi +.RE +.PP +By default the \*(lqTo:\*(rq and \*(lqcc:\*(rq fields are empty. You may +add addresses to these fields with the +.B \-to +.I address +and +.B \-cc +.I address +switches. You may give these switches multiple times to add multiple +addresses. +.PP +By default the \*(lqFrom:\*(rq field has either the value of the +.B Local\-Mailbox +profile entry or a system default email address. This default can be +overridden by using the +.B \-from +.I address +switch. +.PP If the draft already exists, .B comp will ask you as to the disposition diff --git a/uip/comp.c b/uip/comp.c index a29bfcd..2eea08a 100644 --- a/uip/comp.c +++ b/uip/comp.c @@ -39,6 +39,16 @@ static struct swit switches[] = { { "version", 0 }, #define HELPSW 12 { "help", 0 }, +#define TOSW 13 + { "to address", 0 }, +#define CCSW 14 + { "cc address", 0 }, +#define FROMSW 15 + { "from address", 0 }, +#define FCCSW 16 + { "fcc mailbox", 0 }, +#define WIDTHSW 17 + { "width colums", 0 }, { NULL, 0 } }; @@ -67,6 +77,11 @@ static struct swit aqrul[] = { { NULL, 0 } }; +/* + * Add an item to a comma seperated list + */ + +static char *addlist(char *, char *); int main (int argc, char **argv) @@ -77,6 +92,7 @@ main (int argc, char **argv) char *cp, *cwd, *maildir, *dfolder = NULL; char *ed = NULL, *file = NULL, *form = NULL; char *folder = NULL, *msg = NULL, buf[BUFSIZ]; + char *to = NULL, *from = NULL, *cc = NULL, *fcc = NULL, *dp; char drft[BUFSIZ], **argp, **arguments; struct msgs *mp = NULL; struct format *fmt; @@ -167,6 +183,42 @@ main (int argc, char **argv) dfolder = NULL; isdf = NOTOK; continue; + + case TOSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + to = addlist(to, cp); + continue; + + case CCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + cc = addlist(cc, cp); + continue; + + case FROMSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + from = addlist(from, cp); + continue; + + case FCCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + dp = NULL; + if (*cp == '@') + cp = dp = path(cp + 1, TSUBCWF); + fcc = addlist(fcc, cp); + if (dp) + free(dp); + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((outputlinelen = atoi(cp)) < 10) + adios (NULL, "impossible width %d", outputlinelen); + continue; } } if (*cp == '+' || *cp == '@') { @@ -232,14 +284,38 @@ main (int argc, char **argv) if ((in = open (form = getcpy (m_name (mp->lowsel)), O_RDONLY)) == NOTOK) adios (form, "unable to open message"); } else { + struct comp *cptr; + if (! form) form = components; cp = new_fs(form, NULL, NULL); format_len = strlen(cp); ncomps = fmt_compile(cp, &fmt); - if (ncomps > 0) { - adios(NULL, "format components not supported when using comp"); + + /* + * Set up any components that were fed to us on the command line + */ + + if (from) { + FINDCOMP(cptr, "from"); + if (cptr) + cptr->c_text = from; + } + if (to) { + FINDCOMP(cptr, "to"); + if (cptr) + cptr->c_text = to; + } + if (cc) { + FINDCOMP(cptr, "cc"); + if (cptr) + cptr->c_text = cc; + } + if (fcc) { + FINDCOMP(cptr, "fcc"); + if (cptr) + cptr->c_text = fcc; } } @@ -326,3 +402,16 @@ edit_it: done (1); return 1; } + +/* + * Append an item to a comma separated list + */ + +static char * +addlist (char *list, char *item) +{ + if (list) + list = add (", ", list); + + return add (item, list); +}