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*67831Seric static char sccsid[] = "@(#)collect.c 8.25 (Berkeley) 10/17/94"; 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; 4667599Seric static int 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 6367546Seric collect(fp, smtpmode, requeueflag, hdrp, e) 6467546Seric FILE *fp; 6552105Seric bool smtpmode; 6658929Seric bool requeueflag; 6767546Seric HDR **hdrp; 6855012Seric register ENVELOPE *e; 691392Seric { 701392Seric register FILE *tf; 7152105Seric bool ignrdot = smtpmode ? FALSE : IgnrDot; 7267268Seric time_t dbto = smtpmode ? TimeOuts.to_datablock : 0; 7367599Seric register char *bp; 7467599Seric register int c; 7564718Seric bool inputerr = FALSE; 7667546Seric bool headeronly = FALSE; 7767599Seric char *buf; 7867599Seric int buflen; 7967599Seric int istate; 8067599Seric int mstate; 8167599Seric char *pbp; 8267599Seric char peekbuf[8]; 8367599Seric char bufbuf[MAXLINE]; 8467599Seric extern bool isheader(); 851392Seric 8666796Seric CollectErrorMessage = NULL; 8766796Seric CollectErrno = 0; 8867546Seric if (hdrp == NULL) 8967546Seric hdrp = &e->e_header; 9067546Seric else 9167546Seric headeronly = TRUE; 9266796Seric 931392Seric /* 941392Seric ** Create the temp file name and create the file. 951392Seric */ 961392Seric 9767546Seric if (!headeronly) 981392Seric { 9967617Seric struct stat stbuf; 10067617Seric 10167546Seric e->e_df = queuename(e, 'd'); 10267546Seric e->e_df = newstr(e->e_df); 10367546Seric if ((tf = dfopen(e->e_df, O_WRONLY|O_CREAT|O_TRUNC, FileMode)) == NULL) 10467546Seric { 10567546Seric syserr("Cannot create %s", e->e_df); 10667546Seric e->e_flags |= EF_NORETURN; 10767546Seric finis(); 10867546Seric } 10967617Seric if (fstat(fileno(tf), &stbuf) < 0) 11067617Seric e->e_dfino = -1; 11167617Seric else 11267688Seric { 11367688Seric e->e_dfdev = stbuf.st_dev; 11467617Seric e->e_dfino = stbuf.st_ino; 11567688Seric } 11667546Seric HasEightBits = FALSE; 1171392Seric } 1181392Seric 1194316Seric /* 1204322Seric ** Tell ARPANET to go ahead. 1214322Seric */ 1224322Seric 12352105Seric if (smtpmode) 12458151Seric message("354 Enter mail, end with \".\" on a line by itself"); 1254322Seric 1264322Seric /* 12767599Seric ** Read the message. 12867599Seric ** 12967599Seric ** This is done using two interleaved state machines. 13067599Seric ** The input state machine is looking for things like 13167599Seric ** hidden dots; the message state machine is handling 13267599Seric ** the larger picture (e.g., header versus body). 1334316Seric */ 1344316Seric 13567599Seric buf = bp = bufbuf; 13667599Seric buflen = sizeof bufbuf; 13767599Seric pbp = peekbuf; 13867599Seric istate = IS_BOL; 13967599Seric mstate = SaveFrom ? MS_HEADER : MS_UFROM; 14067599Seric CollectProgress = FALSE; 14167599Seric 14267599Seric /* if transmitting binary, don't map NL to EOL */ 14367599Seric if (e->e_bodytype != NULL && strcasecmp(e->e_bodytype, "8BITMIME") == 0) 14467599Seric e->e_flags |= EF_NL_NOT_EOL; 14567599Seric 14667599Seric if (dbto != 0) 1472900Seric { 14867599Seric /* handle possible input timeout */ 14967599Seric if (setjmp(CtxCollectTimeout) != 0) 15067599Seric { 15167599Seric #ifdef LOG 15267599Seric syslog(LOG_NOTICE, 15367599Seric "timeout waiting for input from %s during message collect", 15467599Seric CurHostName ? CurHostName : "<local machine>"); 15567599Seric #endif 15667599Seric errno = 0; 15767599Seric usrerr("451 timeout waiting for input during message collect"); 15840965Sbostic goto readerr; 15967599Seric } 16067599Seric CollectTimeout = setevent(dbto, collecttimeout, dbto); 1612900Seric } 1622900Seric 16340965Sbostic for (;;) 1641392Seric { 16567599Seric if (tTd(30, 35)) 16667599Seric printf("top, istate=%d, mstate=%d\n", istate, mstate); 16740965Sbostic for (;;) 1681392Seric { 16967599Seric if (pbp > peekbuf) 17067599Seric c = *--pbp; 17167599Seric else 17264916Seric { 17367599Seric while (!feof(InChannel) && !ferror(InChannel)) 17467599Seric { 17567599Seric errno = 0; 17667599Seric c = fgetc(InChannel); 17767599Seric if (errno != EINTR) 17867599Seric break; 17967599Seric clearerr(InChannel); 18067599Seric } 18167599Seric CollectProgress = TRUE; 18267599Seric if (TrafficLogFile != NULL) 18367599Seric { 18467599Seric if (istate == IS_BOL) 18567599Seric fprintf(TrafficLogFile, "%05d <<< ", 18667599Seric getpid()); 18767599Seric if (c == EOF) 18867599Seric fprintf(TrafficLogFile, "[EOF]\n"); 18967599Seric else 19067599Seric fputc(c, TrafficLogFile); 19167599Seric } 19267599Seric if (c == EOF) 19367599Seric goto readerr; 19467599Seric if (SevenBitInput) 19567599Seric c &= 0x7f; 19667599Seric else 19767599Seric HasEightBits |= bitset(0x80, c); 19867599Seric e->e_msgsize++; 19967599Seric } 20067599Seric if (tTd(30, 94)) 20167599Seric printf("istate=%d, c=%c (0x%x)\n", 20267599Seric istate, c, c); 20367599Seric switch (istate) 20467599Seric { 20567599Seric case IS_BOL: 20667599Seric if (c == '.') 20767599Seric { 20867599Seric istate = IS_DOT; 20967599Seric continue; 21067599Seric } 21164916Seric break; 21240965Sbostic 21367599Seric case IS_DOT: 21467599Seric if (c == '\n' && !ignrdot && 21567599Seric !bitset(EF_NL_NOT_EOL, e->e_flags)) 21667599Seric goto readerr; 21767599Seric else if (c == '\r' && 21867599Seric !bitset(EF_CRLF_NOT_EOL, e->e_flags)) 21967599Seric { 22067599Seric istate = IS_DOTCR; 22167599Seric continue; 22267599Seric } 22367599Seric else if (c != '.' || 22467599Seric (OpMode != MD_SMTP && 22567599Seric OpMode != MD_DAEMON && 22667599Seric OpMode != MD_ARPAFTP)) 22767599Seric { 22867599Seric *pbp++ = c; 22967599Seric c = '.'; 23067599Seric } 2312900Seric break; 23240965Sbostic 23367599Seric case IS_DOTCR: 23467599Seric if (c == '\n') 23567599Seric goto readerr; 23667599Seric else 23767599Seric { 23867599Seric /* push back the ".\rx" */ 23967599Seric *pbp++ = c; 24067599Seric *pbp++ = '\r'; 24167599Seric c = '.'; 24267599Seric } 24367599Seric break; 24440965Sbostic 24567599Seric case IS_CR: 24667689Seric if (c == '\n') 24767689Seric istate = IS_BOL; 24867689Seric else 24967599Seric { 25067599Seric ungetc(c, InChannel); 25167599Seric c = '\r'; 25267689Seric istate = IS_NORM; 25367599Seric } 25467689Seric goto bufferchar; 25567599Seric } 25657135Seric 25767689Seric if (c == '\r' && !bitset(EF_CRLF_NOT_EOL, e->e_flags)) 25840965Sbostic { 25967599Seric istate = IS_CR; 26067599Seric continue; 26167599Seric } 26267599Seric else if (c == '\n' && !bitset(EF_NL_NOT_EOL, e->e_flags)) 26367599Seric istate = IS_BOL; 26467599Seric else 26567599Seric istate = IS_NORM; 26640965Sbostic 26767689Seric bufferchar: 26867599Seric if (mstate == MS_BODY) 26967599Seric { 27067599Seric /* just put the character out */ 271*67831Seric if (MaxMessageSize <= 0 || 272*67831Seric e->e_msgsize <= MaxMessageSize) 273*67831Seric fputc(c, tf); 27467599Seric continue; 27540965Sbostic } 2761392Seric 27767599Seric /* header -- buffer up */ 27867599Seric if (bp >= &buf[buflen - 2]) 27967599Seric { 28067599Seric char *obuf; 2811392Seric 28267599Seric if (mstate != MS_HEADER) 28367599Seric break; 28440965Sbostic 28567599Seric /* out of space for header */ 28667599Seric obuf = buf; 28767599Seric if (buflen < MEMCHUNKSIZE) 28867599Seric buflen *= 2; 28967599Seric else 29067599Seric buflen += MEMCHUNKSIZE; 29167599Seric buf = xalloc(buflen); 29267599Seric bcopy(obuf, buf, bp - obuf); 29367599Seric bp = &buf[bp - obuf]; 29467599Seric if (obuf != bufbuf) 29567599Seric free(obuf); 29667599Seric } 29767599Seric *bp++ = c; 29867599Seric if (istate == IS_BOL) 29967599Seric break; 30040965Sbostic } 30167599Seric *bp = '\0'; 30240965Sbostic 30367599Seric nextstate: 30467599Seric if (tTd(30, 35)) 30567599Seric printf("nextstate, istate=%d, mstate=%d, line = \"%s\"\n", 30667599Seric istate, mstate, buf); 30767599Seric switch (mstate) 30867599Seric { 30967599Seric case MS_UFROM: 31067599Seric mstate = MS_HEADER; 31167599Seric if (strncmp(buf, "From ", 5) == 0) 31267599Seric { 31367704Seric bp = buf; 31467599Seric eatfrom(buf, e); 31567599Seric continue; 31667599Seric } 31767599Seric /* fall through */ 3182900Seric 31967599Seric case MS_HEADER: 32067599Seric if (!isheader(buf)) 32167599Seric { 32267599Seric mstate = MS_BODY; 32367599Seric goto nextstate; 32467599Seric } 32557135Seric 32667599Seric /* check for possible continuation line */ 32767599Seric do 32867599Seric { 32967599Seric clearerr(InChannel); 33067599Seric errno = 0; 33167599Seric c = fgetc(InChannel); 33267599Seric } while (errno == EINTR); 33367599Seric if (c != EOF) 33467599Seric ungetc(c, InChannel); 33567599Seric if (c == ' ' || c == '\t') 33667599Seric { 33767599Seric /* yep -- defer this */ 33867599Seric continue; 33967599Seric } 34057135Seric 34167599Seric /* trim off trailing CRLF or NL */ 34267599Seric if (*--bp != '\n' || *--bp != '\r') 34367599Seric bp++; 34467599Seric *bp = '\0'; 34567599Seric if (bitset(H_EOH, chompheader(buf, FALSE, e))) 34667599Seric mstate = MS_BODY; 34767599Seric break; 3481392Seric 34967599Seric case MS_BODY: 35067599Seric if (tTd(30, 1)) 35167599Seric printf("EOH\n"); 35267599Seric if (headeronly) 35367599Seric goto readerr; 35467599Seric bp = buf; 3552900Seric 35667599Seric /* toss blank line */ 35767599Seric if ((!bitset(EF_CRLF_NOT_EOL, e->e_flags) && 35867599Seric bp[0] == '\r' && bp[1] == '\n') || 35967599Seric (!bitset(EF_NL_NOT_EOL, e->e_flags) && 36067599Seric bp[0] == '\n')) 36167599Seric { 36267599Seric break; 36367599Seric } 36467546Seric 36567599Seric /* if not a blank separator, write it out */ 366*67831Seric if (MaxMessageSize <= 0 || 367*67831Seric e->e_msgsize <= MaxMessageSize) 368*67831Seric { 369*67831Seric while (*bp != '\0') 370*67831Seric fputc(*bp++, tf); 371*67831Seric } 3722900Seric break; 37367599Seric } 37467599Seric bp = buf; 37564718Seric } 37640965Sbostic 37767546Seric readerr: 37867546Seric if ((feof(fp) && smtpmode) || ferror(fp)) 37964718Seric { 38064916Seric if (tTd(30, 1)) 38164916Seric printf("collect: read error\n"); 38264718Seric inputerr = TRUE; 38364718Seric } 38464718Seric 38566765Seric /* reset global timer */ 38667599Seric clrevent(CollectTimeout); 38766765Seric 38867546Seric if (headeronly) 38967546Seric return; 39067546Seric 39167546Seric if (tf != NULL) 39264762Seric { 39367546Seric if (fflush(tf) != 0) 39467546Seric tferror(tf, e); 39567546Seric if (fsync(fileno(tf)) < 0 || fclose(tf) < 0) 39667546Seric { 39767546Seric tferror(tf, e); 39867546Seric finis(); 39967546Seric } 40064762Seric } 4012900Seric 40266796Seric if (CollectErrorMessage != NULL && Errors <= 0) 40316136Seric { 40466796Seric if (CollectErrno != 0) 40566796Seric { 40666796Seric errno = CollectErrno; 40766796Seric syserr(CollectErrorMessage, e->e_df); 40866796Seric finis(); 40966796Seric } 41066796Seric usrerr(CollectErrorMessage); 41166796Seric } 41266796Seric else if (inputerr && (OpMode == MD_SMTP || OpMode == MD_DAEMON)) 41366796Seric { 41466796Seric /* An EOF when running SMTP is an error */ 41558308Seric char *host; 41664718Seric char *problem; 41758082Seric 41858308Seric host = RealHostName; 41958308Seric if (host == NULL) 42058308Seric host = "localhost"; 42158308Seric 42267546Seric if (feof(fp)) 42364718Seric problem = "unexpected close"; 42467546Seric else if (ferror(fp)) 42564718Seric problem = "I/O error"; 42664718Seric else 42764718Seric problem = "read timeout"; 42836233Skarels # ifdef LOG 42967546Seric if (LogLevel > 0 && feof(fp)) 43036230Skarels syslog(LOG_NOTICE, 43166864Seric "collect: %s on connection from %s, sender=%s: %s\n", 43266864Seric problem, host, e->e_from.q_paddr, errstring(errno)); 43336233Skarels # endif 43467546Seric if (feof(fp)) 43565951Seric usrerr("451 collect: %s on connection from %s, from=%s", 43664718Seric problem, host, e->e_from.q_paddr); 43765951Seric else 43865951Seric syserr("451 collect: %s on connection from %s, from=%s", 43965951Seric problem, host, e->e_from.q_paddr); 44011145Seric 44116136Seric /* don't return an error indication */ 44255012Seric e->e_to = NULL; 44355012Seric e->e_flags &= ~EF_FATALERRS; 44464124Seric e->e_flags |= EF_CLRQUEUE; 44516136Seric 44616136Seric /* and don't try to deliver the partial message either */ 44764718Seric if (InChild) 44864718Seric ExitStat = EX_QUIT; 44916136Seric finis(); 45016136Seric } 45116136Seric 4522900Seric /* 4532900Seric ** Find out some information from the headers. 4543386Seric ** Examples are who is the from person & the date. 4552900Seric */ 4562900Seric 45758929Seric eatheader(e, !requeueflag); 4587673Seric 45964068Seric /* collect statistics */ 46064068Seric if (OpMode != MD_VERIFY) 46164068Seric markstats(e, (ADDRESS *) NULL); 46264068Seric 4637782Seric /* 4647782Seric ** Add an Apparently-To: line if we have no recipient lines. 4657782Seric */ 4664622Seric 46767546Seric if (hvalue("to", e->e_header) == NULL && 46867546Seric hvalue("cc", e->e_header) == NULL && 46967546Seric hvalue("bcc", e->e_header) == NULL && 47067546Seric hvalue("apparently-to", e->e_header) == NULL) 4717367Seric { 4727367Seric register ADDRESS *q; 4737367Seric 4747367Seric /* create an Apparently-To: field */ 4757367Seric /* that or reject the message.... */ 47655012Seric for (q = e->e_sendqueue; q != NULL; q = q->q_next) 4777367Seric { 4787389Seric if (q->q_alias != NULL) 4797389Seric continue; 4807673Seric if (tTd(30, 3)) 4817367Seric printf("Adding Apparently-To: %s\n", q->q_paddr); 48267546Seric addheader("Apparently-To", q->q_paddr, &e->e_header); 4837367Seric } 4847367Seric } 4857367Seric 48659320Seric /* check for message too large */ 48759320Seric if (MaxMessageSize > 0 && e->e_msgsize > MaxMessageSize) 48859320Seric { 48959320Seric usrerr("552 Message exceeds maximum fixed size (%ld)", 49059320Seric MaxMessageSize); 49159320Seric } 49259320Seric 49367547Seric /* check for illegal 8-bit data */ 49467547Seric if (HasEightBits) 49567547Seric { 49667547Seric e->e_flags |= EF_HAS8BIT; 49767547Seric if (bitset(MM_MIME8BIT, MimeMode)) 49867547Seric { 49967547Seric /* convert it to MIME */ 50067547Seric if (hvalue("MIME-Version", e->e_header) == NULL) 50167547Seric { 50267547Seric char mimebuf[20]; 50367547Seric 50467547Seric strcpy(mimebuf, "MIME-Version: 1.0"); 50567547Seric chompheader(mimebuf, FALSE, e); 50667547Seric } 50767547Seric if (e->e_bodytype == NULL) 50867547Seric e->e_bodytype = "8BITMIME"; 50967547Seric } 51067547Seric else if (!bitset(MM_PASS8BIT, MimeMode)) 51167547Seric usrerr("554 Eight bit data not allowed"); 51267547Seric } 51367547Seric 51455012Seric if ((e->e_dfp = fopen(e->e_df, "r")) == NULL) 51558690Seric { 51658690Seric /* we haven't acked receipt yet, so just chuck this */ 51755012Seric syserr("Cannot reopen %s", e->e_df); 51858690Seric finis(); 51958690Seric } 5201392Seric } 52140965Sbostic 52267599Seric 52367599Seric static 52467599Seric collecttimeout(timeout) 52567599Seric time_t timeout; 52640965Sbostic { 52767599Seric /* if no progress was made, die now */ 52867599Seric if (!CollectProgress) 52967599Seric longjmp(CtxCollectTimeout, 1); 53040965Sbostic 53167599Seric /* otherwise reset the timeout */ 53267599Seric CollectTimeout = setevent(timeout, collecttimeout, timeout); 53367599Seric CollectProgress = FALSE; 53440965Sbostic } 53540965Sbostic /* 53611544Seric ** TFERROR -- signal error on writing the temporary file. 53711544Seric ** 53811544Seric ** Parameters: 53911544Seric ** tf -- the file pointer for the temporary file. 54011544Seric ** 54111544Seric ** Returns: 54211544Seric ** none. 54311544Seric ** 54411544Seric ** Side Effects: 54511544Seric ** Gives an error message. 54611544Seric ** Arranges for following output to go elsewhere. 54711544Seric */ 54811544Seric 54955012Seric tferror(tf, e) 55011544Seric FILE *tf; 55155012Seric register ENVELOPE *e; 55211544Seric { 55366796Seric CollectErrno = errno; 55411544Seric if (errno == ENOSPC) 55511544Seric { 55666782Seric struct stat st; 55766782Seric long avail; 55866782Seric long bsize; 55966782Seric 56067473Seric e->e_flags |= EF_NORETURN; 56166782Seric if (fstat(fileno(tf), &st) < 0) 56266782Seric st.st_size = 0; 56355012Seric (void) freopen(e->e_df, "w", tf); 56466782Seric if (st.st_size <= 0) 56566782Seric fprintf(tf, "\n*** Mail could not be accepted"); 56666782Seric else if (sizeof st.st_size > sizeof (long)) 56766782Seric fprintf(tf, "\n*** Mail of at least %qd bytes could not be accepted\n", 56866782Seric st.st_size); 56966782Seric else 57066782Seric fprintf(tf, "\n*** Mail of at least %ld bytes could not be accepted\n", 57166782Seric st.st_size); 57266782Seric fprintf(tf, "*** at %s due to lack of disk space for temp file.\n", 57366782Seric MyHostName); 57466782Seric avail = freespace(QueueDir, &bsize); 57566782Seric if (avail > 0) 57666782Seric { 57766782Seric if (bsize > 1024) 57866782Seric avail *= bsize / 1024; 57966782Seric else if (bsize < 1024) 58066782Seric avail /= 1024 / bsize; 58166782Seric fprintf(tf, "*** Currently, %ld kilobytes are available for mail temp files.\n", 58266782Seric avail); 58366782Seric } 58466796Seric CollectErrorMessage = "452 Out of disk space for temp file"; 58511544Seric } 58611544Seric else 58766796Seric { 58866796Seric CollectErrorMessage = "cannot write message body to disk (%s)"; 58966796Seric } 59011544Seric (void) freopen("/dev/null", "w", tf); 59111544Seric } 59211544Seric /* 5932900Seric ** EATFROM -- chew up a UNIX style from line and process 5942900Seric ** 5952900Seric ** This does indeed make some assumptions about the format 5962900Seric ** of UNIX messages. 5972900Seric ** 5982900Seric ** Parameters: 5992900Seric ** fm -- the from line. 6002900Seric ** 6012900Seric ** Returns: 6022900Seric ** none. 6032900Seric ** 6042900Seric ** Side Effects: 6052900Seric ** extracts what information it can from the header, 6063386Seric ** such as the date. 6072900Seric */ 6082900Seric 6094321Seric # ifndef NOTUNIX 6104321Seric 6114203Seric char *DowList[] = 6124203Seric { 6134203Seric "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL 6144203Seric }; 6154203Seric 6162900Seric char *MonthList[] = 6172900Seric { 6182900Seric "Jan", "Feb", "Mar", "Apr", "May", "Jun", 6192900Seric "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", 6202900Seric NULL 6212900Seric }; 6222900Seric 62355012Seric eatfrom(fm, e) 6242900Seric char *fm; 62555012Seric register ENVELOPE *e; 6262900Seric { 6272900Seric register char *p; 6282900Seric register char **dt; 6292900Seric 6307673Seric if (tTd(30, 2)) 6314203Seric printf("eatfrom(%s)\n", fm); 6324203Seric 6332900Seric /* find the date part */ 6342900Seric p = fm; 6352900Seric while (*p != '\0') 6362900Seric { 6372900Seric /* skip a word */ 6382900Seric while (*p != '\0' && *p != ' ') 63916896Seric p++; 6402900Seric while (*p == ' ') 64116896Seric p++; 64258050Seric if (!(isascii(*p) && isupper(*p)) || 64358050Seric p[3] != ' ' || p[13] != ':' || p[16] != ':') 6442900Seric continue; 6452900Seric 6462900Seric /* we have a possible date */ 6474203Seric for (dt = DowList; *dt != NULL; dt++) 6482900Seric if (strncmp(*dt, p, 3) == 0) 6492900Seric break; 6504203Seric if (*dt == NULL) 6514203Seric continue; 6522900Seric 6534203Seric for (dt = MonthList; *dt != NULL; dt++) 6544203Seric if (strncmp(*dt, &p[4], 3) == 0) 6554203Seric break; 6562900Seric if (*dt != NULL) 6572900Seric break; 6582900Seric } 6592900Seric 66060502Seric if (*p != '\0') 6612900Seric { 6623386Seric char *q; 6635366Seric extern char *arpadate(); 6643386Seric 6652900Seric /* we have found a date */ 6663386Seric q = xalloc(25); 66723103Seric (void) strncpy(q, p, 25); 6683386Seric q[24] = '\0'; 6695366Seric q = arpadate(q); 67055012Seric define('a', newstr(q), e); 6712900Seric } 6722900Seric } 6734321Seric 67456795Seric # endif /* NOTUNIX */ 675