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
41 #pragma ident "%Z%%M% %I% %E% SMI"
47 * mailx -- a modified version of a University of California at Berkeley
53 static char *stripquotes(char *str
);
56 * pipe messages to cmd.
62 register int *ip
, mesg
;
63 register struct message
*mp
;
65 int f
, *msgvec
, nowait
=0;
66 void (*sigint
)(int), (*sigpipe
)(int);
69 int page
, s
, pivec
[2];
72 extern jmp_buf pipestop
;
73 extern void brokpipe(int);
75 msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
76 if ((cmd
= stripquotes(snarf(str
, &f
, 0))) == NOSTR
) {
78 printf(gettext("pipe command error\n"));
81 if ( (cmd
= value("cmd")) == NOSTR
) {
82 printf(gettext("\"cmd\" not set, ignored.\n"));
87 *msgvec
= first(0, MMNORM
);
88 if (*msgvec
== NULL
) {
89 printf(gettext("No messages to pipe.\n"));
94 if (f
&& getmsglist(str
, msgvec
, 0) < 0)
96 if (*(cp
=cmd
+strlen(cmd
)-1)=='&') {
100 printf(gettext("Pipe to: \"%s\"\n"), cmd
);
103 if (setjmp(pipestop
))
106 if (pipe(pivec
) < 0) {
111 if ((pid
= vfork()) == 0) {
112 close(pivec
[1]); /* child */
116 if ((Shell
= value("SHELL")) == NOSTR
|| *Shell
=='\0')
118 execlp(Shell
, Shell
, "-c", cmd
, 0);
122 if (pid
== (pid_t
)-1) { /* error */
129 close(pivec
[0]); /* parent */
130 pio
=fdopen(pivec
[1],"w");
131 sigint
= sigset(SIGINT
, SIG_IGN
);
132 sigpipe
= sigset(SIGPIPE
, brokpipe
);
134 /* send all messages to cmd */
135 page
= (value("page")!=NOSTR
);
137 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
140 mp
= &message
[mesg
-1];
142 if ((t
= msend(mp
, pio
,
143 (value("alwaysignore") != NOSTR
||
144 value("pipeignore") != NOSTR
)
145 ? M_IGNORE
: 0, fputs
)) < 0) {
147 sigset(SIGPIPE
, sigpipe
);
148 sigset(SIGINT
, sigint
);
154 if (page
) putc('\f', pio
);
165 while (wait(&s
) != pid
);
171 printf("\"%s\" %ld/%ld\n", cmd
, lc
, cc
);
172 sigset(SIGPIPE
, sigpipe
);
173 sigset(SIGINT
, sigint
);
177 printf(gettext("Pipe to \"%s\" failed\n"), cmd
);
180 sigset(SIGPIPE
, sigpipe
);
181 sigset(SIGINT
, sigint
);
186 * Load the named message from the named file.
193 register int c
, lastc
= '\n';
201 msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
202 if ((file
= snarf(str
, &f
, 1)) == NOSTR
)
207 *msgvec
= first(0, MMNORM
);
208 if (*msgvec
== NULL
) {
209 printf(gettext("No message to load into.\n"));
214 if (f
&& getmsglist(str
, msgvec
, 0) < 0)
216 if (msgvec
[1] != NULL
) {
217 printf(gettext("Can only load into a single message.\n"));
220 if ((file
= expand(file
)) == NOSTR
)
222 printf("\"%s\" ", file
);
224 if ((ibuf
= fopen(file
, "r")) == NULL
) {
228 mp
= &message
[*msgvec
-1];
230 mp
->m_flag
|= MODIFY
;
231 mp
->m_flag
&= ~MSAVED
; /* should probably turn off more */
232 fseek(otf
, (long) 0, 2);
237 while ((c
= getc(ibuf
)) != EOF
) {
240 blank
= lastc
== '\n';
259 printf(gettext("[Loaded] %d/%ld\n"), lines
, ms
);
264 * Display the named field.
270 register struct message
*mp
;
271 register char *cp
, *fld
;
274 msgvec
= (int *) salloc((msgCount
+ 2) * sizeof *msgvec
);
275 if ((fld
= stripquotes(snarf(str
, &f
, 0))) == NOSTR
) {
277 printf(gettext("Bad field\n"));
279 printf(gettext("No field specified\n"));
283 *msgvec
= first(0, MMNORM
);
284 if (*msgvec
== NULL
) {
285 printf(gettext("No messages to display.\n"));
290 if (f
&& getmsglist(str
, msgvec
, 0) < 0)
293 for (ip
= msgvec
; *ip
&& ip
-msgvec
< msgCount
; ip
++) {
294 mp
= &message
[*ip
- 1];
296 if ((cp
= hfield(fld
, mp
, addone
)) != NULL
)
303 * Remove the quotes from around the string passed in (if any). Return
304 * the beginning of the result.
308 stripquotes(char *str
)
314 lastch
= strlen(str
)-1;
315 if (any(*str
, "\"'") && str
[lastch
] == *str
) {