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
* 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);
.HP 5
.B mhbuild
.I file
+.RB [ \-auto " | " \-noauto ]
.RB [ \-list " | " \-nolist ]
.RB [ \-realsize " | " \-norealsize ]
.RB [ \-headers " | " \-noheaders ]
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
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
.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
#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) \
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;
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;
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);
}
*/
/* 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;
*/
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];
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)) {