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
35 static char copyright
[] =
36 "@(#) Copyright (c) 1980, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
42 static char sccsid
[] = "@(#)main.c 8.2 (Berkeley) 4/20/95";
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
53 * Mail -- a mail program
55 * Startup -- interface with user.
58 static jmp_buf hdrjmp
;
60 extern const char *version
;
68 struct name
*to
, *cc
, *bcc
, *smopts
;
69 char *subject
, *replyto
;
75 * Set up a reasonable environment.
76 * Figure out whether we are being run interactively,
77 * start the SIGCHLD catcher, and so forth.
79 (void)signal(SIGCHLD
, sigchild
);
81 assign("interactive", "");
84 * Now, determine how we are being used.
85 * We successively pick off - flags.
86 * If there is anything left, it is the base of the list
87 * of users to mail to. Argp will be set to point to the
88 * first of these users.
96 while ((i
= getopt(argc
, argv
, "FEHINT:b:c:edfins:u:v")) != -1) {
100 * Next argument is temp file to write which
101 * articles have been read/deleted for netnews.
104 if ((i
= open(Tflag
, O_CREAT
| O_TRUNC
| O_WRONLY
,
111 * Next argument is person to pretend to be.
118 * User wants to ignore interrupts.
119 * Set the variable "ignore"
121 assign("ignore", "");
128 * User wants to check mail and exit.
130 assign("checkmode", "");
134 * User wants a header summary only.
136 assign("headersummary", "");
140 * User wants to record messages to files
141 * named after first recipient username.
143 assign("recordrecip", "");
147 * Give a subject field for sending from
154 * User is specifying file to "edit" with Mail,
155 * as opposed to reading system mailbox.
156 * If no argument is given after -f, we read his
159 * getopt() can't handle optional arguments, so here
160 * is an ugly hack to get around it.
162 if ((argv
[optind
] != NULL
) && (argv
[optind
][0] != '-'))
169 * User doesn't want to source /usr/lib/Mail.rc
175 * Avoid initial header printing.
177 assign("noheader", "");
181 * Send mailer verbose flag
183 assign("verbose", "");
189 assign("interactive", "");
193 * Get Carbon Copy Recipient list
195 cc
= cat(cc
, nalloc(optarg
, GCC
));
199 * Get Blind Carbon Copy Recipient list
201 bcc
= cat(bcc
, nalloc(optarg
, GBCC
));
205 * Don't send empty files.
207 assign("dontsendempty", "");
211 Usage: %s [-dEiInv] [-s subject] [-c cc-addr] [-b bcc-addr] [-F] to-addr ...\n\
212 %*s [-sendmail-option ...]\n\
213 %s [-dEHiInNv] [-F] -f [name]\n\
214 %s [-dEHiInNv] [-F] [-u user]\n\
215 %s [-d] -e [-f name]\n", __progname
, strlen(__progname
), "",
216 __progname
, __progname
, __progname
);
220 for (i
= optind
; (argv
[i
] != NULL
) && (*argv
[i
] != '-'); i
++)
221 to
= cat(to
, nalloc(argv
[i
], GTO
));
222 for (; argv
[i
] != NULL
; i
++)
223 smopts
= cat(smopts
, nalloc(argv
[i
], 0));
225 * Check for inconsistent arguments.
227 if (to
== NULL
&& (subject
!= NULL
|| cc
!= NULL
|| bcc
!= NULL
))
228 errx(1, "You must specify direct recipients with -s, -c, or -b.");
229 if (ef
!= NULL
&& to
!= NULL
)
230 errx(1, "Cannot give -f and people to send to.");
239 if ((path_rc
= malloc(sizeof(_PATH_MASTER_RC
))) == NULL
)
240 err(1, "malloc(path_rc) failed");
242 strcpy(path_rc
, _PATH_MASTER_RC
);
243 while ((s
= strsep(&path_rc
, ":")) != NULL
)
248 * Expand returns a savestr, but load only uses the file name
249 * for fopen, so it's safe to do this.
251 if ((rc
= getenv("MAILRC")) == NULL
)
255 replyto
= value("REPLYTO");
257 mail(to
, cc
, bcc
, smopts
, subject
, replyto
);
264 if(value("checkmode") != NULL
) {
267 if (setfile(ef
) <= 0)
268 /* Either an error has occured, or no mail */
276 * Ok, we are reading mail.
277 * Decide whether we are editing a mailbox or reading
278 * the system mailbox, and open up the right stuff.
283 exit(1); /* error already reported */
284 if (setjmp(hdrjmp
) == 0) {
285 if ((prevint
= signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
286 (void)signal(SIGINT
, hdrstop
);
287 if (value("quiet") == NULL
)
288 printf("Mail version %s. Type ? for help.\n",
291 (void)fflush(stdout
);
292 (void)signal(SIGINT
, prevint
);
295 /* If we were in header summary mode, it's time to exit. */
296 if (value("headersummary") != NULL
)
300 (void)signal(SIGHUP
, SIG_IGN
);
301 (void)signal(SIGINT
, SIG_IGN
);
302 (void)signal(SIGQUIT
, SIG_IGN
);
308 * Interrupt printing of the headers.
316 (void)fflush(stdout
);
317 fprintf(stderr
, "\nInterrupt\n");
322 * Compute what the screen size for printing headers should be.
323 * We use the following algorithm for the height:
324 * If baud rate < 1200, use 9
325 * If baud rate = 1200, use 14
326 * If baud rate > 1200, use 24 or ws_row
327 * Width is either 80 or ws_col;
336 if (ioctl(1, TIOCGWINSZ
, (char *)&ws
) < 0)
337 ws
.ws_col
= ws
.ws_row
= 0;
338 if (tcgetattr(1, &tbuf
) < 0)
341 speed
= cfgetospeed(&tbuf
);
344 else if (speed
== B1200
)
346 else if (ws
.ws_row
!= 0)
347 screenheight
= ws
.ws_row
;
350 if ((realscreenheight
= ws
.ws_row
) == 0)
351 realscreenheight
= 24;
352 if ((screenwidth
= ws
.ws_col
) == 0)