From: Ken Hornstein Date: Fri, 17 Jan 2014 20:45:31 +0000 (-0500) Subject: Add support for -auto flag to mhbuild. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/30d2bc627c8010e4fbe4774d86bed189a57210e2?ds=sidebyside;hp=-c Add support for -auto flag to mhbuild. --- 30d2bc627c8010e4fbe4774d86bed189a57210e2 diff --git a/docs/pending-release-notes b/docs/pending-release-notes index a2fd5987..2e15c714 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -65,6 +65,8 @@ NEW FEATURES configuration time. If not, it will use mhshow-suffix- entries as before. The -v switch to attach causes it to display the mhbuild directive for an attachformat specied by an optional -a switch. +- mhbuild(1) now supports the -auto/-noauto flags (to be used by send(1) + when invoking mhbuild automatically). ----------------- OBSOLETE FEATURES diff --git a/h/mhparse.h b/h/mhparse.h index 1dfd7ed8..62e6c0b3 100644 --- a/h/mhparse.h +++ b/h/mhparse.h @@ -290,15 +290,23 @@ CT parse_mime (char *); * Translate a composition file into a MIME data structure. Arguments are: * * infile - Name of input filename + * autobuild - A flag to indicate if the composition file parser is + * being run in automatic mode or not. In auto mode, + * if a MIME-Version header is encountered it is assumed + * that the composition file is already in MIME format + * and will not be processed further. Otherwise, an + * error is generated. * directives - A flag to control whether or not build directives are * processed by default. * encoding - The default encoding to use when doing RFC 2047 header * encoding. Must be one of CE_UNKNOWN, CE_BASE64, or * CE_QUOTED; * - * Returns a CT structure describing the resulting MIME message. + * Returns a CT structure describing the resulting MIME message. If the + * -auto flag is set and a MIME-Version header is encountered, the return + * value is NULL. */ -CT build_mime (char *infile, int directives, int encoding); +CT build_mime (char *infile, int autobuild, int directives, int encoding); int add_header (CT, char *, char *); int get_ctinfo (char *, CT, int); diff --git a/man/mhbuild.man b/man/mhbuild.man index 710c4491..2f0e8ee7 100644 --- a/man/mhbuild.man +++ b/man/mhbuild.man @@ -9,6 +9,7 @@ mhbuild \- translate MIME composition draft .HP 5 .B mhbuild .I file +.RB [ \-auto " | " \-noauto ] .RB [ \-list " | " \-nolist ] .RB [ \-realsize " | " \-norealsize ] .RB [ \-headers " | " \-noheaders ] @@ -77,19 +78,6 @@ switch is present, then the listing will show any \*(lqextra\*(rq information that is present in the message, such as comments in the \*(lqContent-Type\*(rq header. -.PP -The -.B \-headerencoding -switch will indicate which algorithm to use when encoding any message headers -that contain 8\-bit characters. The valid arguments are -.I base64 -for based\-64 encoding and -.I quoted -for quoted\-printable encoding. The -.B \-autoheaderencoding -switch will instruct -.B mhbuild -to automatically pick the algorithm that results in a shorter encoded string. .SS "Translating the Composition File" .B mhbuild is essentially a filter to aid in the composition of MIME @@ -467,6 +455,19 @@ If a text content contains only 7\-bit characters and the character set is not specified as above, then the character set will be labeled as \*(lqus-ascii\*(rq. .PP +The +.B \-headerencoding +switch will indicate which algorithm to use when encoding any message headers +that contain 8\-bit characters. The valid arguments are +.I base64 +for based\-64 encoding and +.I quoted +for quoted\-printable encoding. The +.B \-autoheaderencoding +switch will instruct +.B mhbuild +to automatically pick the algorithm that results in a shorter encoded string. +.PP Putting this all together, here is an example of a more complicated message draft. The following draft will expand into a multipart/mixed message @@ -545,6 +546,14 @@ to execute .B mhbuild to translate the composition file into MIME format. .PP +Normally it is an error to invoke +.B mhbuild +on file that already in MIME format. The +.B \-auto +switch will cause +.B mhbuild +to exit without error if the input file already has valid MIME headers. +.PP It is also possible to have the .B whatnow program invoke diff --git a/uip/mhbuild.c b/uip/mhbuild.c index ef459858..18844b56 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -19,6 +19,8 @@ #include #define MHBUILD_SWITCHES \ + X("auto", 0, AUTOSW) \ + X("noauto", 0, NAUTOSW) \ X("check", 0, CHECKSW) \ X("nocheck", 0, NCHECKSW) \ X("directives", 0, DIRECTIVES) \ @@ -101,7 +103,7 @@ int list_all_messages (CT *, int, int, int, int); int main (int argc, char **argv) { - int sizesw = 1, headsw = 1, directives = 1; + int sizesw = 1, headsw = 1, directives = 1, autobuild = 0; int *icachesw; char *cp, buf[BUFSIZ]; char buffer[BUFSIZ], *compfile = NULL; @@ -150,6 +152,20 @@ main (int argc, char **argv) print_version(invo_name); done (0); + case AUTOSW: + /* -auto implies -nodirectives */ + autobuild = 1; + directives = 0; + continue; + case NAUTOSW: + /* + * We're turning directives back on since this is likely here + * to override a profile entry + */ + autobuild = 0; + directives = 1; + continue; + case RCACHESW: icachesw = &rcachesw; goto do_cache; @@ -320,32 +336,28 @@ main (int argc, char **argv) unlink_infile = 1; /* build the content structures for MIME message */ - ct = build_mime (infile, directives, header_encoding); - cts[0] = ct; - cts[1] = NULL; - - /* output MIME message to this temporary file */ - strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile)); - unlink_outfile = 1; - - /* output the message */ - output_message_fp (ct, fp_out, outfile); - fclose(fp_out); - - /* output the temp file to standard output */ - if ((fp = fopen (outfile, "r")) == NULL) - adios (outfile, "unable to open"); - while (fgets (buffer, BUFSIZ, fp)) - fputs (buffer, stdout); - fclose (fp); + ct = build_mime (infile, autobuild, directives, header_encoding); + + /* + * If ct == NULL, that means that -auto was set and a MIME version + * header was already seen. Just use the input file as the output + */ + + if (!ct) { + if (! (fp = fopen(infile, "r"))) { + adios(NULL, "Unable to open %s for reading", infile); + } + while (fgets(buffer, BUFSIZ, fp)) + fputs(buffer, stdout); + } else { + /* output the message */ + output_message_fp (ct, stdout, NULL); + free_content (ct); + } unlink (infile); unlink_infile = 0; - unlink (outfile); - unlink_outfile = 0; - - free_content (ct); done (0); } @@ -354,7 +366,16 @@ main (int argc, char **argv) */ /* build the content structures for MIME message */ - ct = build_mime (compfile, directives, header_encoding); + ct = build_mime (compfile, autobuild, directives, header_encoding); + + /* + * If ct == NULL, that means -auto was set and we found a MIME version + * header. Simply exit and do nothing. + */ + + if (! ct) + done(0); + cts[0] = ct; cts[1] = NULL; diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 53c06e95..df9bf5b7 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -129,7 +129,7 @@ static void directive_pop(void) */ CT -build_mime (char *infile, int directives, int header_encoding) +build_mime (char *infile, int autobuild, int directives, int header_encoding) { int compnum, state; char buf[BUFSIZ], name[NAMESZ]; @@ -176,13 +176,16 @@ build_mime (char *infile, int directives, int header_encoding) case FLDPLUS: compnum++; - /* abort if draft has Mime-Version header field */ - if (!strcasecmp (name, VRSN_FIELD)) - adios (NULL, "draft shouldn't contain %s: field", VRSN_FIELD); - - /* abort if draft has Content-Transfer-Encoding header field */ - if (!strcasecmp (name, ENCODING_FIELD)) - adios (NULL, "draft shouldn't contain %s: field", ENCODING_FIELD); + /* abort if draft has Mime-Version or C-T-E header field */ + if (strcasecmp (name, VRSN_FIELD) == 0 || + strcasecmp (name, ENCODING_FIELD) == 0) { + if (autobuild) { + fclose(in); + return NULL; + } else { + adios (NULL, "draft shouldn't contain %s: field", name); + } + } /* ignore any Content-Type fields in the header */ if (!strcasecmp (name, TYPE_FIELD)) {