- 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 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;
+ if (extrnal)
+ adios (NULL, "external definition not allowed for \"#%s\"",
+ ci->ci_type);
+
+ /*
+ ** Message directive
+ ** #forw [+folder] [msgs]
+ */
+ if (!mh_strcasecmp (ci->ci_type, "forw")) {
+ int msgnum;
+ char *folder, *arguments[MAXARGS];
+ struct msgs *mp;
+
+ if (ci->ci_magic) {
+ ap = brkstring (ci->ci_magic, " ", "\n");
+ copyip (ap, arguments, MAXARGS);
+ } else {
+ arguments[0] = "cur";
+ arguments[1] = NULL;
+ }
+ folder = NULL;
+
+ /* search the arguments for a folder name */
+ for (ap = arguments; *ap; ap++) {
+ cp = *ap;
+ if (*cp == '+' || *cp == '@') {
+ if (folder)
+ adios (NULL, "only one folder per #forw directive");
+ else
+ folder = pluspath (cp);
+ }
+ }
+
+ /* 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