]>
git.cameronkatri.com Git - apple_cmds.git/blob - mail_cmds/mail/cmd1.c
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.2 (Berkeley) 4/20/95";
38 static const char rcsid
[] =
39 "$FreeBSD: src/usr.bin/mail/cmd1.c,v 1.7 2002/06/30 05:25:05 obrien Exp $";
42 #include <sys/cdefs.h>
48 * Mail -- a mail program
53 extern const struct cmd cmdtab
[];
56 * Print the current active headings.
57 * Don't change dot if invoker didn't give an argument.
66 int n
, mesg
, flag
, size
;
75 mp
= &message
[screen
* size
];
76 if (mp
>= &message
[msgCount
])
77 mp
= &message
[msgCount
- size
];
81 mesg
= mp
- &message
[0];
82 if (dot
!= &message
[n
-1])
84 for (; mp
< &message
[msgCount
]; mp
++) {
86 if (mp
->m_flag
& MDELETED
)
93 printf("No more mail.\n");
100 * Scroll to the next/previous screen
116 if (s
* size
>= msgCount
) {
117 printf("On last screenful of messages\n");
125 printf("On first screenful of messages\n");
132 printf("Unrecognized scrolling command \"%s\"\n", arg
);
135 return (headers(cur
));
139 * Compute screen size.
147 if ((cp
= value("screen")) != NULL
&& (s
= atoi(cp
)) > 0)
149 return (screenheight
- 4);
153 * Print out the headlines for each message
154 * in the passed message list.
162 for (ip
= msgvec
; *ip
!= 0; ip
++)
165 dot
= &message
[*ip
- 1];
170 * Print out the header of a specific message.
171 * This is a slight improvement to the standard one.
178 char headline
[LINESIZE
], wcount
[LINESIZE
], *subjline
, dispc
, curind
;
184 mp
= &message
[mesg
-1];
185 (void)readline(setinput(mp
), headline
, LINESIZE
);
186 if ((subjline
= hfield("subject", mp
)) == NULL
)
187 subjline
= hfield("subj", mp
);
191 curind
= dot
== mp
? '>' : ' ';
193 if (mp
->m_flag
& MSAVED
)
195 if (mp
->m_flag
& MPRESERVE
)
197 if ((mp
->m_flag
& (MREAD
|MNEW
)) == MNEW
)
199 if ((mp
->m_flag
& (MREAD
|MNEW
)) == 0)
201 if (mp
->m_flag
& MBOX
)
203 parse(headline
, &hl
, pbuf
);
204 sprintf(wcount
, "%3ld/%-5ld", mp
->m_lines
, mp
->m_size
);
205 subjlen
= screenwidth
- 50 - strlen(wcount
);
206 name
= value("show-rcpt") != NULL
?
207 skin(hfield("to", mp
)) : nameof(mp
, 0);
208 if (subjline
== NULL
|| subjlen
< 0) /* pretty pathetic */
209 printf("%c%c%3d %-20.20s %16.16s %s\n",
210 curind
, dispc
, mesg
, name
, hl
.l_date
, wcount
);
212 printf("%c%c%3d %-20.20s %16.16s %s \"%.*s\"\n",
213 curind
, dispc
, mesg
, name
, hl
.l_date
, wcount
,
218 * Print out the value of dot.
223 printf("%ld\n", (uintptr_t)dot
- (uintptr_t)&message
[0] + 1);
228 * Print out all the possible commands.
233 const struct cmd
*cp
;
236 printf("Commands are:\n");
237 for (cc
= 0, cp
= cmdtab
; cp
->c_name
!= NULL
; cp
++) {
238 cc
+= strlen(cp
->c_name
) + 2;
241 cc
= strlen(cp
->c_name
) + 2;
243 if ((cp
+1)->c_name
!= NULL
)
244 printf("%s, ", cp
->c_name
);
246 printf("%s\n", cp
->c_name
);
252 * Paginate messages, honor ignored fields.
259 return (type1(msgvec
, 1, 1));
263 * Paginate messages, even printing ignored fields.
270 return (type1(msgvec
, 0, 1));
274 * Type out messages, honor ignored fields.
281 return (type1(msgvec
, 1, 0));
285 * Type out messages, even printing ignored fields.
292 return (type1(msgvec
, 0, 0));
296 * Type out the messages requested.
300 type1(msgvec
, doign
, page
)
310 if (setjmp(pipestop
))
312 if (value("interactive") != NULL
&&
313 (page
|| (cp
= value("crt")) != NULL
)) {
316 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++)
317 nlines
+= message
[*ip
- 1].m_lines
;
319 if (page
|| nlines
> (*cp
? atoi(cp
) : realscreenheight
)) {
321 if (cp
== NULL
|| *cp
== '\0')
323 obuf
= Popen(cp
, "w");
328 (void)signal(SIGPIPE
, brokpipe
);
333 * Send messages to the output.
336 for (ip
= msgvec
; *ip
&& ip
- msgvec
< msgCount
; ip
++) {
337 mp
= &message
[*ip
- 1];
340 if (value("quiet") == NULL
)
341 fprintf(obuf
, "Message %d:\n", *ip
);
342 (void)sendmessage(mp
, obuf
, doign
? ignore
: 0, NULL
);
346 if (obuf
!= stdout
) {
348 * Ignore SIGPIPE so it can't cause a duplicate close.
350 (void)signal(SIGPIPE
, SIG_IGN
);
352 (void)signal(SIGPIPE
, SIG_DFL
);
358 * Respond to a broken pipe signal --
359 * probably caused by quitting more.
366 longjmp(pipestop
, 1);
370 * Print the top so many lines of each desired message.
371 * The number of lines is taken from the variable "toplines"
380 int c
, topl
, lines
, lineb
;
381 char *valtop
, linebuf
[LINESIZE
];
385 valtop
= value("toplines");
386 if (valtop
!= NULL
) {
388 if (topl
< 0 || topl
> 10000)
392 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
393 mp
= &message
[*ip
- 1];
396 if (value("quiet") == NULL
)
397 printf("Message %d:\n", *ip
);
402 for (lines
= 0; lines
< c
&& lines
<= topl
; lines
++) {
403 if (readline(ibuf
, linebuf
, sizeof(linebuf
)) < 0)
406 lineb
= strspn(linebuf
, " \t") == strlen(linebuf
);
413 * Touch all the given messages so that they will
422 for (ip
= msgvec
; *ip
!= 0; ip
++) {
423 dot
= &message
[*ip
-1];
424 dot
->m_flag
|= MTOUCH
;
425 dot
->m_flag
&= ~MPRESERVE
;
431 * Make sure all passed messages get mboxed.
439 for (ip
= msgvec
; *ip
!= 0; ip
++) {
440 dot
= &message
[*ip
-1];
441 dot
->m_flag
|= MTOUCH
|MBOX
;
442 dot
->m_flag
&= ~MPRESERVE
;
448 * List the folders the user currently has.
453 char dirname
[PATHSIZE
];
456 if (getfold(dirname
, sizeof(dirname
)) < 0) {
457 printf("No value set for \"folder\"\n");
460 if ((cmd
= value("LISTER")) == NULL
)
462 (void)run_command(cmd
, 0, -1, -1, dirname
, NULL
, NULL
);
467 * Update the mail file with any new messages that have
468 * come in since we started reading mail.
479 printf("No new mail.\n");
481 mdot
= newfileinfo(msgCount
- nmsg
);
482 dot
= &message
[mdot
- 1];
484 printf("\"inc\" command failed...\n");