- * mhbuildsbr.c -- routines to expand/translate MIME composition files
- *
- * This code is Copyright (c) 2002, by the authors of nmh. See the
- * COPYRIGHT file in the root directory of the nmh distribution for
- * complete copyright information.
- */
+** mhbuildsbr.c -- routines to expand/translate MIME composition files
+**
+** This code is Copyright (c) 2002, by the authors of nmh. See the
+** COPYRIGHT file in the root directory of the nmh distribution for
+** complete copyright information.
+*/
- * This code was originally part of mhn.c. I split it into
- * a separate program (mhbuild.c) and then later split it
- * again (mhbuildsbr.c). But the code still has some of
- * the mhn.c code in it. This program needs additional
- * streamlining and removal of unneeded code.
- */
+** This code was originally part of mhn.c. I split it into
+** a separate program (mhbuild.c) and then later split it
+** again (mhbuildsbr.c). But the code still has some of
+** the mhn.c code in it. This program needs additional
+** streamlining and removal of unneeded code.
+*/
static int init_decoded_content (CT);
static char *fgetstr (char *, int, FILE *);
static int user_content (FILE *, char *, char *, CT *);
static int init_decoded_content (CT);
static char *fgetstr (char *, int, FILE *);
static int user_content (FILE *, char *, char *, CT *);
- * Main routine for translating composition file
- * into valid MIME message. It translates the draft
- * into a content structure (actually a tree of content
- * structures). This message then can be manipulated
- * in various ways, including being output via
- * output_message().
- */
+** Main routine for translating composition file
+** into valid MIME message. It translates the draft
+** into a content structure (actually a tree of content
+** structures). This message then can be manipulated
+** in various ways, including being output via
+** output_message().
+*/
if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL)
adios (NULL, "out of memory");
/*
if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL)
adios (NULL, "out of memory");
/*
- * Allocate structure for handling decoded content
- * for this part. We don't really need this, but
- * allocate it to remain consistent.
- */
+ ** Allocate structure for handling decoded content
+ ** for this part. We don't really need this, but
+ ** allocate it to remain consistent.
+ */
- * Parse some of the header fields in the composition
- * draft into the linked list of header fields for
- * the new MIME message.
- */
+ ** Parse some of the header fields in the composition
+ ** draft into the linked list of header fields for
+ ** the new MIME message.
+ */
for (compnum = 1, state = FLD;;) {
switch (state = m_getfld (state, name, buf, sizeof(buf), in)) {
case FLD:
for (compnum = 1, state = FLD;;) {
switch (state = m_getfld (state, name, buf, sizeof(buf), in)) {
case FLD:
if (!mh_strcasecmp (name, VRSN_FIELD))
adios (NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
if (!mh_strcasecmp (name, VRSN_FIELD))
adios (NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
if (!mh_strcasecmp (name, ENCODING_FIELD))
adios (NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
/* ignore any Content-Type fields in the header */
if (!mh_strcasecmp (name, TYPE_FIELD)) {
while (state == FLDPLUS)
if (!mh_strcasecmp (name, ENCODING_FIELD))
adios (NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
/* ignore any Content-Type fields in the header */
if (!mh_strcasecmp (name, TYPE_FIELD)) {
while (state == FLDPLUS)
- state = m_getfld (state, name, buf, sizeof(buf), in);
+ state = m_getfld (state, name, buf,
+ sizeof(buf), in);
/* if necessary, get rest of field */
while (state == FLDPLUS) {
state = m_getfld (state, name, buf, sizeof(buf), in);
/* if necessary, get rest of field */
while (state == FLDPLUS) {
state = m_getfld (state, name, buf, sizeof(buf), in);
np = add (VRSN_FIELD, NULL);
vp = concat (" ", VRSN_VALUE, "\n", NULL);
add_header (ct, np, vp);
/*
np = add (VRSN_FIELD, NULL);
vp = concat (" ", VRSN_VALUE, "\n", NULL);
add_header (ct, np, vp);
/*
- * We initally assume we will find multiple contents in the
- * draft. So create a multipart/mixed content to hold everything.
- * We can remove this later, if it is not needed.
- */
+ ** We initally assume we will find multiple contents in the
+ ** draft. So create a multipart/mixed content to hold everything.
+ ** We can remove this later, if it is not needed.
+ */
if (get_ctinfo ("multipart/mixed", ct, 0) == NOTOK)
done (1);
ct->c_type = CT_MULTIPART;
if (get_ctinfo ("multipart/mixed", ct, 0) == NOTOK)
done (1);
ct->c_type = CT_MULTIPART;
- * If only one content was found, then remove and
- * free the outer multipart content.
- */
+ ** If only one content was found, then remove and
+ ** free the outer multipart content.
+ */
- * Fill out, or expand directives. Parse and execute
- * commands specified by profile composition strings.
- */
+ ** Fill out, or expand directives. Parse and execute
+ ** commands specified by profile composition strings.
+ */
compose_content (ct);
if ((cp = strchr(prefix, 'a')) == NULL)
adios (NULL, "internal error(4)");
/*
compose_content (ct);
if ((cp = strchr(prefix, 'a')) == NULL)
adios (NULL, "internal error(4)");
/*
- * Scan the contents. Choose a transfer encoding, and
- * check if prefix for multipart boundary clashes with
- * any of the contents.
- */
+ ** Scan the contents. Choose a transfer encoding, and
+ ** check if prefix for multipart boundary clashes with
+ ** any of the contents.
+ */
static int
user_content (FILE *in, char *file, char *buf, CT *ctp)
static int
user_content (FILE *in, char *file, char *buf, CT *ctp)
- * Handle inline text. Check if line
- * is one of the following forms:
- *
- * 1) doesn't begin with '#' (implicit directive)
- * 2) begins with "##" (implicit directive)
- * 3) begins with "#<"
- */
+ ** Handle inline text. Check if line
+ ** is one of the following forms:
+ **
+ ** 1) doesn't begin with '#' (implicit directive)
+ ** 2) begins with "##" (implicit directive)
+ ** 3) begins with "#<"
+ */
char *cp;
cp = m_mktemp2(NULL, invo_name, NULL, &out);
char *cp;
cp = m_mktemp2(NULL, invo_name, NULL, &out);
/* use a temp file to collect the plain text lines */
ce->ce_file = add (cp, NULL);
/* use a temp file to collect the plain text lines */
ce->ce_file = add (cp, NULL);
switch (ct->c_type = s2i->si_val) {
case CT_MESSAGE:
if (!mh_strcasecmp (ci->ci_subtype, "rfc822")) {
switch (ct->c_type = s2i->si_val) {
case CT_MESSAGE:
if (!mh_strcasecmp (ci->ci_subtype, "rfc822")) {
- * If we've reached this point, the next line
- * must be some type of explicit directive.
- */
+ ** If we've reached this point, the next line
+ ** must be some type of explicit directive.
+ */
- * Check if the directive specified a valid type.
- * This will happen if it was one of the following forms:
- *
- * #type/subtype (or)
- * #@type/subtype
- */
+ ** Check if the directive specified a valid type.
+ ** This will happen if it was one of the following forms:
+ **
+ ** #type/subtype (or)
+ ** #@type/subtype
+ */
- * Since we are using the current Content structure to
- * hold information about the type of the external
- * reference, we need to create another Content structure
- * for the message/external-body to wrap it in.
- */
+ ** Since we are using the current Content structure to
+ ** hold information about the type of the external
+ ** reference, we need to create another Content
+ ** structure for the message/external-body to wrap
+ ** it in.
+ */
if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL)
adios (NULL, "out of memory");
*ctp = ct;
if ((ct = (CT) calloc (1, sizeof(*ct))) == NULL)
adios (NULL, "out of memory");
*ctp = ct;
- * No [file] argument, so check profile for
- * method to compose content.
- */
+ ** No [file] argument, so check profile for
+ ** method to compose content.
+ */
snprintf (buffer, sizeof(buffer), "%s-compose-%s/%s",
invo_name, ci->ci_type, ci->ci_subtype);
if ((cp = context_find (buffer)) == NULL || *cp == '\0') {
snprintf (buffer, sizeof(buffer), "%s-compose-%s/%s",
invo_name, ci->ci_type, ci->ci_subtype);
if ((cp = context_find (buffer)) == NULL || *cp == '\0') {
- snprintf (buffer, sizeof(buffer), "%s-compose-%s", invo_name, ci->ci_type);
+ snprintf (buffer, sizeof(buffer), "%s-compose-%s",
+ invo_name, ci->ci_type);
if ((cp = context_find (buffer)) == NULL || *cp == '\0') {
content_error (NULL, ct, "don't know how to compose content");
done (1);
if ((cp = context_find (buffer)) == NULL || *cp == '\0') {
content_error (NULL, ct, "don't know how to compose content");
done (1);
if (!mh_strcasecmp (ci->ci_type, "forw")) {
int msgnum;
char *folder, *arguments[MAXARGS];
if (!mh_strcasecmp (ci->ci_type, "forw")) {
int msgnum;
char *folder, *arguments[MAXARGS];
- * If there is more than one message to include, make this
- * a content of type "multipart/digest" and insert each message
- * as a subpart. If there is only one message, then make this
- * a content of type "message/rfc822".
- */
+ ** If there is more than one message to include, make this
+ ** a content of type "multipart/digest" and insert each message
+ ** as a subpart. If there is only one message, then make this
+ ** a content of type "message/rfc822".
+ */
if (mp->numsel > 1) {
/* we are forwarding multiple messages */
if (get_ctinfo ("multipart/digest", ct, 0) == NOTOK)
if (mp->numsel > 1) {
/* we are forwarding multiple messages */
if (get_ctinfo ("multipart/digest", ct, 0) == NOTOK)
adios (NULL, "unknown directive \"#%s\"", ci->ci_type);
return NOTOK; /* NOT REACHED */
}
adios (NULL, "unknown directive \"#%s\"", ci->ci_type);
return NOTOK; /* NOT REACHED */
}
- * Fill out, or expand the various contents in the composition
- * draft. Read-in any necessary files. Parse and execute any
- * commands specified by profile composition strings.
- */
+** Fill out, or expand the various contents in the composition
+** draft. Read-in any necessary files. Parse and execute any
+** commands specified by profile composition strings.
+*/
- for (part = m->mp_parts, partnum = 1; part; part = part->mp_next, partnum++) {
+ for (part = m->mp_parts, partnum = 1; part;
+ part = part->mp_next, partnum++) {
- * If the -rfc934mode switch is given, then check all
- * the subparts of a multipart/digest. If they are all
- * message/rfc822, then mark this content and all
- * subparts with the rfc934 compatibility mode flag.
- */
+ ** If the -rfc934mode switch is given, then check all
+ ** the subparts of a multipart/digest. If they are all
+ ** message/rfc822, then mark this content and all
+ ** subparts with the rfc934 compatibility mode flag.
+ */
snprintf (bp, buflen, "%s", ce->ce_file);
break;
snprintf (bp, buflen, "%s", ce->ce_file);
break;
- * Scan the content.
- *
- * 1) choose a transfer encoding.
- * 2) check for clashes with multipart boundary string.
- * 3) for text content, figure out which character set is being used.
- *
- * If there is a clash with one of the contents and the multipart boundary,
- * this function will exit with NOTOK. This will cause the scanning process
- * to be repeated with a different multipart boundary. It is possible
- * (although highly unlikely) that this scan will be repeated multiple times.
- */
+** Scan the content.
+**
+** 1) choose a transfer encoding.
+** 2) check for clashes with multipart boundary string.
+** 3) for text content, figure out which character set is being used.
+**
+** If there is a clash with one of the contents and the multipart boundary,
+** this function will exit with NOTOK. This will cause the scanning process
+** to be repeated with a different multipart boundary. It is possible
+** (although highly unlikely) that this scan will be repeated multiple times.
+*/
if (p->c_encoding == CE_BINARY)
ct->c_encoding = CE_BINARY;
if (p->c_encoding == CE_8BIT && ct->c_encoding != CE_BINARY)
if (p->c_encoding == CE_BINARY)
ct->c_encoding = CE_BINARY;
if (p->c_encoding == CE_8BIT && ct->c_encoding != CE_BINARY)
- * Don't check anything for these types,
- * since we are forcing use of base64.
- */
+ ** Don't check anything for these types,
+ ** since we are forcing use of base64.
+ */
if (check8bit || checklinelen || checklinespace || checkboundary) {
if ((in = fopen (ce->ce_file, "r")) == NULL)
adios (ce->ce_file, "unable to open for reading");
if (check8bit || checklinelen || checklinespace || checkboundary) {
if ((in = fopen (ce->ce_file, "r")) == NULL)
adios (ce->ce_file, "unable to open for reading");
if (checklinelen && (strlen (buffer) > CPERLIN + 1)) {
linelen = 1;
checklinelen = 0; /* no need to keep checking */
}
/*
if (checklinelen && (strlen (buffer) > CPERLIN + 1)) {
linelen = 1;
checklinelen = 0; /* no need to keep checking */
}
/*
- * Check if line ends with a space.
- */
- if (checklinespace && (cp = buffer + strlen (buffer) - 2) > buffer && isspace (*cp)) {
+ ** Check if line ends with a space.
+ */
+ if (checklinespace &&
+ (cp = buffer + strlen (buffer) - 2) >
+ buffer && isspace (*cp)) {
- * Check if content contains a line that clashes
- * with our standard boundary for multipart messages.
- */
+ ** Check if content contains a line that clashes
+ ** with our standard boundary for multipart messages.
+ */
if (checkboundary && buffer[0] == '-' && buffer[1] == '-') {
for (cp = buffer + strlen (buffer) - 1; cp >= buffer; cp--)
if (!isspace (*cp))
if (checkboundary && buffer[0] == '-' && buffer[1] == '-') {
for (cp = buffer + strlen (buffer) - 1; cp >= buffer; cp--)
if (!isspace (*cp))
- * If the text content didn't specify a character
- * set, we need to figure out which one was used.
- */
+ ** If the text content didn't specify a character
+ ** set, we need to figure out which one was used.
+ */
- * Scan the content structures, and build header
- * fields that will need to be output into the
- * message.
- */
+** Scan the content structures, and build header
+** fields that will need to be output into the
+** message.
+*/
- * If message is type multipart, then add the multipart
- * boundary to the list of attribute/value pairs.
- */
+ ** If message is type multipart, then add the multipart
+ ** boundary to the list of attribute/value pairs.
+ */
- * Skip the output of Content-Type, parameters, content
- * description and disposition, and Content-ID if the
- * content is of type "message" and the rfc934 compatibility
- * flag is set (which means we are inside multipart/digest
- * and the switch -rfc934mode was given).
- */
+ ** Skip the output of Content-Type, parameters, content
+ ** description and disposition, and Content-ID if the
+ ** content is of type "message" and the rfc934 compatibility
+ ** flag is set (which means we are inside multipart/digest
+ ** and the switch -rfc934mode was given).
+ */
np = add (TYPE_FIELD, NULL);
vp = concat (" ", ci->ci_type, "/", ci->ci_subtype, NULL);
np = add (TYPE_FIELD, NULL);
vp = concat (" ", ci->ci_type, "/", ci->ci_subtype, NULL);
for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
if (mailbody && !mh_strcasecmp (*ap, "body"))
continue;
for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
if (mailbody && !mh_strcasecmp (*ap, "body"))
continue;
if (ci->ci_comment) {
snprintf (buffer, sizeof(buffer), "(%s)", ci->ci_comment);
if (len + 1 + (cc = 2 + strlen (ci->ci_comment)) >= CPERLIN) {
if (ci->ci_comment) {
snprintf (buffer, sizeof(buffer), "(%s)", ci->ci_comment);
if (len + 1 + (cc = 2 + strlen (ci->ci_comment)) >= CPERLIN) {
if (contentidsw && ct->c_id) {
np = add (ID_FIELD, NULL);
vp = concat (" ", ct->c_id, NULL);
if (contentidsw && ct->c_id) {
np = add (ID_FIELD, NULL);
vp = concat (" ", ct->c_id, NULL);
if (ct->c_descr) {
np = add (DESCR_FIELD, NULL);
vp = concat (" ", ct->c_descr, NULL);
if (ct->c_descr) {
np = add (DESCR_FIELD, NULL);
vp = concat (" ", ct->c_descr, NULL);
if (ct->c_dispo) {
np = add (DISPO_FIELD, NULL);
vp = concat (" ", ct->c_dispo, NULL);
if (ct->c_dispo) {
np = add (DISPO_FIELD, NULL);
vp = concat (" ", ct->c_dispo, NULL);
- * If this is the internal content structure for a
- * "message/external", then we are done with the
- * headers (since it has no body).
- */
+ ** If this is the internal content structure for a
+ ** "message/external", then we are done with the
+ ** headers (since it has no body).
+ */
if (checksw) {
np = add (MD5_FIELD, NULL);
vp = calculate_digest (ct, (ct->c_encoding == CE_QUOTED) ? 1 : 0);
if (checksw) {
np = add (MD5_FIELD, NULL);
vp = calculate_digest (ct, (ct->c_encoding == CE_QUOTED) ? 1 : 0);
}
} else {
while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), in)) > 0)
}
} else {
while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), in)) > 0)