19b50d902SRodney W. Grimes /* 29b50d902SRodney W. Grimes * Copyright (c) 1980, 1993 39b50d902SRodney W. Grimes * The Regents of the University of California. All rights reserved. 49b50d902SRodney W. Grimes * 59b50d902SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 69b50d902SRodney W. Grimes * modification, are permitted provided that the following conditions 79b50d902SRodney W. Grimes * are met: 89b50d902SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 99b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 109b50d902SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 119b50d902SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 129b50d902SRodney W. Grimes * documentation and/or other materials provided with the distribution. 139b50d902SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 149b50d902SRodney W. Grimes * must display the following acknowledgement: 159b50d902SRodney W. Grimes * This product includes software developed by the University of 169b50d902SRodney W. Grimes * California, Berkeley and its contributors. 179b50d902SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 189b50d902SRodney W. Grimes * may be used to endorse or promote products derived from this software 199b50d902SRodney W. Grimes * without specific prior written permission. 209b50d902SRodney W. Grimes * 219b50d902SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 229b50d902SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 239b50d902SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 249b50d902SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 259b50d902SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 269b50d902SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 279b50d902SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 289b50d902SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 299b50d902SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 309b50d902SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 319b50d902SRodney W. Grimes * SUCH DAMAGE. 329b50d902SRodney W. Grimes */ 339b50d902SRodney W. Grimes 349b50d902SRodney W. Grimes #ifndef lint 359b50d902SRodney W. Grimes static char copyright[] = 369b50d902SRodney W. Grimes "@(#) Copyright (c) 1980, 1993\n\ 379b50d902SRodney W. Grimes The Regents of the University of California. All rights reserved.\n"; 389b50d902SRodney W. Grimes #endif /* not lint */ 399b50d902SRodney W. Grimes 409b50d902SRodney W. Grimes #ifndef lint 410c3a8314SMike Heffner #if 0 429b50d902SRodney W. Grimes static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; 430c3a8314SMike Heffner #endif 440c3a8314SMike Heffner static const char rcsid[] = 450c3a8314SMike Heffner "$FreeBSD$"; 469b50d902SRodney W. Grimes #endif /* not lint */ 479b50d902SRodney W. Grimes 489b50d902SRodney W. Grimes #include "rcv.h" 499b50d902SRodney W. Grimes #include <fcntl.h> 509b50d902SRodney W. Grimes #include "extern.h" 519b50d902SRodney W. Grimes 529b50d902SRodney W. Grimes /* 539b50d902SRodney W. Grimes * Mail -- a mail program 549b50d902SRodney W. Grimes * 559b50d902SRodney W. Grimes * Startup -- interface with user. 569b50d902SRodney W. Grimes */ 579b50d902SRodney W. Grimes 589b50d902SRodney W. Grimes jmp_buf hdrjmp; 599b50d902SRodney W. Grimes 609ce73e90SMike Heffner extern const char *version; 619ce73e90SMike Heffner 629b50d902SRodney W. Grimes int 639b50d902SRodney W. Grimes main(argc, argv) 649b50d902SRodney W. Grimes int argc; 659b50d902SRodney W. Grimes char *argv[]; 669b50d902SRodney W. Grimes { 679ce73e90SMike Heffner int i; 689b50d902SRodney W. Grimes struct name *to, *cc, *bcc, *smopts; 6999bd6601SJoerg Wunsch char *subject, *replyto; 707309915eSDima Dorfman char *ef; 719b50d902SRodney W. Grimes char nosrc = 0; 729b50d902SRodney W. Grimes sig_t prevint; 739b50d902SRodney W. Grimes 749b50d902SRodney W. Grimes /* 759b50d902SRodney W. Grimes * Set up a reasonable environment. 769b50d902SRodney W. Grimes * Figure out whether we are being run interactively, 779b50d902SRodney W. Grimes * start the SIGCHLD catcher, and so forth. 789b50d902SRodney W. Grimes */ 799b50d902SRodney W. Grimes (void)signal(SIGCHLD, sigchild); 809b50d902SRodney W. Grimes if (isatty(0)) 819b50d902SRodney W. Grimes assign("interactive", ""); 829b50d902SRodney W. Grimes image = -1; 839b50d902SRodney W. Grimes /* 849b50d902SRodney W. Grimes * Now, determine how we are being used. 859b50d902SRodney W. Grimes * We successively pick off - flags. 869b50d902SRodney W. Grimes * If there is anything left, it is the base of the list 879b50d902SRodney W. Grimes * of users to mail to. Argp will be set to point to the 889b50d902SRodney W. Grimes * first of these users. 899b50d902SRodney W. Grimes */ 909ce73e90SMike Heffner ef = NULL; 919ce73e90SMike Heffner to = NULL; 929ce73e90SMike Heffner cc = NULL; 939ce73e90SMike Heffner bcc = NULL; 949ce73e90SMike Heffner smopts = NULL; 959ce73e90SMike Heffner subject = NULL; 96dcd24e27SMike Heffner while ((i = getopt(argc, argv, "EINT:b:c:dfins:u:v")) != -1) { 979b50d902SRodney W. Grimes switch (i) { 989b50d902SRodney W. Grimes case 'T': 999b50d902SRodney W. Grimes /* 1009b50d902SRodney W. Grimes * Next argument is temp file to write which 1019b50d902SRodney W. Grimes * articles have been read/deleted for netnews. 1029b50d902SRodney W. Grimes */ 1039b50d902SRodney W. Grimes Tflag = optarg; 1040c3a8314SMike Heffner if ((i = open(Tflag, O_CREAT | O_TRUNC | O_WRONLY, 1050c3a8314SMike Heffner 0600)) < 0) 1060c3a8314SMike Heffner err(1, "%s", Tflag); 1079ce73e90SMike Heffner (void)close(i); 1089b50d902SRodney W. Grimes break; 1099b50d902SRodney W. Grimes case 'u': 1109b50d902SRodney W. Grimes /* 1119b50d902SRodney W. Grimes * Next argument is person to pretend to be. 1129b50d902SRodney W. Grimes */ 1139b50d902SRodney W. Grimes myname = optarg; 11449936df3SJean-Marc Zucconi unsetenv("MAIL"); 1159b50d902SRodney W. Grimes break; 1169b50d902SRodney W. Grimes case 'i': 1179b50d902SRodney W. Grimes /* 1189b50d902SRodney W. Grimes * User wants to ignore interrupts. 1199b50d902SRodney W. Grimes * Set the variable "ignore" 1209b50d902SRodney W. Grimes */ 1219b50d902SRodney W. Grimes assign("ignore", ""); 1229b50d902SRodney W. Grimes break; 1239b50d902SRodney W. Grimes case 'd': 1249b50d902SRodney W. Grimes debug++; 1259b50d902SRodney W. Grimes break; 1269b50d902SRodney W. Grimes case 's': 1279b50d902SRodney W. Grimes /* 1289b50d902SRodney W. Grimes * Give a subject field for sending from 1299b50d902SRodney W. Grimes * non terminal 1309b50d902SRodney W. Grimes */ 1319b50d902SRodney W. Grimes subject = optarg; 1329b50d902SRodney W. Grimes break; 1339b50d902SRodney W. Grimes case 'f': 1349b50d902SRodney W. Grimes /* 1359b50d902SRodney W. Grimes * User is specifying file to "edit" with Mail, 1369b50d902SRodney W. Grimes * as opposed to reading system mailbox. 1379b50d902SRodney W. Grimes * If no argument is given after -f, we read his 1389b50d902SRodney W. Grimes * mbox file. 1399b50d902SRodney W. Grimes * 1409b50d902SRodney W. Grimes * getopt() can't handle optional arguments, so here 1419b50d902SRodney W. Grimes * is an ugly hack to get around it. 1429b50d902SRodney W. Grimes */ 1439ce73e90SMike Heffner if ((argv[optind] != NULL) && (argv[optind][0] != '-')) 1449b50d902SRodney W. Grimes ef = argv[optind++]; 1459b50d902SRodney W. Grimes else 1469b50d902SRodney W. Grimes ef = "&"; 1479b50d902SRodney W. Grimes break; 1489b50d902SRodney W. Grimes case 'n': 1499b50d902SRodney W. Grimes /* 1509b50d902SRodney W. Grimes * User doesn't want to source /usr/lib/Mail.rc 1519b50d902SRodney W. Grimes */ 1529b50d902SRodney W. Grimes nosrc++; 1539b50d902SRodney W. Grimes break; 1549b50d902SRodney W. Grimes case 'N': 1559b50d902SRodney W. Grimes /* 1569b50d902SRodney W. Grimes * Avoid initial header printing. 1579b50d902SRodney W. Grimes */ 1589b50d902SRodney W. Grimes assign("noheader", ""); 1599b50d902SRodney W. Grimes break; 1609b50d902SRodney W. Grimes case 'v': 1619b50d902SRodney W. Grimes /* 1629b50d902SRodney W. Grimes * Send mailer verbose flag 1639b50d902SRodney W. Grimes */ 1649b50d902SRodney W. Grimes assign("verbose", ""); 1659b50d902SRodney W. Grimes break; 1669b50d902SRodney W. Grimes case 'I': 1679b50d902SRodney W. Grimes /* 1689b50d902SRodney W. Grimes * We're interactive 1699b50d902SRodney W. Grimes */ 1709b50d902SRodney W. Grimes assign("interactive", ""); 1719b50d902SRodney W. Grimes break; 1729b50d902SRodney W. Grimes case 'c': 1739b50d902SRodney W. Grimes /* 1749b50d902SRodney W. Grimes * Get Carbon Copy Recipient list 1759b50d902SRodney W. Grimes */ 1769b50d902SRodney W. Grimes cc = cat(cc, nalloc(optarg, GCC)); 1779b50d902SRodney W. Grimes break; 1789b50d902SRodney W. Grimes case 'b': 1799b50d902SRodney W. Grimes /* 1809b50d902SRodney W. Grimes * Get Blind Carbon Copy Recipient list 1819b50d902SRodney W. Grimes */ 1829b50d902SRodney W. Grimes bcc = cat(bcc, nalloc(optarg, GBCC)); 1839b50d902SRodney W. Grimes break; 184dcd24e27SMike Heffner case 'E': 185dcd24e27SMike Heffner /* 186dcd24e27SMike Heffner * Don't send empty files. 187dcd24e27SMike Heffner */ 188dcd24e27SMike Heffner assign("dontsendempty", ""); 189dcd24e27SMike Heffner break; 1909b50d902SRodney W. Grimes case '?': 1910c3a8314SMike Heffner fprintf(stderr, "\ 192dcd24e27SMike Heffner Usage: %s [-EiInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\ 1930c3a8314SMike Heffner %*s [- sendmail-options ...]\n\ 194dcd24e27SMike Heffner %s [-EiInNv] -f [name]\n\ 195dcd24e27SMike Heffner %s [-EiInNv] [-u user]\n",__progname, strlen(__progname), "", 196dcd24e27SMike Heffner __progname, __progname); 1979b50d902SRodney W. Grimes exit(1); 1989b50d902SRodney W. Grimes } 1999b50d902SRodney W. Grimes } 2009ce73e90SMike Heffner for (i = optind; (argv[i] != NULL) && (*argv[i] != '-'); i++) 2019b50d902SRodney W. Grimes to = cat(to, nalloc(argv[i], GTO)); 2029ce73e90SMike Heffner for (; argv[i] != NULL; i++) 2039b50d902SRodney W. Grimes smopts = cat(smopts, nalloc(argv[i], 0)); 2049b50d902SRodney W. Grimes /* 2059b50d902SRodney W. Grimes * Check for inconsistent arguments. 2069b50d902SRodney W. Grimes */ 2079ce73e90SMike Heffner if (to == NULL && (subject != NULL || cc != NULL || bcc != NULL)) 2080c3a8314SMike Heffner errx(1, "You must specify direct recipients with -s, -c, or -b."); 2099ce73e90SMike Heffner if (ef != NULL && to != NULL) 2100c3a8314SMike Heffner errx(1, "Cannot give -f and people to send to."); 2119b50d902SRodney W. Grimes tinit(); 2129b50d902SRodney W. Grimes setscreensize(); 2139b50d902SRodney W. Grimes input = stdin; 2149b50d902SRodney W. Grimes rcvmode = !to; 2159b50d902SRodney W. Grimes spreserve(); 216e9b074c3SJordan K. Hubbard if (!nosrc) { 217e9b074c3SJordan K. Hubbard char *s, *path_rc; 218e9b074c3SJordan K. Hubbard 2190c3a8314SMike Heffner if ((path_rc = malloc(sizeof(_PATH_MASTER_RC))) == NULL) 2200c3a8314SMike Heffner err(1, "malloc(path_rc) failed"); 221e9b074c3SJordan K. Hubbard 222e9b074c3SJordan K. Hubbard strcpy(path_rc, _PATH_MASTER_RC); 223e9b074c3SJordan K. Hubbard while ((s = strsep(&path_rc, ":")) != NULL) 224e9b074c3SJordan K. Hubbard if (*s != '\0') 225e9b074c3SJordan K. Hubbard load(s); 226e9b074c3SJordan K. Hubbard } 2279b50d902SRodney W. Grimes /* 2289b50d902SRodney W. Grimes * Expand returns a savestr, but load only uses the file name 2299b50d902SRodney W. Grimes * for fopen, so it's safe to do this. 2309b50d902SRodney W. Grimes */ 2319b50d902SRodney W. Grimes load(expand("~/.mailrc")); 23259c3f4f7SMike Heffner 23359c3f4f7SMike Heffner replyto = value("REPLYTO"); 2349b50d902SRodney W. Grimes if (!rcvmode) { 23599bd6601SJoerg Wunsch mail(to, cc, bcc, smopts, subject, replyto); 2369b50d902SRodney W. Grimes /* 2379b50d902SRodney W. Grimes * why wait? 2389b50d902SRodney W. Grimes */ 2399b50d902SRodney W. Grimes exit(senderr); 2409b50d902SRodney W. Grimes } 2419b50d902SRodney W. Grimes /* 2429b50d902SRodney W. Grimes * Ok, we are reading mail. 2439b50d902SRodney W. Grimes * Decide whether we are editing a mailbox or reading 2449b50d902SRodney W. Grimes * the system mailbox, and open up the right stuff. 2459b50d902SRodney W. Grimes */ 2469ce73e90SMike Heffner if (ef == NULL) 2479b50d902SRodney W. Grimes ef = "%"; 2489b50d902SRodney W. Grimes if (setfile(ef) < 0) 2499b50d902SRodney W. Grimes exit(1); /* error already reported */ 2509b50d902SRodney W. Grimes if (setjmp(hdrjmp) == 0) { 2519b50d902SRodney W. Grimes if ((prevint = signal(SIGINT, SIG_IGN)) != SIG_IGN) 2529ce73e90SMike Heffner (void)signal(SIGINT, hdrstop); 2539ce73e90SMike Heffner if (value("quiet") == NULL) 2549b50d902SRodney W. Grimes printf("Mail version %s. Type ? for help.\n", 2559b50d902SRodney W. Grimes version); 2569b50d902SRodney W. Grimes announce(); 2579ce73e90SMike Heffner (void)fflush(stdout); 2589ce73e90SMike Heffner (void)signal(SIGINT, prevint); 2599b50d902SRodney W. Grimes } 2609b50d902SRodney W. Grimes commands(); 2619ce73e90SMike Heffner (void)signal(SIGHUP, SIG_IGN); 2629ce73e90SMike Heffner (void)signal(SIGINT, SIG_IGN); 2639ce73e90SMike Heffner (void)signal(SIGQUIT, SIG_IGN); 2649b50d902SRodney W. Grimes quit(); 2659b50d902SRodney W. Grimes exit(0); 2669b50d902SRodney W. Grimes } 2679b50d902SRodney W. Grimes 2689b50d902SRodney W. Grimes /* 2699b50d902SRodney W. Grimes * Interrupt printing of the headers. 2709b50d902SRodney W. Grimes */ 2719ce73e90SMike Heffner /*ARGSUSED*/ 2729b50d902SRodney W. Grimes void 2739b50d902SRodney W. Grimes hdrstop(signo) 2749b50d902SRodney W. Grimes int signo; 2759b50d902SRodney W. Grimes { 2769b50d902SRodney W. Grimes 2779ce73e90SMike Heffner (void)fflush(stdout); 2789b50d902SRodney W. Grimes fprintf(stderr, "\nInterrupt\n"); 2799b50d902SRodney W. Grimes longjmp(hdrjmp, 1); 2809b50d902SRodney W. Grimes } 2819b50d902SRodney W. Grimes 2829b50d902SRodney W. Grimes /* 2839b50d902SRodney W. Grimes * Compute what the screen size for printing headers should be. 2849b50d902SRodney W. Grimes * We use the following algorithm for the height: 2859b50d902SRodney W. Grimes * If baud rate < 1200, use 9 2869b50d902SRodney W. Grimes * If baud rate = 1200, use 14 2879b50d902SRodney W. Grimes * If baud rate > 1200, use 24 or ws_row 2889b50d902SRodney W. Grimes * Width is either 80 or ws_col; 2899b50d902SRodney W. Grimes */ 2909b50d902SRodney W. Grimes void 2919b50d902SRodney W. Grimes setscreensize() 2929b50d902SRodney W. Grimes { 2939b50d902SRodney W. Grimes struct winsize ws; 2947c6d202aSPeter Wemm struct termios tio; 2957c6d202aSPeter Wemm speed_t speed = 0; 2969b50d902SRodney W. Grimes 2979b50d902SRodney W. Grimes if (ioctl(1, TIOCGWINSZ, (char *)&ws) < 0) 2989b50d902SRodney W. Grimes ws.ws_col = ws.ws_row = 0; 2997c6d202aSPeter Wemm if (tcgetattr(1, &tio) != -1) 3007c6d202aSPeter Wemm speed = cfgetospeed(&tio); 3017c6d202aSPeter Wemm if (speed <= 0) 3027c6d202aSPeter Wemm speed = B9600; 3037c6d202aSPeter Wemm if (speed < B1200) 3049b50d902SRodney W. Grimes screenheight = 9; 3057c6d202aSPeter Wemm else if (speed == B1200) 3069b50d902SRodney W. Grimes screenheight = 14; 3079b50d902SRodney W. Grimes else if (ws.ws_row != 0) 3089b50d902SRodney W. Grimes screenheight = ws.ws_row; 3099b50d902SRodney W. Grimes else 3109b50d902SRodney W. Grimes screenheight = 24; 3119b50d902SRodney W. Grimes if ((realscreenheight = ws.ws_row) == 0) 3129b50d902SRodney W. Grimes realscreenheight = 24; 3139b50d902SRodney W. Grimes if ((screenwidth = ws.ws_col) == 0) 3149b50d902SRodney W. Grimes screenwidth = 80; 3159b50d902SRodney W. Grimes } 316