- int compnum, state;
- char buf[BUFSIZ], name[NAMESZ];
- char *cp, *np, *vp;
- struct multipart *m;
- struct part **pp;
- CT ct;
- FILE *in;
-
- umask (~m_gmprot ());
-
- /* open the composition draft */
- if ((in = fopen (infile, "r")) == NULL)
- adios (infile, "unable to open for reading");
-
- /*
- * Allocate space for primary (outside) content
- */
- 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.
- */
- init_decoded_content (ct);
-
- /*
- * 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:
- case FLDPLUS:
- case FLDEOF:
- compnum++;
-
- /* abort if draft has Mime-Version header field */
- if (!mh_strcasecmp (name, VRSN_FIELD))
- adios (NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
-
- /* abort if draft has Content-Transfer-Encoding header 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)
- state = m_getfld (state, name, buf, sizeof(buf), in);
- goto finish_field;
- }
-
- /* get copies of the buffers */
- np = add (name, NULL);
- vp = add (buf, NULL);
-
- /* if necessary, get rest of field */
- while (state == FLDPLUS) {
- state = m_getfld (state, name, buf, sizeof(buf), in);
- vp = add (buf, vp); /* add to previous value */
- }
-
- /* Now add the header data to the list */
- add_header (ct, np, vp);
+ int compnum, state;
+ char buf[BUFSIZ], name[NAMESZ];
+ char *cp, *np, *vp;
+ struct multipart *m;
+ struct part **pp;
+ CT ct;
+ FILE *in;
+
+ umask (~m_gmprot ());
+
+ /* open the composition draft */
+ if ((in = fopen (infile, "r")) == NULL)
+ adios (infile, "unable to open for reading");
+
+ /*
+ * Allocate space for primary (outside) content
+ */
+ 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.
+ */
+ init_decoded_content (ct);
+
+ /*
+ * 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:
+ case FLDPLUS:
+ case FLDEOF:
+ compnum++;
+
+ /* abort if draft has Mime-Version header field */
+ if (!mh_strcasecmp (name, VRSN_FIELD))
+ adios (NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
+
+ /* abort if draft has Content-Transfer-Encoding header 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)
+ state = m_getfld (state, name, buf, sizeof(buf), in);
+ goto finish_field;
+ }
+
+ /* get copies of the buffers */
+ np = add (name, NULL);
+ vp = add (buf, NULL);
+
+ /* if necessary, get rest of field */
+ while (state == FLDPLUS) {
+ state = m_getfld (state, name, buf, sizeof(buf), in);
+ vp = add (buf, vp); /* add to previous value */
+ }
+
+ /* Now add the header data to the list */
+ add_header (ct, np, vp);
- /* Handle [file] argument */
- if (ci->ci_magic) {
- /* check if specifies command to execute */
- if (*ci->ci_magic == '|' || *ci->ci_magic == '!') {
- for (cp = ci->ci_magic + 1; isspace (*cp); cp++)
- continue;
- if (!*cp)
- adios (NULL, "empty pipe command for #%s directive", ci->ci_type);
- cp = add (cp, NULL);
- free (ci->ci_magic);
- ci->ci_magic = cp;
- } else {
- /* record filename of decoded contents */
- ce->ce_file = ci->ci_magic;
- if (access (ce->ce_file, R_OK) == NOTOK)
- adios ("reading", "unable to access %s for", ce->ce_file);
- if (listsw && stat (ce->ce_file, &st) != NOTOK)
- ct->c_end = (long) st.st_size;
- ci->ci_magic = NULL;
- }
- return OK;
+ /*
+ * 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;
+ ci = &ct->c_ctinfo;
+ if (get_ctinfo (buffer, ct, 0) == NOTOK)
+ done (1);
+ ct->c_type = CT_MESSAGE;
+ ct->c_subtype = MESSAGE_EXTERNAL;
+
+ if ((e = (struct exbody *) calloc (1, sizeof(*e))) == NULL)
+ adios (NULL, "out of memory");
+ ct->c_ctparams = (void *) e;
+
+ e->eb_parent = ct;
+ e->eb_content = p;
+ p->c_ctexbody = e;
+
+ if (params_external (ct, 1) == NOTOK)
+ done (1);
+
+ return OK;
+ }
+
+ /* Handle [file] argument */
+ if (ci->ci_magic) {
+ /* check if specifies command to execute */
+ if (*ci->ci_magic == '|' || *ci->ci_magic == '!') {
+ for (cp = ci->ci_magic + 1; isspace (*cp); cp++)
+ continue;
+ if (!*cp)
+ adios (NULL, "empty pipe command for #%s directive", ci->ci_type);
+ cp = add (cp, NULL);
+ free (ci->ci_magic);
+ ci->ci_magic = cp;
+ } else {
+ /* record filename of decoded contents */
+ ce->ce_file = ci->ci_magic;
+ if (access (ce->ce_file, R_OK) == NOTOK)
+ adios ("reading", "unable to access %s for", ce->ce_file);
+ if (listsw && stat (ce->ce_file, &st) != NOTOK)
+ ct->c_end = (long) st.st_size;
+ ci->ci_magic = NULL;
+ }
+ return OK;
+ }
+
+ /*
+ * 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", 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);
+ }
+ }
+ ci->ci_magic = add (cp, NULL);
+ return OK;
- /* else, use the current folder */
- if (!folder)
- folder = add (getfolder (1), NULL);
-
- if (!(mp = folder_read (folder)))
- adios (NULL, "unable to read folder %s", folder);
- for (ap = arguments; *ap; ap++) {
- cp = *ap;
- if (*cp != '+' && *cp != '@')
- if (!m_convert (mp, cp))
- done (1);
+ /* else, use the current folder */
+ if (!folder)
+ folder = add (getfolder (1), NULL);
+
+ if (!(mp = folder_read (folder)))
+ adios (NULL, "unable to read folder %s", folder);
+ for (ap = arguments; *ap; ap++) {
+ cp = *ap;
+ if (*cp != '+' && *cp != '@')
+ if (!m_convert (mp, cp))
+ done (1);
+ }
+ free (folder);
+ free_ctinfo (ct);
+
+ /*
+ * 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)
+ done (1);
+ ct->c_type = CT_MULTIPART;
+ ct->c_subtype = MULTI_DIGEST;
+
+ if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL)
+ adios (NULL, "out of memory");
+ ct->c_ctparams = (void *) m;
+ pp = &m->mp_parts;
+
+ for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
+ if (is_selected(mp, msgnum)) {
+ struct part *part;
+ CT p;
+ CE pe;
+
+ if ((p = (CT) calloc (1, sizeof(*p))) == NULL)
+ adios (NULL, "out of memory");
+ init_decoded_content (p);
+ pe = p->c_cefile;
+ if (get_ctinfo ("message/rfc822", p, 0) == NOTOK)
+ done (1);
+ p->c_type = CT_MESSAGE;
+ p->c_subtype = MESSAGE_RFC822;
+
+ snprintf (buffer, sizeof(buffer), "%s/%d", mp->foldpath, msgnum);
+ pe->ce_file = add (buffer, NULL);
+ if (listsw && stat (pe->ce_file, &st) != NOTOK)
+ p->c_end = (long) st.st_size;
+
+ if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL)
+ adios (NULL, "out of memory");
+ *pp = part;
+ pp = &part->mp_next;
+ part->mp_part = p;
+ }
+ }
+ } else {
+ /* we are forwarding one message */
+ if (get_ctinfo ("message/rfc822", ct, 0) == NOTOK)
+ done (1);
+ ct->c_type = CT_MESSAGE;
+ ct->c_subtype = MESSAGE_RFC822;
+
+ msgnum = mp->lowsel;
+ snprintf (buffer, sizeof(buffer), "%s/%d", mp->foldpath, msgnum);
+ ce->ce_file = add (buffer, NULL);
+ if (listsw && stat (ce->ce_file, &st) != NOTOK)
+ ct->c_end = (long) st.st_size;
+ }
+
+ folder_free (mp); /* free folder/message structure */
+ return OK;
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
- 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00