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>
17 #include <h/mhparse.h>
18 #include <h/mhcachesbr.h>
21 static struct swit switches[] = {
26 #define FILESW 2 /* interface from show */
31 { "type content", 0 },
33 { "rcache policy", 0 },
35 { "wcache policy", 0 },
47 extern char *tmp; /* directory to place temp files */
52 extern char *cache_public;
53 extern char *cache_private;
58 extern char *parts[NPARTS + 1];
59 extern char *types[NTYPES + 1];
64 #define quitser pipeser
67 CT parse_mime(char *);
72 void set_endian(void);
73 void flush_errors(void);
76 void free_content(CT);
77 extern CT *cts; /* The list of top-level contents to display */
78 void freects_done(int) NORETURN;
83 static void pipeser(int);
88 ** Cache of current directory. This must be
89 ** set before these routines are called.
94 ** The directory in which to store the contents.
99 ** Type for a compare function for qsort. This keeps
100 ** the compiler happy.
102 typedef int (*qsort_comp) (const void *, const void *);
106 int part_ok(CT, int);
107 int type_ok(CT, int);
108 int make_intermediates(char *);
109 void flush_errors(void);
112 int show_content_aux(CT, int, char *, char *);
117 static void store_single_message(CT);
118 static int store_switch(CT);
119 static int store_generic(CT);
120 static int store_application(CT);
121 static int store_multi(CT);
122 static int store_partial(CT);
123 static int store_external(CT);
124 static int ct_compar(CT *, CT *);
125 static int store_content(CT, CT);
126 static int output_content_file(CT, int);
127 static int output_content_folder(char *, char *);
128 static int parse_format_string(CT, char *, char *, int, char *);
129 static void get_storeproc(CT);
130 static int copy_some_headers(FILE *, CT);
131 static void store_all_messages(CT *);
135 main(int argc, char **argv)
137 int msgnum, *icachesw;
138 char *cp, *file = NULL, *folder = NULL;
139 char *maildir, buf[100], **argp;
141 struct msgs_array msgs = { 0, 0, NULL };
142 struct msgs *mp = NULL;
149 setlocale(LC_ALL, "");
151 invo_name = mhbasename(argv[0]);
153 /* read user profile/context */
156 arguments = getarguments(invo_name, argc, argv, 1);
162 while ((cp = *argp++)) {
164 switch (smatch(++cp, switches)) {
166 ambigsw(cp, switches);
169 adios(NULL, "-%s unknown", cp);
172 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
173 print_help(buf, switches, 1);
176 print_version(invo_name);
187 icachesw = &rcachesw;
190 icachesw = &wcachesw;
192 if (!(cp = *argp++) || *cp == '-')
193 adios(NULL, "missing argument to %s",
195 switch (*icachesw = smatch(cp, caches)) {
200 adios(NULL, "%s unknown", cp);
207 if (!(cp = *argp++) || *cp == '-')
208 adios(NULL, "missing argument to %s",
211 adios(NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
216 if (!(cp = *argp++) || *cp == '-')
217 adios(NULL, "missing argument to %s",
220 adios(NULL, "too many types (starting with %s), %d max", cp, NTYPES);
225 if (!(cp = *argp++) || (*cp == '-' && cp[1]))
226 adios(NULL, "missing argument to %s",
228 file = *cp == '-' ? cp : getcpy(expanddir(cp));
236 if (*cp == '+' || *cp == '@') {
238 adios(NULL, "only one folder at a time!");
240 folder = getcpy(expandfol(cp));
242 app_msgarg(&msgs, cp);
245 /* null terminate the list of acceptable parts/types */
252 ** Check if we've specified an additional profile
254 if ((cp = getenv("MHSTORE"))) {
255 if ((fp = fopen(cp, "r"))) {
256 readconfig((struct node **) 0, fp, cp, 0);
259 admonish("", "unable to read $MHSTORE profile (%s)",
265 ** Read the standard profile setup
267 if ((fp = fopen(cp = etcpath("mhn.defaults"), "r"))) {
268 readconfig((struct node **) 0, fp, cp, 0);
272 /* Check for public cache location */
273 if ((cache_public = context_find(nmhcache)) && *cache_public != '/')
276 /* Check for private cache location */
277 if (!(cache_private = context_find(nmhprivcache)))
278 cache_private = ".cache";
279 cache_private = getcpy(toabsdir(cache_private));
282 ** Cache the current directory before we do any chdirs()'s.
287 ** Check for storage directory. If specified,
288 ** then store temporary files there. Else we
289 ** store them in standard nmh directory.
291 if ((cp = context_find(nmhstorage)) && *cp)
292 tmp = concat(cp, "/", invo_name, NULL);
294 tmp = getcpy(toabsdir(invo_name));
296 if (file && msgs.size)
297 adios(NULL, "cannot specify msg and file at same time!");
300 ** check if message is coming from file
303 if (!(cts = (CT *) calloc((size_t) 2, sizeof(*cts))))
304 adios(NULL, "out of memory");
307 if ((ct = parse_mime(file)))
311 ** message(s) are coming from a folder
314 app_msgarg(&msgs, seq_cur);
316 folder = getcurfol();
317 maildir = toabsdir(folder);
319 if (chdir(maildir) == NOTOK)
320 adios(maildir, "unable to change directory to");
322 /* read folder and create message structure */
323 if (!(mp = folder_read(folder)))
324 adios(NULL, "unable to read folder %s", folder);
326 /* check for empty folder */
328 adios(NULL, "no messages in %s", folder);
330 /* parse all the message ranges/sequences and set SELECTED */
331 for (msgnum = 0; msgnum < msgs.size; msgnum++)
332 if (!m_convert(mp, msgs.msgs[msgnum]))
334 seq_setprev(mp); /* set the previous-sequence */
336 if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
338 adios(NULL, "out of memory");
341 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
342 if (is_selected(mp, msgnum)) {
345 msgnam = m_name(msgnum);
346 if ((ct = parse_mime(msgnam)))
356 SIGNAL(SIGQUIT, quitser);
357 SIGNAL(SIGPIPE, pipeser);
360 ** Get the associated umask for the relevant contents.
362 for (ctp = cts; *ctp; ctp++) {
366 if (type_ok(ct, 1) && !ct->c_umask) {
367 if (stat(ct->c_file, &st) != NOTOK)
368 ct->c_umask = ~(st.st_mode & 0777);
370 ct->c_umask = ~m_gmprot();
375 ** Store the message content
377 store_all_messages(cts);
379 /* Now free all the structures for the content */
380 for (ctp = cts; *ctp; ctp++)
386 /* If reading from a folder, do some updating */
388 context_replace(curfolder, folder); /* update current folder */
389 seq_setcur(mp, mp->hghsel); /* update current message */
390 seq_save(mp); /* synchronize sequences */
391 context_save(); /* save the context file */
405 fprintf(stderr, "\n");
415 ** Main entry point to store content from a collection of messages.
418 store_all_messages(CT *cts)
424 ** Check for the directory in which to
425 ** store any contents.
429 if ((cp = context_find(nmhstorage)) && *cp)
434 for (ctp = cts; *ctp; ctp++) {
436 store_single_message(ct);
444 ** Entry point to store the content
445 ** in a (single) message
449 store_single_message(CT ct)
451 if (type_ok(ct, 1)) {
458 if (ct->c_ceclosefnx)
459 (*ct->c_ceclosefnx) (ct);
465 ** Switching routine to store different content types
471 switch (ct->c_type) {
473 return store_multi(ct);
477 switch (ct->c_subtype) {
478 case MESSAGE_PARTIAL:
479 return store_partial(ct);
482 case MESSAGE_EXTERNAL:
483 return store_external(ct);
487 return store_generic(ct);
493 return store_application(ct);
500 return store_generic(ct);
504 adios(NULL, "unknown content type %d", ct->c_type);
508 return OK; /* NOT REACHED */
513 ** Generic routine to store a MIME content.
514 ** (audio, video, image, text, message/rfc922)
521 ** Check if the content specifies a filename.
522 ** Don't bother with this for type "message"
523 ** (only "message/rfc822" will use store_generic).
525 if (autosw && ct->c_type != CT_MESSAGE)
528 return store_content(ct, NULL);
533 ** Store content of type "application"
537 store_application(CT ct)
540 CI ci = &ct->c_ctinfo;
542 /* Check if the content specifies a filename */
547 ** If storeproc is not defined, and the content is type
548 ** "application/octet-stream", we also check for various
549 ** attribute/value pairs which specify if this a tar file.
551 if (!ct->c_storeproc && ct->c_subtype == APPLICATION_OCTETS) {
552 int tarP = 0, zP = 0, gzP = 0;
554 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
555 /* check for "type=tar" attribute */
556 if (!mh_strcasecmp(*ap, "type")) {
557 if (mh_strcasecmp(*ep, "tar"))
564 /* check for "conversions=compress" attribute */
565 if ((!mh_strcasecmp(*ap, "conversions") ||
566 !mh_strcasecmp(*ap, "x-conversions"))
567 && (!mh_strcasecmp(*ep, "compress") ||
568 !mh_strcasecmp(*ep, "x-compress"))) {
572 /* check for "conversions=gzip" attribute */
573 if ((!mh_strcasecmp(*ap, "conversions") ||
574 !mh_strcasecmp(*ap, "x-conversions"))
575 && (!mh_strcasecmp(*ep, "gzip") ||
576 !mh_strcasecmp(*ep, "x-gzip"))) {
583 ct->c_showproc = getcpy(zP ? "%euncompress | tar tvf -" : (gzP ? "%egzip -dc | tar tvf -" : "%etar tvf -"));
584 if (!ct->c_storeproc) {
586 ct->c_storeproc = getcpy(zP ? "| uncompress | tar xvpf -" : (gzP ? "| gzip -dc | tar xvpf -" : "| tar xvpf -"));
589 ct->c_storeproc= getcpy(zP ? "%m%P.tar.Z" : (gzP ? "%m%P.tar.gz" : "%m%P.tar"));
595 return store_content(ct, NULL);
600 ** Store the content of a multipart message
607 struct multipart *m = (struct multipart *) ct->c_ctparams;
611 for (part = m->mp_parts; part; part = part->mp_next) {
612 CT p = part->mp_part;
614 if (part_ok(p, 1) && type_ok(p, 1)) {
615 result = store_switch(p);
616 if (result == OK && ct->c_subtype == MULTI_ALTERNATE)
626 ** Reassemble and store the contents of a collection
627 ** of messages of type "message/partial".
636 struct partial *pm, *qm;
638 qm = (struct partial *) ct->c_ctparams;
643 for (ctp = cts; *ctp; ctp++) {
645 if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) {
646 pm = (struct partial *) p->c_ctparams;
647 if (!pm->pm_stored &&
648 strcmp(qm->pm_partid, pm->pm_partid)
650 pm->pm_marked = pm->pm_partno;
661 advise(NULL, "missing (at least) last part of multipart message");
665 if ((base = (CT *) calloc((size_t) (i + 1), sizeof(*base))) == NULL)
666 adios(NULL, "out of memory");
669 for (ctp = cts; *ctp; ctp++) {
671 if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) {
672 pm = (struct partial *) p->c_ctparams;
680 qsort((char *) base, i, sizeof(*base), (qsort_comp) ct_compar);
683 for (ctq = base; *ctq; ctq++) {
685 pm = (struct partial *) p->c_ctparams;
686 if (pm->pm_marked != cur) {
687 if (pm->pm_marked == cur - 1) {
688 admonish(NULL, "duplicate part %d of %d part multipart message", pm->pm_marked, hi);
693 advise (NULL, "missing %spart %d of %d part multipart message", cur != hi ? "(at least) " : "", cur, hi);
704 ** Now cycle through the sorted list of messages of type
705 ** "message/partial" and save/append them to a file.
710 if (store_content(ct, NULL) == NOTOK) {
716 for (; *ctq; ctq++) {
718 if (store_content(p, ct) == NOTOK)
728 ** Store content from a message of type "message/external".
732 store_external(CT ct)
735 struct exbody *e = (struct exbody *) ct->c_ctparams;
736 CT p = e->eb_content;
742 ** Check if the parameters for the external body
743 ** specified a filename.
748 if ((cp = e->eb_name) && *cp != '/' && *cp != '.' &&
749 *cp != '|' && *cp != '!' && !strchr(cp, '%')) {
750 if (!ct->c_storeproc)
751 ct->c_storeproc = getcpy(cp);
753 p->c_storeproc = getcpy(cp);
758 ** Since we will let the Content structure for the
759 ** external body substitute for the current content,
760 ** we temporarily change its partno (number inside
761 ** multipart), so everything looks right.
763 p->c_partno = ct->c_partno;
765 /* we probably need to check if content is really there */
766 result = store_switch(p);
774 ** Compare the numbering from two different
775 ** message/partials (needed for sorting).
779 ct_compar(CT *a, CT *b)
781 struct partial *am = (struct partial *) ((*a)->c_ctparams);
782 struct partial *bm = (struct partial *) ((*b)->c_ctparams);
784 return (am->pm_marked - bm->pm_marked);
789 ** Store contents of a message or message part to
790 ** a folder, a file, the standard output, or pass
791 ** the contents to a command.
793 ** If the current content to be saved is a followup part
794 ** to a collection of messages of type "message/partial",
795 ** then field "p" is a pointer to the Content structure
796 ** to the first message/partial in the group.
800 store_content(CT ct, CT p)
802 int appending = 0, msgnum = 0;
803 int is_partial = 0, first_partial = 0;
804 int last_partial = 0;
805 char *cp, buffer[BUFSIZ];
808 ** Do special processing for messages of
809 ** type "message/partial".
811 ** We first check if this content is of type
812 ** "message/partial". If it is, then we need to check
813 ** whether it is the first and/or last in the group.
815 ** Then if "p" is a valid pointer, it points to the Content
816 ** structure of the first partial in the group. So we copy
817 ** the file name and/or folder name from that message. In
818 ** this case, we also note that we will be appending.
820 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
821 struct partial *pm = (struct partial *) ct->c_ctparams;
823 /* Yep, it's a message/partial */
826 /* But is it the first and/or last in the collection? */
827 if (pm->pm_partno == 1)
829 if (pm->pm_maxno && pm->pm_partno == pm->pm_maxno)
833 ** If "p" is a valid pointer, then it points to the
834 ** Content structure for the first message in the group.
835 ** So we just copy the filename or foldername information
836 ** from the previous iteration of this function.
840 ct->c_storage = getcpy(p->c_storage);
842 /* record the folder name */
844 ct->c_folder = getcpy(p->c_folder);
851 ** Get storage formatting string.
853 ** 1) If we have storeproc defined, then use that
854 ** 2) Else check for a mhstore-store-<type>/<subtype> entry
855 ** 3) Else check for a mhstore-store-<type> entry
856 ** 4) Else if content is "message", use "+" (current folder)
857 ** 5) Else use string "%m%P.%s".
859 if ((cp = ct->c_storeproc) == NULL || *cp == '\0') {
860 CI ci = &ct->c_ctinfo;
862 snprintf(buffer, sizeof(buffer), "%s-store-%s/%s",
863 invo_name, ci->ci_type, ci->ci_subtype);
864 if ((cp = context_find(buffer)) == NULL || *cp == '\0') {
865 snprintf(buffer, sizeof(buffer), "%s-store-%s",
866 invo_name, ci->ci_type);
867 if ((cp = context_find(buffer)) == NULL ||
869 cp = ct->c_type == CT_MESSAGE ?
876 ** Check the beginning of storage formatting string
877 ** to see if we are saving content to a folder.
879 if (*cp == '+' || *cp == '@') {
880 char *tmpfilenam, *folder;
882 /* Store content in temporary file for now */
883 tmpfilenam = m_mktemp(invo_name, NULL, NULL);
884 ct->c_storage = getcpy(tmpfilenam);
886 /* Get the folder name */
888 folder = getcpy(expandfol(cp));
890 folder = getcurfol();
892 /* Check if folder exists */
893 create_folder(toabsdir(folder), 0, exit);
895 /* Record the folder name */
896 ct->c_folder = getcpy(folder);
905 ** Parse and expand the storage formatting string
906 ** in `cp' into `buffer'.
908 parse_format_string(ct, cp, buffer, sizeof(buffer), dir);
911 ** If formatting begins with '|' or '!', then pass
912 ** content to standard input of a command and return.
914 if (buffer[0] == '|' || buffer[0] == '!')
915 return show_content_aux(ct, 0, buffer + 1, dir);
917 /* record the filename */
918 ct->c_storage = getcpy(buffer);
921 /* flush the output stream */
924 /* Now save or append the content to a file */
925 if (output_content_file(ct, appending) == NOTOK)
929 ** If necessary, link the file into a folder and remove
930 ** the temporary file. If this message is a partial,
931 ** then only do this if it is the last one in the group.
933 if (ct->c_folder && (!is_partial || last_partial)) {
934 msgnum = output_content_folder(ct->c_folder, ct->c_storage);
935 unlink(ct->c_storage);
941 ** Now print out the name/number of the message
942 ** that we are storing.
946 fprintf(stderr, "reassembling partials ");
948 fprintf(stderr, "%s", ct->c_file);
950 fprintf(stderr, "%s,", ct->c_file);
952 fprintf(stderr, "storing message %s", ct->c_file);
954 fprintf(stderr, " part %s", ct->c_partno);
958 ** Unless we are in the "middle" of group of message/partials,
959 ** we now print the name of the file, folder, and/or message
960 ** to which we are storing the content.
962 if (!is_partial || last_partial) {
964 fprintf(stderr, " to folder %s as message %d\n",
965 ct->c_folder, msgnum);
966 } else if (strcmp(ct->c_storage, "-")==0) {
967 fprintf(stderr, " to stdout\n");
971 cwdlen = strlen(cwd);
972 fprintf(stderr, " as file %s\n",
973 strncmp(ct->c_storage, cwd,
975 ct->c_storage[cwdlen] != '/' ?
977 ct->c_storage + cwdlen + 1);
986 ** Output content to a file
990 output_content_file(CT ct, int appending)
993 char *file, buffer[BUFSIZ];
998 ** If the pathname is absolute, make sure
999 ** all the relevant directories exist.
1001 if (strchr(ct->c_storage, '/') && make_intermediates(ct->c_storage)
1005 if (ct->c_encoding != CE_7BIT) {
1008 if (!ct->c_ceopenfnx) {
1009 advise(NULL, "don't know how to decode part %s of message %s", ct->c_partno, ct->c_file);
1013 file = appending || strcmp(ct->c_storage, "-")==0 ?
1014 NULL : ct->c_storage;
1015 if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
1017 if (strcmp(file, ct->c_storage)==0) {
1018 (*ct->c_ceclosefnx) (ct);
1023 ** Send to standard output
1025 if (strcmp(ct->c_storage, "-")==0) {
1028 if ((gd = dup(fileno(stdout))) == NOTOK) {
1029 advise("stdout", "unable to dup");
1031 (*ct->c_ceclosefnx) (ct);
1034 if ((fp = fdopen(gd, appending ? "a" : "w")) == NULL) {
1035 advise("stdout", "unable to fdopen (%d, \"%s\") from", gd, appending ? "a" : "w");
1043 if ((fp = fopen(ct->c_storage, appending ? "a" : "w"))
1045 advise(ct->c_storage, "unable to fopen for %s",
1047 "appending" : "writing");
1053 ** Filter the header fields of the initial enclosing
1054 ** message/partial into the file.
1056 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
1057 struct partial *pm = (struct partial *) ct->c_ctparams;
1059 if (pm->pm_partno == 1)
1060 copy_some_headers(fp, ct);
1064 switch (cc = read(fd, buffer, sizeof(buffer))) {
1066 advise(file, "error reading content from");
1073 fwrite(buffer, sizeof(*buffer), cc, fp);
1079 (*ct->c_ceclosefnx) (ct);
1081 if (cc != NOTOK && fflush(fp))
1082 advise(ct->c_storage, "error writing to");
1086 return (cc != NOTOK ? OK : NOTOK);
1089 if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
1090 advise(ct->c_file, "unable to open for reading");
1096 fseek(ct->c_fp, pos, SEEK_SET);
1098 if (strcmp(ct->c_storage, "-")==0) {
1101 if ((gd = dup(fileno(stdout))) == NOTOK) {
1102 advise("stdout", "unable to dup");
1105 if ((fp = fdopen(gd, appending ? "a" : "w")) == NULL) {
1106 advise("stdout", "unable to fdopen (%d, \"%s\") from",
1107 gd, appending ? "a" : "w");
1112 if ((fp = fopen(ct->c_storage, appending ? "a" : "w"))
1114 advise(ct->c_storage, "unable to fopen for %s",
1115 appending ? "appending" : "writing");
1121 ** Copy a few of the header fields of the initial
1122 ** enclosing message/partial into the file.
1125 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
1126 struct partial *pm = (struct partial *) ct->c_ctparams;
1128 if (pm->pm_partno == 1) {
1129 copy_some_headers(fp, ct);
1134 while (fgets(buffer, sizeof(buffer) - 1, ct->c_fp)) {
1135 if ((pos += strlen(buffer)) > last) {
1138 diff = strlen(buffer) - (pos - last);
1140 buffer[diff] = '\0';
1143 ** If this is the first content of a group of
1144 ** message/partial contents, then we only copy a few
1145 ** of the header fields of the enclosed message.
1148 switch (buffer[0]) {
1151 if (filterstate < 0)
1160 if (!uprf(buffer, XXX_FIELD_PRF) && !uprf(buffer, VRSN_FIELD) && !uprf(buffer, "Subject:") && !uprf(buffer, "Message-ID:")) {
1175 advise(ct->c_storage, "error writing to");
1185 ** Add a file to a folder.
1187 ** Return the new message number of the file
1188 ** when added to the folder. Return -1, if
1189 ** there is an error.
1193 output_content_folder(char *folder, char *filename)
1198 /* Read the folder. */
1199 if ((mp = folder_read(folder))) {
1200 /* Link file into folder */
1201 msgnum = folder_addmsg(&mp, filename, 0, 0, 0, 0, NULL);
1203 advise(NULL, "unable to read folder %s", folder);
1207 /* free folder structure */
1211 ** Return msgnum. We are relying on the fact that
1212 ** msgnum will be -1, if folder_addmsg() had an error.
1219 ** Parse and expand the storage formatting string
1220 ** pointed to by "cp" into "buffer".
1224 parse_format_string(CT ct, char *cp, char *buffer, int buflen, char *dir)
1228 CI ci = &ct->c_ctinfo;
1231 ** If storage string is "-", just copy it, and
1232 ** return (send content to standard output).
1234 if (cp[0] == '-' && cp[1] == '\0') {
1235 strncpy(buffer, cp, buflen);
1243 ** If formatting string is a pathname that doesn't
1244 ** begin with '/', then preface the path with the
1245 ** appropriate directory.
1247 if (*cp != '/' && *cp != '|' && *cp != '!') {
1248 snprintf(bp, buflen, "%s/", dir[1] ? dir : "");
1256 /* We are processing a storage escape */
1261 ** Insert parameters from Content-Type.
1262 ** This is only valid for '|' commands.
1264 if (buffer[0] != '|' && buffer[0] != '!') {
1273 for (ap=ci->ci_attrs, ep=ci->ci_values;
1275 snprintf(bp, buflen,
1287 /* insert message number */
1288 snprintf(bp, buflen, "%s",
1289 mhbasename(ct->c_file));
1293 /* insert part number with leading dot */
1295 snprintf(bp, buflen, ".%s",
1300 /* insert part number withouth leading dot */
1302 strncpy(bp, ct->c_partno, buflen);
1306 /* insert content type */
1307 strncpy(bp, ci->ci_type, buflen);
1311 /* insert content subtype */
1312 strncpy(bp, ci->ci_subtype, buflen);
1316 /* insert the character % */
1326 /* Advance bp and decrement buflen */
1344 ** Check if the content specifies a filename
1345 ** in its MIME parameters.
1349 get_storeproc(CT ct)
1351 char **ap, **ep, *cp;
1352 CI ci = &ct->c_ctinfo;
1355 ** If the storeproc has already been defined,
1356 ** we just return (for instance, if this content
1357 ** is part of a "message/external".
1359 if (ct->c_storeproc)
1363 ** Check the attribute/value pairs, for the attribute "name".
1364 ** If found, do a few sanity checks and copy the value into
1367 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
1368 if (!mh_strcasecmp(*ap, "name") && *(cp = *ep) != '/' &&
1369 *cp != '.' && *cp != '|' && *cp != '!' &&
1371 ct->c_storeproc = getcpy(cp);
1379 ** Copy some of the header fields of the initial message/partial
1380 ** message into the header of the reassembled message.
1384 copy_some_headers(FILE *out, CT ct)
1388 hp = ct->c_first_hf; /* start at first header field */
1392 ** A few of the header fields of the enclosing
1393 ** messages are not copied.
1395 if (!uprf(hp->name, XXX_FIELD_PRF) &&
1396 mh_strcasecmp(hp->name, VRSN_FIELD) &&
1397 mh_strcasecmp(hp->name, "Subject") &&
1398 mh_strcasecmp(hp->name, "Message-ID"))
1399 fprintf(out, "%s:%s", hp->name, hp->value);
1400 hp = hp->next; /* next header field */