]> diplodocus.org Git - nmh/blob - uip/mhshowsbr.c
updating changelog, should have been done with last commit
[nmh] / uip / mhshowsbr.c
1
2 /*
3 * mhshowsbr.c -- routines to display the contents of MIME messages
4 *
5 * $Id$
6 */
7
8 #include <h/mh.h>
9 #include <fcntl.h>
10 #include <h/signals.h>
11 #include <h/md5.h>
12 #include <errno.h>
13 #include <setjmp.h>
14 #include <signal.h>
15 #include <zotnet/mts/mts.h>
16 #include <zotnet/tws/tws.h>
17 #include <h/mime.h>
18 #include <h/mhparse.h>
19
20 #ifdef HAVE_SYS_WAIT_H
21 # include <sys/wait.h>
22 #endif
23
24 /*
25 * Just use sigjmp/longjmp on older machines that
26 * don't have sigsetjmp/siglongjmp.
27 */
28 #ifndef HAVE_SIGSETJMP
29 # define sigjmp_buf jmp_buf
30 # define sigsetjmp(env,mask) setjmp(env)
31 # define siglongjmp(env,val) longjmp(env,val)
32 #endif
33
34 extern int errno;
35 extern int debugsw;
36
37 int pausesw = 1;
38 int serialsw = 0;
39 int nolist = 0;
40
41 char *progsw = NULL;
42
43 /* flags for moreproc/header display */
44 int nomore = 0;
45 char *formsw = NULL;
46
47 pid_t xpid = 0;
48
49 static sigjmp_buf intrenv;
50
51
52 /* termsbr.c */
53 int SOprintf (char *, ...);
54
55 /* mhparse.c */
56 int pidcheck (int);
57
58 /* mhmisc.c */
59 int part_ok (CT, int);
60 int type_ok (CT, int);
61 void content_error (char *, CT, char *, ...);
62 void flush_errors (void);
63
64 /* mhlistsbr.c */
65 int list_switch (CT, int, int, int, int);
66 int list_content (CT, int, int, int, int);
67
68 /*
69 * prototypes
70 */
71 void show_all_messages (CT *);
72 int show_content_aux (CT, int, int, char *, char *);
73
74 /*
75 * static prototypes
76 */
77 static void show_single_message (CT, char *);
78 static void DisplayMsgHeader (CT, char *);
79 static int show_switch (CT, int, int);
80 static int show_content (CT, int, int);
81 static int show_content_aux2 (CT, int, int, char *, char *, int, int, int, int, int);
82 static int show_text (CT, int, int);
83 static int show_multi (CT, int, int);
84 static int show_multi_internal (CT, int, int);
85 static int show_multi_aux (CT, int, int, char *);
86 static int show_message_rfc822 (CT, int, int);
87 static int show_partial (CT, int, int);
88 static int show_external (CT, int, int);
89 static RETSIGTYPE intrser (int);
90
91
92 /*
93 * Top level entry point to show/display a group of messages
94 */
95
96 void
97 show_all_messages (CT *cts)
98 {
99 CT ct, *ctp;
100
101 /*
102 * If form is not specified, then get default form
103 * for showing headers of MIME messages.
104 */
105 if (!formsw)
106 formsw = getcpy (etcpath ("mhl.headers"));
107
108 /*
109 * If form is "mhl.null", suppress display of header.
110 */
111 if (!strcmp (formsw, "mhl.null"))
112 formsw = NULL;
113
114 for (ctp = cts; *ctp; ctp++) {
115 ct = *ctp;
116
117 /* if top-level type is ok, then display message */
118 if (type_ok (ct, 0))
119 show_single_message (ct, formsw);
120 }
121 }
122
123
124 /*
125 * Entry point to show/display a single message
126 */
127
128 static void
129 show_single_message (CT ct, char *form)
130 {
131 sigset_t set, oset;
132
133 #ifdef WAITINT
134 int status;
135 #else
136 union wait status;
137 #endif
138
139 umask (ct->c_umask);
140
141 /*
142 * If you have a format file, then display
143 * the message headers.
144 */
145 if (form)
146 DisplayMsgHeader(ct, form);
147 else
148 xpid = 0;
149
150 /* Show the body of the message */
151 show_switch (ct, 1, 0);
152
153 if (ct->c_fp) {
154 fclose (ct->c_fp);
155 ct->c_fp = NULL;
156 }
157 if (ct->c_ceclosefnx)
158 (*ct->c_ceclosefnx) (ct);
159
160 /* block a few signals */
161 sigemptyset (&set);
162 sigaddset (&set, SIGHUP);
163 sigaddset (&set, SIGINT);
164 sigaddset (&set, SIGQUIT);
165 sigaddset (&set, SIGTERM);
166 SIGPROCMASK (SIG_BLOCK, &set, &oset);
167
168 while (wait (&status) != NOTOK) {
169 #ifdef WAITINT
170 pidcheck (status);
171 #else
172 pidcheck (status.w_status);
173 #endif
174 continue;
175 }
176
177 /* reset the signal mask */
178 SIGPROCMASK (SIG_SETMASK, &oset, &set);
179
180 xpid = 0;
181 flush_errors ();
182 }
183
184
185 /*
186 * Use the mhlproc to show the header fields
187 */
188
189 static void
190 DisplayMsgHeader (CT ct, char *form)
191 {
192 pid_t child_id;
193 int i, vecp;
194 char *vec[8];
195
196 vecp = 0;
197 vec[vecp++] = r1bindex (mhlproc, '/');
198 vec[vecp++] = "-form";
199 vec[vecp++] = form;
200 vec[vecp++] = "-nobody";
201 vec[vecp++] = ct->c_file;
202
203 /*
204 * If we've specified -(no)moreproc,
205 * then just pass that along.
206 */
207 if (nomore) {
208 vec[vecp++] = "-nomoreproc";
209 } else if (progsw) {
210 vec[vecp++] = "-moreproc";
211 vec[vecp++] = progsw;
212 }
213 vec[vecp] = NULL;
214
215 fflush (stdout);
216
217 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
218 sleep (5);
219
220 switch (child_id) {
221 case NOTOK:
222 adios ("fork", "unable to");
223 /* NOTREACHED */
224
225 case OK:
226 execvp (mhlproc, vec);
227 fprintf (stderr, "unable to exec ");
228 perror (mhlproc);
229 _exit (-1);
230 /* NOTREACHED */
231
232 default:
233 xpid = -child_id;
234 break;
235 }
236 }
237
238
239 /*
240 * Switching routine. Call the correct routine
241 * based on content type.
242 */
243
244 static int
245 show_switch (CT ct, int serial, int alternate)
246 {
247 switch (ct->c_type) {
248 case CT_MULTIPART:
249 return show_multi (ct, serial, alternate);
250 break;
251
252 case CT_MESSAGE:
253 switch (ct->c_subtype) {
254 case MESSAGE_PARTIAL:
255 return show_partial (ct, serial, alternate);
256 break;
257
258 case MESSAGE_EXTERNAL:
259 return show_external (ct, serial, alternate);
260 break;
261
262 case MESSAGE_RFC822:
263 default:
264 return show_message_rfc822 (ct, serial, alternate);
265 break;
266 }
267 break;
268
269 case CT_TEXT:
270 return show_text (ct, serial, alternate);
271 break;
272
273 case CT_AUDIO:
274 case CT_IMAGE:
275 case CT_VIDEO:
276 case CT_APPLICATION:
277 return show_content (ct, serial, alternate);
278 break;
279
280 default:
281 adios (NULL, "unknown content type %d", ct->c_type);
282 break;
283 }
284
285 return 0; /* NOT REACHED */
286 }
287
288
289 /*
290 * Generic method for displaying content
291 */
292
293 static int
294 show_content (CT ct, int serial, int alternate)
295 {
296 char *cp, buffer[BUFSIZ];
297 CI ci = &ct->c_ctinfo;
298
299 /* Check for mhn-show-type/subtype */
300 snprintf (buffer, sizeof(buffer), "%s-show-%s/%s",
301 invo_name, ci->ci_type, ci->ci_subtype);
302 if ((cp = context_find (buffer)) && *cp != '\0')
303 return show_content_aux (ct, serial, alternate, cp, NULL);
304
305 /* Check for mhn-show-type */
306 snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type);
307 if ((cp = context_find (buffer)) && *cp != '\0')
308 return show_content_aux (ct, serial, alternate, cp, NULL);
309
310 if ((cp = ct->c_showproc))
311 return show_content_aux (ct, serial, alternate, cp, NULL);
312
313 /* complain if we are not a part of a multipart/alternative */
314 if (!alternate)
315 content_error (NULL, ct, "don't know how to display content");
316
317 return NOTOK;
318 }
319
320
321 /*
322 * Parse the display string for displaying generic content
323 */
324
325 int
326 show_content_aux (CT ct, int serial, int alternate, char *cp, char *cracked)
327 {
328 int fd, len, buflen;
329 int xstdin, xlist, xpause, xtty;
330 char *bp, *file, buffer[BUFSIZ];
331 CI ci = &ct->c_ctinfo;
332
333 if (!ct->c_ceopenfnx) {
334 if (!alternate)
335 content_error (NULL, ct, "don't know how to decode content");
336
337 return NOTOK;
338 }
339
340 file = NULL;
341 if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
342 return NOTOK;
343 if (ct->c_showproc && !strcmp (ct->c_showproc, "true"))
344 return (alternate ? DONE : OK);
345
346 xlist = 0;
347 xpause = 0;
348 xstdin = 0;
349 xtty = 0;
350
351 if (cracked) {
352 strncpy (buffer, cp, sizeof(buffer));
353 goto got_command;
354 }
355
356 /* get buffer ready to go */
357 bp = buffer;
358 bp[0] = '\0';
359 buflen = sizeof(buffer);
360
361 /* Now parse display string */
362 for ( ; *cp; cp++) {
363 if (*cp == '%') {
364 switch (*++cp) {
365 case 'a':
366 /* insert parameters from Content-Type field */
367 {
368 char **ap, **ep;
369 char *s = "";
370
371 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
372 snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep);
373 len = strlen (bp);
374 bp += len;
375 buflen -= len;
376 s = " ";
377 }
378 }
379 break;
380
381 case 'd':
382 /* insert content description */
383 if (ct->c_descr) {
384 char *s;
385
386 s = trimcpy (ct->c_descr);
387 strncpy (bp, s, buflen);
388 free (s);
389 }
390 break;
391
392 case 'e':
393 /* exclusive execution */
394 xtty = 1;
395 break;
396
397 case 'F':
398 /* %e, %f, and stdin is terminal not content */
399 xstdin = 1;
400 xtty = 1;
401 /* and fall... */
402
403 case 'f':
404 /* insert filename containing content */
405 snprintf (bp, buflen, "%s", file);
406 break;
407
408 case 'p':
409 /* %l, and pause prior to displaying content */
410 xpause = pausesw;
411 /* and fall... */
412
413 case 'l':
414 /* display listing prior to displaying content */
415 xlist = !nolist;
416 break;
417
418 case 's':
419 /* insert subtype of content */
420 strncpy (bp, ci->ci_subtype, buflen);
421 break;
422
423 case '%':
424 /* insert character % */
425 goto raw;
426
427 default:
428 *bp++ = *--cp;
429 *bp = '\0';
430 buflen--;
431 continue;
432 }
433 len = strlen (bp);
434 bp += len;
435 buflen -= len;
436 } else {
437 raw:
438 *bp++ = *cp;
439 *bp = '\0';
440 buflen--;
441 }
442 }
443
444 /* use charset string to modify display method */
445 if (ct->c_termproc) {
446 char term[BUFSIZ];
447
448 strncpy (term, buffer, sizeof(term));
449 snprintf (buffer, sizeof(buffer), ct->c_termproc, term);
450 }
451
452 got_command:
453 return show_content_aux2 (ct, serial, alternate, cracked, buffer,
454 fd, xlist, xpause, xstdin, xtty);
455 }
456
457
458 /*
459 * Routine to actually display the content
460 */
461
462 static int
463 show_content_aux2 (CT ct, int serial, int alternate, char *cracked, char *buffer,
464 int fd, int xlist, int xpause, int xstdin, int xtty)
465 {
466 pid_t child_id;
467 int i;
468 char *vec[4], exec[BUFSIZ + sizeof "exec "];
469
470 if (debugsw || cracked) {
471 fflush (stdout);
472
473 fprintf (stderr, "%s msg %s", cracked ? "storing" : "show",
474 ct->c_file);
475 if (ct->c_partno)
476 fprintf (stderr, " part %s", ct->c_partno);
477 if (cracked)
478 fprintf (stderr, " using command (cd %s; %s)\n", cracked, buffer);
479 else
480 fprintf (stderr, " using command %s\n", buffer);
481 }
482
483 if (xpid < 0 || (xtty && xpid)) {
484 if (xpid < 0)
485 xpid = -xpid;
486 pidcheck(pidwait (xpid, NOTOK));
487 xpid = 0;
488 }
489
490 if (xlist) {
491 char prompt[BUFSIZ];
492
493 if (ct->c_type == CT_MULTIPART)
494 list_content (ct, -1, 1, 0, 0);
495 else
496 list_switch (ct, -1, 1, 0, 0);
497
498 if (xpause && SOprintf ("Press <return> to show content..."))
499 printf ("Press <return> to show content...");
500
501 if (xpause) {
502 int intr;
503 SIGNAL_HANDLER istat;
504
505 istat = SIGNAL (SIGINT, intrser);
506 if ((intr = sigsetjmp (intrenv, 1)) == OK) {
507 fflush (stdout);
508 prompt[0] = 0;
509 read (fileno (stdout), prompt, sizeof(prompt));
510 }
511 SIGNAL (SIGINT, istat);
512 if (intr != OK) {
513 (*ct->c_ceclosefnx) (ct);
514 return (alternate ? DONE : NOTOK);
515 }
516 }
517 }
518
519 snprintf (exec, sizeof(exec), "exec %s", buffer);
520
521 vec[0] = "/bin/sh";
522 vec[1] = "-c";
523 vec[2] = exec;
524 vec[3] = NULL;
525
526 fflush (stdout);
527
528 for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++)
529 sleep (5);
530 switch (child_id) {
531 case NOTOK:
532 advise ("fork", "unable to");
533 (*ct->c_ceclosefnx) (ct);
534 return NOTOK;
535
536 case OK:
537 if (cracked)
538 chdir (cracked);
539 if (!xstdin)
540 dup2 (fd, 0);
541 close (fd);
542 execvp ("/bin/sh", vec);
543 fprintf (stderr, "unable to exec ");
544 perror ("/bin/sh");
545 _exit (-1);
546 /* NOTREACHED */
547
548 default:
549 if (!serial) {
550 ct->c_pid = child_id;
551 if (xtty)
552 xpid = child_id;
553 } else {
554 pidcheck (pidXwait (child_id, NULL));
555 }
556
557 if (fd != NOTOK)
558 (*ct->c_ceclosefnx) (ct);
559 return (alternate ? DONE : OK);
560 }
561 }
562
563
564 /*
565 * show content of type "text"
566 */
567
568 static int
569 show_text (CT ct, int serial, int alternate)
570 {
571 char *cp, buffer[BUFSIZ];
572 CI ci = &ct->c_ctinfo;
573
574 /* Check for mhn-show-type/subtype */
575 snprintf (buffer, sizeof(buffer), "%s-show-%s/%s",
576 invo_name, ci->ci_type, ci->ci_subtype);
577 if ((cp = context_find (buffer)) && *cp != '\0')
578 return show_content_aux (ct, serial, alternate, cp, NULL);
579
580 /* Check for mhn-show-type */
581 snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type);
582 if ((cp = context_find (buffer)) && *cp != '\0')
583 return show_content_aux (ct, serial, alternate, cp, NULL);
584
585 /*
586 * Use default method if content is text/plain, or if
587 * if it is not a text part of a multipart/alternative
588 */
589 if (!alternate || ct->c_subtype == TEXT_PLAIN) {
590 snprintf (buffer, sizeof(buffer), "%%p%s '%%F'", progsw ? progsw :
591 moreproc && *moreproc ? moreproc : "more");
592 cp = (ct->c_showproc = add (buffer, NULL));
593 return show_content_aux (ct, serial, alternate, cp, NULL);
594 }
595
596 return NOTOK;
597 }
598
599
600 /*
601 * show message body of type "multipart"
602 */
603
604 static int
605 show_multi (CT ct, int serial, int alternate)
606 {
607 char *cp, buffer[BUFSIZ];
608 CI ci = &ct->c_ctinfo;
609
610 /* Check for mhn-show-type/subtype */
611 snprintf (buffer, sizeof(buffer), "%s-show-%s/%s",
612 invo_name, ci->ci_type, ci->ci_subtype);
613 if ((cp = context_find (buffer)) && *cp != '\0')
614 return show_multi_aux (ct, serial, alternate, cp);
615
616 /* Check for mhn-show-type */
617 snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type);
618 if ((cp = context_find (buffer)) && *cp != '\0')
619 return show_multi_aux (ct, serial, alternate, cp);
620
621 if ((cp = ct->c_showproc))
622 return show_multi_aux (ct, serial, alternate, cp);
623
624 /*
625 * Use default method to display this multipart content
626 * if it is not a (nested) part of a multipart/alternative,
627 * or if it is one of the known subtypes of multipart.
628 */
629 if (!alternate || ct->c_subtype != MULTI_UNKNOWN)
630 return show_multi_internal (ct, serial, alternate);
631
632 return NOTOK;
633 }
634
635
636 /*
637 * show message body of subtypes of multipart that
638 * we understand directly (mixed, alternate, etc...)
639 */
640
641 static int
642 show_multi_internal (CT ct, int serial, int alternate)
643 {
644 int alternating, nowalternate, nowserial, result;
645 struct multipart *m = (struct multipart *) ct->c_ctparams;
646 struct part *part;
647 CT p;
648 sigset_t set, oset;
649
650 alternating = 0;
651 nowalternate = alternate;
652
653 if (ct->c_subtype == MULTI_PARALLEL) {
654 nowserial = serialsw;
655 } else if (ct->c_subtype == MULTI_ALTERNATE) {
656 nowalternate = 1;
657 alternating = 1;
658 nowserial = serial;
659 } else {
660 /*
661 * multipart/mixed
662 * mutlipart/digest
663 * unknown subtypes of multipart (treat as mixed per rfc2046)
664 */
665 nowserial = serial;
666 }
667
668 /* block a few signals */
669 if (!nowserial) {
670 sigemptyset (&set);
671 sigaddset (&set, SIGHUP);
672 sigaddset (&set, SIGINT);
673 sigaddset (&set, SIGQUIT);
674 sigaddset (&set, SIGTERM);
675 SIGPROCMASK (SIG_BLOCK, &set, &oset);
676 }
677
678 /*
679 * alternate -> we are a part inside an multipart/alternative
680 * alternating -> we are a multipart/alternative
681 */
682
683 result = alternate ? NOTOK : OK;
684
685 for (part = m->mp_parts; part; part = part->mp_next) {
686 p = part->mp_part;
687
688 if (part_ok (p, 0) && type_ok (p, 0)) {
689 int inneresult;
690
691 inneresult = show_switch (p, nowserial, nowalternate);
692 switch (inneresult) {
693 case NOTOK:
694 if (alternate && !alternating) {
695 result = NOTOK;
696 goto out;
697 }
698 continue;
699
700 case OK:
701 case DONE:
702 if (alternating) {
703 result = DONE;
704 break;
705 }
706 if (alternate) {
707 alternate = nowalternate = 0;
708 if (result == NOTOK)
709 result = inneresult;
710 }
711 continue;
712 }
713 break;
714 }
715 }
716
717 if (alternating && !part) {
718 if (!alternate)
719 content_error (NULL, ct, "don't know how to display any of the contents");
720 result = NOTOK;
721 goto out;
722 }
723
724 if (serial && !nowserial) {
725 pid_t pid;
726 int kids;
727 #ifdef WAITINT
728 int status;
729 #else
730 union wait status;
731 #endif
732
733 kids = 0;
734 for (part = m->mp_parts; part; part = part->mp_next) {
735 p = part->mp_part;
736
737 if (p->c_pid > OK) {
738 if (kill (p->c_pid, 0) == NOTOK)
739 p->c_pid = 0;
740 else
741 kids++;
742 }
743 }
744
745 while (kids > 0 && (pid = wait (&status)) != NOTOK) {
746 #ifdef WAITINT
747 pidcheck (status);
748 #else
749 pidcheck (status.w_status);
750 #endif
751
752 for (part = m->mp_parts; part; part = part->mp_next) {
753 p = part->mp_part;
754
755 if (xpid == pid)
756 xpid = 0;
757 if (p->c_pid == pid) {
758 p->c_pid = 0;
759 kids--;
760 break;
761 }
762 }
763 }
764 }
765
766 out:
767 if (!nowserial) {
768 /* reset the signal mask */
769 SIGPROCMASK (SIG_SETMASK, &oset, &set);
770 }
771
772 return result;
773 }
774
775
776 /*
777 * Parse display string for multipart content
778 * and use external program to display it.
779 */
780
781 static int
782 show_multi_aux (CT ct, int serial, int alternate, char *cp)
783 {
784 int len, buflen;
785 int xlist, xpause, xtty;
786 char *bp, *file, buffer[BUFSIZ];
787 struct multipart *m = (struct multipart *) ct->c_ctparams;
788 struct part *part;
789 CI ci = &ct->c_ctinfo;
790 CT p;
791
792 for (part = m->mp_parts; part; part = part->mp_next) {
793 p = part->mp_part;
794
795 if (!p->c_ceopenfnx) {
796 if (!alternate)
797 content_error (NULL, p, "don't know how to decode content");
798 return NOTOK;
799 }
800
801 if (p->c_storage == NULL) {
802 file = NULL;
803 if ((*p->c_ceopenfnx) (p, &file) == NOTOK)
804 return NOTOK;
805
806 /* I'm not sure if this is necessary? */
807 p->c_storage = add (file, NULL);
808
809 if (p->c_showproc && !strcmp (p->c_showproc, "true"))
810 return (alternate ? DONE : OK);
811 (*p->c_ceclosefnx) (p);
812 }
813 }
814
815 xlist = 0;
816 xpause = 0;
817 xtty = 0;
818
819 /* get buffer ready to go */
820 bp = buffer;
821 bp[0] = '\0';
822 buflen = sizeof(buffer);
823
824 /* Now parse display string */
825 for ( ; *cp; cp++) {
826 if (*cp == '%') {
827 switch (*++cp) {
828 case 'a':
829 /* insert parameters from Content-Type field */
830 {
831 char **ap, **ep;
832 char *s = "";
833
834 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
835 snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep);
836 len = strlen (bp);
837 bp += len;
838 buflen -= len;
839 s = " ";
840 }
841 }
842 break;
843
844 case 'd':
845 /* insert content description */
846 if (ct->c_descr) {
847 char *s;
848
849 s = trimcpy (ct->c_descr);
850 strncpy (bp, s, buflen);
851 free (s);
852 }
853 break;
854
855 case 'e':
856 /* exclusive execution */
857 xtty = 1;
858 break;
859
860 case 'F':
861 /* %e and %f */
862 xtty = 1;
863 /* and fall... */
864
865 case 'f':
866 /* insert filename(s) containing content */
867 {
868 char *s = "";
869
870 for (part = m->mp_parts; part; part = part->mp_next) {
871 p = part->mp_part;
872
873 snprintf (bp, buflen, "%s'%s'", s, p->c_storage);
874 len = strlen (bp);
875 bp += len;
876 buflen -= len;
877 s = " ";
878 }
879 }
880 break;
881
882 case 'p':
883 /* %l, and pause prior to displaying content */
884 xpause = pausesw;
885 /* and fall... */
886
887 case 'l':
888 /* display listing prior to displaying content */
889 xlist = !nolist;
890 break;
891
892 case 's':
893 /* insert subtype of content */
894 strncpy (bp, ci->ci_subtype, buflen);
895 break;
896
897 case '%':
898 /* insert character % */
899 goto raw;
900
901 default:
902 *bp++ = *--cp;
903 *bp = '\0';
904 buflen--;
905 continue;
906 }
907 len = strlen (bp);
908 bp += len;
909 buflen -= len;
910 } else {
911 raw:
912 *bp++ = *cp;
913 *bp = '\0';
914 buflen--;
915 }
916 }
917
918 /* use charset string to modify display method */
919 if (ct->c_termproc) {
920 char term[BUFSIZ];
921
922 strncpy (term, buffer, sizeof(term));
923 snprintf (buffer, sizeof(buffer), ct->c_termproc, term);
924 }
925
926 return show_content_aux2 (ct, serial, alternate, NULL, buffer,
927 NOTOK, xlist, xpause, 0, xtty);
928 }
929
930
931 /*
932 * show content of type "message/rfc822"
933 */
934
935 static int
936 show_message_rfc822 (CT ct, int serial, int alternate)
937 {
938 char *cp, buffer[BUFSIZ];
939 CI ci = &ct->c_ctinfo;
940
941 /* Check for mhn-show-type/subtype */
942 snprintf (buffer, sizeof(buffer), "%s-show-%s/%s",
943 invo_name, ci->ci_type, ci->ci_subtype);
944 if ((cp = context_find (buffer)) && *cp != '\0')
945 return show_content_aux (ct, serial, alternate, cp, NULL);
946
947 /* Check for mhn-show-type */
948 snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type);
949 if ((cp = context_find (buffer)) && *cp != '\0')
950 return show_content_aux (ct, serial, alternate, cp, NULL);
951
952 if ((cp = ct->c_showproc))
953 return show_content_aux (ct, serial, alternate, cp, NULL);
954
955 /* default method for message/rfc822 */
956 if (ct->c_subtype == MESSAGE_RFC822) {
957 cp = (ct->c_showproc = add ("%pshow -file '%F'", NULL));
958 return show_content_aux (ct, serial, alternate, cp, NULL);
959 }
960
961 /* complain if we are not a part of a multipart/alternative */
962 if (!alternate)
963 content_error (NULL, ct, "don't know how to display content");
964
965 return NOTOK;
966 }
967
968
969 /*
970 * Show content of type "message/partial".
971 */
972
973 static int
974 show_partial (CT ct, int serial, int alternate)
975 {
976 content_error (NULL, ct,
977 "in order to display this message, you must reassemble it");
978 return NOTOK;
979 }
980
981
982 /*
983 * Show content of type "message/external".
984 *
985 * THE ERROR CHECKING IN THIS ONE IS NOT DONE YET.
986 */
987
988 static int
989 show_external (CT ct, int serial, int alternate)
990 {
991 struct exbody *e = (struct exbody *) ct->c_ctparams;
992 CT p = e->eb_content;
993
994 if (!type_ok (p, 0))
995 return OK;
996
997 return show_switch (p, serial, alternate);
998
999 #if 0
1000 content_error (NULL, p, "don't know how to display content");
1001 return NOTOK;
1002 #endif
1003 }
1004
1005
1006 static RETSIGTYPE
1007 intrser (int i)
1008 {
1009 #ifndef RELIABLE_SIGNALS
1010 SIGNAL (SIGINT, intrser);
1011 #endif
1012
1013 putchar ('\n');
1014 siglongjmp (intrenv, DONE);
1015 }