]> diplodocus.org Git - nmh/blob - uip/mhshowsbr.c
ef6f02c17459c9dfe6632b37bb0fe74ca0b3b3e4
[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 || prompt[0] == 'n') {
513 (*ct->c_ceclosefnx) (ct);
514 return (alternate ? DONE : NOTOK);
515 }
516 if (prompt[0] == 'q') done(OK);
517 }
518 }
519
520 snprintf (exec, sizeof(exec), "exec %s", buffer);
521
522 vec[0] = "/bin/sh";
523 vec[1] = "-c";
524 vec[2] = exec;
525 vec[3] = NULL;
526
527 fflush (stdout);
528
529 for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++)
530 sleep (5);
531 switch (child_id) {
532 case NOTOK:
533 advise ("fork", "unable to");
534 (*ct->c_ceclosefnx) (ct);
535 return NOTOK;
536
537 case OK:
538 if (cracked)
539 chdir (cracked);
540 if (!xstdin)
541 dup2 (fd, 0);
542 close (fd);
543 execvp ("/bin/sh", vec);
544 fprintf (stderr, "unable to exec ");
545 perror ("/bin/sh");
546 _exit (-1);
547 /* NOTREACHED */
548
549 default:
550 if (!serial) {
551 ct->c_pid = child_id;
552 if (xtty)
553 xpid = child_id;
554 } else {
555 pidcheck (pidXwait (child_id, NULL));
556 }
557
558 if (fd != NOTOK)
559 (*ct->c_ceclosefnx) (ct);
560 return (alternate ? DONE : OK);
561 }
562 }
563
564
565 /*
566 * show content of type "text"
567 */
568
569 static int
570 show_text (CT ct, int serial, int alternate)
571 {
572 char *cp, buffer[BUFSIZ];
573 CI ci = &ct->c_ctinfo;
574
575 /* Check for mhn-show-type/subtype */
576 snprintf (buffer, sizeof(buffer), "%s-show-%s/%s",
577 invo_name, ci->ci_type, ci->ci_subtype);
578 if ((cp = context_find (buffer)) && *cp != '\0')
579 return show_content_aux (ct, serial, alternate, cp, NULL);
580
581 /* Check for mhn-show-type */
582 snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type);
583 if ((cp = context_find (buffer)) && *cp != '\0')
584 return show_content_aux (ct, serial, alternate, cp, NULL);
585
586 /*
587 * Use default method if content is text/plain, or if
588 * if it is not a text part of a multipart/alternative
589 */
590 if (!alternate || ct->c_subtype == TEXT_PLAIN) {
591 snprintf (buffer, sizeof(buffer), "%%p%s '%%F'", progsw ? progsw :
592 moreproc && *moreproc ? moreproc : "more");
593 cp = (ct->c_showproc = add (buffer, NULL));
594 return show_content_aux (ct, serial, alternate, cp, NULL);
595 }
596
597 return NOTOK;
598 }
599
600
601 /*
602 * show message body of type "multipart"
603 */
604
605 static int
606 show_multi (CT ct, int serial, int alternate)
607 {
608 char *cp, buffer[BUFSIZ];
609 CI ci = &ct->c_ctinfo;
610
611 /* Check for mhn-show-type/subtype */
612 snprintf (buffer, sizeof(buffer), "%s-show-%s/%s",
613 invo_name, ci->ci_type, ci->ci_subtype);
614 if ((cp = context_find (buffer)) && *cp != '\0')
615 return show_multi_aux (ct, serial, alternate, cp);
616
617 /* Check for mhn-show-type */
618 snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type);
619 if ((cp = context_find (buffer)) && *cp != '\0')
620 return show_multi_aux (ct, serial, alternate, cp);
621
622 if ((cp = ct->c_showproc))
623 return show_multi_aux (ct, serial, alternate, cp);
624
625 /*
626 * Use default method to display this multipart content
627 * if it is not a (nested) part of a multipart/alternative,
628 * or if it is one of the known subtypes of multipart.
629 */
630 if (!alternate || ct->c_subtype != MULTI_UNKNOWN)
631 return show_multi_internal (ct, serial, alternate);
632
633 return NOTOK;
634 }
635
636
637 /*
638 * show message body of subtypes of multipart that
639 * we understand directly (mixed, alternate, etc...)
640 */
641
642 static int
643 show_multi_internal (CT ct, int serial, int alternate)
644 {
645 int alternating, nowalternate, nowserial, result;
646 struct multipart *m = (struct multipart *) ct->c_ctparams;
647 struct part *part;
648 CT p;
649 sigset_t set, oset;
650
651 alternating = 0;
652 nowalternate = alternate;
653
654 if (ct->c_subtype == MULTI_PARALLEL) {
655 nowserial = serialsw;
656 } else if (ct->c_subtype == MULTI_ALTERNATE) {
657 nowalternate = 1;
658 alternating = 1;
659 nowserial = serial;
660 } else {
661 /*
662 * multipart/mixed
663 * mutlipart/digest
664 * unknown subtypes of multipart (treat as mixed per rfc2046)
665 */
666 nowserial = serial;
667 }
668
669 /* block a few signals */
670 if (!nowserial) {
671 sigemptyset (&set);
672 sigaddset (&set, SIGHUP);
673 sigaddset (&set, SIGINT);
674 sigaddset (&set, SIGQUIT);
675 sigaddset (&set, SIGTERM);
676 SIGPROCMASK (SIG_BLOCK, &set, &oset);
677 }
678
679 /*
680 * alternate -> we are a part inside an multipart/alternative
681 * alternating -> we are a multipart/alternative
682 */
683
684 result = alternate ? NOTOK : OK;
685
686 for (part = m->mp_parts; part; part = part->mp_next) {
687 p = part->mp_part;
688
689 if (part_ok (p, 0) && type_ok (p, 0)) {
690 int inneresult;
691
692 inneresult = show_switch (p, nowserial, nowalternate);
693 switch (inneresult) {
694 case NOTOK:
695 if (alternate && !alternating) {
696 result = NOTOK;
697 goto out;
698 }
699 continue;
700
701 case OK:
702 case DONE:
703 if (alternating) {
704 result = DONE;
705 break;
706 }
707 if (alternate) {
708 alternate = nowalternate = 0;
709 if (result == NOTOK)
710 result = inneresult;
711 }
712 continue;
713 }
714 break;
715 }
716 }
717
718 if (alternating && !part) {
719 if (!alternate)
720 content_error (NULL, ct, "don't know how to display any of the contents");
721 result = NOTOK;
722 goto out;
723 }
724
725 if (serial && !nowserial) {
726 pid_t pid;
727 int kids;
728 #ifdef WAITINT
729 int status;
730 #else
731 union wait status;
732 #endif
733
734 kids = 0;
735 for (part = m->mp_parts; part; part = part->mp_next) {
736 p = part->mp_part;
737
738 if (p->c_pid > OK) {
739 if (kill (p->c_pid, 0) == NOTOK)
740 p->c_pid = 0;
741 else
742 kids++;
743 }
744 }
745
746 while (kids > 0 && (pid = wait (&status)) != NOTOK) {
747 #ifdef WAITINT
748 pidcheck (status);
749 #else
750 pidcheck (status.w_status);
751 #endif
752
753 for (part = m->mp_parts; part; part = part->mp_next) {
754 p = part->mp_part;
755
756 if (xpid == pid)
757 xpid = 0;
758 if (p->c_pid == pid) {
759 p->c_pid = 0;
760 kids--;
761 break;
762 }
763 }
764 }
765 }
766
767 out:
768 if (!nowserial) {
769 /* reset the signal mask */
770 SIGPROCMASK (SIG_SETMASK, &oset, &set);
771 }
772
773 return result;
774 }
775
776
777 /*
778 * Parse display string for multipart content
779 * and use external program to display it.
780 */
781
782 static int
783 show_multi_aux (CT ct, int serial, int alternate, char *cp)
784 {
785 int len, buflen;
786 int xlist, xpause, xtty;
787 char *bp, *file, buffer[BUFSIZ];
788 struct multipart *m = (struct multipart *) ct->c_ctparams;
789 struct part *part;
790 CI ci = &ct->c_ctinfo;
791 CT p;
792
793 for (part = m->mp_parts; part; part = part->mp_next) {
794 p = part->mp_part;
795
796 if (!p->c_ceopenfnx) {
797 if (!alternate)
798 content_error (NULL, p, "don't know how to decode content");
799 return NOTOK;
800 }
801
802 if (p->c_storage == NULL) {
803 file = NULL;
804 if ((*p->c_ceopenfnx) (p, &file) == NOTOK)
805 return NOTOK;
806
807 /* I'm not sure if this is necessary? */
808 p->c_storage = add (file, NULL);
809
810 if (p->c_showproc && !strcmp (p->c_showproc, "true"))
811 return (alternate ? DONE : OK);
812 (*p->c_ceclosefnx) (p);
813 }
814 }
815
816 xlist = 0;
817 xpause = 0;
818 xtty = 0;
819
820 /* get buffer ready to go */
821 bp = buffer;
822 bp[0] = '\0';
823 buflen = sizeof(buffer);
824
825 /* Now parse display string */
826 for ( ; *cp; cp++) {
827 if (*cp == '%') {
828 switch (*++cp) {
829 case 'a':
830 /* insert parameters from Content-Type field */
831 {
832 char **ap, **ep;
833 char *s = "";
834
835 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
836 snprintf (bp, buflen, "%s%s=\"%s\"", s, *ap, *ep);
837 len = strlen (bp);
838 bp += len;
839 buflen -= len;
840 s = " ";
841 }
842 }
843 break;
844
845 case 'd':
846 /* insert content description */
847 if (ct->c_descr) {
848 char *s;
849
850 s = trimcpy (ct->c_descr);
851 strncpy (bp, s, buflen);
852 free (s);
853 }
854 break;
855
856 case 'e':
857 /* exclusive execution */
858 xtty = 1;
859 break;
860
861 case 'F':
862 /* %e and %f */
863 xtty = 1;
864 /* and fall... */
865
866 case 'f':
867 /* insert filename(s) containing content */
868 {
869 char *s = "";
870
871 for (part = m->mp_parts; part; part = part->mp_next) {
872 p = part->mp_part;
873
874 snprintf (bp, buflen, "%s'%s'", s, p->c_storage);
875 len = strlen (bp);
876 bp += len;
877 buflen -= len;
878 s = " ";
879 }
880 }
881 break;
882
883 case 'p':
884 /* %l, and pause prior to displaying content */
885 xpause = pausesw;
886 /* and fall... */
887
888 case 'l':
889 /* display listing prior to displaying content */
890 xlist = !nolist;
891 break;
892
893 case 's':
894 /* insert subtype of content */
895 strncpy (bp, ci->ci_subtype, buflen);
896 break;
897
898 case '%':
899 /* insert character % */
900 goto raw;
901
902 default:
903 *bp++ = *--cp;
904 *bp = '\0';
905 buflen--;
906 continue;
907 }
908 len = strlen (bp);
909 bp += len;
910 buflen -= len;
911 } else {
912 raw:
913 *bp++ = *cp;
914 *bp = '\0';
915 buflen--;
916 }
917 }
918
919 /* use charset string to modify display method */
920 if (ct->c_termproc) {
921 char term[BUFSIZ];
922
923 strncpy (term, buffer, sizeof(term));
924 snprintf (buffer, sizeof(buffer), ct->c_termproc, term);
925 }
926
927 return show_content_aux2 (ct, serial, alternate, NULL, buffer,
928 NOTOK, xlist, xpause, 0, xtty);
929 }
930
931
932 /*
933 * show content of type "message/rfc822"
934 */
935
936 static int
937 show_message_rfc822 (CT ct, int serial, int alternate)
938 {
939 char *cp, buffer[BUFSIZ];
940 CI ci = &ct->c_ctinfo;
941
942 /* Check for mhn-show-type/subtype */
943 snprintf (buffer, sizeof(buffer), "%s-show-%s/%s",
944 invo_name, ci->ci_type, ci->ci_subtype);
945 if ((cp = context_find (buffer)) && *cp != '\0')
946 return show_content_aux (ct, serial, alternate, cp, NULL);
947
948 /* Check for mhn-show-type */
949 snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type);
950 if ((cp = context_find (buffer)) && *cp != '\0')
951 return show_content_aux (ct, serial, alternate, cp, NULL);
952
953 if ((cp = ct->c_showproc))
954 return show_content_aux (ct, serial, alternate, cp, NULL);
955
956 /* default method for message/rfc822 */
957 if (ct->c_subtype == MESSAGE_RFC822) {
958 cp = (ct->c_showproc = add ("%pshow -file '%F'", NULL));
959 return show_content_aux (ct, serial, alternate, cp, NULL);
960 }
961
962 /* complain if we are not a part of a multipart/alternative */
963 if (!alternate)
964 content_error (NULL, ct, "don't know how to display content");
965
966 return NOTOK;
967 }
968
969
970 /*
971 * Show content of type "message/partial".
972 */
973
974 static int
975 show_partial (CT ct, int serial, int alternate)
976 {
977 content_error (NULL, ct,
978 "in order to display this message, you must reassemble it");
979 return NOTOK;
980 }
981
982
983 /*
984 * Show content of type "message/external".
985 *
986 * THE ERROR CHECKING IN THIS ONE IS NOT DONE YET.
987 */
988
989 static int
990 show_external (CT ct, int serial, int alternate)
991 {
992 struct exbody *e = (struct exbody *) ct->c_ctparams;
993 CT p = e->eb_content;
994
995 if (!type_ok (p, 0))
996 return OK;
997
998 return show_switch (p, serial, alternate);
999
1000 #if 0
1001 content_error (NULL, p, "don't know how to display content");
1002 return NOTOK;
1003 #endif
1004 }
1005
1006
1007 static RETSIGTYPE
1008 intrser (int i)
1009 {
1010 #ifndef RELIABLE_SIGNALS
1011 SIGNAL (SIGINT, intrser);
1012 #endif
1013
1014 putchar ('\n');
1015 siglongjmp (intrenv, DONE);
1016 }