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[] = {
35 #define FILESW 6 /* interface from show */
40 { "type content", 0 },
42 { "rcache policy", 0 },
44 { "wcache policy", 0 },
51 ** switches for debugging
60 extern char *tmp; /* directory to place temp files */
65 extern char *cache_public;
66 extern char *cache_private;
71 extern char *parts[NPARTS + 1];
72 extern char *types[NTYPES + 1];
78 #define quitser pipeser
81 CT parse_mime(char *);
86 void set_endian(void);
87 void flush_errors(void);
90 void free_content(CT);
91 extern CT *cts; /* The list of top-level contents to display */
92 void freects_done(int) NORETURN;
97 static void pipeser(int);
102 ** Cache of current directory. This must be
103 ** set before these routines are called.
108 ** The directory in which to store the contents.
113 ** Type for a compare function for qsort. This keeps
114 ** the compiler happy.
116 typedef int (*qsort_comp) (const void *, const void *);
120 int part_ok(CT, int);
121 int type_ok(CT, int);
122 int make_intermediates(char *);
123 void flush_errors(void);
126 int show_content_aux(CT, int, int, char *, char *);
131 static void store_single_message(CT);
132 static int store_switch(CT);
133 static int store_generic(CT);
134 static int store_application(CT);
135 static int store_multi(CT);
136 static int store_partial(CT);
137 static int store_external(CT);
138 static int ct_compar(CT *, CT *);
139 static int store_content(CT, CT);
140 static int output_content_file(CT, int);
141 static int output_content_folder(char *, char *);
142 static int parse_format_string(CT, char *, char *, int, char *);
143 static void get_storeproc(CT);
144 static int copy_some_headers(FILE *, CT);
145 static void store_all_messages(CT *);
149 main(int argc, char **argv)
151 int msgnum, *icachesw;
152 char *cp, *file = NULL, *folder = NULL;
153 char *maildir, buf[100], **argp;
155 struct msgs_array msgs = { 0, 0, NULL };
156 struct msgs *mp = NULL;
163 setlocale(LC_ALL, "");
165 invo_name = mhbasename(argv[0]);
167 /* read user profile/context */
170 arguments = getarguments(invo_name, argc, argv, 1);
176 while ((cp = *argp++)) {
178 switch (smatch(++cp, switches)) {
180 ambigsw(cp, switches);
183 adios(NULL, "-%s unknown", cp);
186 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
187 print_help(buf, switches, 1);
190 print_version(invo_name);
201 icachesw = &rcachesw;
204 icachesw = &wcachesw;
206 if (!(cp = *argp++) || *cp == '-')
207 adios(NULL, "missing argument to %s",
209 switch (*icachesw = smatch(cp, caches)) {
214 adios(NULL, "%s unknown", cp);
228 if (!(cp = *argp++) || *cp == '-')
229 adios(NULL, "missing argument to %s",
232 adios(NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
237 if (!(cp = *argp++) || *cp == '-')
238 adios(NULL, "missing argument to %s",
241 adios(NULL, "too many types (starting with %s), %d max", cp, NTYPES);
246 if (!(cp = *argp++) || (*cp == '-' && cp[1]))
247 adios(NULL, "missing argument to %s",
249 file = *cp == '-' ? cp : getcpy(expanddir(cp));
263 if (*cp == '+' || *cp == '@') {
265 adios(NULL, "only one folder at a time!");
267 folder = getcpy(expandfol(cp));
269 app_msgarg(&msgs, cp);
272 /* null terminate the list of acceptable parts/types */
279 ** Check if we've specified an additional profile
281 if ((cp = getenv("MHSTORE"))) {
282 if ((fp = fopen(cp, "r"))) {
283 readconfig((struct node **) 0, fp, cp, 0);
286 admonish("", "unable to read $MHSTORE profile (%s)",
292 ** Read the standard profile setup
294 if ((fp = fopen(cp = etcpath("mhn.defaults"), "r"))) {
295 readconfig((struct node **) 0, fp, cp, 0);
299 /* Check for public cache location */
300 if ((cache_public = context_find(nmhcache)) && *cache_public != '/')
303 /* Check for private cache location */
304 if (!(cache_private = context_find(nmhprivcache)))
305 cache_private = ".cache";
306 cache_private = getcpy(toabsdir(cache_private));
309 ** Cache the current directory before we do any chdirs()'s.
314 ** Check for storage directory. If specified,
315 ** then store temporary files there. Else we
316 ** store them in standard nmh directory.
318 if ((cp = context_find(nmhstorage)) && *cp)
319 tmp = concat(cp, "/", invo_name, NULL);
321 tmp = getcpy(toabsdir(invo_name));
323 if (file && msgs.size)
324 adios(NULL, "cannot specify msg and file at same time!");
327 ** check if message is coming from file
330 if (!(cts = (CT *) calloc((size_t) 2, sizeof(*cts))))
331 adios(NULL, "out of memory");
334 if ((ct = parse_mime(file)))
338 ** message(s) are coming from a folder
341 app_msgarg(&msgs, seq_cur);
343 folder = getcurfol();
344 maildir = toabsdir(folder);
346 if (chdir(maildir) == NOTOK)
347 adios(maildir, "unable to change directory to");
349 /* read folder and create message structure */
350 if (!(mp = folder_read(folder)))
351 adios(NULL, "unable to read folder %s", folder);
353 /* check for empty folder */
355 adios(NULL, "no messages in %s", folder);
357 /* parse all the message ranges/sequences and set SELECTED */
358 for (msgnum = 0; msgnum < msgs.size; msgnum++)
359 if (!m_convert(mp, msgs.msgs[msgnum]))
361 seq_setprev(mp); /* set the previous-sequence */
363 if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
365 adios(NULL, "out of memory");
368 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
369 if (is_selected(mp, msgnum)) {
372 msgnam = m_name(msgnum);
373 if ((ct = parse_mime(msgnam)))
383 SIGNAL(SIGQUIT, quitser);
384 SIGNAL(SIGPIPE, pipeser);
387 ** Get the associated umask for the relevant contents.
389 for (ctp = cts; *ctp; ctp++) {
393 if (type_ok(ct, 1) && !ct->c_umask) {
394 if (stat(ct->c_file, &st) != NOTOK)
395 ct->c_umask = ~(st.st_mode & 0777);
397 ct->c_umask = ~m_gmprot();
402 ** Store the message content
404 store_all_messages(cts);
406 /* Now free all the structures for the content */
407 for (ctp = cts; *ctp; ctp++)
413 /* If reading from a folder, do some updating */
415 context_replace(curfolder, folder); /* update current folder */
416 seq_setcur(mp, mp->hghsel); /* update current message */
417 seq_save(mp); /* synchronize sequences */
418 context_save(); /* save the context file */
432 fprintf(stderr, "\n");
442 ** Main entry point to store content from a collection of messages.
445 store_all_messages(CT *cts)
451 ** Check for the directory in which to
452 ** store any contents.
456 else if ((cp = context_find(nmhstorage)) && *cp)
461 for (ctp = cts; *ctp; ctp++) {
463 store_single_message(ct);
471 ** Entry point to store the content
472 ** in a (single) message
476 store_single_message(CT ct)
478 if (type_ok(ct, 1)) {
485 if (ct->c_ceclosefnx)
486 (*ct->c_ceclosefnx) (ct);
492 ** Switching routine to store different content types
498 switch (ct->c_type) {
500 return store_multi(ct);
504 switch (ct->c_subtype) {
505 case MESSAGE_PARTIAL:
506 return store_partial(ct);
509 case MESSAGE_EXTERNAL:
510 return store_external(ct);
514 return store_generic(ct);
520 return store_application(ct);
527 return store_generic(ct);
531 adios(NULL, "unknown content type %d", ct->c_type);
535 return OK; /* NOT REACHED */
540 ** Generic routine to store a MIME content.
541 ** (audio, video, image, text, message/rfc922)
548 ** Check if the content specifies a filename.
549 ** Don't bother with this for type "message"
550 ** (only "message/rfc822" will use store_generic).
552 if (autosw && ct->c_type != CT_MESSAGE)
555 return store_content(ct, NULL);
560 ** Store content of type "application"
564 store_application(CT ct)
567 CI ci = &ct->c_ctinfo;
569 /* Check if the content specifies a filename */
574 ** If storeproc is not defined, and the content is type
575 ** "application/octet-stream", we also check for various
576 ** attribute/value pairs which specify if this a tar file.
578 if (!ct->c_storeproc && ct->c_subtype == APPLICATION_OCTETS) {
579 int tarP = 0, zP = 0, gzP = 0;
581 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
582 /* check for "type=tar" attribute */
583 if (!mh_strcasecmp(*ap, "type")) {
584 if (mh_strcasecmp(*ep, "tar"))
591 /* check for "conversions=compress" attribute */
592 if ((!mh_strcasecmp(*ap, "conversions") ||
593 !mh_strcasecmp(*ap, "x-conversions"))
594 && (!mh_strcasecmp(*ep, "compress") ||
595 !mh_strcasecmp(*ep, "x-compress"))) {
599 /* check for "conversions=gzip" attribute */
600 if ((!mh_strcasecmp(*ap, "conversions") ||
601 !mh_strcasecmp(*ap, "x-conversions"))
602 && (!mh_strcasecmp(*ep, "gzip") ||
603 !mh_strcasecmp(*ep, "x-gzip"))) {
610 ct->c_showproc = getcpy(zP ? "%euncompress | tar tvf -" : (gzP ? "%egzip -dc | tar tvf -" : "%etar tvf -"));
611 if (!ct->c_storeproc) {
613 ct->c_storeproc = getcpy(zP ? "| uncompress | tar xvpf -" : (gzP ? "| gzip -dc | tar xvpf -" : "| tar xvpf -"));
616 ct->c_storeproc= getcpy(zP ? "%m%P.tar.Z" : (gzP ? "%m%P.tar.gz" : "%m%P.tar"));
622 return store_content(ct, NULL);
627 ** Store the content of a multipart message
634 struct multipart *m = (struct multipart *) ct->c_ctparams;
638 for (part = m->mp_parts; part; part = part->mp_next) {
639 CT p = part->mp_part;
641 if (part_ok(p, 1) && type_ok(p, 1)) {
642 result = store_switch(p);
643 if (result == OK && ct->c_subtype == MULTI_ALTERNATE)
653 ** Reassemble and store the contents of a collection
654 ** of messages of type "message/partial".
663 struct partial *pm, *qm;
665 qm = (struct partial *) ct->c_ctparams;
670 for (ctp = cts; *ctp; ctp++) {
672 if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) {
673 pm = (struct partial *) p->c_ctparams;
674 if (!pm->pm_stored &&
675 strcmp(qm->pm_partid, pm->pm_partid)
677 pm->pm_marked = pm->pm_partno;
688 advise(NULL, "missing (at least) last part of multipart message");
692 if ((base = (CT *) calloc((size_t) (i + 1), sizeof(*base))) == NULL)
693 adios(NULL, "out of memory");
696 for (ctp = cts; *ctp; ctp++) {
698 if (p->c_type == CT_MESSAGE && p->c_subtype == ct->c_subtype) {
699 pm = (struct partial *) p->c_ctparams;
707 qsort((char *) base, i, sizeof(*base), (qsort_comp) ct_compar);
710 for (ctq = base; *ctq; ctq++) {
712 pm = (struct partial *) p->c_ctparams;
713 if (pm->pm_marked != cur) {
714 if (pm->pm_marked == cur - 1) {
715 admonish(NULL, "duplicate part %d of %d part multipart message", pm->pm_marked, hi);
720 advise (NULL, "missing %spart %d of %d part multipart message", cur != hi ? "(at least) " : "", cur, hi);
731 ** Now cycle through the sorted list of messages of type
732 ** "message/partial" and save/append them to a file.
737 if (store_content(ct, NULL) == NOTOK) {
743 for (; *ctq; ctq++) {
745 if (store_content(p, ct) == NOTOK)
755 ** Store content from a message of type "message/external".
759 store_external(CT ct)
762 struct exbody *e = (struct exbody *) ct->c_ctparams;
763 CT p = e->eb_content;
769 ** Check if the parameters for the external body
770 ** specified a filename.
775 if ((cp = e->eb_name) && *cp != '/' && *cp != '.' &&
776 *cp != '|' && *cp != '!' && !strchr(cp, '%')) {
777 if (!ct->c_storeproc)
778 ct->c_storeproc = getcpy(cp);
780 p->c_storeproc = getcpy(cp);
785 ** Since we will let the Content structure for the
786 ** external body substitute for the current content,
787 ** we temporarily change its partno (number inside
788 ** multipart), so everything looks right.
790 p->c_partno = ct->c_partno;
792 /* we probably need to check if content is really there */
793 result = store_switch(p);
801 ** Compare the numbering from two different
802 ** message/partials (needed for sorting).
806 ct_compar(CT *a, CT *b)
808 struct partial *am = (struct partial *) ((*a)->c_ctparams);
809 struct partial *bm = (struct partial *) ((*b)->c_ctparams);
811 return (am->pm_marked - bm->pm_marked);
816 ** Store contents of a message or message part to
817 ** a folder, a file, the standard output, or pass
818 ** the contents to a command.
820 ** If the current content to be saved is a followup part
821 ** to a collection of messages of type "message/partial",
822 ** then field "p" is a pointer to the Content structure
823 ** to the first message/partial in the group.
827 store_content(CT ct, CT p)
829 int appending = 0, msgnum = 0;
830 int is_partial = 0, first_partial = 0;
831 int last_partial = 0;
832 char *cp, buffer[BUFSIZ];
835 ** Do special processing for messages of
836 ** type "message/partial".
838 ** We first check if this content is of type
839 ** "message/partial". If it is, then we need to check
840 ** whether it is the first and/or last in the group.
842 ** Then if "p" is a valid pointer, it points to the Content
843 ** structure of the first partial in the group. So we copy
844 ** the file name and/or folder name from that message. In
845 ** this case, we also note that we will be appending.
847 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
848 struct partial *pm = (struct partial *) ct->c_ctparams;
850 /* Yep, it's a message/partial */
853 /* But is it the first and/or last in the collection? */
854 if (pm->pm_partno == 1)
856 if (pm->pm_maxno && pm->pm_partno == pm->pm_maxno)
860 ** If "p" is a valid pointer, then it points to the
861 ** Content structure for the first message in the group.
862 ** So we just copy the filename or foldername information
863 ** from the previous iteration of this function.
867 ct->c_storage = getcpy(p->c_storage);
869 /* record the folder name */
871 ct->c_folder = getcpy(p->c_folder);
878 ** Get storage formatting string.
880 ** 1) If we have storeproc defined, then use that
881 ** 2) Else check for a mhstore-store-<type>/<subtype> entry
882 ** 3) Else check for a mhstore-store-<type> entry
883 ** 4) Else if content is "message", use "+" (current folder)
884 ** 5) Else use string "%m%P.%s".
886 if ((cp = ct->c_storeproc) == NULL || *cp == '\0') {
887 CI ci = &ct->c_ctinfo;
889 snprintf(buffer, sizeof(buffer), "%s-store-%s/%s",
890 invo_name, ci->ci_type, ci->ci_subtype);
891 if ((cp = context_find(buffer)) == NULL || *cp == '\0') {
892 snprintf(buffer, sizeof(buffer), "%s-store-%s",
893 invo_name, ci->ci_type);
894 if ((cp = context_find(buffer)) == NULL ||
896 cp = ct->c_type == CT_MESSAGE ?
903 ** Check the beginning of storage formatting string
904 ** to see if we are saving content to a folder.
906 if (*cp == '+' || *cp == '@') {
907 char *tmpfilenam, *folder;
909 /* Store content in temporary file for now */
910 tmpfilenam = m_mktemp(invo_name, NULL, NULL);
911 ct->c_storage = getcpy(tmpfilenam);
913 /* Get the folder name */
915 folder = getcpy(expandfol(cp));
917 folder = getcurfol();
919 /* Check if folder exists */
920 create_folder(toabsdir(folder), 0, exit);
922 /* Record the folder name */
923 ct->c_folder = getcpy(folder);
932 ** Parse and expand the storage formatting string
933 ** in `cp' into `buffer'.
935 parse_format_string(ct, cp, buffer, sizeof(buffer), dir);
938 ** If formatting begins with '|' or '!', then pass
939 ** content to standard input of a command and return.
941 if (buffer[0] == '|' || buffer[0] == '!')
942 return show_content_aux(ct, 1, 0, buffer + 1, dir);
944 /* record the filename */
945 ct->c_storage = getcpy(buffer);
948 /* flush the output stream */
951 /* Now save or append the content to a file */
952 if (output_content_file(ct, appending) == NOTOK)
956 ** If necessary, link the file into a folder and remove
957 ** the temporary file. If this message is a partial,
958 ** then only do this if it is the last one in the group.
960 if (ct->c_folder && (!is_partial || last_partial)) {
961 msgnum = output_content_folder(ct->c_folder, ct->c_storage);
962 unlink(ct->c_storage);
968 ** Now print out the name/number of the message
969 ** that we are storing.
973 fprintf(stderr, "reassembling partials ");
975 fprintf(stderr, "%s", ct->c_file);
977 fprintf(stderr, "%s,", ct->c_file);
979 fprintf(stderr, "storing message %s", ct->c_file);
981 fprintf(stderr, " part %s", ct->c_partno);
985 ** Unless we are in the "middle" of group of message/partials,
986 ** we now print the name of the file, folder, and/or message
987 ** to which we are storing the content.
989 if (!is_partial || last_partial) {
991 fprintf(stderr, " to folder %s as message %d\n",
992 ct->c_folder, msgnum);
993 } else if (strcmp(ct->c_storage, "-")==0) {
994 fprintf(stderr, " to stdout\n");
998 cwdlen = strlen(cwd);
999 fprintf(stderr, " as file %s\n",
1000 strncmp(ct->c_storage, cwd,
1002 ct->c_storage[cwdlen] != '/' ?
1004 ct->c_storage + cwdlen + 1);
1013 ** Output content to a file
1017 output_content_file(CT ct, int appending)
1020 char *file, buffer[BUFSIZ];
1025 ** If the pathname is absolute, make sure
1026 ** all the relevant directories exist.
1028 if (strchr(ct->c_storage, '/') && make_intermediates(ct->c_storage)
1032 if (ct->c_encoding != CE_7BIT) {
1035 if (!ct->c_ceopenfnx) {
1036 advise(NULL, "don't know how to decode part %s of message %s", ct->c_partno, ct->c_file);
1040 file = appending || strcmp(ct->c_storage, "-")==0 ?
1041 NULL : ct->c_storage;
1042 if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
1044 if (strcmp(file, ct->c_storage)==0) {
1045 (*ct->c_ceclosefnx) (ct);
1050 ** Send to standard output
1052 if (strcmp(ct->c_storage, "-")==0) {
1055 if ((gd = dup(fileno(stdout))) == NOTOK) {
1056 advise("stdout", "unable to dup");
1058 (*ct->c_ceclosefnx) (ct);
1061 if ((fp = fdopen(gd, appending ? "a" : "w")) == NULL) {
1062 advise("stdout", "unable to fdopen (%d, \"%s\") from", gd, appending ? "a" : "w");
1070 if ((fp = fopen(ct->c_storage, appending ? "a" : "w"))
1072 advise(ct->c_storage, "unable to fopen for %s",
1074 "appending" : "writing");
1080 ** Filter the header fields of the initial enclosing
1081 ** message/partial into the file.
1083 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
1084 struct partial *pm = (struct partial *) ct->c_ctparams;
1086 if (pm->pm_partno == 1)
1087 copy_some_headers(fp, ct);
1091 switch (cc = read(fd, buffer, sizeof(buffer))) {
1093 advise(file, "error reading content from");
1100 fwrite(buffer, sizeof(*buffer), cc, fp);
1106 (*ct->c_ceclosefnx) (ct);
1108 if (cc != NOTOK && fflush(fp))
1109 advise(ct->c_storage, "error writing to");
1113 return (cc != NOTOK ? OK : NOTOK);
1116 if (!ct->c_fp && (ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
1117 advise(ct->c_file, "unable to open for reading");
1123 fseek(ct->c_fp, pos, SEEK_SET);
1125 if (strcmp(ct->c_storage, "-")==0) {
1128 if ((gd = dup(fileno(stdout))) == NOTOK) {
1129 advise("stdout", "unable to dup");
1132 if ((fp = fdopen(gd, appending ? "a" : "w")) == NULL) {
1133 advise("stdout", "unable to fdopen (%d, \"%s\") from",
1134 gd, appending ? "a" : "w");
1139 if ((fp = fopen(ct->c_storage, appending ? "a" : "w"))
1141 advise(ct->c_storage, "unable to fopen for %s",
1142 appending ? "appending" : "writing");
1148 ** Copy a few of the header fields of the initial
1149 ** enclosing message/partial into the file.
1152 if (ct->c_type == CT_MESSAGE && ct->c_subtype == MESSAGE_PARTIAL) {
1153 struct partial *pm = (struct partial *) ct->c_ctparams;
1155 if (pm->pm_partno == 1) {
1156 copy_some_headers(fp, ct);
1161 while (fgets(buffer, sizeof(buffer) - 1, ct->c_fp)) {
1162 if ((pos += strlen(buffer)) > last) {
1165 diff = strlen(buffer) - (pos - last);
1167 buffer[diff] = '\0';
1170 ** If this is the first content of a group of
1171 ** message/partial contents, then we only copy a few
1172 ** of the header fields of the enclosed message.
1175 switch (buffer[0]) {
1178 if (filterstate < 0)
1187 if (!uprf(buffer, XXX_FIELD_PRF) && !uprf(buffer, VRSN_FIELD) && !uprf(buffer, "Subject:") && !uprf(buffer, "Message-ID:")) {
1202 advise(ct->c_storage, "error writing to");
1212 ** Add a file to a folder.
1214 ** Return the new message number of the file
1215 ** when added to the folder. Return -1, if
1216 ** there is an error.
1220 output_content_folder(char *folder, char *filename)
1225 /* Read the folder. */
1226 if ((mp = folder_read(folder))) {
1227 /* Link file into folder */
1228 msgnum = folder_addmsg(&mp, filename, 0, 0, 0, 0, NULL);
1230 advise(NULL, "unable to read folder %s", folder);
1234 /* free folder structure */
1238 ** Return msgnum. We are relying on the fact that
1239 ** msgnum will be -1, if folder_addmsg() had an error.
1246 ** Parse and expand the storage formatting string
1247 ** pointed to by "cp" into "buffer".
1251 parse_format_string(CT ct, char *cp, char *buffer, int buflen, char *dir)
1255 CI ci = &ct->c_ctinfo;
1258 ** If storage string is "-", just copy it, and
1259 ** return (send content to standard output).
1261 if (cp[0] == '-' && cp[1] == '\0') {
1262 strncpy(buffer, cp, buflen);
1270 ** If formatting string is a pathname that doesn't
1271 ** begin with '/', then preface the path with the
1272 ** appropriate directory.
1274 if (*cp != '/' && *cp != '|' && *cp != '!') {
1275 snprintf(bp, buflen, "%s/", dir[1] ? dir : "");
1283 /* We are processing a storage escape */
1288 ** Insert parameters from Content-Type.
1289 ** This is only valid for '|' commands.
1291 if (buffer[0] != '|' && buffer[0] != '!') {
1300 for (ap=ci->ci_attrs, ep=ci->ci_values;
1302 snprintf(bp, buflen,
1314 /* insert message number */
1315 snprintf(bp, buflen, "%s",
1316 mhbasename(ct->c_file));
1320 /* insert part number with leading dot */
1322 snprintf(bp, buflen, ".%s",
1327 /* insert part number withouth leading dot */
1329 strncpy(bp, ct->c_partno, buflen);
1333 /* insert content type */
1334 strncpy(bp, ci->ci_type, buflen);
1338 /* insert content subtype */
1339 strncpy(bp, ci->ci_subtype, buflen);
1343 /* insert the character % */
1353 /* Advance bp and decrement buflen */
1371 ** Check if the content specifies a filename
1372 ** in its MIME parameters.
1376 get_storeproc(CT ct)
1378 char **ap, **ep, *cp;
1379 CI ci = &ct->c_ctinfo;
1382 ** If the storeproc has already been defined,
1383 ** we just return (for instance, if this content
1384 ** is part of a "message/external".
1386 if (ct->c_storeproc)
1390 ** Check the attribute/value pairs, for the attribute "name".
1391 ** If found, do a few sanity checks and copy the value into
1394 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
1395 if (!mh_strcasecmp(*ap, "name") && *(cp = *ep) != '/' &&
1396 *cp != '.' && *cp != '|' && *cp != '!' &&
1398 ct->c_storeproc = getcpy(cp);
1406 ** Copy some of the header fields of the initial message/partial
1407 ** message into the header of the reassembled message.
1411 copy_some_headers(FILE *out, CT ct)
1415 hp = ct->c_first_hf; /* start at first header field */
1419 ** A few of the header fields of the enclosing
1420 ** messages are not copied.
1422 if (!uprf(hp->name, XXX_FIELD_PRF) &&
1423 mh_strcasecmp(hp->name, VRSN_FIELD) &&
1424 mh_strcasecmp(hp->name, "Subject") &&
1425 mh_strcasecmp(hp->name, "Message-ID"))
1426 fprintf(out, "%s:%s", hp->name, hp->value);
1427 hp = hp->next; /* next header field */