122697Sdist /* 234920Sbostic * Copyright (c) 1983 Eric P. Allman 362522Sbostic * Copyright (c) 1988, 1993 462522Sbostic * The Regents of the University of California. All rights reserved. 533728Sbostic * 642824Sbostic * %sccs.include.redist.c% 733728Sbostic */ 822697Sdist 922697Sdist #ifndef lint 10*68559Seric static char sccsid[] = "@(#)collect.c 8.29 (Berkeley) 03/21/95"; 1133728Sbostic #endif /* not lint */ 1222697Sdist 131439Seric # include <errno.h> 143309Seric # include "sendmail.h" 151392Seric 161392Seric /* 172969Seric ** COLLECT -- read & parse message header & make temp file. 181392Seric ** 191392Seric ** Creates a temporary file name and copies the standard 209371Seric ** input to that file. Leading UNIX-style "From" lines are 219371Seric ** stripped off (after important information is extracted). 221392Seric ** 231392Seric ** Parameters: 2467546Seric ** fp -- file to read. 2552106Seric ** smtpmode -- if set, we are running SMTP: give an RFC821 2652105Seric ** style message to say we are ready to collect 2752105Seric ** input, and never ignore a single dot to mean 2852105Seric ** end of message. 2958929Seric ** requeueflag -- this message will be requeued later, so 3058929Seric ** don't do final processing on it. 3167546Seric ** hdrp -- the location to stash the header. 3258929Seric ** e -- the current envelope. 331392Seric ** 341392Seric ** Returns: 354162Seric ** none. 361392Seric ** 371392Seric ** Side Effects: 381392Seric ** Temp file is created and filled. 394162Seric ** The from person may be set. 401392Seric */ 411392Seric 4266796Seric char *CollectErrorMessage; 4366796Seric bool CollectErrno; 4466796Seric 4567599Seric static jmp_buf CtxCollectTimeout; 4668433Seric static void collecttimeout(); 4767599Seric static bool CollectProgress; 4867599Seric static EVENT *CollectTimeout; 4967599Seric 5067599Seric /* values for input state machine */ 5167599Seric #define IS_NORM 0 /* middle of line */ 5267599Seric #define IS_BOL 1 /* beginning of line */ 5367599Seric #define IS_DOT 2 /* read a dot at beginning of line */ 5467599Seric #define IS_DOTCR 3 /* read ".\r" at beginning of line */ 5567599Seric #define IS_CR 4 /* read a carriage return */ 5667599Seric 5767599Seric /* values for message state machine */ 5867599Seric #define MS_UFROM 0 /* reading Unix from line */ 5967599Seric #define MS_HEADER 1 /* reading message header */ 6067599Seric #define MS_BODY 2 /* reading message body */ 6167599Seric 6267599Seric 6368433Seric void 6467546Seric collect(fp, smtpmode, requeueflag, hdrp, e) 6567546Seric FILE *fp; 6652105Seric bool smtpmode; 6758929Seric bool requeueflag; 6867546Seric HDR **hdrp; 6955012Seric register ENVELOPE *e; 701392Seric { 711392Seric register FILE *tf; 7252105Seric bool ignrdot = smtpmode ? FALSE : IgnrDot; 7367268Seric time_t dbto = smtpmode ? TimeOuts.to_datablock : 0; 7467599Seric register char *bp; 7568433Seric int c = '\0'; 7664718Seric bool inputerr = FALSE; 7767546Seric bool headeronly = FALSE; 7867599Seric char *buf; 7967599Seric int buflen; 8067599Seric int istate; 8167599Seric int mstate; 8267599Seric char *pbp; 8367599Seric char peekbuf[8]; 8467599Seric char bufbuf[MAXLINE]; 8567599Seric extern bool isheader(); 8668433Seric extern void eatheader(); 8768433Seric extern void tferror(); 881392Seric 8966796Seric CollectErrorMessage = NULL; 9066796Seric CollectErrno = 0; 9167546Seric if (hdrp == NULL) 9267546Seric hdrp = &e->e_header; 9367546Seric else 9467546Seric headeronly = TRUE; 9566796Seric 961392Seric /* 971392Seric ** Create the temp file name and create the file. 981392Seric */ 991392Seric 10067546Seric if (!headeronly) 1011392Seric { 10267617Seric struct stat stbuf; 10367617Seric 10467546Seric e->e_df = queuename(e, 'd'); 10567546Seric e->e_df = newstr(e->e_df); 10667546Seric if ((tf = dfopen(e->e_df, O_WRONLY|O_CREAT|O_TRUNC, FileMode)) == NULL) 10767546Seric { 10867546Seric syserr("Cannot create %s", e->e_df); 109*68559Seric e->e_flags |= EF_NO_BODY_RETN; 11067546Seric finis(); 11167546Seric } 11267617Seric if (fstat(fileno(tf), &stbuf) < 0) 11367617Seric e->e_dfino = -1; 11467617Seric else 11567688Seric { 11667688Seric e->e_dfdev = stbuf.st_dev; 11767617Seric e->e_dfino = stbuf.st_ino; 11867688Seric } 11967546Seric HasEightBits = FALSE; 1201392Seric } 1211392Seric 1224316Seric /* 1234322Seric ** Tell ARPANET to go ahead. 1244322Seric */ 1254322Seric 12652105Seric if (smtpmode) 12758151Seric message("354 Enter mail, end with \".\" on a line by itself"); 1284322Seric 1294322Seric /* 13067599Seric ** Read the message. 13167599Seric ** 13267599Seric ** This is done using two interleaved state machines. 13367599Seric ** The input state machine is looking for things like 13467599Seric ** hidden dots; the message state machine is handling 13567599Seric ** the larger picture (e.g., header versus body). 1364316Seric */ 1374316Seric 13867599Seric buf = bp = bufbuf; 13967599Seric buflen = sizeof bufbuf; 14067599Seric pbp = peekbuf; 14167599Seric istate = IS_BOL; 14267599Seric mstate = SaveFrom ? MS_HEADER : MS_UFROM; 14367599Seric CollectProgress = FALSE; 14467599Seric 14567599Seric /* if transmitting binary, don't map NL to EOL */ 14667599Seric if (e->e_bodytype != NULL && strcasecmp(e->e_bodytype, "8BITMIME") == 0) 14767599Seric e->e_flags |= EF_NL_NOT_EOL; 14867599Seric 14967599Seric if (dbto != 0) 1502900Seric { 15167599Seric /* handle possible input timeout */ 15267599Seric if (setjmp(CtxCollectTimeout) != 0) 15367599Seric { 15467599Seric #ifdef LOG 15567599Seric syslog(LOG_NOTICE, 15667599Seric "timeout waiting for input from %s during message collect", 15767599Seric CurHostName ? CurHostName : "<local machine>"); 15867599Seric #endif 15967599Seric errno = 0; 16067599Seric usrerr("451 timeout waiting for input during message collect"); 16140965Sbostic goto readerr; 16267599Seric } 16367599Seric CollectTimeout = setevent(dbto, collecttimeout, dbto); 1642900Seric } 1652900Seric 16640965Sbostic for (;;) 1671392Seric { 16867599Seric if (tTd(30, 35)) 16967599Seric printf("top, istate=%d, mstate=%d\n", istate, mstate); 17040965Sbostic for (;;) 1711392Seric { 17267599Seric if (pbp > peekbuf) 17367599Seric c = *--pbp; 17467599Seric else 17564916Seric { 17667599Seric while (!feof(InChannel) && !ferror(InChannel)) 17767599Seric { 17867599Seric errno = 0; 17967599Seric c = fgetc(InChannel); 18067599Seric if (errno != EINTR) 18167599Seric break; 18267599Seric clearerr(InChannel); 18367599Seric } 18467599Seric CollectProgress = TRUE; 18567599Seric if (TrafficLogFile != NULL) 18667599Seric { 18767599Seric if (istate == IS_BOL) 18867599Seric fprintf(TrafficLogFile, "%05d <<< ", 18967599Seric getpid()); 19067599Seric if (c == EOF) 19167599Seric fprintf(TrafficLogFile, "[EOF]\n"); 19267599Seric else 19367599Seric fputc(c, TrafficLogFile); 19467599Seric } 19567599Seric if (c == EOF) 19667599Seric goto readerr; 19767599Seric if (SevenBitInput) 19867599Seric c &= 0x7f; 19967599Seric else 20067599Seric HasEightBits |= bitset(0x80, c); 20167599Seric e->e_msgsize++; 20267599Seric } 20367599Seric if (tTd(30, 94)) 20467599Seric printf("istate=%d, c=%c (0x%x)\n", 20567599Seric istate, c, c); 20667599Seric switch (istate) 20767599Seric { 20867599Seric case IS_BOL: 20967599Seric if (c == '.') 21067599Seric { 21167599Seric istate = IS_DOT; 21267599Seric continue; 21367599Seric } 21464916Seric break; 21540965Sbostic 21667599Seric case IS_DOT: 21767599Seric if (c == '\n' && !ignrdot && 21867599Seric !bitset(EF_NL_NOT_EOL, e->e_flags)) 21967599Seric goto readerr; 22067599Seric else if (c == '\r' && 22167599Seric !bitset(EF_CRLF_NOT_EOL, e->e_flags)) 22267599Seric { 22367599Seric istate = IS_DOTCR; 22467599Seric continue; 22567599Seric } 22667599Seric else if (c != '.' || 22767599Seric (OpMode != MD_SMTP && 22867599Seric OpMode != MD_DAEMON && 22967599Seric OpMode != MD_ARPAFTP)) 23067599Seric { 23167599Seric *pbp++ = c; 23267599Seric c = '.'; 23367599Seric } 2342900Seric break; 23540965Sbostic 23667599Seric case IS_DOTCR: 23767599Seric if (c == '\n') 23867599Seric goto readerr; 23967599Seric else 24067599Seric { 24167599Seric /* push back the ".\rx" */ 24267599Seric *pbp++ = c; 24367599Seric *pbp++ = '\r'; 24467599Seric c = '.'; 24567599Seric } 24667599Seric break; 24740965Sbostic 24867599Seric case IS_CR: 24967689Seric if (c == '\n') 25067689Seric istate = IS_BOL; 25167689Seric else 25267599Seric { 25367599Seric ungetc(c, InChannel); 25467599Seric c = '\r'; 25567689Seric istate = IS_NORM; 25667599Seric } 25767689Seric goto bufferchar; 25867599Seric } 25957135Seric 26067689Seric if (c == '\r' && !bitset(EF_CRLF_NOT_EOL, e->e_flags)) 26140965Sbostic { 26267599Seric istate = IS_CR; 26367599Seric continue; 26467599Seric } 26567599Seric else if (c == '\n' && !bitset(EF_NL_NOT_EOL, e->e_flags)) 26667599Seric istate = IS_BOL; 26767599Seric else 26867599Seric istate = IS_NORM; 26940965Sbostic 27067689Seric bufferchar: 27167599Seric if (mstate == MS_BODY) 27267599Seric { 27367599Seric /* just put the character out */ 27467831Seric if (MaxMessageSize <= 0 || 27567831Seric e->e_msgsize <= MaxMessageSize) 27667831Seric fputc(c, tf); 27767599Seric continue; 27840965Sbostic } 2791392Seric 28067599Seric /* header -- buffer up */ 28167599Seric if (bp >= &buf[buflen - 2]) 28267599Seric { 28367599Seric char *obuf; 2841392Seric 28567599Seric if (mstate != MS_HEADER) 28667599Seric break; 28740965Sbostic 28867599Seric /* out of space for header */ 28967599Seric obuf = buf; 29067599Seric if (buflen < MEMCHUNKSIZE) 29167599Seric buflen *= 2; 29267599Seric else 29367599Seric buflen += MEMCHUNKSIZE; 29467599Seric buf = xalloc(buflen); 29567599Seric bcopy(obuf, buf, bp - obuf); 29667599Seric bp = &buf[bp - obuf]; 29767599Seric if (obuf != bufbuf) 29867599Seric free(obuf); 29967599Seric } 30067599Seric *bp++ = c; 30167599Seric if (istate == IS_BOL) 30267599Seric break; 30340965Sbostic } 30467599Seric *bp = '\0'; 30540965Sbostic 30667599Seric nextstate: 30767599Seric if (tTd(30, 35)) 30867599Seric printf("nextstate, istate=%d, mstate=%d, line = \"%s\"\n", 30967599Seric istate, mstate, buf); 31067599Seric switch (mstate) 31167599Seric { 31268433Seric extern int chompheader(); 31368433Seric 31467599Seric case MS_UFROM: 31567599Seric mstate = MS_HEADER; 31667599Seric if (strncmp(buf, "From ", 5) == 0) 31767599Seric { 31868433Seric extern void eatfrom(); 31968433Seric 32067704Seric bp = buf; 32167599Seric eatfrom(buf, e); 32267599Seric continue; 32367599Seric } 32467599Seric /* fall through */ 3252900Seric 32667599Seric case MS_HEADER: 32767599Seric if (!isheader(buf)) 32867599Seric { 32967599Seric mstate = MS_BODY; 33067599Seric goto nextstate; 33167599Seric } 33257135Seric 33367599Seric /* check for possible continuation line */ 33467599Seric do 33567599Seric { 33667599Seric clearerr(InChannel); 33767599Seric errno = 0; 33867599Seric c = fgetc(InChannel); 33967599Seric } while (errno == EINTR); 34067599Seric if (c != EOF) 34167599Seric ungetc(c, InChannel); 34267599Seric if (c == ' ' || c == '\t') 34367599Seric { 34467599Seric /* yep -- defer this */ 34567599Seric continue; 34667599Seric } 34757135Seric 34867599Seric /* trim off trailing CRLF or NL */ 34967599Seric if (*--bp != '\n' || *--bp != '\r') 35067599Seric bp++; 35167599Seric *bp = '\0'; 35267599Seric if (bitset(H_EOH, chompheader(buf, FALSE, e))) 35367599Seric mstate = MS_BODY; 35467599Seric break; 3551392Seric 35667599Seric case MS_BODY: 35767599Seric if (tTd(30, 1)) 35867599Seric printf("EOH\n"); 35967599Seric if (headeronly) 36067599Seric goto readerr; 36167599Seric bp = buf; 3622900Seric 36367599Seric /* toss blank line */ 36467599Seric if ((!bitset(EF_CRLF_NOT_EOL, e->e_flags) && 36567599Seric bp[0] == '\r' && bp[1] == '\n') || 36667599Seric (!bitset(EF_NL_NOT_EOL, e->e_flags) && 36767599Seric bp[0] == '\n')) 36867599Seric { 36967599Seric break; 37067599Seric } 37167546Seric 37267599Seric /* if not a blank separator, write it out */ 37367831Seric if (MaxMessageSize <= 0 || 37467831Seric e->e_msgsize <= MaxMessageSize) 37567831Seric { 37667831Seric while (*bp != '\0') 37767831Seric fputc(*bp++, tf); 37867831Seric } 3792900Seric break; 38067599Seric } 38167599Seric bp = buf; 38264718Seric } 38340965Sbostic 38467546Seric readerr: 38567546Seric if ((feof(fp) && smtpmode) || ferror(fp)) 38664718Seric { 38764916Seric if (tTd(30, 1)) 38864916Seric printf("collect: read error\n"); 38964718Seric inputerr = TRUE; 39064718Seric } 39164718Seric 39266765Seric /* reset global timer */ 39367599Seric clrevent(CollectTimeout); 39466765Seric 39567546Seric if (headeronly) 39667546Seric return; 39767546Seric 39867546Seric if (tf != NULL) 39964762Seric { 40067546Seric if (fflush(tf) != 0) 40167546Seric tferror(tf, e); 40267546Seric if (fsync(fileno(tf)) < 0 || fclose(tf) < 0) 40367546Seric { 40467546Seric tferror(tf, e); 40567546Seric finis(); 40667546Seric } 40764762Seric } 4082900Seric 40966796Seric if (CollectErrorMessage != NULL && Errors <= 0) 41016136Seric { 41166796Seric if (CollectErrno != 0) 41266796Seric { 41366796Seric errno = CollectErrno; 41466796Seric syserr(CollectErrorMessage, e->e_df); 41566796Seric finis(); 41666796Seric } 41766796Seric usrerr(CollectErrorMessage); 41866796Seric } 41966796Seric else if (inputerr && (OpMode == MD_SMTP || OpMode == MD_DAEMON)) 42066796Seric { 42166796Seric /* An EOF when running SMTP is an error */ 42258308Seric char *host; 42364718Seric char *problem; 42458082Seric 42558308Seric host = RealHostName; 42658308Seric if (host == NULL) 42758308Seric host = "localhost"; 42858308Seric 42967546Seric if (feof(fp)) 43064718Seric problem = "unexpected close"; 43167546Seric else if (ferror(fp)) 43264718Seric problem = "I/O error"; 43364718Seric else 43464718Seric problem = "read timeout"; 43536233Skarels # ifdef LOG 43667546Seric if (LogLevel > 0 && feof(fp)) 43736230Skarels syslog(LOG_NOTICE, 43866864Seric "collect: %s on connection from %s, sender=%s: %s\n", 43966864Seric problem, host, e->e_from.q_paddr, errstring(errno)); 44036233Skarels # endif 44167546Seric if (feof(fp)) 44265951Seric usrerr("451 collect: %s on connection from %s, from=%s", 44364718Seric problem, host, e->e_from.q_paddr); 44465951Seric else 44565951Seric syserr("451 collect: %s on connection from %s, from=%s", 44665951Seric problem, host, e->e_from.q_paddr); 44711145Seric 44816136Seric /* don't return an error indication */ 44955012Seric e->e_to = NULL; 45055012Seric e->e_flags &= ~EF_FATALERRS; 45164124Seric e->e_flags |= EF_CLRQUEUE; 45216136Seric 45316136Seric /* and don't try to deliver the partial message either */ 45464718Seric if (InChild) 45564718Seric ExitStat = EX_QUIT; 45616136Seric finis(); 45716136Seric } 45816136Seric 4592900Seric /* 4602900Seric ** Find out some information from the headers. 4613386Seric ** Examples are who is the from person & the date. 4622900Seric */ 4632900Seric 46458929Seric eatheader(e, !requeueflag); 4657673Seric 46664068Seric /* collect statistics */ 46764068Seric if (OpMode != MD_VERIFY) 46868433Seric { 46968433Seric extern void markstats(); 47068433Seric 47164068Seric markstats(e, (ADDRESS *) NULL); 47268433Seric } 47364068Seric 4747782Seric /* 4757782Seric ** Add an Apparently-To: line if we have no recipient lines. 4767782Seric */ 4774622Seric 47867546Seric if (hvalue("to", e->e_header) == NULL && 47967546Seric hvalue("cc", e->e_header) == NULL && 48067546Seric hvalue("bcc", e->e_header) == NULL && 48167546Seric hvalue("apparently-to", e->e_header) == NULL) 4827367Seric { 4837367Seric register ADDRESS *q; 48468449Seric char *hdr = NULL; 48568449Seric extern void addheader(); 4867367Seric 4877367Seric /* create an Apparently-To: field */ 4887367Seric /* that or reject the message.... */ 48968449Seric switch (NoRecipientAction) 4907367Seric { 49168449Seric case NRA_ADD_APPARENTLY_TO: 49268449Seric hdr = "Apparently-To"; 49368449Seric break; 49468433Seric 49568449Seric case NRA_ADD_TO: 49668449Seric hdr = "To"; 49768449Seric break; 49868449Seric 49968449Seric case NRA_ADD_BCC: 50068449Seric addheader("Bcc", "", &e->e_header); 50168449Seric break; 50268449Seric 50368449Seric case NRA_ADD_TO_UNDISCLOSED: 50468449Seric addheader("To", "undisclosed-recipients:;", &e->e_header); 50568449Seric break; 5067367Seric } 50768449Seric 50868449Seric if (hdr != NULL) 50968449Seric { 51068449Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 51168449Seric { 51268449Seric if (q->q_alias != NULL) 51368449Seric continue; 51468449Seric if (tTd(30, 3)) 51568449Seric printf("Adding %s: %s\n", 51668449Seric hdr, q->q_paddr); 51768449Seric addheader(hdr, q->q_paddr, &e->e_header); 51868449Seric } 51968449Seric } 5207367Seric } 5217367Seric 52259320Seric /* check for message too large */ 52359320Seric if (MaxMessageSize > 0 && e->e_msgsize > MaxMessageSize) 52459320Seric { 52559320Seric usrerr("552 Message exceeds maximum fixed size (%ld)", 52659320Seric MaxMessageSize); 52759320Seric } 52859320Seric 52967547Seric /* check for illegal 8-bit data */ 53067547Seric if (HasEightBits) 53167547Seric { 53267547Seric e->e_flags |= EF_HAS8BIT; 53367887Seric if (!bitset(MM_PASS8BIT|MM_MIME8BIT, MimeMode)) 53467547Seric usrerr("554 Eight bit data not allowed"); 53567547Seric } 53667547Seric 53755012Seric if ((e->e_dfp = fopen(e->e_df, "r")) == NULL) 53858690Seric { 53958690Seric /* we haven't acked receipt yet, so just chuck this */ 54055012Seric syserr("Cannot reopen %s", e->e_df); 54158690Seric finis(); 54258690Seric } 5431392Seric } 54440965Sbostic 54567599Seric 54668433Seric static void 54767599Seric collecttimeout(timeout) 54867599Seric time_t timeout; 54940965Sbostic { 55067599Seric /* if no progress was made, die now */ 55167599Seric if (!CollectProgress) 55267599Seric longjmp(CtxCollectTimeout, 1); 55340965Sbostic 55467599Seric /* otherwise reset the timeout */ 55567599Seric CollectTimeout = setevent(timeout, collecttimeout, timeout); 55667599Seric CollectProgress = FALSE; 55740965Sbostic } 55840965Sbostic /* 55911544Seric ** TFERROR -- signal error on writing the temporary file. 56011544Seric ** 56111544Seric ** Parameters: 56211544Seric ** tf -- the file pointer for the temporary file. 56311544Seric ** 56411544Seric ** Returns: 56511544Seric ** none. 56611544Seric ** 56711544Seric ** Side Effects: 56811544Seric ** Gives an error message. 56911544Seric ** Arranges for following output to go elsewhere. 57011544Seric */ 57111544Seric 57268433Seric void 57355012Seric tferror(tf, e) 57411544Seric FILE *tf; 57555012Seric register ENVELOPE *e; 57611544Seric { 57766796Seric CollectErrno = errno; 57811544Seric if (errno == ENOSPC) 57911544Seric { 58066782Seric struct stat st; 58166782Seric long avail; 58266782Seric long bsize; 58366782Seric 584*68559Seric e->e_flags |= EF_NO_BODY_RETN; 58566782Seric if (fstat(fileno(tf), &st) < 0) 58666782Seric st.st_size = 0; 58755012Seric (void) freopen(e->e_df, "w", tf); 58866782Seric if (st.st_size <= 0) 58966782Seric fprintf(tf, "\n*** Mail could not be accepted"); 59066782Seric else if (sizeof st.st_size > sizeof (long)) 59166782Seric fprintf(tf, "\n*** Mail of at least %qd bytes could not be accepted\n", 59266782Seric st.st_size); 59366782Seric else 59466782Seric fprintf(tf, "\n*** Mail of at least %ld bytes could not be accepted\n", 59566782Seric st.st_size); 59666782Seric fprintf(tf, "*** at %s due to lack of disk space for temp file.\n", 59766782Seric MyHostName); 59866782Seric avail = freespace(QueueDir, &bsize); 59966782Seric if (avail > 0) 60066782Seric { 60166782Seric if (bsize > 1024) 60266782Seric avail *= bsize / 1024; 60366782Seric else if (bsize < 1024) 60466782Seric avail /= 1024 / bsize; 60566782Seric fprintf(tf, "*** Currently, %ld kilobytes are available for mail temp files.\n", 60666782Seric avail); 60766782Seric } 60866796Seric CollectErrorMessage = "452 Out of disk space for temp file"; 60911544Seric } 61011544Seric else 61166796Seric { 61266796Seric CollectErrorMessage = "cannot write message body to disk (%s)"; 61366796Seric } 61411544Seric (void) freopen("/dev/null", "w", tf); 61511544Seric } 61611544Seric /* 6172900Seric ** EATFROM -- chew up a UNIX style from line and process 6182900Seric ** 6192900Seric ** This does indeed make some assumptions about the format 6202900Seric ** of UNIX messages. 6212900Seric ** 6222900Seric ** Parameters: 6232900Seric ** fm -- the from line. 6242900Seric ** 6252900Seric ** Returns: 6262900Seric ** none. 6272900Seric ** 6282900Seric ** Side Effects: 6292900Seric ** extracts what information it can from the header, 6303386Seric ** such as the date. 6312900Seric */ 6322900Seric 6334321Seric # ifndef NOTUNIX 6344321Seric 6354203Seric char *DowList[] = 6364203Seric { 6374203Seric "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL 6384203Seric }; 6394203Seric 6402900Seric char *MonthList[] = 6412900Seric { 6422900Seric "Jan", "Feb", "Mar", "Apr", "May", "Jun", 6432900Seric "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 6442900Seric NULL 6452900Seric }; 6462900Seric 64768433Seric void 64855012Seric eatfrom(fm, e) 6492900Seric char *fm; 65055012Seric register ENVELOPE *e; 6512900Seric { 6522900Seric register char *p; 6532900Seric register char **dt; 6542900Seric 6557673Seric if (tTd(30, 2)) 6564203Seric printf("eatfrom(%s)\n", fm); 6574203Seric 6582900Seric /* find the date part */ 6592900Seric p = fm; 6602900Seric while (*p != '\0') 6612900Seric { 6622900Seric /* skip a word */ 6632900Seric while (*p != '\0' && *p != ' ') 66416896Seric p++; 6652900Seric while (*p == ' ') 66616896Seric p++; 66758050Seric if (!(isascii(*p) && isupper(*p)) || 66858050Seric p[3] != ' ' || p[13] != ':' || p[16] != ':') 6692900Seric continue; 6702900Seric 6712900Seric /* we have a possible date */ 6724203Seric for (dt = DowList; *dt != NULL; dt++) 6732900Seric if (strncmp(*dt, p, 3) == 0) 6742900Seric break; 6754203Seric if (*dt == NULL) 6764203Seric continue; 6772900Seric 6784203Seric for (dt = MonthList; *dt != NULL; dt++) 6794203Seric if (strncmp(*dt, &p[4], 3) == 0) 6804203Seric break; 6812900Seric if (*dt != NULL) 6822900Seric break; 6832900Seric } 6842900Seric 68560502Seric if (*p != '\0') 6862900Seric { 6873386Seric char *q; 6885366Seric extern char *arpadate(); 6893386Seric 6902900Seric /* we have found a date */ 6913386Seric q = xalloc(25); 69223103Seric (void) strncpy(q, p, 25); 6933386Seric q[24] = '\0'; 6945366Seric q = arpadate(q); 69555012Seric define('a', newstr(q), e); 6962900Seric } 6972900Seric } 6984321Seric 69956795Seric # endif /* NOTUNIX */ 700