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
33 * @(#)cmd1.c 8.2 (Berkeley) 4/20/95
34 * $FreeBSD: src/usr.bin/mail/cmd1.c,v 1.3.6.3 2003/01/06 05:46:03 mikeh Exp $
35 * $DragonFly: src/usr.bin/mail/cmd1.c,v 1.4 2004/09/08 03:01:11 joerg Exp $
42 * Mail -- a mail program
47 extern const struct cmd cmdtab
[];
50 * Print the current active headings.
51 * Don't change dot if invoker didn't give an argument.
59 int n
, mesg
, flag
, size
;
68 mp
= &message
[screen
* size
];
69 if (mp
>= &message
[msgCount
])
70 mp
= &message
[msgCount
- size
];
74 mesg
= mp
- &message
[0];
75 if (dot
!= &message
[n
-1])
77 for (; mp
< &message
[msgCount
]; mp
++) {
79 if (mp
->m_flag
& MDELETED
)
86 printf("No more mail.\n");
93 * Scroll to the next/previous screen
108 if (s
* size
>= msgCount
) {
109 printf("On last screenful of messages\n");
117 printf("On first screenful of messages\n");
124 printf("Unrecognized scrolling command \"%s\"\n", arg
);
127 return (headers(cur
));
131 * Compute screen size.
139 if ((cp
= value("screen")) != NULL
&& (s
= atoi(cp
)) > 0)
141 return (screenheight
- 4);
145 * Print out the headlines for each message
146 * in the passed message list.
153 for (ip
= msgvec
; *ip
!= 0; ip
++)
156 dot
= &message
[*ip
- 1];
161 * Print out the header of a specific message.
162 * This is a slight improvement to the standard one.
168 char headline
[LINESIZE
], wcount
[LINESIZE
], *subjline
, dispc
, curind
;
174 mp
= &message
[mesg
-1];
175 readline(setinput(mp
), headline
, LINESIZE
);
176 if ((subjline
= hfield("subject", mp
)) == NULL
)
177 subjline
= hfield("subj", mp
);
181 curind
= dot
== mp
? '>' : ' ';
183 if (mp
->m_flag
& MSAVED
)
185 if (mp
->m_flag
& MPRESERVE
)
187 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MNEW
)
189 if ((mp
->m_flag
& (MREAD
|MNEW
)) == 0)
191 if (mp
->m_flag
& MBOX
)
193 parse(headline
, &hl
, pbuf
);
194 sprintf(wcount
, "%3ld/%-5ld", mp
->m_lines
, mp
->m_size
);
195 subjlen
= screenwidth
- 50 - strlen(wcount
);
196 name
= value("show-rcpt") != NULL
?
197 skin(hfield("to", mp
)) : nameof(mp
, 0);
198 if (subjline
== NULL
|| subjlen
< 0) /* pretty pathetic */
199 printf("%c%c%3d %-20.20s %16.16s %s\n",
200 curind
, dispc
, mesg
, name
, hl
.l_date
, wcount
);
202 printf("%c%c%3d %-20.20s %16.16s %s \"%.*s\"\n",
203 curind
, dispc
, mesg
, name
, hl
.l_date
, wcount
,
208 * Print out the value of dot.
213 printf("%d\n", dot
- &message
[0] + 1);
218 * Print out all the possible commands.
223 const struct cmd
*cp
;
226 printf("Commands are:\n");
227 for (cc
= 0, cp
= cmdtab
; cp
->c_name
!= NULL
; cp
++) {
228 cc
+= strlen(cp
->c_name
) + 2;
231 cc
= strlen(cp
->c_name
) + 2;
233 if ((cp
+1)->c_name
!= NULL
)
234 printf("%s, ", cp
->c_name
);
236 printf("%s\n", cp
->c_name
);
242 * Paginate messages, honor ignored fields.
247 return (type1(msgvec
, 1, 1));
251 * Paginate messages, even printing ignored fields.
256 return (type1(msgvec
, 0, 1));
260 * Type out messages, honor ignored fields.
265 return (type1(msgvec
, 1, 0));
269 * Type out messages, even printing ignored fields.
274 return (type1(msgvec
, 0, 0));
278 * Type out the messages requested.
282 type1(int *msgvec
, int doign
, int page
)
290 if (setjmp(pipestop
))
292 if (value("interactive") != NULL
&&
293 (page
|| (cp
= value("crt")) != NULL
)) {
296 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++)
297 nlines
+= message
[*ip
- 1].m_lines
;
299 if (page
|| nlines
> (*cp
? atoi(cp
) : realscreenheight
)) {
301 if (cp
== NULL
|| *cp
== '\0')
303 obuf
= Popen(cp
, "w");
308 signal(SIGPIPE
, brokpipe
);
313 * Send messages to the output.
316 for (ip
= msgvec
; *ip
&& ip
- msgvec
< msgCount
; ip
++) {
317 mp
= &message
[*ip
- 1];
320 if (value("quiet") == NULL
)
321 fprintf(obuf
, "Message %d:\n", *ip
);
322 sendmessage(mp
, obuf
, doign
? ignore
: 0, NULL
);
326 if (obuf
!= stdout
) {
328 * Ignore SIGPIPE so it can't cause a duplicate close.
330 signal(SIGPIPE
, SIG_IGN
);
332 signal(SIGPIPE
, SIG_DFL
);
338 * Respond to a broken pipe signal --
339 * probably caused by quitting more.
345 longjmp(pipestop
, 1);
349 * Print the top so many lines of each desired message.
350 * The number of lines is taken from the variable "toplines"
358 int c
, topl
, lines
, lineb
;
359 char *valtop
, linebuf
[LINESIZE
];
363 valtop
= value("toplines");
364 if (valtop
!= NULL
) {
366 if (topl
< 0 || topl
> 10000)
370 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
371 mp
= &message
[*ip
- 1];
374 if (value("quiet") == NULL
)
375 printf("Message %d:\n", *ip
);
380 for (lines
= 0; lines
< c
&& lines
<= topl
; lines
++) {
381 if (readline(ibuf
, linebuf
, sizeof(linebuf
)) < 0)
384 lineb
= strspn(linebuf
, " \t") == strlen(linebuf
);
391 * Touch all the given messages so that they will
399 for (ip
= msgvec
; *ip
!= 0; ip
++) {
400 dot
= &message
[*ip
-1];
401 dot
->m_flag
|= MTOUCH
;
402 dot
->m_flag
&= ~MPRESERVE
;
408 * Make sure all passed messages get mboxed.
415 for (ip
= msgvec
; *ip
!= 0; ip
++) {
416 dot
= &message
[*ip
-1];
417 dot
->m_flag
|= MTOUCH
|MBOX
;
418 dot
->m_flag
&= ~MPRESERVE
;
424 * List the folders the user currently has.
429 char dirname
[PATHSIZE
];
432 if (getfold(dirname
, sizeof(dirname
)) < 0) {
433 printf("No value set for \"folder\"\n");
436 if ((cmd
= value("LISTER")) == NULL
)
438 run_command(cmd
, 0, -1, -1, dirname
, NULL
, NULL
);
443 * Update the mail file with any new messages that have
444 * come in since we started reading mail.
454 printf("No new mail.\n");
456 mdot
= newfileinfo(msgCount
- nmsg
);
457 dot
= &message
[mdot
- 1];
459 printf("\"inc\" command failed...\n");