2 ** mhstore.c -- store the contents of MIME messages
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
11 #include <h/signals.h>
18 #include <h/mhparse.h>
19 #include <h/mhcachesbr.h>
22 static struct swit switches[] = {
31 #define FILESW 4 /* interface from show */
36 { "type content", 0 },
38 { "rcache policy", 0 },
40 { "wcache policy", 0 },
52 extern char *tmp; /* directory to place temp files */
57 extern char *cache_public;
58 extern char *cache_private;
63 extern char *parts[NPARTS + 1];
64 extern char *types[NTYPES + 1];
69 #define quitser pipeser
72 CT parse_mime(char *);
77 void set_endian(void);
78 void flush_errors(void);
81 void free_content(CT);
82 extern CT *cts; /* The list of top-level contents to display */
83 void freects_done(int) NORETURN;
88 static void pipeser(int);
93 ** Cache of current directory. This must be
94 ** set before these routines are called.
99 ** The directory in which to store the contents.
104 ** Type for a compare function for qsort. This keeps
105 ** the compiler happy.
107 typedef int (*qsort_comp) (const void *, const void *);
111 int part_ok(CT, int);
112 int type_ok(CT, int);
113 int make_intermediates(char *);
114 void flush_errors(void);
117 int show_content_aux(CT, int, int, char *, char *);
122 static void store_single_message(CT);
123 static int store_switch(CT);
124 static int store_generic(CT);
125 static int store_application(CT);
126 static int store_multi(CT);
127 static int store_partial(CT);
128 static int store_external(CT);
129 static int ct_compar(CT *, CT *);
130 static int store_content(CT, CT);
131 static int output_content_file(CT, int);
132 static int output_content_folder(char *, char *);
133 static int parse_format_string(CT, char *, char *, int, char *);
134 static void get_storeproc(CT);
135 static int copy_some_headers(FILE *, CT);
136 static void store_all_messages(CT *);
140 main(int argc, char **argv)
142 int msgnum, *icachesw;
143 char *cp, *file = NULL, *folder = NULL;
144 char *maildir, buf[100], **argp;
146 struct msgs_array msgs = { 0, 0, NULL };
147 struct msgs *mp = NULL;
154 setlocale(LC_ALL, "");
156 invo_name = mhbasename(argv[0]);
158 /* read user profile/context */
161 arguments = getarguments(invo_name, argc, argv, 1);
167 while ((cp = *argp++)) {
169 switch (smatch(++cp, switches)) {
171 ambigsw(cp, switches);
174 adios(NULL, "-%s unknown", cp);
177 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
178 print_help(buf, switches, 1);
181 print_version(invo_name);
192 icachesw = &rcachesw;
195 icachesw = &wcachesw;
197 if (!(cp = *argp++) || *cp == '-')
198 adios(NULL, "missing argument to %s",
200 switch (*icachesw = smatch(cp, caches)) {
205 adios(NULL, "%s unknown", cp);
219 if (!(cp = *argp++) || *cp == '-')
220 adios(NULL, "missing argument to %s",
223 adios(NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
228 if (!(cp = *argp++) || *cp == '-')
229 adios(NULL, "missing argument to %s",
232 adios(NULL, "too many types (starting with %s), %d max", cp, NTYPES);
237 if (!(cp = *argp++) || (*cp == '-' && cp[1]))
238 adios(NULL, "missing argument to %s",
240 file = *cp == '-' ? cp : getcpy(expanddir(cp));
248 if (*cp == '+' || *cp == '@') {
250 adios(NULL, "only one folder at a time!");
252 folder = getcpy(expandfol(cp));
254 app_msgarg(&msgs, cp);
257 /* null terminate the list of acceptable parts/types */
264 ** Check if we've specified an additional profile
266 if ((cp = getenv("MHSTORE"))) {
267 if ((fp = fopen(cp, "r"))) {
268 readconfig((struct node **) 0, fp, cp, 0);
271 admonish("", "unable to read $MHSTORE profile (%s)",
277 ** Read the standard profile setup
279 if ((fp = fopen(cp = etcpath("mhn.defaults"), "r"))) {
280 readconfig((struct node **) 0, fp, cp, 0);
284 /* Check for public cache location */
285 if ((cache_public = context_find(nmhcache)) && *cache_public != '/')
288 /* Check for private cache location */
289 if (!(cache_private = context_find(nmhprivcache)))
290 cache_private = ".cache";
291 cache_private = getcpy(toabsdir(cache_private));
294 ** Cache the current directory before we do any chdirs()'s.
299 ** Check for storage directory. If specified,
300 ** then store temporary files there. Else we
301 ** store them in standard nmh directory.
303 if ((cp = context_find(nmhstorage)) && *cp)
304 tmp = concat(cp, "/", invo_name, NULL);
306 tmp = getcpy(toabsdir(invo_name));
308 if (file && msgs.size)
309 adios(NULL, "cannot specify msg and file at same time!");
312 ** check if message is coming from file
315 if (!(cts = (CT *) calloc((size_t) 2, sizeof(*cts))))
316 adios(NULL, "out of memory");
319 if ((ct = parse_mime(file)))
323 ** message(s) are coming from a folder
326 app_msgarg(&msgs, seq_cur);
328 folder = getcurfol();
329 maildir = toabsdir(folder);
331 if (chdir(maildir) == NOTOK)
332 adios(maildir, "unable to change directory to");
334 /* read folder and create message structure */
335 if (!(mp = folder_read(folder)))
336 adios(NULL, "unable to read folder %s", folder);
338 /* check for empty folder */
340 adios(NULL, "no messages in %s", folder);
342 /* parse all the message ranges/sequences and set SELECTED */
343 for (msgnum = 0; msgnum < msgs.size; msgnum++)
344 if (!m_convert(mp, msgs.msgs[msgnum]))
346 seq_setprev(mp); /* set the previous-sequence */
348 if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
350 adios(NULL, "out of memory");
353 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
354 if (is_selected(mp, msgnum)) {
357 msgnam = m_name(msgnum);
358 if ((ct = parse_mime(msgnam)))
368 SIGNAL(SIGQUIT, quitser);
369 SIGNAL(SIGPIPE, pipeser);
372 ** Get the associated umask for the relevant contents.
374 for (ctp = cts; *ctp; ctp++) {
378 if (type_ok(ct, 1) && !ct->c_umask) {
379 if (stat(ct->c_file, &st) != NOTOK)
380 ct->c_umask = ~(st.st_mode & 0777);
382 ct->c_umask = ~m_gmprot();
387 ** Store the message content
389 store_all_messages(cts);
391 /* Now free all the structures for the content */
392 for (ctp = cts; *ctp; ctp++)
398 /* If reading from a folder, do some updating */
400 context_replace(curfolder, folder); /* update current folder */
401 seq_setcur(mp, mp->hghsel); /* update current message */
402 seq_save(mp); /* synchronize sequences */
403 context_save(); /* save the context file */
417 fprintf(stderr, "\n");
427 ** Main entry point to store content from a collection of messages.
430 store_all_messages(CT *cts)
436 ** Check for the directory in which to
437 ** store any contents.
441 if ((cp = context_find(nmhstorage)) && *cp)
446 for (ctp = cts; *ctp; ctp++) {
448 store_single_message(ct);
456 ** Entry point to store the content
457 ** in a (single) message
461 store_single_message(CT ct)
463 if (type_ok(ct, 1)) {
470 if (ct->c_ceclosefnx)
471 (*ct->c_ceclosefnx) (ct);
477 ** Switching routine to store different content types
483 switch (ct->c_type) {
485 return store_multi(ct);
489 switch (ct->c_subtype) {
490 case MESSAGE_PARTIAL:
491 return store_partial(ct);
494 case MESSAGE_EXTERNAL:
495 return store_external(ct);
499 return store_generic(ct);
505 return store_application(ct);
512 return store_generic(ct);
516 adios(NULL, "unknown content type %d", ct->c_type);
520 return OK; /* NOT REACHED */
525 ** Generic routine to store a MIME content.
526 ** (audio, video, image, text, message/rfc922)
533 ** Check if the content specifies a filename.
534 ** Don't bother with this for type "message"
535 ** (only "message/rfc822" will use store_generic).
537 if (autosw && ct->c_type != CT_MESSAGE)
540 return store_content(ct, NULL);
545 ** Store content of type "application"
549 store_application(CT ct)
552 CI ci = &ct->c_ctinfo;
554 /* Check if the content specifies a filename */
559 ** If storeproc is not defined, and the content is type
560 ** "application/octet-stream", we also check for various
561 ** attribute/value pairs which specify if this a tar file.
563 if (!ct->c_storeproc && ct->c_subtype == APPLICATION_OCTETS) {
564 int tarP = 0, zP = 0, gzP = 0;
566 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
567 /* check for "type=tar" attribute */
568 if (!mh_strcasecmp(*ap, "type")) {
569 if (mh_strcasecmp(*ep, "tar"))
576 /* check for "conversions=compress" attribute */
577 if ((!mh_strcasecmp(*ap, "conversions") ||
578 !mh_strcasecmp(*ap, "x-conversions"))
579 && (!mh_strcasecmp(*ep, "compress") ||
580 !mh_strcasecmp(*ep, "x-compress"))) {
584 /* check for "conversions=gzip" attribute */
585 if ((!mh_strcasecmp(*ap, "conversions") ||
586 !mh_strcasecmp(*ap, "x-conversions"))
587 && (!mh_strcasecmp(*ep, "gzip") ||
588 !mh_strcasecmp(*ep, "x-gzip"))) {
595 ct->c_showproc = getcpy(zP ? "%euncompress | tar tvf -" : (gzP ? "%egzip -dc | tar tvf -" : "%etar tvf -"));
596 if (!ct->c_storeproc) {
598 ct->c_storeproc = getcpy(zP ? "| uncompress | tar xvpf -" : (gzP ? "| gzip -dc | tar xvpf -" : "| tar xvpf -"));
601 ct->c_storeproc= getcpy(zP ? "%m%P.tar.Z" : (gzP ? "%m%P.tar.gz" : "%m%P.tar"));
607 return store_content(ct, NULL);
612 ** Store the content of a multipart message
619 struct multipart *m = (struct multipart *) ct->c_ctparams;
623 for (part = m->mp_parts; part; part = part->mp_next) {
624 CT p = part->mp_part;
626 if (part_ok(p, 1) && type_ok(p, 1)) {
627 result = store_switch(p);
628 if (result == OK && ct->c_subtype == MULTI_ALTERNATE)
638 ** Reassemble and store the contents of a collection
639 ** of messages of type "message/partial".
648 struct partial *pm, *qm;
650 qm = (struct partial *) ct->c_ctparams;
655 for (ctp = cts; *ctp; ctp++) {
657 if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) {
658 pm = (struct partial *) p->c_ctparams;
659 if (!pm->pm_stored &&
660 strcmp(qm->pm_partid, pm->pm_partid)
662 pm->pm_marked = pm->pm_partno;
673 advise(NULL, "missing (at least) last part of multipart message");
677 if ((base = (CT *) calloc((size_t) (i + 1), sizeof(*base))) == NULL)
678 adios(NULL, "out of memory");
681 for (ctp = cts; *ctp; ctp++) {
683 if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) {
684 pm = (struct partial *) p->c_ctparams;
692 qsort((char *) base, i, sizeof(*base), (qsort_comp) ct_compar);
695 for (ctq = base; *ctq; ctq++) {
697 pm = (struct partial *) p->c_ctparams;
698 if (pm->pm_marked != cur) {
699 if (pm->pm_marked == cur - 1) {
700 admonish(NULL, "duplicate part %d of %d part multipart message", pm->pm_marked, hi);
705 advise (NULL, "missing %spart %d of %d part multipart message", cur != hi ? "(at least) " : "", cur, hi);
716 ** Now cycle through the sorted list of messages of type
717 ** "message/partial" and save/append them to a file.
722 if (store_content(ct, NULL) == NOTOK) {
728 for (; *ctq; ctq++) {
730 if (store_content(p, ct) == NOTOK)
740 ** Store content from a message of type "message/external".
744 store_external(CT ct)
747 struct exbody *e = (struct exbody *) ct->c_ctparams;
748 CT p = e->eb_content;
754 ** Check if the parameters for the external body
755 ** specified a filename.
760 if ((cp = e->eb_name) && *cp != '/' && *cp != '.' &&
761 *cp != '|' && *cp != '!' && !strchr(cp, '%')) {
762 if (!ct->c_storeproc)
763 ct->c_storeproc = getcpy(cp);
765 p->c_storeproc = getcpy(cp);
770 ** Since we will let the Content structure for the
771 ** external body substitute for the current content,
772 ** we temporarily change its partno (number inside
773 ** multipart), so everything looks right.
775 p->c_partno = ct->c_partno;
777 /* we probably need to check if content is really there */
778 result = store_switch(p);
786 ** Compare the numbering from two different
787 ** message/partials (needed for sorting).
791 ct_compar(CT *a, CT *b)
793 struct partial *am = (struct partial *) ((*a)->c_ctparams);
794 struct partial *bm = (struct partial *) ((*b)->c_ctparams);
796 return (am->pm_marked - bm->pm_marked);
801 ** Store contents of a message or message part to
802 ** a folder, a file, the standard output, or pass
803 ** the contents to a command.
805 ** If the current content to be saved is a followup part
806 ** to a collection of messages of type "message/partial",
807 ** then field "p" is a pointer to the Content structure
808 ** to the first message/partial in the group.
812 store_content(CT ct, CT p)
814 int appending = 0, msgnum = 0;
815 int is_partial = 0, first_partial = 0;
816 int last_partial = 0;
817 char *cp, buffer[BUFSIZ];
820 ** Do special processing for messages of
821 ** type "message/partial".
823 ** We first check if this content is of type
824 ** "message/partial". If it is, then we need to check
825 ** whether it is the first and/or last in the group.
827 ** Then if "p" is a valid pointer, it points to the Content
828 ** structure of the first partial in the group. So we copy
829 ** the file name and/or folder name from that message. In
830 ** this case, we also note that we will be appending.
832 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
833 struct partial *pm = (struct partial *) ct->c_ctparams;
835 /* Yep, it's a message/partial */
838 /* But is it the first and/or last in the collection? */
839 if (pm->pm_partno == 1)
841 if (pm->pm_maxno && pm->pm_partno == pm->pm_maxno)
845 ** If "p" is a valid pointer, then it points to the
846 ** Content structure for the first message in the group.
847 ** So we just copy the filename or foldername information
848 ** from the previous iteration of this function.
852 ct->c_storage = getcpy(p->c_storage);
854 /* record the folder name */
856 ct->c_folder = getcpy(p->c_folder);
863 ** Get storage formatting string.
865 ** 1) If we have storeproc defined, then use that
866 ** 2) Else check for a mhstore-store-<type>/<subtype> entry
867 ** 3) Else check for a mhstore-store-<type> entry
868 ** 4) Else if content is "message", use "+" (current folder)
869 ** 5) Else use string "%m%P.%s".
871 if ((cp = ct->c_storeproc) == NULL || *cp == '\0') {
872 CI ci = &ct->c_ctinfo;
874 snprintf(buffer, sizeof(buffer), "%s-store-%s/%s",
875 invo_name, ci->ci_type, ci->ci_subtype);
876 if ((cp = context_find(buffer)) == NULL || *cp == '\0') {
877 snprintf(buffer, sizeof(buffer), "%s-store-%s",
878 invo_name, ci->ci_type);
879 if ((cp = context_find(buffer)) == NULL ||
881 cp = ct->c_type == CT_MESSAGE ?
888 ** Check the beginning of storage formatting string
889 ** to see if we are saving content to a folder.
891 if (*cp == '+' || *cp == '@') {
892 char *tmpfilenam, *folder;
894 /* Store content in temporary file for now */
895 tmpfilenam = m_mktemp(invo_name, NULL, NULL);
896 ct->c_storage = getcpy(tmpfilenam);
898 /* Get the folder name */
900 folder = getcpy(expandfol(cp));
902 folder = getcurfol();
904 /* Check if folder exists */
905 create_folder(toabsdir(folder), 0, exit);
907 /* Record the folder name */
908 ct->c_folder = getcpy(folder);
917 ** Parse and expand the storage formatting string
918 ** in `cp' into `buffer'.
920 parse_format_string(ct, cp, buffer, sizeof(buffer), dir);
923 ** If formatting begins with '|' or '!', then pass
924 ** content to standard input of a command and return.
926 if (buffer[0] == '|' || buffer[0] == '!')
927 return show_content_aux(ct, 1, 0, buffer + 1, dir);
929 /* record the filename */
930 ct->c_storage = getcpy(buffer);
933 /* flush the output stream */
936 /* Now save or append the content to a file */
937 if (output_content_file(ct, appending) == NOTOK)
941 ** If necessary, link the file into a folder and remove
942 ** the temporary file. If this message is a partial,
943 ** then only do this if it is the last one in the group.
945 if (ct->c_folder && (!is_partial || last_partial)) {
946 msgnum = output_content_folder(ct->c_folder, ct->c_storage);
947 unlink(ct->c_storage);
953 ** Now print out the name/number of the message
954 ** that we are storing.
958 fprintf(stderr, "reassembling partials ");
960 fprintf(stderr, "%s", ct->c_file);
962 fprintf(stderr, "%s,", ct->c_file);
964 fprintf(stderr, "storing message %s", ct->c_file);
966 fprintf(stderr, " part %s", ct->c_partno);
970 ** Unless we are in the "middle" of group of message/partials,
971 ** we now print the name of the file, folder, and/or message
972 ** to which we are storing the content.
974 if (!is_partial || last_partial) {
976 fprintf(stderr, " to folder %s as message %d\n",
977 ct->c_folder, msgnum);
978 } else if (strcmp(ct->c_storage, "-")==0) {
979 fprintf(stderr, " to stdout\n");
983 cwdlen = strlen(cwd);
984 fprintf(stderr, " as file %s\n",
985 strncmp(ct->c_storage, cwd,
987 ct->c_storage[cwdlen] != '/' ?
989 ct->c_storage + cwdlen + 1);
998 ** Output content to a file
1002 output_content_file(CT ct, int appending)
1005 char *file, buffer[BUFSIZ];
1010 ** If the pathname is absolute, make sure
1011 ** all the relevant directories exist.
1013 if (strchr(ct->c_storage, '/') && make_intermediates(ct->c_storage)
1017 if (ct->c_encoding != CE_7BIT) {
1020 if (!ct->c_ceopenfnx) {
1021 advise(NULL, "don't know how to decode part %s of message %s", ct->c_partno, ct->c_file);
1025 file = appending || strcmp(ct->c_storage, "-")==0 ?
1026 NULL : ct->c_storage;
1027 if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
1029 if (strcmp(file, ct->c_storage)==0) {
1030 (*ct->c_ceclosefnx) (ct);
1035 ** Send to standard output
1037 if (strcmp(ct->c_storage, "-")==0) {
1040 if ((gd = dup(fileno(stdout))) == NOTOK) {
1041 advise("stdout", "unable to dup");
1043 (*ct->c_ceclosefnx) (ct);
1046 if ((fp = fdopen(gd, appending ? "a" : "w")) == NULL) {
1047 advise("stdout", "unable to fdopen (%d, \"%s\") from", gd, appending ? "a" : "w");
1055 if ((fp = fopen(ct->c_storage, appending ? "a" : "w"))
1057 advise(ct->c_storage, "unable to fopen for %s",
1059 "appending" : "writing");
1065 ** Filter the header fields of the initial enclosing
1066 ** message/partial into the file.
1068 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
1069 struct partial *pm = (struct partial *) ct->c_ctparams;
1071 if (pm->pm_partno == 1)
1072 copy_some_headers(fp, ct);
1076 switch (cc = read(fd, buffer, sizeof(buffer))) {
1078 advise(file, "error reading content from");
1085 fwrite(buffer, sizeof(*buffer), cc, fp);
1091 (*ct->c_ceclosefnx) (ct);
1093 if (cc != NOTOK && fflush(fp))
1094 advise(ct->c_storage, "error writing to");
1098 return (cc != NOTOK ? OK : NOTOK);
1101 if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
1102 advise(ct->c_file, "unable to open for reading");
1108 fseek(ct->c_fp, pos, SEEK_SET);
1110 if (strcmp(ct->c_storage, "-")==0) {
1113 if ((gd = dup(fileno(stdout))) == NOTOK) {
1114 advise("stdout", "unable to dup");
1117 if ((fp = fdopen(gd, appending ? "a" : "w")) == NULL) {
1118 advise("stdout", "unable to fdopen (%d, \"%s\") from",
1119 gd, appending ? "a" : "w");
1124 if ((fp = fopen(ct->c_storage, appending ? "a" : "w"))
1126 advise(ct->c_storage, "unable to fopen for %s",
1127 appending ? "appending" : "writing");
1133 ** Copy a few of the header fields of the initial
1134 ** enclosing message/partial into the file.
1137 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
1138 struct partial *pm = (struct partial *) ct->c_ctparams;
1140 if (pm->pm_partno == 1) {
1141 copy_some_headers(fp, ct);
1146 while (fgets(buffer, sizeof(buffer) - 1, ct->c_fp)) {
1147 if ((pos += strlen(buffer)) > last) {
1150 diff = strlen(buffer) - (pos - last);
1152 buffer[diff] = '\0';
1155 ** If this is the first content of a group of
1156 ** message/partial contents, then we only copy a few
1157 ** of the header fields of the enclosed message.
1160 switch (buffer[0]) {
1163 if (filterstate < 0)
1172 if (!uprf(buffer, XXX_FIELD_PRF) && !uprf(buffer, VRSN_FIELD) && !uprf(buffer, "Subject:") && !uprf(buffer, "Message-ID:")) {
1187 advise(ct->c_storage, "error writing to");
1197 ** Add a file to a folder.
1199 ** Return the new message number of the file
1200 ** when added to the folder. Return -1, if
1201 ** there is an error.
1205 output_content_folder(char *folder, char *filename)
1210 /* Read the folder. */
1211 if ((mp = folder_read(folder))) {
1212 /* Link file into folder */
1213 msgnum = folder_addmsg(&mp, filename, 0, 0, 0, 0, NULL);
1215 advise(NULL, "unable to read folder %s", folder);
1219 /* free folder structure */
1223 ** Return msgnum. We are relying on the fact that
1224 ** msgnum will be -1, if folder_addmsg() had an error.
1231 ** Parse and expand the storage formatting string
1232 ** pointed to by "cp" into "buffer".
1236 parse_format_string(CT ct, char *cp, char *buffer, int buflen, char *dir)
1240 CI ci = &ct->c_ctinfo;
1243 ** If storage string is "-", just copy it, and
1244 ** return (send content to standard output).
1246 if (cp[0] == '-' && cp[1] == '\0') {
1247 strncpy(buffer, cp, buflen);
1255 ** If formatting string is a pathname that doesn't
1256 ** begin with '/', then preface the path with the
1257 ** appropriate directory.
1259 if (*cp != '/' && *cp != '|' && *cp != '!') {
1260 snprintf(bp, buflen, "%s/", dir[1] ? dir : "");
1268 /* We are processing a storage escape */
1273 ** Insert parameters from Content-Type.
1274 ** This is only valid for '|' commands.
1276 if (buffer[0] != '|' && buffer[0] != '!') {
1285 for (ap=ci->ci_attrs, ep=ci->ci_values;
1287 snprintf(bp, buflen,
1299 /* insert message number */
1300 snprintf(bp, buflen, "%s",
1301 mhbasename(ct->c_file));
1305 /* insert part number with leading dot */
1307 snprintf(bp, buflen, ".%s",
1312 /* insert part number withouth leading dot */
1314 strncpy(bp, ct->c_partno, buflen);
1318 /* insert content type */
1319 strncpy(bp, ci->ci_type, buflen);
1323 /* insert content subtype */
1324 strncpy(bp, ci->ci_subtype, buflen);
1328 /* insert the character % */
1338 /* Advance bp and decrement buflen */
1356 ** Check if the content specifies a filename
1357 ** in its MIME parameters.
1361 get_storeproc(CT ct)
1363 char **ap, **ep, *cp;
1364 CI ci = &ct->c_ctinfo;
1367 ** If the storeproc has already been defined,
1368 ** we just return (for instance, if this content
1369 ** is part of a "message/external".
1371 if (ct->c_storeproc)
1375 ** Check the attribute/value pairs, for the attribute "name".
1376 ** If found, do a few sanity checks and copy the value into
1379 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
1380 if (!mh_strcasecmp(*ap, "name") && *(cp = *ep) != '/' &&
1381 *cp != '.' && *cp != '|' && *cp != '!' &&
1383 ct->c_storeproc = getcpy(cp);
1391 ** Copy some of the header fields of the initial message/partial
1392 ** message into the header of the reassembled message.
1396 copy_some_headers(FILE *out, CT ct)
1400 hp = ct->c_first_hf; /* start at first header field */
1404 ** A few of the header fields of the enclosing
1405 ** messages are not copied.
1407 if (!uprf(hp->name, XXX_FIELD_PRF) &&
1408 mh_strcasecmp(hp->name, VRSN_FIELD) &&
1409 mh_strcasecmp(hp->name, "Subject") &&
1410 mh_strcasecmp(hp->name, "Message-ID"))
1411 fprintf(out, "%s:%s", hp->name, hp->value);
1412 hp = hp->next; /* next header field */