4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1995 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
45 * mailx -- a modified version of a University of California at Berkeley
51 static char *stripquotes(char *str
);
54 * pipe messages to cmd.
60 register int *ip
, mesg
;
61 register struct message
*mp
;
63 int f
, *msgvec
, nowait
=0;
64 void (*sigint
)(int), (*sigpipe
)(int);
67 int page
, s
, pivec
[2];
70 extern jmp_buf pipestop
;
71 extern void brokpipe(int);
73 msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
74 if ((cmd
= stripquotes(snarf(str
, &f
, 0))) == NOSTR
) {
76 printf(gettext("pipe command error\n"));
79 if ( (cmd
= value("cmd")) == NOSTR
) {
80 printf(gettext("\"cmd\" not set, ignored.\n"));
85 *msgvec
= first(0, MMNORM
);
87 printf(gettext("No messages to pipe.\n"));
92 if (f
&& getmsglist(str
, msgvec
, 0) < 0)
94 if (*(cp
=cmd
+strlen(cmd
)-1)=='&') {
98 printf(gettext("Pipe to: \"%s\"\n"), cmd
);
101 if (setjmp(pipestop
))
104 if (pipe(pivec
) < 0) {
109 if ((pid
= vfork()) == 0) {
110 close(pivec
[1]); /* child */
114 if ((Shell
= value("SHELL")) == NOSTR
|| *Shell
=='\0')
116 execlp(Shell
, Shell
, "-c", cmd
, 0);
120 if (pid
== (pid_t
)-1) { /* error */
127 close(pivec
[0]); /* parent */
128 pio
=fdopen(pivec
[1],"w");
129 sigint
= sigset(SIGINT
, SIG_IGN
);
130 sigpipe
= sigset(SIGPIPE
, brokpipe
);
132 /* send all messages to cmd */
133 page
= (value("page")!=NOSTR
);
135 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
138 mp
= &message
[mesg
-1];
140 if ((t
= msend(mp
, pio
,
141 (value("alwaysignore") != NOSTR
||
142 value("pipeignore") != NOSTR
)
143 ? M_IGNORE
: 0, fputs
)) < 0) {
145 sigset(SIGPIPE
, sigpipe
);
146 sigset(SIGINT
, sigint
);
152 if (page
) putc('\f', pio
);
163 while (wait(&s
) != pid
);
169 printf("\"%s\" %ld/%ld\n", cmd
, lc
, cc
);
170 sigset(SIGPIPE
, sigpipe
);
171 sigset(SIGINT
, sigint
);
175 printf(gettext("Pipe to \"%s\" failed\n"), cmd
);
178 sigset(SIGPIPE
, sigpipe
);
179 sigset(SIGINT
, sigint
);
184 * Load the named message from the named file.
191 register int c
, lastc
= '\n';
199 msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
200 if ((file
= snarf(str
, &f
, 1)) == NOSTR
)
205 *msgvec
= first(0, MMNORM
);
207 printf(gettext("No message to load into.\n"));
212 if (f
&& getmsglist(str
, msgvec
, 0) < 0)
214 if (msgvec
[1] != 0) {
215 printf(gettext("Can only load into a single message.\n"));
218 if ((file
= expand(file
)) == NOSTR
)
220 printf("\"%s\" ", file
);
222 if ((ibuf
= fopen(file
, "r")) == NULL
) {
226 mp
= &message
[*msgvec
-1];
228 mp
->m_flag
|= MODIFY
;
229 mp
->m_flag
&= ~MSAVED
; /* should probably turn off more */
230 fseek(otf
, (long) 0, 2);
235 while ((c
= getc(ibuf
)) != EOF
) {
238 blank
= lastc
== '\n';
257 printf(gettext("[Loaded] %d/%ld\n"), lines
, ms
);
262 * Display the named field.
268 register struct message
*mp
;
269 register char *cp
, *fld
;
272 msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
273 if ((fld
= stripquotes(snarf(str
, &f
, 0))) == NOSTR
) {
275 printf(gettext("Bad field\n"));
277 printf(gettext("No field specified\n"));
281 *msgvec
= first(0, MMNORM
);
283 printf(gettext("No messages to display.\n"));
288 if (f
&& getmsglist(str
, msgvec
, 0) < 0)
291 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
292 mp
= &message
[*ip
- 1];
294 if ((cp
= hfield(fld
, mp
, addone
)) != NULL
)
301 * Remove the quotes from around the string passed in (if any). Return
302 * the beginning of the result.
306 stripquotes(char *str
)
312 lastch
= strlen(str
)-1;
313 if (any(*str
, "\"'") && str
[lastch
] == *str
) {