10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22*18Srobbin /*
23*18Srobbin * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
24*18Srobbin * Use is subject to license terms.
25*18Srobbin */
26*18Srobbin
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate * The Regents of the University of California
330Sstevel@tonic-gate * All Rights Reserved
340Sstevel@tonic-gate *
350Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate * contributors.
380Sstevel@tonic-gate */
390Sstevel@tonic-gate
400Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
410Sstevel@tonic-gate
420Sstevel@tonic-gate #include "rcv.h"
430Sstevel@tonic-gate #include <locale.h>
440Sstevel@tonic-gate
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate * mailx -- a modified version of a University of California at Berkeley
470Sstevel@tonic-gate * mail program
480Sstevel@tonic-gate *
490Sstevel@tonic-gate * User commands.
500Sstevel@tonic-gate */
510Sstevel@tonic-gate
520Sstevel@tonic-gate static char *dispname(char *hdr);
530Sstevel@tonic-gate static void print(register struct message *mp, FILE *obuf, int doign);
540Sstevel@tonic-gate static int type1(int *msgvec, int doign, int page);
550Sstevel@tonic-gate static int topputs(const char *line, FILE *obuf);
560Sstevel@tonic-gate
570Sstevel@tonic-gate void brokpipe(int sig);
580Sstevel@tonic-gate jmp_buf pipestop;
590Sstevel@tonic-gate
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate * Print the current active headings.
620Sstevel@tonic-gate * Don't change dot if invoker didn't give an argument.
630Sstevel@tonic-gate */
640Sstevel@tonic-gate
650Sstevel@tonic-gate static int curscreen = 0, oldscreensize = 0;
660Sstevel@tonic-gate
670Sstevel@tonic-gate int
headers(int * msgvec)680Sstevel@tonic-gate headers(int *msgvec)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate register int n, mesg, flag;
710Sstevel@tonic-gate register struct message *mp;
720Sstevel@tonic-gate int size;
730Sstevel@tonic-gate
740Sstevel@tonic-gate size = screensize();
750Sstevel@tonic-gate n = msgvec[0];
760Sstevel@tonic-gate if (n != 0)
770Sstevel@tonic-gate curscreen = (n-1)/size;
780Sstevel@tonic-gate if (curscreen < 0)
790Sstevel@tonic-gate curscreen = 0;
800Sstevel@tonic-gate mp = &message[curscreen * size];
810Sstevel@tonic-gate if (mp >= &message[msgCount])
820Sstevel@tonic-gate mp = &message[msgCount - size];
830Sstevel@tonic-gate if (mp < &message[0])
840Sstevel@tonic-gate mp = &message[0];
850Sstevel@tonic-gate flag = 0;
860Sstevel@tonic-gate mesg = mp - &message[0];
870Sstevel@tonic-gate if (dot != &message[n-1])
880Sstevel@tonic-gate dot = mp;
890Sstevel@tonic-gate if (Hflag)
900Sstevel@tonic-gate mp = message;
910Sstevel@tonic-gate for (; mp < &message[msgCount]; mp++) {
920Sstevel@tonic-gate mesg++;
930Sstevel@tonic-gate if (mp->m_flag & MDELETED)
940Sstevel@tonic-gate continue;
950Sstevel@tonic-gate if (flag++ >= size && !Hflag)
960Sstevel@tonic-gate break;
970Sstevel@tonic-gate printhead(mesg);
980Sstevel@tonic-gate sreset();
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate if (flag == 0) {
1010Sstevel@tonic-gate printf(gettext("No more mail.\n"));
1020Sstevel@tonic-gate return (1);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate return (0);
1050Sstevel@tonic-gate }
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate /*
1080Sstevel@tonic-gate * Scroll to the next/previous screen
1090Sstevel@tonic-gate */
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate int
scroll(char arg[])1120Sstevel@tonic-gate scroll(char arg[])
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate register int s, size;
1150Sstevel@tonic-gate int cur[1];
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate cur[0] = 0;
1180Sstevel@tonic-gate size = screensize();
1190Sstevel@tonic-gate s = curscreen;
1200Sstevel@tonic-gate switch (*arg) {
1210Sstevel@tonic-gate case 0:
1220Sstevel@tonic-gate case '+':
1230Sstevel@tonic-gate s++;
1240Sstevel@tonic-gate if (s * size > msgCount) {
1250Sstevel@tonic-gate printf(gettext("On last screenful of messages\n"));
1260Sstevel@tonic-gate return (0);
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate curscreen = s;
1290Sstevel@tonic-gate break;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate case '-':
1320Sstevel@tonic-gate if (--s < 0) {
1330Sstevel@tonic-gate printf(gettext("On first screenful of messages\n"));
1340Sstevel@tonic-gate return (0);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate curscreen = s;
1370Sstevel@tonic-gate break;
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate default:
1400Sstevel@tonic-gate printf(gettext("Unrecognized scrolling command \"%s\"\n"), arg);
1410Sstevel@tonic-gate return (1);
1420Sstevel@tonic-gate }
1430Sstevel@tonic-gate return (headers(cur));
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate * Compute what the screen size should be.
1480Sstevel@tonic-gate * We use the following algorithm:
1490Sstevel@tonic-gate * If user specifies with screen option, use that.
1500Sstevel@tonic-gate * If baud rate < 1200, use 5
1510Sstevel@tonic-gate * If baud rate = 1200, use 10
1520Sstevel@tonic-gate * If baud rate > 1200, use 20
1530Sstevel@tonic-gate */
1540Sstevel@tonic-gate int
screensize(void)1550Sstevel@tonic-gate screensize(void)
1560Sstevel@tonic-gate {
1570Sstevel@tonic-gate register char *cp;
1580Sstevel@tonic-gate register int newscreensize, tmp;
1590Sstevel@tonic-gate #ifdef TIOCGWINSZ
1600Sstevel@tonic-gate struct winsize ws;
1610Sstevel@tonic-gate #endif
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate if ((cp = value("screen")) != NOSTR && (tmp = atoi(cp)) > 0)
1640Sstevel@tonic-gate newscreensize = tmp;
1650Sstevel@tonic-gate else if (baud < B1200)
1660Sstevel@tonic-gate newscreensize = 5;
1670Sstevel@tonic-gate else if (baud == B1200)
1680Sstevel@tonic-gate newscreensize = 10;
1690Sstevel@tonic-gate #ifdef TIOCGWINSZ
1700Sstevel@tonic-gate else if (ioctl(fileno(stdout), TIOCGWINSZ, &ws) == 0 && ws.ws_row > 4)
1710Sstevel@tonic-gate newscreensize = ws.ws_row - 4;
1720Sstevel@tonic-gate #endif
1730Sstevel@tonic-gate else
1740Sstevel@tonic-gate newscreensize = 20;
1750Sstevel@tonic-gate /* renormalize the value of curscreen */
1760Sstevel@tonic-gate if (newscreensize != oldscreensize) {
1770Sstevel@tonic-gate curscreen = curscreen * oldscreensize / newscreensize;
1780Sstevel@tonic-gate oldscreensize = newscreensize;
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate return (newscreensize);
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate /*
1840Sstevel@tonic-gate * Print out the headlines for each message
1850Sstevel@tonic-gate * in the passed message list.
1860Sstevel@tonic-gate */
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate int
from(int * msgvec)1890Sstevel@tonic-gate from(int *msgvec)
1900Sstevel@tonic-gate {
1910Sstevel@tonic-gate register int *ip;
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate for (ip = msgvec; *ip != NULL; ip++) {
1940Sstevel@tonic-gate printhead(*ip);
1950Sstevel@tonic-gate sreset();
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate if (--ip >= msgvec)
1980Sstevel@tonic-gate dot = &message[*ip - 1];
1990Sstevel@tonic-gate return (0);
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate * Print out the header of a specific message.
2040Sstevel@tonic-gate * This is a slight improvement to the standard one.
2050Sstevel@tonic-gate */
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate void
printhead(int mesg)2080Sstevel@tonic-gate printhead(int mesg)
2090Sstevel@tonic-gate {
2100Sstevel@tonic-gate struct message *mp;
2110Sstevel@tonic-gate FILE *ibuf;
2120Sstevel@tonic-gate char headline[LINESIZE], *subjline, dispc, curind;
2130Sstevel@tonic-gate char *fromline;
2140Sstevel@tonic-gate char pbuf[LINESIZE];
2150Sstevel@tonic-gate char name[LINESIZE];
2160Sstevel@tonic-gate struct headline hl;
2170Sstevel@tonic-gate register char *cp;
2180Sstevel@tonic-gate int showto;
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate mp = &message[mesg-1];
2210Sstevel@tonic-gate ibuf = setinput(mp);
2220Sstevel@tonic-gate readline(ibuf, headline);
2230Sstevel@tonic-gate if ((subjline = hfield("subject", mp, addone)) == NOSTR &&
2240Sstevel@tonic-gate (subjline = hfield("subj", mp, addone)) == NOSTR &&
2250Sstevel@tonic-gate (subjline = hfield("message-status", mp, addone)) == NOSTR)
2260Sstevel@tonic-gate subjline = "";
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate curind = (!Hflag && dot == mp) ? '>' : ' ';
2290Sstevel@tonic-gate dispc = ' ';
2300Sstevel@tonic-gate showto = 0;
2310Sstevel@tonic-gate if ((mp->m_flag & (MREAD|MNEW)) == (MREAD|MNEW))
2320Sstevel@tonic-gate dispc = 'R';
2330Sstevel@tonic-gate if (!(int)value("bsdcompat") && (mp->m_flag & (MREAD|MNEW)) == MREAD)
2340Sstevel@tonic-gate dispc = 'O';
2350Sstevel@tonic-gate if ((mp->m_flag & (MREAD|MNEW)) == MNEW)
2360Sstevel@tonic-gate dispc = 'N';
2370Sstevel@tonic-gate if ((mp->m_flag & (MREAD|MNEW)) == 0)
2380Sstevel@tonic-gate dispc = 'U';
2390Sstevel@tonic-gate if (mp->m_flag & MSAVED)
2400Sstevel@tonic-gate if ((int)value("bsdcompat"))
2410Sstevel@tonic-gate dispc = '*';
2420Sstevel@tonic-gate else
2430Sstevel@tonic-gate dispc = 'S';
2440Sstevel@tonic-gate if (mp->m_flag & MPRESERVE)
2450Sstevel@tonic-gate if ((int)value("bsdcompat"))
2460Sstevel@tonic-gate dispc = 'P';
2470Sstevel@tonic-gate else
2480Sstevel@tonic-gate dispc = 'H';
2490Sstevel@tonic-gate if (mp->m_flag & MBOX)
2500Sstevel@tonic-gate dispc = 'M';
2510Sstevel@tonic-gate parse(headline, &hl, pbuf);
2520Sstevel@tonic-gate if (hl.l_date == NOSTR)
2530Sstevel@tonic-gate hl.l_date = "<Unknown date>";
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate /*
2560Sstevel@tonic-gate * Netnews interface?
2570Sstevel@tonic-gate */
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate if (newsflg) {
2600Sstevel@tonic-gate if ((fromline = hfield("newsgroups", mp, addone)) == NOSTR &&
2610Sstevel@tonic-gate (fromline = hfield("article-id", mp, addone)) == NOSTR)
2620Sstevel@tonic-gate fromline = "<>";
2630Sstevel@tonic-gate else
2640Sstevel@tonic-gate for (cp = fromline; *cp; cp++) { /* limit length */
2650Sstevel@tonic-gate if (any(*cp, " ,\n")) {
2660Sstevel@tonic-gate *cp = '\0';
2670Sstevel@tonic-gate break;
2680Sstevel@tonic-gate }
2690Sstevel@tonic-gate }
2700Sstevel@tonic-gate /*
2710Sstevel@tonic-gate * else regular.
2720Sstevel@tonic-gate */
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate } else {
2750Sstevel@tonic-gate fromline = nameof(mp);
2760Sstevel@tonic-gate if (value("showto") &&
2770Sstevel@tonic-gate samebody(myname, skin(fromline), FALSE) &&
2780Sstevel@tonic-gate (cp = hfield("to", mp, addto))) {
2790Sstevel@tonic-gate showto = 1;
2800Sstevel@tonic-gate yankword(cp, fromline = name, sizeof (name),
2810Sstevel@tonic-gate docomma(cp));
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate if (value("showname"))
2840Sstevel@tonic-gate fromline = dispname(fromline);
2850Sstevel@tonic-gate else
2860Sstevel@tonic-gate fromline = skin(fromline);
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate printf("%c%c%3d ", curind, dispc, mesg);
2890Sstevel@tonic-gate if ((int)value("showfull")) {
2900Sstevel@tonic-gate if (showto)
2910Sstevel@tonic-gate printf("To %-15s ", fromline);
2920Sstevel@tonic-gate else
2930Sstevel@tonic-gate printf("%-18s ", fromline);
2940Sstevel@tonic-gate } else {
2950Sstevel@tonic-gate if (showto)
2960Sstevel@tonic-gate printf("To %-15.15s ", fromline);
2970Sstevel@tonic-gate else
2980Sstevel@tonic-gate printf("%-18.18s ", fromline);
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate if (mp->m_text) {
3010Sstevel@tonic-gate printf("%16.16s %4ld/%-5ld %-.25s\n",
3020Sstevel@tonic-gate hl.l_date, mp->m_lines, mp->m_size, subjline);
3030Sstevel@tonic-gate } else {
3040Sstevel@tonic-gate printf("%16.16s binary/%-5ld %-.25s\n", hl.l_date, mp->m_size,
3050Sstevel@tonic-gate subjline);
3060Sstevel@tonic-gate }
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate /*
3100Sstevel@tonic-gate * Return the full name from an RFC-822 header line
3110Sstevel@tonic-gate * or the last two (or one) component of the address.
3120Sstevel@tonic-gate */
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate static char *
dispname(char * hdr)3150Sstevel@tonic-gate dispname(char *hdr)
3160Sstevel@tonic-gate {
3170Sstevel@tonic-gate char *cp, *cp2;
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate if (hdr == 0)
3200Sstevel@tonic-gate return (0);
3210Sstevel@tonic-gate if (((cp = strchr(hdr, '<')) != 0) && (cp > hdr)) {
3220Sstevel@tonic-gate *cp = 0;
3230Sstevel@tonic-gate if ((*hdr == '"') && ((cp = strrchr(++hdr, '"')) != 0))
3240Sstevel@tonic-gate *cp = 0;
3250Sstevel@tonic-gate return (hdr);
3260Sstevel@tonic-gate } else if ((cp = strchr(hdr, '(')) != 0) {
3270Sstevel@tonic-gate hdr = ++cp;
3280Sstevel@tonic-gate if ((cp = strchr(hdr, '+')) != 0)
3290Sstevel@tonic-gate *cp = 0;
3300Sstevel@tonic-gate if ((cp = strrchr(hdr, ')')) != 0)
3310Sstevel@tonic-gate *cp = 0;
3320Sstevel@tonic-gate return (hdr);
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate cp = skin(hdr);
3350Sstevel@tonic-gate if ((cp2 = strrchr(cp, '!')) != 0) {
3360Sstevel@tonic-gate while (cp2 >= cp && *--cp2 != '!');
3370Sstevel@tonic-gate cp = ++cp2;
3380Sstevel@tonic-gate }
3390Sstevel@tonic-gate return (cp);
3400Sstevel@tonic-gate }
3410Sstevel@tonic-gate
3420Sstevel@tonic-gate /*
3430Sstevel@tonic-gate * Print out the value of dot.
3440Sstevel@tonic-gate */
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate int
pdot(void)3470Sstevel@tonic-gate pdot(void)
3480Sstevel@tonic-gate {
3490Sstevel@tonic-gate printf("%d\n", dot - &message[0] + 1);
3500Sstevel@tonic-gate return (0);
3510Sstevel@tonic-gate }
3520Sstevel@tonic-gate
3530Sstevel@tonic-gate /*
3540Sstevel@tonic-gate * Print out all the possible commands.
3550Sstevel@tonic-gate */
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate int
pcmdlist(void)3580Sstevel@tonic-gate pcmdlist(void)
3590Sstevel@tonic-gate {
3600Sstevel@tonic-gate register const struct cmd *cp;
3610Sstevel@tonic-gate register int cc;
3620Sstevel@tonic-gate
3630Sstevel@tonic-gate printf("Commands are:\n");
3640Sstevel@tonic-gate for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) {
3650Sstevel@tonic-gate cc += strlen(cp->c_name) + 2;
3660Sstevel@tonic-gate if (cc > 72) {
3670Sstevel@tonic-gate printf("\n");
3680Sstevel@tonic-gate cc = strlen(cp->c_name) + 2;
3690Sstevel@tonic-gate }
3700Sstevel@tonic-gate if ((cp+1)->c_name != NOSTR)
3710Sstevel@tonic-gate printf("%s, ", cp->c_name);
3720Sstevel@tonic-gate else
3730Sstevel@tonic-gate printf("%s\n", cp->c_name);
3740Sstevel@tonic-gate }
3750Sstevel@tonic-gate return (0);
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate
3780Sstevel@tonic-gate /*
3790Sstevel@tonic-gate * Paginate messages, honor ignored fields.
3800Sstevel@tonic-gate */
3810Sstevel@tonic-gate int
more(int * msgvec)3820Sstevel@tonic-gate more(int *msgvec)
3830Sstevel@tonic-gate {
3840Sstevel@tonic-gate return (type1(msgvec, 1, 1));
3850Sstevel@tonic-gate }
3860Sstevel@tonic-gate
3870Sstevel@tonic-gate /*
3880Sstevel@tonic-gate * Paginate messages, even printing ignored fields.
3890Sstevel@tonic-gate */
3900Sstevel@tonic-gate int
More(int * msgvec)3910Sstevel@tonic-gate More(int *msgvec)
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate
3940Sstevel@tonic-gate return (type1(msgvec, 0, 1));
3950Sstevel@tonic-gate }
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate /*
3980Sstevel@tonic-gate * Type out messages, honor ignored fields.
3990Sstevel@tonic-gate */
4000Sstevel@tonic-gate int
type(int * msgvec)4010Sstevel@tonic-gate type(int *msgvec)
4020Sstevel@tonic-gate {
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate return (type1(msgvec, 1, 0));
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate /*
4080Sstevel@tonic-gate * Type out messages, even printing ignored fields.
4090Sstevel@tonic-gate */
4100Sstevel@tonic-gate int
Type(int * msgvec)4110Sstevel@tonic-gate Type(int *msgvec)
4120Sstevel@tonic-gate {
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate return (type1(msgvec, 0, 0));
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate /*
4180Sstevel@tonic-gate * Type out the messages requested.
4190Sstevel@tonic-gate */
4200Sstevel@tonic-gate static int
type1(int * msgvec,int doign,int page)4210Sstevel@tonic-gate type1(int *msgvec, int doign, int page)
4220Sstevel@tonic-gate {
423*18Srobbin int *ip;
4240Sstevel@tonic-gate register struct message *mp;
4250Sstevel@tonic-gate register int mesg;
4260Sstevel@tonic-gate register char *cp;
4270Sstevel@tonic-gate long nlines;
4280Sstevel@tonic-gate FILE *obuf;
4290Sstevel@tonic-gate void (*sigint)(int), (*sigpipe)(int);
4300Sstevel@tonic-gate int setsigs = 0;
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate obuf = stdout;
4330Sstevel@tonic-gate if (setjmp(pipestop)) {
4340Sstevel@tonic-gate if (obuf != stdout) {
4350Sstevel@tonic-gate pipef = NULL;
4360Sstevel@tonic-gate npclose(obuf);
4370Sstevel@tonic-gate }
4380Sstevel@tonic-gate goto ret0;
4390Sstevel@tonic-gate }
4400Sstevel@tonic-gate if (intty && outtty && (page || (cp = value("crt")) != NOSTR)) {
4410Sstevel@tonic-gate if (!page) {
4420Sstevel@tonic-gate nlines = 0;
4430Sstevel@tonic-gate for (ip = msgvec, nlines = 0;
4440Sstevel@tonic-gate *ip && ip-msgvec < msgCount; ip++)
4450Sstevel@tonic-gate nlines += message[*ip - 1].m_lines;
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate if (page ||
4480Sstevel@tonic-gate nlines > (*cp == '\0' ? screensize() - 2 : atoi(cp))) {
4490Sstevel@tonic-gate obuf = npopen(MORE, "w");
4500Sstevel@tonic-gate if (obuf == NULL) {
4510Sstevel@tonic-gate perror(MORE);
4520Sstevel@tonic-gate obuf = stdout;
4530Sstevel@tonic-gate } else {
4540Sstevel@tonic-gate pipef = obuf;
4550Sstevel@tonic-gate sigint = sigset(SIGINT, SIG_IGN);
4560Sstevel@tonic-gate sigpipe = sigset(SIGPIPE, brokpipe);
4570Sstevel@tonic-gate setsigs++;
4580Sstevel@tonic-gate }
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
4620Sstevel@tonic-gate mesg = *ip;
4630Sstevel@tonic-gate touch(mesg);
4640Sstevel@tonic-gate mp = &message[mesg-1];
4650Sstevel@tonic-gate dot = mp;
4660Sstevel@tonic-gate print(mp, obuf, doign);
4670Sstevel@tonic-gate }
4680Sstevel@tonic-gate if (obuf != stdout) {
4690Sstevel@tonic-gate pipef = NULL;
4700Sstevel@tonic-gate npclose(obuf);
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate ret0:
4730Sstevel@tonic-gate if (setsigs) {
4740Sstevel@tonic-gate sigset(SIGPIPE, sigpipe);
4750Sstevel@tonic-gate sigset(SIGINT, sigint);
4760Sstevel@tonic-gate }
4770Sstevel@tonic-gate return (0);
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate /*
4810Sstevel@tonic-gate * Respond to a broken pipe signal --
4820Sstevel@tonic-gate * probably caused by user quitting more.
4830Sstevel@tonic-gate */
4840Sstevel@tonic-gate void
4850Sstevel@tonic-gate #ifdef __cplusplus
brokpipe(int)4860Sstevel@tonic-gate brokpipe(int)
4870Sstevel@tonic-gate #else
4880Sstevel@tonic-gate /* ARGSUSED */
4890Sstevel@tonic-gate brokpipe(int s)
4900Sstevel@tonic-gate #endif
4910Sstevel@tonic-gate {
4920Sstevel@tonic-gate #ifdef OLD_BSD_SIGS
4930Sstevel@tonic-gate sigrelse(SIGPIPE);
4940Sstevel@tonic-gate #endif
4950Sstevel@tonic-gate longjmp(pipestop, 1);
4960Sstevel@tonic-gate }
4970Sstevel@tonic-gate
4980Sstevel@tonic-gate /*
4990Sstevel@tonic-gate * Print the indicated message on standard output.
5000Sstevel@tonic-gate */
5010Sstevel@tonic-gate
5020Sstevel@tonic-gate static void
print(register struct message * mp,FILE * obuf,int doign)5030Sstevel@tonic-gate print(register struct message *mp, FILE *obuf, int doign)
5040Sstevel@tonic-gate {
5050Sstevel@tonic-gate
5060Sstevel@tonic-gate if (value("quiet") == NOSTR && (!doign || !isign("message", 0)))
5070Sstevel@tonic-gate fprintf(obuf, "Message %2d:\n", mp - &message[0] + 1);
5080Sstevel@tonic-gate touch(mp - &message[0] + 1);
5090Sstevel@tonic-gate if (mp->m_text) {
5100Sstevel@tonic-gate (void) msend(mp, obuf, doign ? M_IGNORE : 0, fputs);
5110Sstevel@tonic-gate } else {
5120Sstevel@tonic-gate fprintf(obuf, "\n%s\n", gettext(binmsg));
5130Sstevel@tonic-gate }
5140Sstevel@tonic-gate }
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate /*
5170Sstevel@tonic-gate * Print the top so many lines of each desired message.
5180Sstevel@tonic-gate * The number of lines is taken from the variable "toplines"
5190Sstevel@tonic-gate * and defaults to 5.
5200Sstevel@tonic-gate */
5210Sstevel@tonic-gate
5220Sstevel@tonic-gate static long top_linecount, top_maxlines, top_lineb;
5230Sstevel@tonic-gate static jmp_buf top_buf;
5240Sstevel@tonic-gate
5250Sstevel@tonic-gate int
top(int * msgvec)5260Sstevel@tonic-gate top(int *msgvec)
5270Sstevel@tonic-gate {
5280Sstevel@tonic-gate register int *ip;
5290Sstevel@tonic-gate register struct message *mp;
5300Sstevel@tonic-gate register int mesg;
5310Sstevel@tonic-gate char *valtop;
5320Sstevel@tonic-gate
5330Sstevel@tonic-gate top_maxlines = 5;
5340Sstevel@tonic-gate valtop = value("toplines");
5350Sstevel@tonic-gate if (valtop != NOSTR) {
5360Sstevel@tonic-gate top_maxlines = atoi(valtop);
5370Sstevel@tonic-gate if (top_maxlines < 0 || top_maxlines > 10000)
5380Sstevel@tonic-gate top_maxlines = 5;
5390Sstevel@tonic-gate }
5400Sstevel@tonic-gate top_lineb = 1;
5410Sstevel@tonic-gate for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
5420Sstevel@tonic-gate mesg = *ip;
5430Sstevel@tonic-gate touch(mesg);
5440Sstevel@tonic-gate mp = &message[mesg-1];
5450Sstevel@tonic-gate dot = mp;
5460Sstevel@tonic-gate if (value("quiet") == NOSTR)
5470Sstevel@tonic-gate printf("Message %2d:\n", mesg);
5480Sstevel@tonic-gate if (!top_lineb)
5490Sstevel@tonic-gate printf("\n");
5500Sstevel@tonic-gate top_linecount = 0;
5510Sstevel@tonic-gate if (setjmp(top_buf) == 0) {
5520Sstevel@tonic-gate if (mp->m_text) {
5530Sstevel@tonic-gate (void) msend(mp, stdout, M_IGNORE, topputs);
5540Sstevel@tonic-gate } else {
5550Sstevel@tonic-gate printf("\n%s\n", gettext(binmsg));
5560Sstevel@tonic-gate }
5570Sstevel@tonic-gate }
5580Sstevel@tonic-gate }
5590Sstevel@tonic-gate return (0);
5600Sstevel@tonic-gate }
5610Sstevel@tonic-gate
5620Sstevel@tonic-gate int
topputs(const char * line,FILE * obuf)5630Sstevel@tonic-gate topputs(const char *line, FILE *obuf)
5640Sstevel@tonic-gate {
5650Sstevel@tonic-gate if (top_linecount++ >= top_maxlines)
5660Sstevel@tonic-gate longjmp(top_buf, 1);
5670Sstevel@tonic-gate top_lineb = blankline(line);
5680Sstevel@tonic-gate return (fputs(line, obuf));
5690Sstevel@tonic-gate }
5700Sstevel@tonic-gate
5710Sstevel@tonic-gate /*
5720Sstevel@tonic-gate * Touch all the given messages so that they will
5730Sstevel@tonic-gate * get mboxed.
5740Sstevel@tonic-gate */
5750Sstevel@tonic-gate
5760Sstevel@tonic-gate int
stouch(int msgvec[])5770Sstevel@tonic-gate stouch(int msgvec[])
5780Sstevel@tonic-gate {
5790Sstevel@tonic-gate register int *ip;
5800Sstevel@tonic-gate
5810Sstevel@tonic-gate for (ip = msgvec; *ip != 0; ip++) {
5820Sstevel@tonic-gate dot = &message[*ip-1];
5830Sstevel@tonic-gate dot->m_flag |= MTOUCH;
5840Sstevel@tonic-gate dot->m_flag &= ~MPRESERVE;
5850Sstevel@tonic-gate }
5860Sstevel@tonic-gate return (0);
5870Sstevel@tonic-gate }
5880Sstevel@tonic-gate
5890Sstevel@tonic-gate /*
5900Sstevel@tonic-gate * Make sure all passed messages get mboxed.
5910Sstevel@tonic-gate */
5920Sstevel@tonic-gate
5930Sstevel@tonic-gate int
mboxit(int msgvec[])5940Sstevel@tonic-gate mboxit(int msgvec[])
5950Sstevel@tonic-gate {
5960Sstevel@tonic-gate register int *ip;
5970Sstevel@tonic-gate
5980Sstevel@tonic-gate for (ip = msgvec; *ip != 0; ip++) {
5990Sstevel@tonic-gate dot = &message[*ip-1];
6000Sstevel@tonic-gate dot->m_flag |= MTOUCH|MBOX;
6010Sstevel@tonic-gate dot->m_flag &= ~MPRESERVE;
6020Sstevel@tonic-gate }
6030Sstevel@tonic-gate return (0);
6040Sstevel@tonic-gate }
6050Sstevel@tonic-gate
6060Sstevel@tonic-gate /*
6070Sstevel@tonic-gate * List the folders the user currently has.
6080Sstevel@tonic-gate */
6090Sstevel@tonic-gate int
folders(char ** arglist)6100Sstevel@tonic-gate folders(char **arglist)
6110Sstevel@tonic-gate {
6120Sstevel@tonic-gate char dirname[BUFSIZ], cmd[BUFSIZ];
6130Sstevel@tonic-gate
6140Sstevel@tonic-gate if (getfold(dirname) < 0) {
6150Sstevel@tonic-gate printf(gettext("No value set for \"folder\"\n"));
6160Sstevel@tonic-gate return (-1);
6170Sstevel@tonic-gate }
6180Sstevel@tonic-gate if (*arglist) {
6190Sstevel@tonic-gate nstrcat(dirname, sizeof (dirname), "/");
6200Sstevel@tonic-gate nstrcat(dirname, sizeof (dirname), *arglist);
6210Sstevel@tonic-gate }
6220Sstevel@tonic-gate snprintf(cmd, sizeof (cmd), "%s %s", LS, dirname);
6230Sstevel@tonic-gate return (system(cmd));
6240Sstevel@tonic-gate }
625