+
+/*
+ * Set things up for the content structure for file "filename" that
+ * we want to attach
+ */
+
+static void
+setup_attach_content(CT ct, char *filename)
+{
+ char *type, *simplename = r1bindex(filename, '/');
+ struct str2init *s2i;
+ PM pm;
+ char *cp;
+
+ if (! (type = mime_type(filename))) {
+ adios(NULL, "Unable to determine MIME type of \"%s\"", filename);
+ }
+
+ /*
+ * Parse the Content-Type. get_ctinfo() parses MIME parameters, but
+ * since we're just feeding it a MIME type we have to add those ourself.
+ * Map that to a valid content-type label and call any initialization
+ * function.
+ */
+
+ if (get_ctinfo(type, ct, 0) == NOTOK)
+ done(1);
+
+ free(type);
+
+ for (s2i = str2cts; s2i->si_key; s2i++)
+ if (strcasecmp(ct->c_ctinfo.ci_type, s2i->si_key) == 0)
+ break;
+ if (!s2i->si_key && !uprf(ct->c_ctinfo.ci_type, "X-"))
+ s2i++;
+
+ /*
+ * Make sure the type isn't incompatible with what we can handle
+ */
+
+ switch (ct->c_type = s2i->si_val) {
+ case CT_MULTIPART:
+ adios (NULL, "multipart types must be specified by mhbuild directives");
+ /* NOTREACHED */
+
+ case CT_MESSAGE:
+ if (strcasecmp(ct->c_ctinfo.ci_subtype, "partial") == 0)
+ adios(NULL, "Sorry, %s/%s isn't supported", ct->c_ctinfo.ci_type,
+ ct->c_ctinfo.ci_subtype);
+ if (strcasecmp(ct->c_ctinfo.ci_subtype, "external-body") == 0)
+ adios(NULL, "external-body messages must be specified "
+ "by mhbuild directives");
+ /* Fall through */
+
+ default:
+ /*
+ * This sets the subtype, if it's significant
+ */
+ if ((ct->c_ctinitfnx = s2i->si_init))
+ (*ct->c_ctinitfnx)(ct);
+ break;
+ }
+
+ /*
+ * Feed in a few attributes; specifically, the name attribute, the
+ * content-description, and the content-disposition.
+ */
+
+ for (pm = ct->c_ctinfo.ci_first_pm; pm; pm = pm->pm_next) {
+ if (strcasecmp(pm->pm_name, "name") == 0) {
+ if (pm->pm_value)
+ free(pm->pm_value);
+ pm->pm_value = getcpy(simplename);
+ break;
+ }
+ }
+
+ if (pm == NULL)
+ add_param(&ct->c_ctinfo.ci_first_pm, &ct->c_ctinfo.ci_last_pm,
+ "name", simplename, 0);
+
+ ct->c_descr = getcpy(simplename);
+ ct->c_descr = add("\n", ct->c_descr);
+ ct->c_cefile.ce_file = getcpy(filename);
+
+ /*
+ * Look for mhbuild-disposition-<type>/<subtype> entry
+ * that specifies Content-Disposition type. Only
+ * 'attachment' and 'inline' are allowed. Default to
+ * 'attachment'.
+ */
+
+ cp = context_find_by_type ("disposition", ct->c_ctinfo.ci_type,
+ ct->c_ctinfo.ci_subtype);
+ if (cp != NULL) {
+ if (strcasecmp (cp, "attachment") && strcasecmp (cp, "inline")) {
+ admonish (NULL, "configuration problem: %s-disposition-%s%s%s "
+ "specifies '%s' but only 'attachment' and 'inline' are "
+ "allowed", invo_name,
+ ct->c_ctinfo.ci_type,
+ ct->c_ctinfo.ci_subtype ? "/" : "",
+ ct->c_ctinfo.ci_subtype ? ct->c_ctinfo.ci_subtype : "",
+ cp);
+ }
+ }
+
+ if (cp) {
+ ct->c_dispo_type = getcpy(cp);
+ } else {
+ ct->c_dispo_type = getcpy("attachment");
+ }
+
+ add_param(&ct->c_dispo_first, &ct->c_dispo_last, "filename", simplename, 0);
+}