17c478bd9Sstevel@tonic-gate /* 2*445f2479Sjbeck * Copyright (c) 1998-2006 Sendmail, Inc. and its suppliers. 37c478bd9Sstevel@tonic-gate * All rights reserved. 47c478bd9Sstevel@tonic-gate * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 57c478bd9Sstevel@tonic-gate * Copyright (c) 1988, 1993 67c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * By using this file, you agree to the terms and conditions set 97c478bd9Sstevel@tonic-gate * forth in the LICENSE file which can be found at the top level of 107c478bd9Sstevel@tonic-gate * the sendmail distribution. 117c478bd9Sstevel@tonic-gate * 127c478bd9Sstevel@tonic-gate */ 137c478bd9Sstevel@tonic-gate 147c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 157c478bd9Sstevel@tonic-gate 167c478bd9Sstevel@tonic-gate #include <sendmail.h> 177c478bd9Sstevel@tonic-gate 18*445f2479Sjbeck SM_RCSID("@(#)$Id: collect.c,v 8.272 2006/03/02 19:09:26 ca Exp $") 197c478bd9Sstevel@tonic-gate 207c478bd9Sstevel@tonic-gate static void eatfrom __P((char *volatile, ENVELOPE *)); 217c478bd9Sstevel@tonic-gate static void collect_doheader __P((ENVELOPE *)); 227c478bd9Sstevel@tonic-gate static SM_FILE_T *collect_dfopen __P((ENVELOPE *)); 237c478bd9Sstevel@tonic-gate static SM_FILE_T *collect_eoh __P((ENVELOPE *, int, int)); 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate /* 267c478bd9Sstevel@tonic-gate ** COLLECT_EOH -- end-of-header processing in collect() 277c478bd9Sstevel@tonic-gate ** 287c478bd9Sstevel@tonic-gate ** Called by collect() when it encounters the blank line 297c478bd9Sstevel@tonic-gate ** separating the header from the message body, or when it 307c478bd9Sstevel@tonic-gate ** encounters EOF in a message that contains only a header. 317c478bd9Sstevel@tonic-gate ** 327c478bd9Sstevel@tonic-gate ** Parameters: 337c478bd9Sstevel@tonic-gate ** e -- envelope 347c478bd9Sstevel@tonic-gate ** numhdrs -- number of headers 357c478bd9Sstevel@tonic-gate ** hdrslen -- length of headers 367c478bd9Sstevel@tonic-gate ** 377c478bd9Sstevel@tonic-gate ** Results: 387c478bd9Sstevel@tonic-gate ** NULL, or handle to open data file 397c478bd9Sstevel@tonic-gate ** 407c478bd9Sstevel@tonic-gate ** Side Effects: 417c478bd9Sstevel@tonic-gate ** end-of-header check ruleset is invoked. 427c478bd9Sstevel@tonic-gate ** envelope state is updated. 437c478bd9Sstevel@tonic-gate ** headers may be added and deleted. 447c478bd9Sstevel@tonic-gate ** selects the queue. 457c478bd9Sstevel@tonic-gate ** opens the data file. 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate static SM_FILE_T * 497c478bd9Sstevel@tonic-gate collect_eoh(e, numhdrs, hdrslen) 507c478bd9Sstevel@tonic-gate ENVELOPE *e; 517c478bd9Sstevel@tonic-gate int numhdrs; 527c478bd9Sstevel@tonic-gate int hdrslen; 537c478bd9Sstevel@tonic-gate { 547c478bd9Sstevel@tonic-gate char hnum[16]; 557c478bd9Sstevel@tonic-gate char hsize[16]; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /* call the end-of-header check ruleset */ 587c478bd9Sstevel@tonic-gate (void) sm_snprintf(hnum, sizeof hnum, "%d", numhdrs); 597c478bd9Sstevel@tonic-gate (void) sm_snprintf(hsize, sizeof hsize, "%d", hdrslen); 607c478bd9Sstevel@tonic-gate if (tTd(30, 10)) 617c478bd9Sstevel@tonic-gate sm_dprintf("collect: rscheck(\"check_eoh\", \"%s $| %s\")\n", 627c478bd9Sstevel@tonic-gate hnum, hsize); 637c478bd9Sstevel@tonic-gate (void) rscheck("check_eoh", hnum, hsize, e, RSF_UNSTRUCTURED|RSF_COUNT, 647c478bd9Sstevel@tonic-gate 3, NULL, e->e_id); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate ** Process the header, 687c478bd9Sstevel@tonic-gate ** select the queue, open the data file. 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate collect_doheader(e); 727c478bd9Sstevel@tonic-gate return collect_dfopen(e); 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* 767c478bd9Sstevel@tonic-gate ** COLLECT_DOHEADER -- process header in collect() 777c478bd9Sstevel@tonic-gate ** 787c478bd9Sstevel@tonic-gate ** Called by collect() after it has finished parsing the header, 797c478bd9Sstevel@tonic-gate ** but before it selects the queue and creates the data file. 807c478bd9Sstevel@tonic-gate ** The results of processing the header will affect queue selection. 817c478bd9Sstevel@tonic-gate ** 827c478bd9Sstevel@tonic-gate ** Parameters: 837c478bd9Sstevel@tonic-gate ** e -- envelope 847c478bd9Sstevel@tonic-gate ** 857c478bd9Sstevel@tonic-gate ** Results: 867c478bd9Sstevel@tonic-gate ** none. 877c478bd9Sstevel@tonic-gate ** 887c478bd9Sstevel@tonic-gate ** Side Effects: 897c478bd9Sstevel@tonic-gate ** envelope state is updated. 907c478bd9Sstevel@tonic-gate ** headers may be added and deleted. 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate static void 947c478bd9Sstevel@tonic-gate collect_doheader(e) 957c478bd9Sstevel@tonic-gate ENVELOPE *e; 967c478bd9Sstevel@tonic-gate { 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate ** Find out some information from the headers. 997c478bd9Sstevel@tonic-gate ** Examples are who is the from person & the date. 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate eatheader(e, true, false); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate if (GrabTo && e->e_sendqueue == NULL) 1057c478bd9Sstevel@tonic-gate usrerr("No recipient addresses found in header"); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate ** If we have a Return-Receipt-To:, turn it into a DSN. 1097c478bd9Sstevel@tonic-gate */ 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate if (RrtImpliesDsn && hvalue("return-receipt-to", e->e_header) != NULL) 1127c478bd9Sstevel@tonic-gate { 1137c478bd9Sstevel@tonic-gate ADDRESS *q; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1167c478bd9Sstevel@tonic-gate if (!bitset(QHASNOTIFY, q->q_flags)) 1177c478bd9Sstevel@tonic-gate q->q_flags |= QHASNOTIFY|QPINGONSUCCESS; 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate ** Add an appropriate recipient line if we have none. 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate if (hvalue("to", e->e_header) != NULL || 1257c478bd9Sstevel@tonic-gate hvalue("cc", e->e_header) != NULL || 1267c478bd9Sstevel@tonic-gate hvalue("apparently-to", e->e_header) != NULL) 1277c478bd9Sstevel@tonic-gate { 1287c478bd9Sstevel@tonic-gate /* have a valid recipient header -- delete Bcc: headers */ 1297c478bd9Sstevel@tonic-gate e->e_flags |= EF_DELETE_BCC; 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate else if (hvalue("bcc", e->e_header) == NULL) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate /* no valid recipient headers */ 1347c478bd9Sstevel@tonic-gate register ADDRESS *q; 1357c478bd9Sstevel@tonic-gate char *hdr = NULL; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* create a recipient field */ 1387c478bd9Sstevel@tonic-gate switch (NoRecipientAction) 1397c478bd9Sstevel@tonic-gate { 1407c478bd9Sstevel@tonic-gate case NRA_ADD_APPARENTLY_TO: 1417c478bd9Sstevel@tonic-gate hdr = "Apparently-To"; 1427c478bd9Sstevel@tonic-gate break; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate case NRA_ADD_TO: 1457c478bd9Sstevel@tonic-gate hdr = "To"; 1467c478bd9Sstevel@tonic-gate break; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate case NRA_ADD_BCC: 1497c478bd9Sstevel@tonic-gate addheader("Bcc", " ", 0, e); 1507c478bd9Sstevel@tonic-gate break; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate case NRA_ADD_TO_UNDISCLOSED: 1537c478bd9Sstevel@tonic-gate addheader("To", "undisclosed-recipients:;", 0, e); 1547c478bd9Sstevel@tonic-gate break; 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate if (hdr != NULL) 1587c478bd9Sstevel@tonic-gate { 1597c478bd9Sstevel@tonic-gate for (q = e->e_sendqueue; q != NULL; q = q->q_next) 1607c478bd9Sstevel@tonic-gate { 1617c478bd9Sstevel@tonic-gate if (q->q_alias != NULL) 1627c478bd9Sstevel@tonic-gate continue; 1637c478bd9Sstevel@tonic-gate if (tTd(30, 3)) 1647c478bd9Sstevel@tonic-gate sm_dprintf("Adding %s: %s\n", 1657c478bd9Sstevel@tonic-gate hdr, q->q_paddr); 1667c478bd9Sstevel@tonic-gate addheader(hdr, q->q_paddr, 0, e); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate /* 1737c478bd9Sstevel@tonic-gate ** COLLECT_DFOPEN -- open the message data file 1747c478bd9Sstevel@tonic-gate ** 1757c478bd9Sstevel@tonic-gate ** Called by collect() after it has finished processing the header. 1767c478bd9Sstevel@tonic-gate ** Queue selection occurs at this point, possibly based on the 1777c478bd9Sstevel@tonic-gate ** envelope's recipient list and on header information. 1787c478bd9Sstevel@tonic-gate ** 1797c478bd9Sstevel@tonic-gate ** Parameters: 1807c478bd9Sstevel@tonic-gate ** e -- envelope 1817c478bd9Sstevel@tonic-gate ** 1827c478bd9Sstevel@tonic-gate ** Results: 1837c478bd9Sstevel@tonic-gate ** NULL, or a pointer to an open data file, 1847c478bd9Sstevel@tonic-gate ** into which the message body will be written by collect(). 1857c478bd9Sstevel@tonic-gate ** 1867c478bd9Sstevel@tonic-gate ** Side Effects: 1877c478bd9Sstevel@tonic-gate ** Calls syserr, sets EF_FATALERRS and returns NULL 1887c478bd9Sstevel@tonic-gate ** if there is insufficient disk space. 1897c478bd9Sstevel@tonic-gate ** Aborts process if data file could not be opened. 1907c478bd9Sstevel@tonic-gate ** Otherwise, the queue is selected, 1917c478bd9Sstevel@tonic-gate ** e->e_{dfino,dfdev,msgsize,flags} are updated, 1927c478bd9Sstevel@tonic-gate ** and a pointer to an open data file is returned. 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate static SM_FILE_T * 1967c478bd9Sstevel@tonic-gate collect_dfopen(e) 1977c478bd9Sstevel@tonic-gate ENVELOPE *e; 1987c478bd9Sstevel@tonic-gate { 1997c478bd9Sstevel@tonic-gate MODE_T oldumask = 0; 2007c478bd9Sstevel@tonic-gate int dfd; 2017c478bd9Sstevel@tonic-gate struct stat stbuf; 2027c478bd9Sstevel@tonic-gate SM_FILE_T *df; 2037c478bd9Sstevel@tonic-gate char *dfname; 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate if (!setnewqueue(e)) 2067c478bd9Sstevel@tonic-gate return NULL; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate dfname = queuename(e, DATAFL_LETTER); 2097c478bd9Sstevel@tonic-gate if (bitset(S_IWGRP, QueueFileMode)) 2107c478bd9Sstevel@tonic-gate oldumask = umask(002); 2117c478bd9Sstevel@tonic-gate df = bfopen(dfname, QueueFileMode, DataFileBufferSize, 2127c478bd9Sstevel@tonic-gate SFF_OPENASROOT); 2137c478bd9Sstevel@tonic-gate if (bitset(S_IWGRP, QueueFileMode)) 2147c478bd9Sstevel@tonic-gate (void) umask(oldumask); 2157c478bd9Sstevel@tonic-gate if (df == NULL) 2167c478bd9Sstevel@tonic-gate { 2177c478bd9Sstevel@tonic-gate syserr("@Cannot create %s", dfname); 2187c478bd9Sstevel@tonic-gate e->e_flags |= EF_NO_BODY_RETN; 2197c478bd9Sstevel@tonic-gate flush_errors(true); 2207c478bd9Sstevel@tonic-gate finis(false, true, ExitStat); 2217c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2227c478bd9Sstevel@tonic-gate } 2237c478bd9Sstevel@tonic-gate dfd = sm_io_getinfo(df, SM_IO_WHAT_FD, NULL); 2247c478bd9Sstevel@tonic-gate if (dfd < 0 || fstat(dfd, &stbuf) < 0) 2257c478bd9Sstevel@tonic-gate e->e_dfino = -1; 2267c478bd9Sstevel@tonic-gate else 2277c478bd9Sstevel@tonic-gate { 2287c478bd9Sstevel@tonic-gate e->e_dfdev = stbuf.st_dev; 2297c478bd9Sstevel@tonic-gate e->e_dfino = stbuf.st_ino; 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate e->e_flags |= EF_HAS_DF; 2327c478bd9Sstevel@tonic-gate return df; 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate ** COLLECT -- read & parse message header & make temp file. 2377c478bd9Sstevel@tonic-gate ** 2387c478bd9Sstevel@tonic-gate ** Creates a temporary file name and copies the standard 2397c478bd9Sstevel@tonic-gate ** input to that file. Leading UNIX-style "From" lines are 2407c478bd9Sstevel@tonic-gate ** stripped off (after important information is extracted). 2417c478bd9Sstevel@tonic-gate ** 2427c478bd9Sstevel@tonic-gate ** Parameters: 2437c478bd9Sstevel@tonic-gate ** fp -- file to read. 2447c478bd9Sstevel@tonic-gate ** smtpmode -- if set, we are running SMTP: give an RFC821 2457c478bd9Sstevel@tonic-gate ** style message to say we are ready to collect 2467c478bd9Sstevel@tonic-gate ** input, and never ignore a single dot to mean 2477c478bd9Sstevel@tonic-gate ** end of message. 2487c478bd9Sstevel@tonic-gate ** hdrp -- the location to stash the header. 2497c478bd9Sstevel@tonic-gate ** e -- the current envelope. 2507c478bd9Sstevel@tonic-gate ** rsetsize -- reset e_msgsize? 2517c478bd9Sstevel@tonic-gate ** 2527c478bd9Sstevel@tonic-gate ** Returns: 2537c478bd9Sstevel@tonic-gate ** none. 2547c478bd9Sstevel@tonic-gate ** 2557c478bd9Sstevel@tonic-gate ** Side Effects: 2567c478bd9Sstevel@tonic-gate ** If successful, 2577c478bd9Sstevel@tonic-gate ** - Data file is created and filled, and e->e_dfp is set. 2587c478bd9Sstevel@tonic-gate ** - The from person may be set. 2597c478bd9Sstevel@tonic-gate ** If the "enough disk space" check fails, 2607c478bd9Sstevel@tonic-gate ** - syserr is called. 2617c478bd9Sstevel@tonic-gate ** - e->e_dfp is NULL. 2627c478bd9Sstevel@tonic-gate ** - e->e_flags & EF_FATALERRS is set. 2637c478bd9Sstevel@tonic-gate ** - collect() returns. 2647c478bd9Sstevel@tonic-gate ** If data file cannot be created, the process is terminated. 2657c478bd9Sstevel@tonic-gate */ 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate /* values for input state machine */ 2687c478bd9Sstevel@tonic-gate #define IS_NORM 0 /* middle of line */ 2697c478bd9Sstevel@tonic-gate #define IS_BOL 1 /* beginning of line */ 2707c478bd9Sstevel@tonic-gate #define IS_DOT 2 /* read a dot at beginning of line */ 2717c478bd9Sstevel@tonic-gate #define IS_DOTCR 3 /* read ".\r" at beginning of line */ 2727c478bd9Sstevel@tonic-gate #define IS_CR 4 /* read a carriage return */ 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate /* values for message state machine */ 2757c478bd9Sstevel@tonic-gate #define MS_UFROM 0 /* reading Unix from line */ 2767c478bd9Sstevel@tonic-gate #define MS_HEADER 1 /* reading message header */ 2777c478bd9Sstevel@tonic-gate #define MS_BODY 2 /* reading message body */ 2787c478bd9Sstevel@tonic-gate #define MS_DISCARD 3 /* discarding rest of message */ 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate void 2817c478bd9Sstevel@tonic-gate collect(fp, smtpmode, hdrp, e, rsetsize) 2827c478bd9Sstevel@tonic-gate SM_FILE_T *fp; 2837c478bd9Sstevel@tonic-gate bool smtpmode; 2847c478bd9Sstevel@tonic-gate HDR **hdrp; 2857c478bd9Sstevel@tonic-gate register ENVELOPE *e; 2867c478bd9Sstevel@tonic-gate bool rsetsize; 2877c478bd9Sstevel@tonic-gate { 288*445f2479Sjbeck register SM_FILE_T *df; 289*445f2479Sjbeck bool ignrdot; 290*445f2479Sjbeck int dbto; 291*445f2479Sjbeck register char *bp; 292*445f2479Sjbeck int c; 293*445f2479Sjbeck bool inputerr; 2947c478bd9Sstevel@tonic-gate bool headeronly; 295*445f2479Sjbeck char *buf; 296*445f2479Sjbeck int buflen; 297*445f2479Sjbeck int istate; 298*445f2479Sjbeck int mstate; 299*445f2479Sjbeck int hdrslen; 300*445f2479Sjbeck int numhdrs; 301*445f2479Sjbeck int afd; 302*445f2479Sjbeck unsigned char *pbp; 3037c478bd9Sstevel@tonic-gate unsigned char peekbuf[8]; 3047c478bd9Sstevel@tonic-gate char bufbuf[MAXLINE]; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate df = NULL; 3077c478bd9Sstevel@tonic-gate ignrdot = smtpmode ? false : IgnrDot; 308*445f2479Sjbeck 309*445f2479Sjbeck /* timeout for I/O functions is in milliseconds */ 310*445f2479Sjbeck dbto = smtpmode ? ((int) TimeOuts.to_datablock * 1000) 311*445f2479Sjbeck : SM_TIME_FOREVER; 312*445f2479Sjbeck sm_io_setinfo(fp, SM_IO_WHAT_TIMEOUT, &dbto); 3137c478bd9Sstevel@tonic-gate c = SM_IO_EOF; 3147c478bd9Sstevel@tonic-gate inputerr = false; 3157c478bd9Sstevel@tonic-gate headeronly = hdrp != NULL; 3167c478bd9Sstevel@tonic-gate hdrslen = 0; 3177c478bd9Sstevel@tonic-gate numhdrs = 0; 3187c478bd9Sstevel@tonic-gate HasEightBits = false; 3197c478bd9Sstevel@tonic-gate buf = bp = bufbuf; 3207c478bd9Sstevel@tonic-gate buflen = sizeof bufbuf; 3217c478bd9Sstevel@tonic-gate pbp = peekbuf; 3227c478bd9Sstevel@tonic-gate istate = IS_BOL; 3237c478bd9Sstevel@tonic-gate mstate = SaveFrom ? MS_HEADER : MS_UFROM; 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate ** Tell ARPANET to go ahead. 3277c478bd9Sstevel@tonic-gate */ 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate if (smtpmode) 3307c478bd9Sstevel@tonic-gate message("354 Enter mail, end with \".\" on a line by itself"); 3317c478bd9Sstevel@tonic-gate 332*445f2479Sjbeck /* simulate an I/O timeout when used as sink */ 333*445f2479Sjbeck if (tTd(83, 101)) 334*445f2479Sjbeck sleep(319); 335*445f2479Sjbeck 3367c478bd9Sstevel@tonic-gate if (tTd(30, 2)) 3377c478bd9Sstevel@tonic-gate sm_dprintf("collect\n"); 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate /* 3407c478bd9Sstevel@tonic-gate ** Read the message. 3417c478bd9Sstevel@tonic-gate ** 3427c478bd9Sstevel@tonic-gate ** This is done using two interleaved state machines. 3437c478bd9Sstevel@tonic-gate ** The input state machine is looking for things like 3447c478bd9Sstevel@tonic-gate ** hidden dots; the message state machine is handling 3457c478bd9Sstevel@tonic-gate ** the larger picture (e.g., header versus body). 3467c478bd9Sstevel@tonic-gate */ 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate if (rsetsize) 3497c478bd9Sstevel@tonic-gate e->e_msgsize = 0; 3507c478bd9Sstevel@tonic-gate for (;;) 3517c478bd9Sstevel@tonic-gate { 3527c478bd9Sstevel@tonic-gate if (tTd(30, 35)) 3537c478bd9Sstevel@tonic-gate sm_dprintf("top, istate=%d, mstate=%d\n", istate, 3547c478bd9Sstevel@tonic-gate mstate); 3557c478bd9Sstevel@tonic-gate for (;;) 3567c478bd9Sstevel@tonic-gate { 3577c478bd9Sstevel@tonic-gate if (pbp > peekbuf) 3587c478bd9Sstevel@tonic-gate c = *--pbp; 3597c478bd9Sstevel@tonic-gate else 3607c478bd9Sstevel@tonic-gate { 3617c478bd9Sstevel@tonic-gate while (!sm_io_eof(fp) && !sm_io_error(fp)) 3627c478bd9Sstevel@tonic-gate { 3637c478bd9Sstevel@tonic-gate errno = 0; 3647c478bd9Sstevel@tonic-gate c = sm_io_getc(fp, SM_TIME_DEFAULT); 3657c478bd9Sstevel@tonic-gate if (c == SM_IO_EOF && errno == EINTR) 3667c478bd9Sstevel@tonic-gate { 3677c478bd9Sstevel@tonic-gate /* Interrupted, retry */ 3687c478bd9Sstevel@tonic-gate sm_io_clearerr(fp); 3697c478bd9Sstevel@tonic-gate continue; 3707c478bd9Sstevel@tonic-gate } 371*445f2479Sjbeck 372*445f2479Sjbeck /* timeout? */ 373*445f2479Sjbeck if (c == SM_IO_EOF && errno == EAGAIN 374*445f2479Sjbeck && smtpmode) 375*445f2479Sjbeck { 376*445f2479Sjbeck /* 377*445f2479Sjbeck ** Override e_message in 378*445f2479Sjbeck ** usrerr() as this is the 379*445f2479Sjbeck ** reason for failure that 380*445f2479Sjbeck ** should be logged for 381*445f2479Sjbeck ** undelivered recipients. 382*445f2479Sjbeck */ 383*445f2479Sjbeck 384*445f2479Sjbeck e->e_message = NULL; 385*445f2479Sjbeck errno = 0; 386*445f2479Sjbeck inputerr = true; 387*445f2479Sjbeck goto readabort; 388*445f2479Sjbeck } 3897c478bd9Sstevel@tonic-gate break; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate if (TrafficLogFile != NULL && !headeronly) 3927c478bd9Sstevel@tonic-gate { 3937c478bd9Sstevel@tonic-gate if (istate == IS_BOL) 3947c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(TrafficLogFile, 3957c478bd9Sstevel@tonic-gate SM_TIME_DEFAULT, 3967c478bd9Sstevel@tonic-gate "%05d <<< ", 3977c478bd9Sstevel@tonic-gate (int) CurrentPid); 3987c478bd9Sstevel@tonic-gate if (c == SM_IO_EOF) 3997c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(TrafficLogFile, 4007c478bd9Sstevel@tonic-gate SM_TIME_DEFAULT, 4017c478bd9Sstevel@tonic-gate "[EOF]\n"); 4027c478bd9Sstevel@tonic-gate else 4037c478bd9Sstevel@tonic-gate (void) sm_io_putc(TrafficLogFile, 4047c478bd9Sstevel@tonic-gate SM_TIME_DEFAULT, 4057c478bd9Sstevel@tonic-gate c); 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate if (c == SM_IO_EOF) 4087c478bd9Sstevel@tonic-gate goto readerr; 4097c478bd9Sstevel@tonic-gate if (SevenBitInput) 4107c478bd9Sstevel@tonic-gate c &= 0x7f; 4117c478bd9Sstevel@tonic-gate else 4127c478bd9Sstevel@tonic-gate HasEightBits |= bitset(0x80, c); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate if (tTd(30, 94)) 4157c478bd9Sstevel@tonic-gate sm_dprintf("istate=%d, c=%c (0x%x)\n", 4167c478bd9Sstevel@tonic-gate istate, (char) c, c); 4177c478bd9Sstevel@tonic-gate switch (istate) 4187c478bd9Sstevel@tonic-gate { 4197c478bd9Sstevel@tonic-gate case IS_BOL: 4207c478bd9Sstevel@tonic-gate if (c == '.') 4217c478bd9Sstevel@tonic-gate { 4227c478bd9Sstevel@tonic-gate istate = IS_DOT; 4237c478bd9Sstevel@tonic-gate continue; 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate break; 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate case IS_DOT: 4287c478bd9Sstevel@tonic-gate if (c == '\n' && !ignrdot && 4297c478bd9Sstevel@tonic-gate !bitset(EF_NL_NOT_EOL, e->e_flags)) 4307c478bd9Sstevel@tonic-gate goto readerr; 4317c478bd9Sstevel@tonic-gate else if (c == '\r' && 4327c478bd9Sstevel@tonic-gate !bitset(EF_CRLF_NOT_EOL, e->e_flags)) 4337c478bd9Sstevel@tonic-gate { 4347c478bd9Sstevel@tonic-gate istate = IS_DOTCR; 4357c478bd9Sstevel@tonic-gate continue; 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate else if (ignrdot || 4387c478bd9Sstevel@tonic-gate (c != '.' && 4397c478bd9Sstevel@tonic-gate OpMode != MD_SMTP && 4407c478bd9Sstevel@tonic-gate OpMode != MD_DAEMON && 4417c478bd9Sstevel@tonic-gate OpMode != MD_ARPAFTP)) 4427c478bd9Sstevel@tonic-gate 4437c478bd9Sstevel@tonic-gate { 444*445f2479Sjbeck SM_ASSERT(pbp < peekbuf + 445*445f2479Sjbeck sizeof(peekbuf)); 4467c478bd9Sstevel@tonic-gate *pbp++ = c; 4477c478bd9Sstevel@tonic-gate c = '.'; 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate break; 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate case IS_DOTCR: 4527c478bd9Sstevel@tonic-gate if (c == '\n' && !ignrdot) 4537c478bd9Sstevel@tonic-gate goto readerr; 4547c478bd9Sstevel@tonic-gate else 4557c478bd9Sstevel@tonic-gate { 4567c478bd9Sstevel@tonic-gate /* push back the ".\rx" */ 457*445f2479Sjbeck SM_ASSERT(pbp < peekbuf + 458*445f2479Sjbeck sizeof(peekbuf)); 4597c478bd9Sstevel@tonic-gate *pbp++ = c; 4607c478bd9Sstevel@tonic-gate if (OpMode != MD_SMTP && 4617c478bd9Sstevel@tonic-gate OpMode != MD_DAEMON && 4627c478bd9Sstevel@tonic-gate OpMode != MD_ARPAFTP) 4637c478bd9Sstevel@tonic-gate { 4647c478bd9Sstevel@tonic-gate SM_ASSERT(pbp < peekbuf + 4657c478bd9Sstevel@tonic-gate sizeof(peekbuf)); 4667c478bd9Sstevel@tonic-gate *pbp++ = '\r'; 4677c478bd9Sstevel@tonic-gate c = '.'; 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate else 4707c478bd9Sstevel@tonic-gate c = '\r'; 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate break; 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate case IS_CR: 4757c478bd9Sstevel@tonic-gate if (c == '\n') 4767c478bd9Sstevel@tonic-gate istate = IS_BOL; 4777c478bd9Sstevel@tonic-gate else 4787c478bd9Sstevel@tonic-gate { 4797c478bd9Sstevel@tonic-gate (void) sm_io_ungetc(fp, SM_TIME_DEFAULT, 4807c478bd9Sstevel@tonic-gate c); 4817c478bd9Sstevel@tonic-gate c = '\r'; 4827c478bd9Sstevel@tonic-gate istate = IS_NORM; 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate goto bufferchar; 4857c478bd9Sstevel@tonic-gate } 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate if (c == '\r' && !bitset(EF_CRLF_NOT_EOL, e->e_flags)) 4887c478bd9Sstevel@tonic-gate { 4897c478bd9Sstevel@tonic-gate istate = IS_CR; 4907c478bd9Sstevel@tonic-gate continue; 4917c478bd9Sstevel@tonic-gate } 4927c478bd9Sstevel@tonic-gate else if (c == '\n' && !bitset(EF_NL_NOT_EOL, 4937c478bd9Sstevel@tonic-gate e->e_flags)) 4947c478bd9Sstevel@tonic-gate istate = IS_BOL; 4957c478bd9Sstevel@tonic-gate else 4967c478bd9Sstevel@tonic-gate istate = IS_NORM; 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate bufferchar: 4997c478bd9Sstevel@tonic-gate if (!headeronly) 5007c478bd9Sstevel@tonic-gate { 5017c478bd9Sstevel@tonic-gate /* no overflow? */ 5027c478bd9Sstevel@tonic-gate if (e->e_msgsize >= 0) 5037c478bd9Sstevel@tonic-gate { 5047c478bd9Sstevel@tonic-gate e->e_msgsize++; 5057c478bd9Sstevel@tonic-gate if (MaxMessageSize > 0 && 5067c478bd9Sstevel@tonic-gate !bitset(EF_TOOBIG, e->e_flags) && 5077c478bd9Sstevel@tonic-gate e->e_msgsize > MaxMessageSize) 5087c478bd9Sstevel@tonic-gate e->e_flags |= EF_TOOBIG; 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate } 5117c478bd9Sstevel@tonic-gate switch (mstate) 5127c478bd9Sstevel@tonic-gate { 5137c478bd9Sstevel@tonic-gate case MS_BODY: 5147c478bd9Sstevel@tonic-gate /* just put the character out */ 5157c478bd9Sstevel@tonic-gate if (!bitset(EF_TOOBIG, e->e_flags)) 5167c478bd9Sstevel@tonic-gate (void) sm_io_putc(df, SM_TIME_DEFAULT, 5177c478bd9Sstevel@tonic-gate c); 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate case MS_DISCARD: 5227c478bd9Sstevel@tonic-gate continue; 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate SM_ASSERT(mstate == MS_UFROM || mstate == MS_HEADER); 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* header -- buffer up */ 5287c478bd9Sstevel@tonic-gate if (bp >= &buf[buflen - 2]) 5297c478bd9Sstevel@tonic-gate { 5307c478bd9Sstevel@tonic-gate char *obuf; 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate /* out of space for header */ 5337c478bd9Sstevel@tonic-gate obuf = buf; 5347c478bd9Sstevel@tonic-gate if (buflen < MEMCHUNKSIZE) 5357c478bd9Sstevel@tonic-gate buflen *= 2; 5367c478bd9Sstevel@tonic-gate else 5377c478bd9Sstevel@tonic-gate buflen += MEMCHUNKSIZE; 538*445f2479Sjbeck if (buflen <= 0) 539*445f2479Sjbeck { 540*445f2479Sjbeck sm_syslog(LOG_NOTICE, e->e_id, 541*445f2479Sjbeck "header overflow from %s during message collect", 542*445f2479Sjbeck CURHOSTNAME); 543*445f2479Sjbeck errno = 0; 544*445f2479Sjbeck e->e_flags |= EF_CLRQUEUE; 545*445f2479Sjbeck e->e_status = "5.6.0"; 546*445f2479Sjbeck usrerrenh(e->e_status, 547*445f2479Sjbeck "552 Headers too large"); 548*445f2479Sjbeck goto discard; 549*445f2479Sjbeck } 5507c478bd9Sstevel@tonic-gate buf = xalloc(buflen); 5517c478bd9Sstevel@tonic-gate memmove(buf, obuf, bp - obuf); 5527c478bd9Sstevel@tonic-gate bp = &buf[bp - obuf]; 5537c478bd9Sstevel@tonic-gate if (obuf != bufbuf) 5547c478bd9Sstevel@tonic-gate sm_free(obuf); /* XXX */ 5557c478bd9Sstevel@tonic-gate } 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate /* 5587c478bd9Sstevel@tonic-gate ** XXX Notice: the logic here is broken. 5597c478bd9Sstevel@tonic-gate ** An input to sendmail that doesn't contain a 5607c478bd9Sstevel@tonic-gate ** header but starts immediately with the body whose 5617c478bd9Sstevel@tonic-gate ** first line contain characters which match the 5627c478bd9Sstevel@tonic-gate ** following "if" will cause problems: those 5637c478bd9Sstevel@tonic-gate ** characters will NOT appear in the output... 5647c478bd9Sstevel@tonic-gate ** Do we care? 5657c478bd9Sstevel@tonic-gate */ 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate if (c >= 0200 && c <= 0237) 5687c478bd9Sstevel@tonic-gate { 5697c478bd9Sstevel@tonic-gate #if 0 /* causes complaints -- figure out something for 8.n+1 */ 5707c478bd9Sstevel@tonic-gate usrerr("Illegal character 0x%x in header", c); 5717c478bd9Sstevel@tonic-gate #else /* 0 */ 5727c478bd9Sstevel@tonic-gate /* EMPTY */ 5737c478bd9Sstevel@tonic-gate #endif /* 0 */ 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate else if (c != '\0') 5767c478bd9Sstevel@tonic-gate { 5777c478bd9Sstevel@tonic-gate *bp++ = c; 5787c478bd9Sstevel@tonic-gate ++hdrslen; 5797c478bd9Sstevel@tonic-gate if (!headeronly && 5807c478bd9Sstevel@tonic-gate MaxHeadersLength > 0 && 5817c478bd9Sstevel@tonic-gate hdrslen > MaxHeadersLength) 5827c478bd9Sstevel@tonic-gate { 5837c478bd9Sstevel@tonic-gate sm_syslog(LOG_NOTICE, e->e_id, 5847c478bd9Sstevel@tonic-gate "headers too large (%d max) from %s during message collect", 5857c478bd9Sstevel@tonic-gate MaxHeadersLength, 5867c478bd9Sstevel@tonic-gate CURHOSTNAME); 5877c478bd9Sstevel@tonic-gate errno = 0; 5887c478bd9Sstevel@tonic-gate e->e_flags |= EF_CLRQUEUE; 5897c478bd9Sstevel@tonic-gate e->e_status = "5.6.0"; 5907c478bd9Sstevel@tonic-gate usrerrenh(e->e_status, 5917c478bd9Sstevel@tonic-gate "552 Headers too large (%d max)", 5927c478bd9Sstevel@tonic-gate MaxHeadersLength); 593*445f2479Sjbeck discard: 5947c478bd9Sstevel@tonic-gate mstate = MS_DISCARD; 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate if (istate == IS_BOL) 5987c478bd9Sstevel@tonic-gate break; 5997c478bd9Sstevel@tonic-gate } 6007c478bd9Sstevel@tonic-gate *bp = '\0'; 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate nextstate: 6037c478bd9Sstevel@tonic-gate if (tTd(30, 35)) 6047c478bd9Sstevel@tonic-gate sm_dprintf("nextstate, istate=%d, mstate=%d, line = \"%s\"\n", 6057c478bd9Sstevel@tonic-gate istate, mstate, buf); 6067c478bd9Sstevel@tonic-gate switch (mstate) 6077c478bd9Sstevel@tonic-gate { 6087c478bd9Sstevel@tonic-gate case MS_UFROM: 6097c478bd9Sstevel@tonic-gate mstate = MS_HEADER; 6107c478bd9Sstevel@tonic-gate #ifndef NOTUNIX 6117c478bd9Sstevel@tonic-gate if (strncmp(buf, "From ", 5) == 0) 6127c478bd9Sstevel@tonic-gate { 6137c478bd9Sstevel@tonic-gate bp = buf; 6147c478bd9Sstevel@tonic-gate eatfrom(buf, e); 6157c478bd9Sstevel@tonic-gate continue; 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate #endif /* ! NOTUNIX */ 6187c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate case MS_HEADER: 6217c478bd9Sstevel@tonic-gate if (!isheader(buf)) 6227c478bd9Sstevel@tonic-gate { 6237c478bd9Sstevel@tonic-gate mstate = MS_BODY; 6247c478bd9Sstevel@tonic-gate goto nextstate; 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate 6277c478bd9Sstevel@tonic-gate /* check for possible continuation line */ 6287c478bd9Sstevel@tonic-gate do 6297c478bd9Sstevel@tonic-gate { 6307c478bd9Sstevel@tonic-gate sm_io_clearerr(fp); 6317c478bd9Sstevel@tonic-gate errno = 0; 6327c478bd9Sstevel@tonic-gate c = sm_io_getc(fp, SM_TIME_DEFAULT); 633*445f2479Sjbeck 634*445f2479Sjbeck /* timeout? */ 635*445f2479Sjbeck if (c == SM_IO_EOF && errno == EAGAIN 636*445f2479Sjbeck && smtpmode) 637*445f2479Sjbeck { 638*445f2479Sjbeck /* 639*445f2479Sjbeck ** Override e_message in 640*445f2479Sjbeck ** usrerr() as this is the 641*445f2479Sjbeck ** reason for failure that 642*445f2479Sjbeck ** should be logged for 643*445f2479Sjbeck ** undelivered recipients. 644*445f2479Sjbeck */ 645*445f2479Sjbeck 646*445f2479Sjbeck e->e_message = NULL; 647*445f2479Sjbeck errno = 0; 648*445f2479Sjbeck inputerr = true; 649*445f2479Sjbeck goto readabort; 650*445f2479Sjbeck } 6517c478bd9Sstevel@tonic-gate } while (c == SM_IO_EOF && errno == EINTR); 6527c478bd9Sstevel@tonic-gate if (c != SM_IO_EOF) 6537c478bd9Sstevel@tonic-gate (void) sm_io_ungetc(fp, SM_TIME_DEFAULT, c); 6547c478bd9Sstevel@tonic-gate if (c == ' ' || c == '\t') 6557c478bd9Sstevel@tonic-gate { 6567c478bd9Sstevel@tonic-gate /* yep -- defer this */ 6577c478bd9Sstevel@tonic-gate continue; 6587c478bd9Sstevel@tonic-gate } 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate SM_ASSERT(bp > buf); 661*445f2479Sjbeck 662*445f2479Sjbeck /* guaranteed by isheader(buf) */ 663*445f2479Sjbeck SM_ASSERT(*(bp - 1) != '\n' || bp > buf + 1); 664*445f2479Sjbeck 665*445f2479Sjbeck /* trim off trailing CRLF or NL */ 6667c478bd9Sstevel@tonic-gate if (*--bp != '\n' || *--bp != '\r') 6677c478bd9Sstevel@tonic-gate bp++; 6687c478bd9Sstevel@tonic-gate *bp = '\0'; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate if (bitset(H_EOH, chompheader(buf, 6717c478bd9Sstevel@tonic-gate CHHDR_CHECK | CHHDR_USER, 6727c478bd9Sstevel@tonic-gate hdrp, e))) 6737c478bd9Sstevel@tonic-gate { 6747c478bd9Sstevel@tonic-gate mstate = MS_BODY; 6757c478bd9Sstevel@tonic-gate goto nextstate; 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate numhdrs++; 6787c478bd9Sstevel@tonic-gate break; 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate case MS_BODY: 6817c478bd9Sstevel@tonic-gate if (tTd(30, 1)) 6827c478bd9Sstevel@tonic-gate sm_dprintf("EOH\n"); 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate if (headeronly) 6857c478bd9Sstevel@tonic-gate goto readerr; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate df = collect_eoh(e, numhdrs, hdrslen); 6887c478bd9Sstevel@tonic-gate if (df == NULL) 6897c478bd9Sstevel@tonic-gate e->e_flags |= EF_TOOBIG; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate bp = buf; 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate /* toss blank line */ 6947c478bd9Sstevel@tonic-gate if ((!bitset(EF_CRLF_NOT_EOL, e->e_flags) && 6957c478bd9Sstevel@tonic-gate bp[0] == '\r' && bp[1] == '\n') || 6967c478bd9Sstevel@tonic-gate (!bitset(EF_NL_NOT_EOL, e->e_flags) && 6977c478bd9Sstevel@tonic-gate bp[0] == '\n')) 6987c478bd9Sstevel@tonic-gate { 6997c478bd9Sstevel@tonic-gate break; 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate /* if not a blank separator, write it out */ 7037c478bd9Sstevel@tonic-gate if (!bitset(EF_TOOBIG, e->e_flags)) 7047c478bd9Sstevel@tonic-gate { 7057c478bd9Sstevel@tonic-gate while (*bp != '\0') 7067c478bd9Sstevel@tonic-gate (void) sm_io_putc(df, SM_TIME_DEFAULT, 7077c478bd9Sstevel@tonic-gate *bp++); 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate break; 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate bp = buf; 7127c478bd9Sstevel@tonic-gate } 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate readerr: 7157c478bd9Sstevel@tonic-gate if ((sm_io_eof(fp) && smtpmode) || sm_io_error(fp)) 7167c478bd9Sstevel@tonic-gate { 7177c478bd9Sstevel@tonic-gate const char *errmsg; 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate if (sm_io_eof(fp)) 7207c478bd9Sstevel@tonic-gate errmsg = "unexpected close"; 7217c478bd9Sstevel@tonic-gate else 7227c478bd9Sstevel@tonic-gate errmsg = sm_errstring(errno); 7237c478bd9Sstevel@tonic-gate if (tTd(30, 1)) 7247c478bd9Sstevel@tonic-gate sm_dprintf("collect: premature EOM: %s\n", errmsg); 7257c478bd9Sstevel@tonic-gate if (LogLevel > 1) 7267c478bd9Sstevel@tonic-gate sm_syslog(LOG_WARNING, e->e_id, 7277c478bd9Sstevel@tonic-gate "collect: premature EOM: %s", errmsg); 7287c478bd9Sstevel@tonic-gate inputerr = true; 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate if (headeronly) 7327c478bd9Sstevel@tonic-gate return; 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate if (mstate != MS_BODY) 7357c478bd9Sstevel@tonic-gate { 7367c478bd9Sstevel@tonic-gate /* no body or discard, so we never opened the data file */ 7377c478bd9Sstevel@tonic-gate SM_ASSERT(df == NULL); 7387c478bd9Sstevel@tonic-gate df = collect_eoh(e, numhdrs, hdrslen); 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate if (df == NULL) 7427c478bd9Sstevel@tonic-gate { 7437c478bd9Sstevel@tonic-gate /* skip next few clauses */ 7447c478bd9Sstevel@tonic-gate /* EMPTY */ 7457c478bd9Sstevel@tonic-gate } 7467c478bd9Sstevel@tonic-gate else if (sm_io_flush(df, SM_TIME_DEFAULT) != 0 || sm_io_error(df)) 7477c478bd9Sstevel@tonic-gate { 7487c478bd9Sstevel@tonic-gate dferror(df, "sm_io_flush||sm_io_error", e); 7497c478bd9Sstevel@tonic-gate flush_errors(true); 7507c478bd9Sstevel@tonic-gate finis(true, true, ExitStat); 7517c478bd9Sstevel@tonic-gate /* NOTREACHED */ 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate else if (SuperSafe == SAFE_NO || 7547c478bd9Sstevel@tonic-gate SuperSafe == SAFE_INTERACTIVE || 7557c478bd9Sstevel@tonic-gate (SuperSafe == SAFE_REALLY_POSTMILTER && smtpmode)) 7567c478bd9Sstevel@tonic-gate { 7577c478bd9Sstevel@tonic-gate /* skip next few clauses */ 7587c478bd9Sstevel@tonic-gate /* EMPTY */ 7597c478bd9Sstevel@tonic-gate /* Note: updfs() is not called in this case! */ 7607c478bd9Sstevel@tonic-gate } 7617c478bd9Sstevel@tonic-gate else if (sm_io_setinfo(df, SM_BF_COMMIT, NULL) < 0 && errno != EINVAL) 7627c478bd9Sstevel@tonic-gate { 7637c478bd9Sstevel@tonic-gate int save_errno = errno; 7647c478bd9Sstevel@tonic-gate 7657c478bd9Sstevel@tonic-gate if (save_errno == EEXIST) 7667c478bd9Sstevel@tonic-gate { 7677c478bd9Sstevel@tonic-gate char *dfile; 7687c478bd9Sstevel@tonic-gate struct stat st; 7697c478bd9Sstevel@tonic-gate int dfd; 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate dfile = queuename(e, DATAFL_LETTER); 7727c478bd9Sstevel@tonic-gate if (stat(dfile, &st) < 0) 7737c478bd9Sstevel@tonic-gate st.st_size = -1; 7747c478bd9Sstevel@tonic-gate errno = EEXIST; 7757c478bd9Sstevel@tonic-gate syserr("@collect: bfcommit(%s): already on disk, size=%ld", 7767c478bd9Sstevel@tonic-gate dfile, (long) st.st_size); 7777c478bd9Sstevel@tonic-gate dfd = sm_io_getinfo(df, SM_IO_WHAT_FD, NULL); 7787c478bd9Sstevel@tonic-gate if (dfd >= 0) 7797c478bd9Sstevel@tonic-gate dumpfd(dfd, true, true); 7807c478bd9Sstevel@tonic-gate } 7817c478bd9Sstevel@tonic-gate errno = save_errno; 7827c478bd9Sstevel@tonic-gate dferror(df, "bfcommit", e); 7837c478bd9Sstevel@tonic-gate flush_errors(true); 7847c478bd9Sstevel@tonic-gate finis(save_errno != EEXIST, true, ExitStat); 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate else if ((afd = sm_io_getinfo(df, SM_IO_WHAT_FD, NULL)) < 0) 7877c478bd9Sstevel@tonic-gate { 7887c478bd9Sstevel@tonic-gate dferror(df, "sm_io_getinfo", e); 7897c478bd9Sstevel@tonic-gate flush_errors(true); 7907c478bd9Sstevel@tonic-gate finis(true, true, ExitStat); 7917c478bd9Sstevel@tonic-gate /* NOTREACHED */ 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate else if (fsync(afd) < 0) 7947c478bd9Sstevel@tonic-gate { 7957c478bd9Sstevel@tonic-gate dferror(df, "fsync", e); 7967c478bd9Sstevel@tonic-gate flush_errors(true); 7977c478bd9Sstevel@tonic-gate finis(true, true, ExitStat); 7987c478bd9Sstevel@tonic-gate /* NOTREACHED */ 7997c478bd9Sstevel@tonic-gate } 8007c478bd9Sstevel@tonic-gate else if (sm_io_close(df, SM_TIME_DEFAULT) < 0) 8017c478bd9Sstevel@tonic-gate { 8027c478bd9Sstevel@tonic-gate dferror(df, "sm_io_close", e); 8037c478bd9Sstevel@tonic-gate flush_errors(true); 8047c478bd9Sstevel@tonic-gate finis(true, true, ExitStat); 8057c478bd9Sstevel@tonic-gate /* NOTREACHED */ 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate else 8087c478bd9Sstevel@tonic-gate { 8097c478bd9Sstevel@tonic-gate /* everything is happily flushed to disk */ 8107c478bd9Sstevel@tonic-gate df = NULL; 8117c478bd9Sstevel@tonic-gate 8127c478bd9Sstevel@tonic-gate /* remove from available space in filesystem */ 8137c478bd9Sstevel@tonic-gate updfs(e, 0, 1, "collect"); 8147c478bd9Sstevel@tonic-gate } 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate /* An EOF when running SMTP is an error */ 817*445f2479Sjbeck readabort: 8187c478bd9Sstevel@tonic-gate if (inputerr && (OpMode == MD_SMTP || OpMode == MD_DAEMON)) 8197c478bd9Sstevel@tonic-gate { 8207c478bd9Sstevel@tonic-gate char *host; 8217c478bd9Sstevel@tonic-gate char *problem; 8227c478bd9Sstevel@tonic-gate ADDRESS *q; 8237c478bd9Sstevel@tonic-gate 8247c478bd9Sstevel@tonic-gate host = RealHostName; 8257c478bd9Sstevel@tonic-gate if (host == NULL) 8267c478bd9Sstevel@tonic-gate host = "localhost"; 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate if (sm_io_eof(fp)) 8297c478bd9Sstevel@tonic-gate problem = "unexpected close"; 8307c478bd9Sstevel@tonic-gate else if (sm_io_error(fp)) 8317c478bd9Sstevel@tonic-gate problem = "I/O error"; 8327c478bd9Sstevel@tonic-gate else 8337c478bd9Sstevel@tonic-gate problem = "read timeout"; 8347c478bd9Sstevel@tonic-gate if (LogLevel > 0 && sm_io_eof(fp)) 8357c478bd9Sstevel@tonic-gate sm_syslog(LOG_NOTICE, e->e_id, 8367c478bd9Sstevel@tonic-gate "collect: %s on connection from %.100s, sender=%s", 8377c478bd9Sstevel@tonic-gate problem, host, 8387c478bd9Sstevel@tonic-gate shortenstring(e->e_from.q_paddr, MAXSHORTSTR)); 8397c478bd9Sstevel@tonic-gate if (sm_io_eof(fp)) 840*445f2479Sjbeck usrerr("421 4.4.1 collect: %s on connection from %s, from=%s", 8417c478bd9Sstevel@tonic-gate problem, host, 8427c478bd9Sstevel@tonic-gate shortenstring(e->e_from.q_paddr, MAXSHORTSTR)); 8437c478bd9Sstevel@tonic-gate else 844*445f2479Sjbeck syserr("421 4.4.1 collect: %s on connection from %s, from=%s", 8457c478bd9Sstevel@tonic-gate problem, host, 8467c478bd9Sstevel@tonic-gate shortenstring(e->e_from.q_paddr, MAXSHORTSTR)); 847*445f2479Sjbeck flush_errors(true); 8487c478bd9Sstevel@tonic-gate 8497c478bd9Sstevel@tonic-gate /* don't return an error indication */ 8507c478bd9Sstevel@tonic-gate e->e_to = NULL; 8517c478bd9Sstevel@tonic-gate e->e_flags &= ~EF_FATALERRS; 8527c478bd9Sstevel@tonic-gate e->e_flags |= EF_CLRQUEUE; 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate /* Don't send any message notification to sender */ 8557c478bd9Sstevel@tonic-gate for (q = e->e_sendqueue; q != NULL; q = q->q_next) 8567c478bd9Sstevel@tonic-gate { 8577c478bd9Sstevel@tonic-gate if (QS_IS_DEAD(q->q_state)) 8587c478bd9Sstevel@tonic-gate continue; 8597c478bd9Sstevel@tonic-gate q->q_state = QS_FATALERR; 8607c478bd9Sstevel@tonic-gate } 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate finis(true, true, ExitStat); 8637c478bd9Sstevel@tonic-gate /* NOTREACHED */ 8647c478bd9Sstevel@tonic-gate } 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate /* Log collection information. */ 8677c478bd9Sstevel@tonic-gate if (bitset(EF_LOGSENDER, e->e_flags) && LogLevel > 4) 8687c478bd9Sstevel@tonic-gate { 8697c478bd9Sstevel@tonic-gate logsender(e, e->e_msgid); 8707c478bd9Sstevel@tonic-gate e->e_flags &= ~EF_LOGSENDER; 8717c478bd9Sstevel@tonic-gate } 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate /* check for message too large */ 8747c478bd9Sstevel@tonic-gate if (bitset(EF_TOOBIG, e->e_flags)) 8757c478bd9Sstevel@tonic-gate { 8767c478bd9Sstevel@tonic-gate e->e_flags |= EF_NO_BODY_RETN|EF_CLRQUEUE; 8777c478bd9Sstevel@tonic-gate if (!bitset(EF_FATALERRS, e->e_flags)) 8787c478bd9Sstevel@tonic-gate { 8797c478bd9Sstevel@tonic-gate e->e_status = "5.2.3"; 8807c478bd9Sstevel@tonic-gate usrerrenh(e->e_status, 8817c478bd9Sstevel@tonic-gate "552 Message exceeds maximum fixed size (%ld)", 8827c478bd9Sstevel@tonic-gate MaxMessageSize); 8837c478bd9Sstevel@tonic-gate if (LogLevel > 6) 8847c478bd9Sstevel@tonic-gate sm_syslog(LOG_NOTICE, e->e_id, 8857c478bd9Sstevel@tonic-gate "message size (%ld) exceeds maximum (%ld)", 8867c478bd9Sstevel@tonic-gate e->e_msgsize, MaxMessageSize); 8877c478bd9Sstevel@tonic-gate } 8887c478bd9Sstevel@tonic-gate } 8897c478bd9Sstevel@tonic-gate 8907c478bd9Sstevel@tonic-gate /* check for illegal 8-bit data */ 8917c478bd9Sstevel@tonic-gate if (HasEightBits) 8927c478bd9Sstevel@tonic-gate { 8937c478bd9Sstevel@tonic-gate e->e_flags |= EF_HAS8BIT; 8947c478bd9Sstevel@tonic-gate if (!bitset(MM_PASS8BIT|MM_MIME8BIT, MimeMode) && 8957c478bd9Sstevel@tonic-gate !bitset(EF_IS_MIME, e->e_flags)) 8967c478bd9Sstevel@tonic-gate { 8977c478bd9Sstevel@tonic-gate e->e_status = "5.6.1"; 8987c478bd9Sstevel@tonic-gate usrerrenh(e->e_status, "554 Eight bit data not allowed"); 8997c478bd9Sstevel@tonic-gate } 9007c478bd9Sstevel@tonic-gate } 9017c478bd9Sstevel@tonic-gate else 9027c478bd9Sstevel@tonic-gate { 9037c478bd9Sstevel@tonic-gate /* if it claimed to be 8 bits, well, it lied.... */ 9047c478bd9Sstevel@tonic-gate if (e->e_bodytype != NULL && 9057c478bd9Sstevel@tonic-gate sm_strcasecmp(e->e_bodytype, "8BITMIME") == 0) 9067c478bd9Sstevel@tonic-gate e->e_bodytype = "7BIT"; 9077c478bd9Sstevel@tonic-gate } 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate if (SuperSafe == SAFE_REALLY && !bitset(EF_FATALERRS, e->e_flags)) 9107c478bd9Sstevel@tonic-gate { 9117c478bd9Sstevel@tonic-gate char *dfname = queuename(e, DATAFL_LETTER); 9127c478bd9Sstevel@tonic-gate if ((e->e_dfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, dfname, 9137c478bd9Sstevel@tonic-gate SM_IO_RDONLY_B, NULL)) == NULL) 9147c478bd9Sstevel@tonic-gate { 9157c478bd9Sstevel@tonic-gate /* we haven't acked receipt yet, so just chuck this */ 9167c478bd9Sstevel@tonic-gate syserr("@Cannot reopen %s", dfname); 9177c478bd9Sstevel@tonic-gate finis(true, true, ExitStat); 9187c478bd9Sstevel@tonic-gate /* NOTREACHED */ 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate } 9217c478bd9Sstevel@tonic-gate else 9227c478bd9Sstevel@tonic-gate e->e_dfp = df; 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate /* collect statistics */ 9257c478bd9Sstevel@tonic-gate if (OpMode != MD_VERIFY) 9267c478bd9Sstevel@tonic-gate { 9277c478bd9Sstevel@tonic-gate /* 9287c478bd9Sstevel@tonic-gate ** Recalculate e_msgpriority, it is done at in eatheader() 9297c478bd9Sstevel@tonic-gate ** which is called (in 8.12) after the header is collected, 9307c478bd9Sstevel@tonic-gate ** hence e_msgsize is (most likely) incorrect. 9317c478bd9Sstevel@tonic-gate */ 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate e->e_msgpriority = e->e_msgsize 9347c478bd9Sstevel@tonic-gate - e->e_class * WkClassFact 9357c478bd9Sstevel@tonic-gate + e->e_nrcpts * WkRecipFact; 9367c478bd9Sstevel@tonic-gate markstats(e, (ADDRESS *) NULL, STATS_NORMAL); 9377c478bd9Sstevel@tonic-gate } 9387c478bd9Sstevel@tonic-gate } 9397c478bd9Sstevel@tonic-gate 9407c478bd9Sstevel@tonic-gate /* 9417c478bd9Sstevel@tonic-gate ** DFERROR -- signal error on writing the data file. 9427c478bd9Sstevel@tonic-gate ** 9437c478bd9Sstevel@tonic-gate ** Called by collect(). Collect() always terminates the process 9447c478bd9Sstevel@tonic-gate ** immediately after calling dferror(), which means that the SMTP 9457c478bd9Sstevel@tonic-gate ** session will be terminated, which means that any error message 9467c478bd9Sstevel@tonic-gate ** issued by dferror must be a 421 error, as per RFC 821. 9477c478bd9Sstevel@tonic-gate ** 9487c478bd9Sstevel@tonic-gate ** Parameters: 9497c478bd9Sstevel@tonic-gate ** df -- the file pointer for the data file. 9507c478bd9Sstevel@tonic-gate ** msg -- detailed message. 9517c478bd9Sstevel@tonic-gate ** e -- the current envelope. 9527c478bd9Sstevel@tonic-gate ** 9537c478bd9Sstevel@tonic-gate ** Returns: 9547c478bd9Sstevel@tonic-gate ** none. 9557c478bd9Sstevel@tonic-gate ** 9567c478bd9Sstevel@tonic-gate ** Side Effects: 9577c478bd9Sstevel@tonic-gate ** Gives an error message. 9587c478bd9Sstevel@tonic-gate ** Arranges for following output to go elsewhere. 9597c478bd9Sstevel@tonic-gate */ 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate void 9627c478bd9Sstevel@tonic-gate dferror(df, msg, e) 9637c478bd9Sstevel@tonic-gate SM_FILE_T *volatile df; 9647c478bd9Sstevel@tonic-gate char *msg; 9657c478bd9Sstevel@tonic-gate register ENVELOPE *e; 9667c478bd9Sstevel@tonic-gate { 9677c478bd9Sstevel@tonic-gate char *dfname; 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate dfname = queuename(e, DATAFL_LETTER); 9707c478bd9Sstevel@tonic-gate setstat(EX_IOERR); 9717c478bd9Sstevel@tonic-gate if (errno == ENOSPC) 9727c478bd9Sstevel@tonic-gate { 9737c478bd9Sstevel@tonic-gate #if STAT64 > 0 9747c478bd9Sstevel@tonic-gate struct stat64 st; 9757c478bd9Sstevel@tonic-gate #else /* STAT64 > 0 */ 9767c478bd9Sstevel@tonic-gate struct stat st; 9777c478bd9Sstevel@tonic-gate #endif /* STAT64 > 0 */ 9787c478bd9Sstevel@tonic-gate long avail; 9797c478bd9Sstevel@tonic-gate long bsize; 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate e->e_flags |= EF_NO_BODY_RETN; 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate if ( 9847c478bd9Sstevel@tonic-gate #if STAT64 > 0 9857c478bd9Sstevel@tonic-gate fstat64(sm_io_getinfo(df, SM_IO_WHAT_FD, NULL), &st) 9867c478bd9Sstevel@tonic-gate #else /* STAT64 > 0 */ 9877c478bd9Sstevel@tonic-gate fstat(sm_io_getinfo(df, SM_IO_WHAT_FD, NULL), &st) 9887c478bd9Sstevel@tonic-gate #endif /* STAT64 > 0 */ 9897c478bd9Sstevel@tonic-gate < 0) 9907c478bd9Sstevel@tonic-gate st.st_size = 0; 9917c478bd9Sstevel@tonic-gate (void) sm_io_reopen(SmFtStdio, SM_TIME_DEFAULT, dfname, 9927c478bd9Sstevel@tonic-gate SM_IO_WRONLY_B, NULL, df); 9937c478bd9Sstevel@tonic-gate if (st.st_size <= 0) 9947c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(df, SM_TIME_DEFAULT, 9957c478bd9Sstevel@tonic-gate "\n*** Mail could not be accepted"); 9967c478bd9Sstevel@tonic-gate else 9977c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(df, SM_TIME_DEFAULT, 9987c478bd9Sstevel@tonic-gate "\n*** Mail of at least %llu bytes could not be accepted\n", 9997c478bd9Sstevel@tonic-gate (ULONGLONG_T) st.st_size); 10007c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(df, SM_TIME_DEFAULT, 10017c478bd9Sstevel@tonic-gate "*** at %s due to lack of disk space for temp file.\n", 10027c478bd9Sstevel@tonic-gate MyHostName); 10037c478bd9Sstevel@tonic-gate avail = freediskspace(qid_printqueue(e->e_qgrp, e->e_qdir), 10047c478bd9Sstevel@tonic-gate &bsize); 10057c478bd9Sstevel@tonic-gate if (avail > 0) 10067c478bd9Sstevel@tonic-gate { 10077c478bd9Sstevel@tonic-gate if (bsize > 1024) 10087c478bd9Sstevel@tonic-gate avail *= bsize / 1024; 10097c478bd9Sstevel@tonic-gate else if (bsize < 1024) 10107c478bd9Sstevel@tonic-gate avail /= 1024 / bsize; 10117c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(df, SM_TIME_DEFAULT, 10127c478bd9Sstevel@tonic-gate "*** Currently, %ld kilobytes are available for mail temp files.\n", 10137c478bd9Sstevel@tonic-gate avail); 10147c478bd9Sstevel@tonic-gate } 10157c478bd9Sstevel@tonic-gate #if 0 10167c478bd9Sstevel@tonic-gate /* Wrong response code; should be 421. */ 10177c478bd9Sstevel@tonic-gate e->e_status = "4.3.1"; 10187c478bd9Sstevel@tonic-gate usrerrenh(e->e_status, "452 Out of disk space for temp file"); 10197c478bd9Sstevel@tonic-gate #else /* 0 */ 10207c478bd9Sstevel@tonic-gate syserr("421 4.3.1 Out of disk space for temp file"); 10217c478bd9Sstevel@tonic-gate #endif /* 0 */ 10227c478bd9Sstevel@tonic-gate } 10237c478bd9Sstevel@tonic-gate else 10247c478bd9Sstevel@tonic-gate syserr("421 4.3.0 collect: Cannot write %s (%s, uid=%d, gid=%d)", 10257c478bd9Sstevel@tonic-gate dfname, msg, (int) geteuid(), (int) getegid()); 10267c478bd9Sstevel@tonic-gate if (sm_io_reopen(SmFtStdio, SM_TIME_DEFAULT, SM_PATH_DEVNULL, 10277c478bd9Sstevel@tonic-gate SM_IO_WRONLY, NULL, df) == NULL) 10287c478bd9Sstevel@tonic-gate sm_syslog(LOG_ERR, e->e_id, 10297c478bd9Sstevel@tonic-gate "dferror: sm_io_reopen(\"/dev/null\") failed: %s", 10307c478bd9Sstevel@tonic-gate sm_errstring(errno)); 10317c478bd9Sstevel@tonic-gate } 10327c478bd9Sstevel@tonic-gate /* 10337c478bd9Sstevel@tonic-gate ** EATFROM -- chew up a UNIX style from line and process 10347c478bd9Sstevel@tonic-gate ** 10357c478bd9Sstevel@tonic-gate ** This does indeed make some assumptions about the format 10367c478bd9Sstevel@tonic-gate ** of UNIX messages. 10377c478bd9Sstevel@tonic-gate ** 10387c478bd9Sstevel@tonic-gate ** Parameters: 10397c478bd9Sstevel@tonic-gate ** fm -- the from line. 10407c478bd9Sstevel@tonic-gate ** e -- envelope 10417c478bd9Sstevel@tonic-gate ** 10427c478bd9Sstevel@tonic-gate ** Returns: 10437c478bd9Sstevel@tonic-gate ** none. 10447c478bd9Sstevel@tonic-gate ** 10457c478bd9Sstevel@tonic-gate ** Side Effects: 10467c478bd9Sstevel@tonic-gate ** extracts what information it can from the header, 10477c478bd9Sstevel@tonic-gate ** such as the date. 10487c478bd9Sstevel@tonic-gate */ 10497c478bd9Sstevel@tonic-gate 10507c478bd9Sstevel@tonic-gate #ifndef NOTUNIX 10517c478bd9Sstevel@tonic-gate 10527c478bd9Sstevel@tonic-gate static char *DowList[] = 10537c478bd9Sstevel@tonic-gate { 10547c478bd9Sstevel@tonic-gate "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL 10557c478bd9Sstevel@tonic-gate }; 10567c478bd9Sstevel@tonic-gate 10577c478bd9Sstevel@tonic-gate static char *MonthList[] = 10587c478bd9Sstevel@tonic-gate { 10597c478bd9Sstevel@tonic-gate "Jan", "Feb", "Mar", "Apr", "May", "Jun", 10607c478bd9Sstevel@tonic-gate "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 10617c478bd9Sstevel@tonic-gate NULL 10627c478bd9Sstevel@tonic-gate }; 10637c478bd9Sstevel@tonic-gate 10647c478bd9Sstevel@tonic-gate static void 10657c478bd9Sstevel@tonic-gate eatfrom(fm, e) 10667c478bd9Sstevel@tonic-gate char *volatile fm; 10677c478bd9Sstevel@tonic-gate register ENVELOPE *e; 10687c478bd9Sstevel@tonic-gate { 10697c478bd9Sstevel@tonic-gate register char *p; 10707c478bd9Sstevel@tonic-gate register char **dt; 10717c478bd9Sstevel@tonic-gate 10727c478bd9Sstevel@tonic-gate if (tTd(30, 2)) 10737c478bd9Sstevel@tonic-gate sm_dprintf("eatfrom(%s)\n", fm); 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate /* find the date part */ 10767c478bd9Sstevel@tonic-gate p = fm; 10777c478bd9Sstevel@tonic-gate while (*p != '\0') 10787c478bd9Sstevel@tonic-gate { 10797c478bd9Sstevel@tonic-gate /* skip a word */ 10807c478bd9Sstevel@tonic-gate while (*p != '\0' && *p != ' ') 10817c478bd9Sstevel@tonic-gate p++; 10827c478bd9Sstevel@tonic-gate while (*p == ' ') 10837c478bd9Sstevel@tonic-gate p++; 10847c478bd9Sstevel@tonic-gate if (strlen(p) < 17) 10857c478bd9Sstevel@tonic-gate { 10867c478bd9Sstevel@tonic-gate /* no room for the date */ 10877c478bd9Sstevel@tonic-gate return; 10887c478bd9Sstevel@tonic-gate } 10897c478bd9Sstevel@tonic-gate if (!(isascii(*p) && isupper(*p)) || 10907c478bd9Sstevel@tonic-gate p[3] != ' ' || p[13] != ':' || p[16] != ':') 10917c478bd9Sstevel@tonic-gate continue; 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate /* we have a possible date */ 10947c478bd9Sstevel@tonic-gate for (dt = DowList; *dt != NULL; dt++) 10957c478bd9Sstevel@tonic-gate if (strncmp(*dt, p, 3) == 0) 10967c478bd9Sstevel@tonic-gate break; 10977c478bd9Sstevel@tonic-gate if (*dt == NULL) 10987c478bd9Sstevel@tonic-gate continue; 10997c478bd9Sstevel@tonic-gate 11007c478bd9Sstevel@tonic-gate for (dt = MonthList; *dt != NULL; dt++) 11017c478bd9Sstevel@tonic-gate { 11027c478bd9Sstevel@tonic-gate if (strncmp(*dt, &p[4], 3) == 0) 11037c478bd9Sstevel@tonic-gate break; 11047c478bd9Sstevel@tonic-gate } 11057c478bd9Sstevel@tonic-gate if (*dt != NULL) 11067c478bd9Sstevel@tonic-gate break; 11077c478bd9Sstevel@tonic-gate } 11087c478bd9Sstevel@tonic-gate 11097c478bd9Sstevel@tonic-gate if (*p != '\0') 11107c478bd9Sstevel@tonic-gate { 11117c478bd9Sstevel@tonic-gate char *q, buf[25]; 11127c478bd9Sstevel@tonic-gate 11137c478bd9Sstevel@tonic-gate /* we have found a date */ 11147c478bd9Sstevel@tonic-gate (void) sm_strlcpy(buf, p, sizeof(buf)); 11157c478bd9Sstevel@tonic-gate q = arpadate(buf); 11167c478bd9Sstevel@tonic-gate macdefine(&e->e_macro, A_TEMP, 'a', q); 11177c478bd9Sstevel@tonic-gate } 11187c478bd9Sstevel@tonic-gate } 11197c478bd9Sstevel@tonic-gate #endif /* ! NOTUNIX */ 1120