#! /bin/sh /usr/share/dpatch/dpatch-run # Subject: Wrap moreproc around as much MIME content as possible # Origin: http://debathena.mit.edu/trac/changeset/13008 # Forwarded: no # Author: Daniel Winship # Reviewed-by: Evan Broder @DPATCH@ --- a/uip/mhshowsbr.c.orig 2003-09-30 12:58:43.000000000 -0400 +++ b/uip/mhshowsbr.c 2010-06-25 20:43:59.000000000 -0400 @@ -47,7 +47,7 @@ int nomore = 0; char *formsw = NULL; -pid_t xpid = 0; +pid_t xpid = 0, m_pid = 0; static sigjmp_buf intrenv; @@ -90,6 +90,8 @@ static int show_partial (CT, int, int); static int show_external (CT, int, int); static RETSIGTYPE intrser (int); +static void m_popen (char *); +static void m_pclose (void); /* @@ -143,6 +145,9 @@ * the viewer (e.g., lynx) are going to be accessible */ umask (ct->c_umask & ~(0100)); + if (!nomore && isatty (fileno (stdout))) + m_popen (progsw ? progsw : moreproc); + /* * If you have a format file, then display * the message headers. @@ -170,6 +175,8 @@ sigaddset (&set, SIGTERM); SIGPROCMASK (SIG_BLOCK, &set, &oset); + m_pclose (); + while (wait (&status) != NOTOK) { #ifdef WAITINT pidcheck (status); @@ -203,18 +210,8 @@ vec[vecp++] = "-form"; vec[vecp++] = form; vec[vecp++] = "-nobody"; + vec[vecp++] = "-nomoreproc"; vec[vecp++] = ct->c_file; - - /* - * If we've specified -(no)moreproc, - * then just pass that along. - */ - if (nomore) { - vec[vecp++] = "-nomoreproc"; - } else if (progsw) { - vec[vecp++] = "-moreproc"; - vec[vecp++] = progsw; - } vec[vecp] = NULL; fflush (stdout); @@ -546,6 +543,9 @@ xpid = 0; } + if (xstdin && m_pid) + m_pclose (); + if (xlist) { char prompt[BUFSIZ]; @@ -647,8 +647,7 @@ * if it is not a text part of a multipart/alternative */ if (!alternate || ct->c_subtype == TEXT_PLAIN) { - snprintf (buffer, sizeof(buffer), "%%p%s '%%F'", progsw ? progsw : - moreproc && *moreproc ? moreproc : "more"); + snprintf (buffer, sizeof(buffer), "%%ecat '%%f'"); cp = (ct->c_showproc = add (buffer, NULL)); return show_content_aux (ct, serial, alternate, cp, NULL); } @@ -1121,3 +1120,65 @@ putchar ('\n'); siglongjmp (intrenv, DONE); } + +static int sd = NOTOK; + +static void +m_popen (char *name) +{ + int pd[2]; + + if ((sd = dup (fileno (stdout))) == NOTOK) + adios ("standard output", "unable to dup()"); + + if (pipe (pd) == NOTOK) + adios ("pipe", "unable to"); + + switch (m_pid = vfork ()) { + case NOTOK: + adios ("fork", "unable to"); + + case OK: + SIGNAL (SIGINT, SIG_DFL); + SIGNAL (SIGQUIT, SIG_DFL); + + close (pd[1]); + if (pd[0] != fileno (stdin)) { + dup2 (pd[0], fileno (stdin)); + close (pd[0]); + } + execlp (name, r1bindex (name, '/'), NULL); + fprintf (stderr, "unable to exec "); + perror (name); + _exit (-1); + + default: + close (pd[0]); + if (pd[1] != fileno (stdout)) { + dup2 (pd[1], fileno (stdout)); + close (pd[1]); + } + } +} + + +void +m_pclose (void) +{ + if (!m_pid) + return; + + if (sd != NOTOK) { + if (dup2 (sd, fileno (stdout)) == NOTOK) + adios ("standard output", "unable to dup2()"); + + clearerr (stdout); + close (sd); + sd = NOTOK; + } + else + fclose (stdout); + + pidwait (m_pid, OK); + m_pid = 0; +}