]> diplodocus.org Git - nmh/commitdiff
Add support for -auto flag to mhbuild.
authorKen Hornstein <kenh@pobox.com>
Fri, 17 Jan 2014 20:45:31 +0000 (15:45 -0500)
committerKen Hornstein <kenh@pobox.com>
Fri, 17 Jan 2014 20:45:31 +0000 (15:45 -0500)
docs/pending-release-notes
h/mhparse.h
man/mhbuild.man
uip/mhbuild.c
uip/mhbuildsbr.c

index a2fd59876b2a519a63065e3fe9e26a92fe28eef6..2e15c714b493bc2324a75e539907d51d21299ea0 100644 (file)
@@ -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.
   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
 
 -----------------
 OBSOLETE FEATURES
index 1dfd7ed8df65abd47bc325a05ab5755b4fd50481..62e6c0b390983f48b75c51db0c792e0b04140e23 100644 (file)
@@ -290,15 +290,23 @@ CT parse_mime (char *);
  * Translate a composition file into a MIME data structure.  Arguments are:
  *
  * infile      - Name of input filename
  * 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;
  *
  * 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);
 
 int add_header (CT, char *, char *);
 int get_ctinfo (char *, CT, int);
index 710c44915f7b736735203790520e460026eaeb04..2f0e8ee7b21c675159c1e0001178a1beb002ff82 100644 (file)
@@ -9,6 +9,7 @@ mhbuild \- translate MIME composition draft
 .HP 5
 .B mhbuild
 .I file
 .HP 5
 .B mhbuild
 .I file
+.RB [ \-auto " | " \-noauto ]
 .RB [ \-list " | " \-nolist ]
 .RB [ \-realsize " | " \-norealsize ]
 .RB [ \-headers " | " \-noheaders ]
 .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.
 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
 .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
 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
 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
 .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
 It is also possible to have the
 .B whatnow
 program invoke
index ef4598581702e8c0773a33b66fca14b2871319cd..18844b56acd95075186c50f0b41fcc3207d29aab 100644 (file)
@@ -19,6 +19,8 @@
 #include <h/utils.h>
 
 #define MHBUILD_SWITCHES \
 #include <h/utils.h>
 
 #define MHBUILD_SWITCHES \
+    X("auto", 0, AUTOSW) \
+    X("noauto", 0, NAUTOSW) \
     X("check", 0, CHECKSW) \
     X("nocheck", 0, NCHECKSW) \
     X("directives", 0, DIRECTIVES) \
     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
 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;
     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);
 
                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;
            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 */
        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 (infile);
        unlink_infile = 0;
 
-       unlink (outfile);
-       unlink_outfile = 0;
-
-       free_content (ct);
        done (0);
     }
 
        done (0);
     }
 
@@ -354,7 +366,16 @@ main (int argc, char **argv)
      */
 
     /* build the content structures for MIME message */
      */
 
     /* 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;
 
     cts[0] = ct;
     cts[1] = NULL;
 
index 53c06e956accef467846d3e308508e8769aff77b..df9bf5b75dd07ff6dc04d868837b469b3beb68fa 100644 (file)
@@ -129,7 +129,7 @@ static void directive_pop(void)
  */
 
 CT
  */
 
 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];
 {
     int        compnum, state;
     char buf[BUFSIZ], name[NAMESZ];
@@ -176,13 +176,16 @@ build_mime (char *infile, int directives, int header_encoding)
        case FLDPLUS:
            compnum++;
 
        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)) {
 
            /* ignore any Content-Type fields in the header */
            if (!strcasecmp (name, TYPE_FIELD)) {