17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*8e472857Sny155746 * Common Development and Distribution License (the "License"). 6*8e472857Sny155746 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 227c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 237c478bd9Sstevel@tonic-gate 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate /* 26*8e472857Sny155746 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include "mail.h" 33*8e472857Sny155746 #include <sys/param.h> 347c478bd9Sstevel@tonic-gate /* 35*8e472857Sny155746 * Send mail - High level sending routine 367c478bd9Sstevel@tonic-gate */ 37*8e472857Sny155746 void 38*8e472857Sny155746 sendmail(argc, argv) 397c478bd9Sstevel@tonic-gate char **argv; 407c478bd9Sstevel@tonic-gate { 417c478bd9Sstevel@tonic-gate char **args; 427c478bd9Sstevel@tonic-gate char *tp, *zp; 437c478bd9Sstevel@tonic-gate char buf[2048], last1c; 447c478bd9Sstevel@tonic-gate FILE *input; 45*8e472857Sny155746 struct stat64 sbuf; 467c478bd9Sstevel@tonic-gate int aret; 477c478bd9Sstevel@tonic-gate int i, n; 487c478bd9Sstevel@tonic-gate int oldn = 1; 497c478bd9Sstevel@tonic-gate int ttyf = 0; 507c478bd9Sstevel@tonic-gate int pushrest = 0; 517c478bd9Sstevel@tonic-gate int hdrtyp = 0; 527c478bd9Sstevel@tonic-gate int ctf = FALSE; 537c478bd9Sstevel@tonic-gate int binflg = 0; 547c478bd9Sstevel@tonic-gate long count = 0L; 557c478bd9Sstevel@tonic-gate struct tm *bp; 567c478bd9Sstevel@tonic-gate struct hdrs *hptr; 577c478bd9Sstevel@tonic-gate static char pn[] = "sendmail"; 587c478bd9Sstevel@tonic-gate reciplist list; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate Dout(pn, 0, "entered\n"); 617c478bd9Sstevel@tonic-gate new_reciplist(&list); 627c478bd9Sstevel@tonic-gate for (i = 1; i < argc; ++i) { 637c478bd9Sstevel@tonic-gate if (argv[i][0] == '-') { 647c478bd9Sstevel@tonic-gate if (argv[i][1] == '\0') { 65*8e472857Sny155746 errmsg(E_SYNTAX, 66*8e472857Sny155746 "Hyphens MAY NOT be followed by spaces"); 677c478bd9Sstevel@tonic-gate } 687c478bd9Sstevel@tonic-gate if (i > 1) { 69*8e472857Sny155746 errmsg(E_SYNTAX, 70*8e472857Sny155746 "Options MUST PRECEDE persons"); 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate done(0); 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate /* 75*8e472857Sny155746 * Ensure no NULL names in list 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate if (argv[i][0] == '\0' || argv[i][strlen(argv[i])-1] == '!') { 787c478bd9Sstevel@tonic-gate errmsg(E_SYNTAX, "Null names are not allowed"); 797c478bd9Sstevel@tonic-gate done(0); 807c478bd9Sstevel@tonic-gate } 81*8e472857Sny155746 /* Don't check for duplication */ 82*8e472857Sny155746 add_recip(&list, argv[i], FALSE); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate mktmp(); 867c478bd9Sstevel@tonic-gate /* 87*8e472857Sny155746 * Format time 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate time(&iop); 907c478bd9Sstevel@tonic-gate bp = localtime(&iop); 917c478bd9Sstevel@tonic-gate tp = asctime(bp); 927c478bd9Sstevel@tonic-gate zp = tzname[bp->tm_isdst]; 937c478bd9Sstevel@tonic-gate sprintf(datestring, "%.16s %.3s %.5s", tp, zp, tp+20); 947c478bd9Sstevel@tonic-gate trimnl(datestring); 957c478bd9Sstevel@tonic-gate /* asctime: Fri Sep 30 00:00:00 1986\n */ 967c478bd9Sstevel@tonic-gate /* 0123456789012345678901234 */ 977c478bd9Sstevel@tonic-gate /* RFCtime: Fri, 28 Jul 89 10:30 EDT */ 987c478bd9Sstevel@tonic-gate sprintf(RFC822datestring, "%.3s, %.2s %.3s %.4s %.5s %.3s", 997c478bd9Sstevel@tonic-gate tp, tp+8, tp+4, tp+20, tp+11, zp); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* 102*8e472857Sny155746 * Write out the from line header for the letter 1037c478bd9Sstevel@tonic-gate */ 1047c478bd9Sstevel@tonic-gate if (fromflag && deliverflag && from_user[0] != '\0') { 1057c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s%s %s\n", 1067c478bd9Sstevel@tonic-gate header[H_FROM].tag, from_user, datestring); 1077c478bd9Sstevel@tonic-gate } else { 1087c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s%s %s\n", 1097c478bd9Sstevel@tonic-gate header[H_FROM].tag, my_name, datestring); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate if (!wtmpf(buf, strlen(buf))) { 1127c478bd9Sstevel@tonic-gate done(0); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate savehdrs(buf, H_FROM); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 117*8e472857Sny155746 * Copy to list in mail entry? 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate if (flgt == 1 && argc > 1) { 1207c478bd9Sstevel@tonic-gate aret = argc; 1217c478bd9Sstevel@tonic-gate args = argv; 1227c478bd9Sstevel@tonic-gate while (--aret > 0) { 123*8e472857Sny155746 (void) snprintf(buf, sizeof (buf), 124*8e472857Sny155746 "%s %s\n", header[H_TO].tag, *++args); 1257c478bd9Sstevel@tonic-gate if (!wtmpf(buf, strlen(buf))) { 1267c478bd9Sstevel@tonic-gate done(0); 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate savehdrs(buf, H_TO); 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate flgf = 1; /* reset when first read of message body succeeds */ 1337c478bd9Sstevel@tonic-gate /* 134*8e472857Sny155746 * Read mail message, allowing for lines of infinite 135*8e472857Sny155746 * length. This is tricky, have to watch for newlines. 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate saveint = setsig(SIGINT, savdead); 1387c478bd9Sstevel@tonic-gate last1c = ' '; /* anything other than newline */ 1397c478bd9Sstevel@tonic-gate ttyf = isatty(fileno(stdin)); 1407c478bd9Sstevel@tonic-gate pushrest = 0; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* 1437c478bd9Sstevel@tonic-gate * scan header & save relevant info. 1447c478bd9Sstevel@tonic-gate */ 1457c478bd9Sstevel@tonic-gate (void) strlcpy(fromU, my_name, sizeof (fromU)); 1467c478bd9Sstevel@tonic-gate fromS[0] = 0; /* set up for >From scan */ 1477c478bd9Sstevel@tonic-gate input = stdin; 148*8e472857Sny155746 /* 149*8e472857Sny155746 * Fifofs cannot handle if the inode number crosses 150*8e472857Sny155746 * 32-bit limit. This results in overflow, if the 151*8e472857Sny155746 * input steam is a pipe. Using 64-bit interface to 152*8e472857Sny155746 * take care of that. 153*8e472857Sny155746 */ 154*8e472857Sny155746 if (fstat64(fileno(input), &sbuf) == 0) { 155*8e472857Sny155746 /* Also care if we could not handle large mail. */ 156*8e472857Sny155746 if ((sbuf.st_size > MAXOFF_T) || (sbuf.st_blocks > LONG_MAX)) { 157*8e472857Sny155746 fprintf(stderr, "%s: stdin: %s\n", program, 158*8e472857Sny155746 strerror(EOVERFLOW)); 1597c478bd9Sstevel@tonic-gate exit(1); 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate 163*8e472857Sny155746 while ((n = getline(line, sizeof (line), stdin)) > 0) { 1647c478bd9Sstevel@tonic-gate last1c = line[n-1]; 1657c478bd9Sstevel@tonic-gate if (pushrest) { 1667c478bd9Sstevel@tonic-gate if (!wtmpf(line, n)) { 1677c478bd9Sstevel@tonic-gate done(0); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate pushrest = (last1c != '\n'); 1707c478bd9Sstevel@tonic-gate continue; 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate pushrest = (last1c != '\n'); 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate if ((hdrtyp = isheader(line, &ctf)) == FALSE) { 1757c478bd9Sstevel@tonic-gate break; 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate flgf = 0; 1787c478bd9Sstevel@tonic-gate switch (hdrtyp) { 1797c478bd9Sstevel@tonic-gate case H_RVERS: 1807c478bd9Sstevel@tonic-gate /* Are we dealing with a delivery report? */ 1817c478bd9Sstevel@tonic-gate /* dflag = 9 ==> do not return on failure */ 1827c478bd9Sstevel@tonic-gate dflag = 9; 1837c478bd9Sstevel@tonic-gate Dout(pn, 0, "dflag = 9\n"); 1847c478bd9Sstevel@tonic-gate break; 1857c478bd9Sstevel@tonic-gate case H_FROM: 1867c478bd9Sstevel@tonic-gate if (!wtmpf(">", 1)) { 1877c478bd9Sstevel@tonic-gate done(0); 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate /* note dropthru */ 1907c478bd9Sstevel@tonic-gate hdrtyp = H_FROM1; 1917c478bd9Sstevel@tonic-gate case H_FROM1: 1927c478bd9Sstevel@tonic-gate if (substr(line, "forwarded by") > -1) { 1937c478bd9Sstevel@tonic-gate break; 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate pickFrom(line); 1967c478bd9Sstevel@tonic-gate if (Rpath[0] != '\0') { 1977c478bd9Sstevel@tonic-gate strcat(Rpath, "!"); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate (void) strlcat(Rpath, fromS, sizeof (Rpath)); 2007c478bd9Sstevel@tonic-gate n = 0; /* don't copy remote from's into mesg. */ 2017c478bd9Sstevel@tonic-gate break; 2027c478bd9Sstevel@tonic-gate case H_MIMEVERS: 2037c478bd9Sstevel@tonic-gate case H_CLEN: 2047c478bd9Sstevel@tonic-gate case H_CTYPE: 2057c478bd9Sstevel@tonic-gate /* suppress it: only generated if needed */ 2067c478bd9Sstevel@tonic-gate n = 0; /* suppress */ 2077c478bd9Sstevel@tonic-gate break; 2087c478bd9Sstevel@tonic-gate case H_TCOPY: 2097c478bd9Sstevel@tonic-gate /* Write out placeholder for later */ 210*8e472857Sny155746 (void) snprintf(buf, sizeof (buf), "%s \n", 211*8e472857Sny155746 header[H_TCOPY].tag); 2127c478bd9Sstevel@tonic-gate if (!wtmpf(buf, strlen(buf))) { 2137c478bd9Sstevel@tonic-gate done(0); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate n = 0; /* suppress */ 2167c478bd9Sstevel@tonic-gate break; 2177c478bd9Sstevel@tonic-gate case H_MTYPE: 2187c478bd9Sstevel@tonic-gate if (flgm) { 2197c478bd9Sstevel@tonic-gate /* suppress if message-type argument */ 2207c478bd9Sstevel@tonic-gate n = 0; 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate break; 2237c478bd9Sstevel@tonic-gate case H_CONT: 2247c478bd9Sstevel@tonic-gate if (oldn == 0) { 2257c478bd9Sstevel@tonic-gate /* suppress continuation line also */ 2267c478bd9Sstevel@tonic-gate n = 0; 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate break; 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate oldn = n; /* remember if this line was suppressed */ 2317c478bd9Sstevel@tonic-gate if (n && !wtmpf(line, n)) { 2327c478bd9Sstevel@tonic-gate done(0); 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate if (!n) savehdrs(line, hdrtyp); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate if (Rpath[0] != '\0') { 2377c478bd9Sstevel@tonic-gate strcat(Rpath, "!"); 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate (void) strlcat(Rpath, fromU, sizeof (Rpath)); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* push out message type if so requested */ 2427c478bd9Sstevel@tonic-gate if (flgm) { /* message-type */ 243*8e472857Sny155746 snprintf(buf, sizeof (buf), "%s%s\n", 244*8e472857Sny155746 header[H_MTYPE].tag, msgtype); 2457c478bd9Sstevel@tonic-gate if (!wtmpf(buf, strlen(buf))) { 2467c478bd9Sstevel@tonic-gate done(0); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate } 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate memcpy(buf, line, n); 2517c478bd9Sstevel@tonic-gate if (n == 0 || (ttyf && !strncmp(buf, ".\n", 2))) { 2527c478bd9Sstevel@tonic-gate if (flgf) { 2537c478bd9Sstevel@tonic-gate /* no input */ 2547c478bd9Sstevel@tonic-gate return; 2557c478bd9Sstevel@tonic-gate } else { 2567c478bd9Sstevel@tonic-gate /* 2577c478bd9Sstevel@tonic-gate * no content: put mime-version, content-type 2587c478bd9Sstevel@tonic-gate * and -length only if explicitly present. 2597c478bd9Sstevel@tonic-gate * Write out 'place-holders' only. (see below....) 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_MIMEVERS].head) != 2627c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 263*8e472857Sny155746 (void) snprintf(line, sizeof (line), "%s \n", 264*8e472857Sny155746 header[H_MIMEVERS].tag); 2657c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 2667c478bd9Sstevel@tonic-gate done(0); 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CTYPE].head) != 2707c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 271*8e472857Sny155746 (void) snprintf(line, sizeof (line), "%s \n", 272*8e472857Sny155746 header[H_CTYPE].tag); 2737c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 2747c478bd9Sstevel@tonic-gate done(0); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CLEN].head) != 2787c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 279*8e472857Sny155746 (void) snprintf(line, sizeof (line), "%s \n", 280*8e472857Sny155746 header[H_CLEN].tag); 2817c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 2827c478bd9Sstevel@tonic-gate done(0); 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate goto wrapsend; 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate if (n == 1 && last1c == '\n') { /* blank line -- suppress */ 290*8e472857Sny155746 n = getline(buf, sizeof (buf), stdin); 2917c478bd9Sstevel@tonic-gate if (n == 0 || (ttyf && !strncmp(buf, ".\n", 2))) { 2927c478bd9Sstevel@tonic-gate /* 2937c478bd9Sstevel@tonic-gate * no content: put mime-version, content-type 2947c478bd9Sstevel@tonic-gate * and -length only if explicitly present. 2957c478bd9Sstevel@tonic-gate * Write out 'place-holders' only. (see below....) 2967c478bd9Sstevel@tonic-gate */ 2977c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_MIMEVERS].head) != 2987c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 299*8e472857Sny155746 (void) snprintf(line, sizeof (line), "%s \n", 300*8e472857Sny155746 header[H_MIMEVERS].tag); 3017c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 3027c478bd9Sstevel@tonic-gate done(0); 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CTYPE].head) != 3067c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 307*8e472857Sny155746 (void) snprintf(line, sizeof (line), "%s \n", 308*8e472857Sny155746 header[H_CTYPE].tag); 3097c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 3107c478bd9Sstevel@tonic-gate done(0); 3117c478bd9Sstevel@tonic-gate } 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CLEN].head) != 3147c478bd9Sstevel@tonic-gate (struct hdrs *)NULL) { 315*8e472857Sny155746 (void) snprintf(line, sizeof (line), "%s \n", 316*8e472857Sny155746 header[H_CLEN].tag); 3177c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 3187c478bd9Sstevel@tonic-gate done(0); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate goto wrapsend; 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate if (debug > 0) { 3267c478bd9Sstevel@tonic-gate buf[n] = '\0'; 327*8e472857Sny155746 Dout(pn, 0, "header scan complete, readahead %d = \"%s\"\n", 328*8e472857Sny155746 n, buf); 3297c478bd9Sstevel@tonic-gate } 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate /* 3327c478bd9Sstevel@tonic-gate * Write out H_MIMEVERS, H_CTYPE & H_CLEN lines. These are used only as 3337c478bd9Sstevel@tonic-gate * placeholders in the tmp file. When the 'real' message is sent, 3347c478bd9Sstevel@tonic-gate * the proper values will be put out by copylet(). 3357c478bd9Sstevel@tonic-gate */ 3367c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), "%s \n", header[H_MIMEVERS].tag); 3377c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 3387c478bd9Sstevel@tonic-gate done(0); 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate if (hdrlines[H_MIMEVERS].head == (struct hdrs *)NULL) { 3417c478bd9Sstevel@tonic-gate savehdrs(line, H_MIMEVERS); 3427c478bd9Sstevel@tonic-gate } 3437c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), "%s \n", header[H_CTYPE].tag); 3447c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 3457c478bd9Sstevel@tonic-gate done(0); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate if (hdrlines[H_CTYPE].head == (struct hdrs *)NULL) { 3487c478bd9Sstevel@tonic-gate savehdrs(line, H_CTYPE); 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate (void) snprintf(line, sizeof (line), "%s \n", header[H_CLEN].tag); 3517c478bd9Sstevel@tonic-gate if (!wtmpf(line, strlen(line))) { 3527c478bd9Sstevel@tonic-gate done(0); 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate if (hdrlines[H_CLEN].head == (struct hdrs *)NULL) { 3557c478bd9Sstevel@tonic-gate savehdrs(line, H_CLEN); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate /* and a blank line */ 3587c478bd9Sstevel@tonic-gate if (!wtmpf("\n", 1)) { 3597c478bd9Sstevel@tonic-gate done(0); 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate Dout(pn, 0, "header out completed\n"); 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate pushrest = 0; 3647c478bd9Sstevel@tonic-gate count = 0L; 3657c478bd9Sstevel@tonic-gate /* 3667c478bd9Sstevel@tonic-gate * Are we returning mail from a delivery failure of an old-style 3677c478bd9Sstevel@tonic-gate * (SVR3.1 or SVR3.0) rmail? If so, we won't return THIS on failure 3687c478bd9Sstevel@tonic-gate * [This line should occur as the FIRST non-blank non-header line] 3697c478bd9Sstevel@tonic-gate */ 3707c478bd9Sstevel@tonic-gate if (!strncmp("***** UNDELIVERABLE MAIL sent to", buf, 32)) { 3717c478bd9Sstevel@tonic-gate dflag = 9; /* 9 says do not return on failure */ 3727c478bd9Sstevel@tonic-gate Dout(pn, 0, "found old-style UNDELIVERABLE line. dflag = 9\n"); 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate /* scan body of message */ 3767c478bd9Sstevel@tonic-gate while (n > 0) { 3777c478bd9Sstevel@tonic-gate if (ttyf && !strcmp(buf, ".\n")) 3787c478bd9Sstevel@tonic-gate break; 3797c478bd9Sstevel@tonic-gate if (!binflg) { 3807c478bd9Sstevel@tonic-gate binflg = !istext((unsigned char *)buf, n); 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate if (!wtmpf(buf, n)) { 3847c478bd9Sstevel@tonic-gate done(0); 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate count += n; 3877c478bd9Sstevel@tonic-gate n = ttyf 388*8e472857Sny155746 ? getline(buf, sizeof (buf), stdin) 389*8e472857Sny155746 : fread(buf, 1, sizeof (buf), stdin); 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate setsig(SIGINT, saveint); 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate wrapsend: 3947c478bd9Sstevel@tonic-gate /* 3957c478bd9Sstevel@tonic-gate * In order to use some of the subroutines that are used to 3967c478bd9Sstevel@tonic-gate * read mail, the let array must be set up 3977c478bd9Sstevel@tonic-gate */ 3987c478bd9Sstevel@tonic-gate nlet = 1; 3997c478bd9Sstevel@tonic-gate let[0].adr = 0; 4007c478bd9Sstevel@tonic-gate let[1].adr = ftell(tmpf); 4017c478bd9Sstevel@tonic-gate let[0].text = (binflg == 1 ? FALSE : TRUE); 4027c478bd9Sstevel@tonic-gate Dout(pn, 0, "body copy complete, count %ld\n", count); 4037c478bd9Sstevel@tonic-gate /* 4047c478bd9Sstevel@tonic-gate * Modify value of H_MIMEVERS if necessary. 4057c478bd9Sstevel@tonic-gate */ 4067c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_MIMEVERS].head) != (struct hdrs *)NULL) { 4077c478bd9Sstevel@tonic-gate if (strlen(hptr->value) == 0) { 4087c478bd9Sstevel@tonic-gate (void) strlcpy(hptr->value, "1.0", 4097c478bd9Sstevel@tonic-gate sizeof (hptr->value)); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate /* 4137c478bd9Sstevel@tonic-gate * Modify value of H_CTYPE if necessary. 4147c478bd9Sstevel@tonic-gate */ 4157c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CTYPE].head) != (struct hdrs *)NULL) { 4167c478bd9Sstevel@tonic-gate if (strlen(hptr->value) == 0) { 4177c478bd9Sstevel@tonic-gate (void) strlcpy(hptr->value, "text/plain", 4187c478bd9Sstevel@tonic-gate sizeof (hptr->value)); 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate /* 4227c478bd9Sstevel@tonic-gate * Set 'place-holder' value of content length to true value 4237c478bd9Sstevel@tonic-gate */ 4247c478bd9Sstevel@tonic-gate if ((hptr = hdrlines[H_CLEN].head) != (struct hdrs *)NULL) { 4257c478bd9Sstevel@tonic-gate (void) snprintf(hptr->value, sizeof (hptr->value), 4267c478bd9Sstevel@tonic-gate "%ld", count); 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate if (fclose(tmpf) == EOF) { 4307c478bd9Sstevel@tonic-gate tmperr(); 4317c478bd9Sstevel@tonic-gate done(0); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate tmpf = doopen(lettmp, "r+", E_TMP); 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate /* Do not send mail on SIGINT */ 4377c478bd9Sstevel@tonic-gate if (dflag == 2) { 4387c478bd9Sstevel@tonic-gate done(0); 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate sendlist(&list, 0, 0); 4427c478bd9Sstevel@tonic-gate done(0); 4437c478bd9Sstevel@tonic-gate } 444