- 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 = getcpy(name);
+ vp = getcpy(buf);
+
+ /* if necessary, get rest of field */
+ while (state == FLDPLUS) {
+ state = m_getfld(state, name, buf,
+ sizeof(buf), in);
+ vp = add(buf, vp); /* add to prev value */
+ }
+
+ /* Now add the header data to the list */
+ add_header(ct, np, vp);
- folder_free (mp); /* free folder/message structure */
- return OK;
- }
-
- /*
- * #end
- */
- if (!mh_strcasecmp (ci->ci_type, "end")) {
- free_content (ct);
- *ctp = NULL;
- return DONE;
- }
-
- /*
- * #begin [ alternative | parallel ]
- */
- if (!mh_strcasecmp (ci->ci_type, "begin")) {
- if (!ci->ci_magic) {
- vrsn = MULTI_MIXED;
- cp = SubMultiPart[vrsn - 1].kv_key;
- } else if (!mh_strcasecmp (ci->ci_magic, "alternative")) {
- vrsn = MULTI_ALTERNATE;
- cp = SubMultiPart[vrsn - 1].kv_key;
- } else if (!mh_strcasecmp (ci->ci_magic, "parallel")) {
- vrsn = MULTI_PARALLEL;
- cp = SubMultiPart[vrsn - 1].kv_key;
- } else if (uprf (ci->ci_magic, "digest")) {
- goto use_forw;
- } else {
- vrsn = MULTI_UNKNOWN;
- cp = ci->ci_magic;
- }
+ /* else, use the current folder */
+ if (!folder)
+ folder = getcpy(getcurfol());
+
+ 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 = getcpy(buffer);
+ 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 = getcpy(buffer);
+ if (listsw && stat(ce->ce_file, &st) != NOTOK)
+ ct->c_end = (long) st.st_size;
+ }
- 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
- vp = add (buffer, vp);
- len += cc;
- }
-
- /*
- * Append any RFC-822 comment to the end of
- * the Content-Type line.
- */
- if (ci->ci_comment) {
- snprintf (buffer, sizeof(buffer), "(%s)", ci->ci_comment);
- if (len + 1 + (cc = 2 + strlen (ci->ci_comment)) >= CPERLIN) {
- vp = add ("\n\t", vp);
- len = 8;
- } else {
- vp = add (" ", vp);
- len++;
+
+ /*
+ ** 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).
+ */
+ if (ct->c_type == CT_MESSAGE && ct->c_rfc934)
+ goto skip_headers;
+
+ /*
+ ** output the content type and subtype
+ */
+ np = getcpy(TYPE_FIELD);
+ vp = concat(" ", ci->ci_type, "/", ci->ci_subtype, NULL);
+
+ /* keep track of length of line */
+ len = strlen(TYPE_FIELD) + strlen(ci->ci_type) +
+ strlen(ci->ci_subtype) + 3;
+
+ mailbody = ct->c_type == CT_MESSAGE &&
+ ct->c_subtype == MESSAGE_EXTERNAL &&
+ ((struct exbody *) ct->c_ctparams)->eb_body;
+
+ /*
+ ** Append the attribute/value pairs to
+ ** the end of the Content-Type line.
+ */
+ for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
+ if (mailbody && !mh_strcasecmp(*ap, "body"))
+ continue;
+
+ vp = add(";", vp);
+ len++;
+
+ snprintf(buffer, sizeof(buffer), "%s=\"%s\"", *ap, *ep);
+ if (len + 1 + (cc = strlen(buffer)) >= CPERLIN) {
+ vp = add("\n\t", vp);
+ len = 8;
+ } else {
+ vp = add(" ", vp);
+ len++;
+ }
+ vp = add(buffer, vp);
+ len += cc;
+ }
+
+ /*
+ ** Append any RFC-822 comment to the end of
+ ** the Content-Type line.
+ */
+ if (ci->ci_comment) {
+ snprintf(buffer, sizeof(buffer), "(%s)", ci->ci_comment);
+ if (len + 1 + (cc = 2 + strlen(ci->ci_comment)) >= CPERLIN) {
+ vp = add("\n\t", vp);
+ len = 8;
+ } else {
+ vp = add(" ", vp);
+ len++;
+ }
+ vp = add(buffer, vp);
+ len += cc;
+ }
+ vp = add("\n", vp);
+ add_header(ct, np, vp);
+
+ /*
+ ** output the Content-ID, unless disabled by -nocontentid
+ */
+ if (contentidsw && ct->c_id) {
+ np = getcpy(ID_FIELD);
+ vp = concat(" ", ct->c_id, NULL);
+ add_header(ct, np, vp);
+ }
+
+ /*
+ ** output the Content-Description
+ */
+ if (ct->c_descr) {
+ np = getcpy(DESCR_FIELD);
+ vp = concat(" ", ct->c_descr, NULL);
+ add_header(ct, np, vp);
+ }
+
+ /*
+ ** output the Content-Disposition
+ */
+ if (ct->c_dispo) {
+ np = getcpy(DISPO_FIELD);
+ vp = concat(" ", ct->c_dispo, NULL);
+ add_header(ct, np, vp);