2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char sccsid[] = "@(#)cmd1.c 8.1 (Berkeley) 6/6/93";
38 static const char rcsid[] =
46 * Mail -- a mail program
52 * Print the current active headings.
53 * Don't change dot if invoker didn't give an argument.
62 register int n, mesg, flag;
63 register struct message *mp;
72 mp = &message[screen * size];
73 if (mp >= &message[msgCount])
74 mp = &message[msgCount - size];
78 mesg = mp - &message[0];
79 if (dot != &message[n-1])
81 for (; mp < &message[msgCount]; mp++) {
83 if (mp->m_flag & MDELETED)
90 printf("No more mail.\n");
97 * Scroll to the next/previous screen
103 register int s, size;
113 if (s * size > msgCount) {
114 printf("On last screenful of messages\n");
122 printf("On first screenful of messages\n");
129 printf("Unrecognized scrolling command \"%s\"\n", arg);
132 return(headers(cur));
136 * Compute screen size.
144 if ((cp = value("screen")) != NOSTR && (s = atoi(cp)) > 0)
146 return screenheight - 4;
150 * Print out the headlines for each message
151 * in the passed message list.
159 for (ip = msgvec; *ip != 0; ip++)
162 dot = &message[*ip - 1];
167 * Print out the header of a specific message.
168 * This is a slight improvement to the standard one.
175 char headline[LINESIZE], wcount[LINESIZE], *subjline, dispc, curind;
181 mp = &message[mesg-1];
182 (void) readline(setinput(mp), headline, LINESIZE);
183 if ((subjline = hfield("subject", mp)) == NOSTR)
184 subjline = hfield("subj", mp);
188 curind = dot == mp ? '>' : ' ';
190 if (mp->m_flag & MSAVED)
192 if (mp->m_flag & MPRESERVE)
194 if ((mp->m_flag & (MREAD|MNEW)) == MNEW)
196 if ((mp->m_flag & (MREAD|MNEW)) == 0)
198 if (mp->m_flag & MBOX)
200 parse(headline, &hl, pbuf);
201 sprintf(wcount, "%3ld/%-5ld", mp->m_lines, mp->m_size);
202 subjlen = screenwidth - 50 - strlen(wcount);
203 name = value("show-rcpt") != NOSTR ?
204 skin(hfield("to", mp)) : nameof(mp, 0);
205 if (subjline == NOSTR || subjlen < 0) /* pretty pathetic */
206 printf("%c%c%3d %-20.20s %16.16s %s\n",
207 curind, dispc, mesg, name, hl.l_date, wcount);
209 printf("%c%c%3d %-20.20s %16.16s %s \"%.*s\"\n",
210 curind, dispc, mesg, name, hl.l_date, wcount,
215 * Print out the value of dot.
220 printf("%d\n", dot - &message[0] + 1);
225 * Print out all the possible commands.
230 register struct cmd *cp;
232 extern struct cmd cmdtab[];
234 printf("Commands are:\n");
235 for (cc = 0, cp = cmdtab; cp->c_name != NULL; cp++) {
236 cc += strlen(cp->c_name) + 2;
239 cc = strlen(cp->c_name) + 2;
241 if ((cp+1)->c_name != NOSTR)
242 printf("%s, ", cp->c_name);
244 printf("%s\n", cp->c_name);
250 * Paginate messages, honor ignored fields.
256 return (type1(msgvec, 1, 1));
260 * Paginate messages, even printing ignored fields.
267 return (type1(msgvec, 0, 1));
271 * Type out messages, honor ignored fields.
278 return(type1(msgvec, 1, 0));
282 * Type out messages, even printing ignored fields.
289 return(type1(msgvec, 0, 0));
293 * Type out the messages requested.
297 type1(msgvec, doign, page)
302 register struct message *mp;
308 if (setjmp(pipestop))
310 if (value("interactive") != NOSTR &&
311 (page || (cp = value("crt")) != NOSTR)) {
314 for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++)
315 nlines += message[*ip - 1].m_lines;
317 if (page || nlines > (*cp ? atoi(cp) : realscreenheight)) {
319 if (cp == NULL || *cp == '\0')
321 obuf = Popen(cp, "w");
326 signal(SIGPIPE, brokpipe);
329 for (ip = msgvec; *ip && ip - msgvec < msgCount; ip++) {
330 mp = &message[*ip - 1];
333 if (value("quiet") == NOSTR)
334 fprintf(obuf, "Message %d:\n", *ip);
335 (void) sendmessage(mp, obuf, doign ? ignore : 0, NOSTR);
338 if (obuf != stdout) {
340 * Ignore SIGPIPE so it can't cause a duplicate close.
342 signal(SIGPIPE, SIG_IGN);
344 signal(SIGPIPE, SIG_DFL);
350 * Respond to a broken pipe signal --
351 * probably caused by quitting more.
357 longjmp(pipestop, 1);
361 * Print the top so many lines of each desired message.
362 * The number of lines is taken from the variable "toplines"
370 register struct message *mp;
371 int c, topl, lines, lineb;
372 char *valtop, linebuf[LINESIZE];
376 valtop = value("toplines");
377 if (valtop != NOSTR) {
379 if (topl < 0 || topl > 10000)
383 for (ip = msgvec; *ip && ip-msgvec < msgCount; ip++) {
384 mp = &message[*ip - 1];
387 if (value("quiet") == NOSTR)
388 printf("Message %d:\n", *ip);
393 for (lines = 0; lines < c && lines <= topl; lines++) {
394 if (readline(ibuf, linebuf, sizeof(linebuf)) < 0)
397 lineb = strspn(linebuf, " \t") == strlen(linebuf);
404 * Touch all the given messages so that they will
413 for (ip = msgvec; *ip != 0; ip++) {
414 dot = &message[*ip-1];
415 dot->m_flag |= MTOUCH;
416 dot->m_flag &= ~MPRESERVE;
422 * Make sure all passed messages get mboxed.
430 for (ip = msgvec; *ip != 0; ip++) {
431 dot = &message[*ip-1];
432 dot->m_flag |= MTOUCH|MBOX;
433 dot->m_flag &= ~MPRESERVE;
439 * List the folders the user currently has.
444 char dirname[PATHSIZE];
447 if (getfold(dirname, sizeof(dirname)) < 0) {
448 printf("No value set for \"folder\"\n");
451 if ((cmd = value("LISTER")) == NOSTR)
453 (void) run_command(cmd, 0, -1, -1, dirname, NOSTR, NOSTR);