2 * Copyright (c) 1998-2006, 2008, 2023, 2024 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 SM_RCSID("@(#)$Id: collect.c,v 8.287 2013-11-22 20:51:55 ca Exp $")
18 #include <sm/sendmail.h>
20 static void eatfrom __P((char *volatile, ENVELOPE *));
21 static void collect_doheader __P((ENVELOPE *));
22 static SM_FILE_T *collect_dfopen __P((ENVELOPE *));
23 static SM_FILE_T *collect_eoh __P((ENVELOPE *, int, int));
26 ** COLLECT_EOH -- end-of-header processing in collect()
28 ** Called by collect() when it encounters the blank line
29 ** separating the header from the message body, or when it
30 ** encounters EOF in a message that contains only a header.
34 ** numhdrs -- number of headers
35 ** hdrslen -- length of headers
38 ** NULL, or handle to open data file
41 ** end-of-header check ruleset is invoked.
42 ** envelope state is updated.
43 ** headers may be added and deleted.
45 ** opens the data file.
49 collect_eoh(e, numhdrs, hdrslen)
57 /* call the end-of-header check ruleset */
58 (void) sm_snprintf(hnum, sizeof(hnum), "%d", numhdrs);
59 (void) sm_snprintf(hsize, sizeof(hsize), "%d", hdrslen);
61 sm_dprintf("collect: rscheck(\"check_eoh\", \"%s $| %s\")\n",
63 (void) rscheck("check_eoh", hnum, hsize, e, RSF_UNSTRUCTURED|RSF_COUNT,
64 3, NULL, e->e_id, NULL, NULL);
67 ** Process the header,
68 ** select the queue, open the data file.
72 return collect_dfopen(e);
76 ** COLLECT_DOHEADER -- process header in collect()
78 ** Called by collect() after it has finished parsing the header,
79 ** but before it selects the queue and creates the data file.
80 ** The results of processing the header will affect queue selection.
89 ** envelope state is updated.
90 ** headers may be added and deleted.
98 ** Find out some information from the headers.
99 ** Examples are who is the from person & the date.
102 eatheader(e, true, false);
104 if (GrabTo && e->e_sendqueue == NULL)
105 usrerr("No recipient addresses found in header");
108 ** If we have a Return-Receipt-To:, turn it into a DSN.
111 if (RrtImpliesDsn && hvalue("return-receipt-to", e->e_header) != NULL)
115 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
116 if (!bitset(QHASNOTIFY, q->q_flags))
117 q->q_flags |= QHASNOTIFY|QPINGONSUCCESS;
121 ** Add an appropriate recipient line if we have none.
124 if (hvalue("to", e->e_header) != NULL ||
125 hvalue("cc", e->e_header) != NULL ||
126 hvalue("apparently-to", e->e_header) != NULL)
128 /* have a valid recipient header -- delete Bcc: headers */
129 e->e_flags |= EF_DELETE_BCC;
131 else if (hvalue("bcc", e->e_header) == NULL)
133 /* no valid recipient headers */
137 /* create a recipient field */
138 switch (NoRecipientAction)
140 case NRA_ADD_APPARENTLY_TO:
141 hdr = "Apparently-To";
149 addheader("Bcc", " ", 0, e, true);
152 case NRA_ADD_TO_UNDISCLOSED:
153 addheader("To", "undisclosed-recipients:;", 0, e, true);
159 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
161 if (q->q_alias != NULL)
164 sm_dprintf("Adding %s: %s\n",
166 addheader(hdr, q->q_paddr, 0, e, true);
173 ** COLLECT_DFOPEN -- open the message data file
175 ** Called by collect() after it has finished processing the header.
176 ** Queue selection occurs at this point, possibly based on the
177 ** envelope's recipient list and on header information.
183 ** NULL, or a pointer to an open data file,
184 ** into which the message body will be written by collect().
187 ** Calls syserr, sets EF_FATALERRS and returns NULL
188 ** if there is insufficient disk space.
189 ** Aborts process if data file could not be opened.
190 ** Otherwise, the queue is selected,
191 ** e->e_{dfino,dfdev,msgsize,flags} are updated,
192 ** and a pointer to an open data file is returned.
208 dfname = queuename(e, DATAFL_LETTER);
209 if (bitset(S_IWGRP, QueueFileMode))
210 oldumask = umask(002);
211 df = bfopen(dfname, QueueFileMode, DataFileBufferSize,
213 if (bitset(S_IWGRP, QueueFileMode))
214 (void) umask(oldumask);
217 syserr("@Cannot create %s", dfname);
218 e->e_flags |= EF_NO_BODY_RETN;
220 finis(false, true, ExitStat);
223 dfd = sm_io_getinfo(df, SM_IO_WHAT_FD, NULL);
224 if (dfd < 0 || fstat(dfd, &stbuf) < 0)
228 e->e_dfdev = stbuf.st_dev;
229 e->e_dfino = stbuf.st_ino;
231 e->e_flags |= EF_HAS_DF;
236 ** INCBUFLEN -- increase buflen for the header buffer in collect()
239 ** buflen -- current size of buffer
245 static int incbuflen __P((int));
252 /* this also handles the case of MaxMessageSize == 0 */
253 if (MaxMessageSize <= MEMCHUNKSIZE)
255 if (buflen < MEMCHUNKSIZE)
258 return buflen + MEMCHUNKSIZE;
261 /* MaxMessageSize > MEMCHUNKSIZE */
263 if (newlen > 0 && newlen < MaxMessageSize)
266 return MaxMessageSize;
270 /* just for testing/debug output */
279 if (isprint((unsigned char)c))
292 snprintf(prt, sizeof(prt), "%o", c);
295 #else /* _FFR_TESTS */
296 # define makeprint(c) "X"
297 #endif /* _FFR_TESTS */
300 ** COLLECT -- read & parse message header & make temp file.
302 ** Creates a temporary file name and copies the standard
303 ** input to that file. Leading UNIX-style "From" lines are
304 ** stripped off (after important information is extracted).
307 ** fp -- file to read.
308 ** smtpmode -- if >= SMTPMODE_LAX we are running SMTP:
309 ** give an RFC821 style message to say we are
310 ** ready to collect input, and never ignore
311 ** a single dot to mean end of message.
312 ** hdrp -- the location to stash the header.
313 ** e -- the current envelope.
314 ** rsetsize -- reset e_msgsize?
321 ** - Data file is created and filled, and e->e_dfp is set.
322 ** - The from person may be set.
323 ** If the "enough disk space" check fails,
324 ** - syserr is called.
325 ** - e->e_dfp is NULL.
326 ** - e->e_flags & EF_FATALERRS is set.
327 ** - collect() returns.
328 ** If data file cannot be created, the process is terminated.
331 /* values for input state machine */
332 #define IS_NORM 0 /* middle of line */
333 #define IS_BOL 1 /* beginning of line */
334 #define IS_DOT 2 /* read "." at beginning of line */
335 #define IS_DOTCR 3 /* read ".\r" at beginning of line */
336 #define IS_CR 4 /* read "\r" */
338 /* hack to enhance readability of debug output */
339 static const char *istates[] = { "NORM", "BOL", "DOT", "DOTCR", "CR" };
340 #define ISTATE istates[istate]
342 /* values for message state machine */
343 #define MS_UFROM 0 /* reading Unix from line */
344 #define MS_HEADER 1 /* reading message header */
345 #define MS_BODY 2 /* reading message body */
346 #define MS_DISCARD 3 /* discarding rest of message */
347 #define BARE_LF_MSG "Bare linefeed (LF) not allowed"
348 #define BARE_CR_MSG "Bare carriage return (CR) not allowed"
351 collect(fp, smtpmode, hdrp, e, rsetsize)
355 register ENVELOPE *e;
358 register SM_FILE_T *df;
374 unsigned char peekbuf[8];
375 char bufbuf[MAXLINE];
376 #if _FFR_REJECT_NUL_BYTE
377 bool hasNUL; /* has at least one NUL input byte */
379 int bare_lf, bare_cr;
381 #define SMTPMODE (smtpmode >= SMTPMODE_LAX)
382 #define SMTPMODE_STRICT ((smtpmode & SMTPMODE_CRLF) != 0)
383 #define BARE_LF_421 ((smtpmode & SMTPMODE_LF_421) != 0)
384 #define BARE_CR_421 ((smtpmode & SMTPMODE_CR_421) != 0)
385 #define BARE_LF_SP ((smtpmode & SMTPMODE_LF_SP) != 0)
386 #define BARE_CR_SP ((smtpmode & SMTPMODE_CR_SP) != 0)
388 /* for bare_{lf,cr} */
389 #define BARE_IN_HDR 0x01
390 #define BARE_IN_BDY 0x02
391 #define BARE_WHERE ((MS_BODY == mstate) ? BARE_IN_BDY : BARE_IN_HDR)
394 ignrdot = SMTPMODE ? false : IgnrDot;
395 bare_lf = bare_cr = 0;
397 /* timeout for I/O functions is in milliseconds */
398 dbto = SMTPMODE ? ((int) TimeOuts.to_datablock * 1000)
400 sm_io_setinfo(fp, SM_IO_WHAT_TIMEOUT, &dbto);
401 old_rd_tmo = set_tls_rd_tmo(TimeOuts.to_datablock);
404 headeronly = hdrp != NULL;
407 HasEightBits = false;
408 #if _FFR_REJECT_NUL_BYTE
412 buflen = sizeof(bufbuf);
415 mstate = SaveFrom ? MS_HEADER : MS_UFROM;
418 ** Tell ARPANET to go ahead.
422 message("354 End data with <CR><LF>.<CR><LF>");
424 /* simulate an I/O timeout when used as sink */
429 sm_dprintf("collect, smtpmode=%#x\n", smtpmode);
434 ** This is done using two interleaved state machines.
435 ** The input state machine is looking for things like
436 ** hidden dots; the message state machine is handling
437 ** the larger picture (e.g., header versus body).
445 sm_dprintf("top, istate=%s, mstate=%d\n", ISTATE,
453 while (!sm_io_eof(fp) && !sm_io_error(fp))
456 c = sm_io_getc(fp, SM_TIME_DEFAULT);
457 if (c == SM_IO_EOF && errno == EINTR)
459 /* Interrupted, retry */
465 if (c == SM_IO_EOF && errno == EAGAIN
469 ** Override e_message in
470 ** usrerr() as this is the
471 ** reason for failure that
472 ** should be logged for
473 ** undelivered recipients.
483 if (TrafficLogFile != NULL && !headeronly)
485 if (istate == IS_BOL)
486 (void) sm_io_fprintf(TrafficLogFile,
491 (void) sm_io_fprintf(TrafficLogFile,
495 (void) sm_io_putc(TrafficLogFile,
499 #if _FFR_REJECT_NUL_BYTE
506 bitset(EF_7BITBODY, e->e_flags))
509 HasEightBits |= bitset(0x80, c);
512 sm_dprintf("istate=%s, c=%s (0x%x)\n",
513 ISTATE, makeprint((char) c), c);
514 if ('\n' == c && SMTPMODE &&
515 !(IS_CR == istate || IS_DOTCR == istate))
517 bare_lf |= BARE_WHERE;
526 sm_dprintf("LF: c=%s %#x\n", makeprint((char) c), c);
541 if (c == '\n' && !ignrdot && !SMTPMODE_STRICT)
551 OpMode != MD_DAEMON &&
552 OpMode != MD_ARPAFTP))
555 SM_ASSERT(pbp < peekbuf +
563 if (c == '\n' && !ignrdot)
567 /* push back the ".\rx" */
568 SM_ASSERT(pbp < peekbuf +
571 if (OpMode != MD_SMTP &&
572 OpMode != MD_DAEMON &&
573 OpMode != MD_ARPAFTP)
575 SM_ASSERT(pbp < peekbuf +
589 sm_dprintf("state=CR, c=%s %#x -> BOL\n", makeprint((char) c), c);
595 sm_dprintf("state=CR, c=%s %#x -> NORM\n", makeprint((char) c), c);
598 bare_cr |= BARE_WHERE;
605 (void) sm_io_ungetc(fp, SM_TIME_DEFAULT,
621 else if (c == '\n' && !SMTPMODE_STRICT)
630 if (e->e_msgsize >= 0)
633 if (MaxMessageSize > 0 &&
634 !bitset(EF_TOOBIG, e->e_flags) &&
635 e->e_msgsize > MaxMessageSize)
636 e->e_flags |= EF_TOOBIG;
642 /* just put the character out */
643 if (!bitset(EF_TOOBIG, e->e_flags))
644 (void) sm_io_putc(df, SM_TIME_DEFAULT,
647 sm_dprintf("state=%s, put=%s %#x\n", ISTATE, makeprint((char) c), c);
654 SM_ASSERT(mstate == MS_UFROM || mstate == MS_HEADER);
656 /* header -- buffer up */
657 if (bp >= &buf[buflen - 2])
661 /* out of space for header */
663 buflen = incbuflen(buflen);
665 sm_dprintf("buflen=%d, hdrslen=%d\n", buflen, hdrslen);
668 sm_syslog(LOG_NOTICE, e->e_id,
669 "header overflow from %s during message collect",
672 e->e_flags |= EF_CLRQUEUE;
673 e->e_status = "5.6.0";
674 usrerrenh(e->e_status,
675 "552 Headers too large");
678 buf = xalloc(buflen);
679 memmove(buf, obuf, bp - obuf);
680 bp = &buf[bp - obuf];
682 sm_free(obuf); /* XXX */
690 MaxHeadersLength > 0 &&
691 hdrslen > MaxHeadersLength)
693 sm_syslog(LOG_NOTICE, e->e_id,
694 "headers too large (%d max) from %s during message collect",
698 e->e_flags |= EF_CLRQUEUE;
699 e->e_status = "5.6.0";
700 usrerrenh(e->e_status,
701 "552 Headers too large (%d max)",
707 if (istate == IS_BOL)
714 sm_dprintf("nextstate, istate=%s, mstate=%d, line=\"%s\"\n",
715 ISTATE, mstate, buf);
721 if (strncmp(buf, "From ", 5) == 0)
727 #endif /* ! NOTUNIX */
737 /* check for possible continuation line */
742 c = sm_io_getc(fp, SM_TIME_DEFAULT);
745 if (c == SM_IO_EOF && errno == EAGAIN
749 ** Override e_message in
750 ** usrerr() as this is the
751 ** reason for failure that
752 ** should be logged for
753 ** undelivered recipients.
761 } while (c == SM_IO_EOF && errno == EINTR);
763 (void) sm_io_ungetc(fp, SM_TIME_DEFAULT, c);
764 if (c == ' ' || c == '\t')
766 /* yep -- defer this */
772 /* guaranteed by isheader(buf) */
773 SM_ASSERT(*(bp - 1) != '\n' || bp > buf + 1);
775 /* trim off trailing CRLF or LF */
776 if (*--bp != '\n' || *--bp != '\r')
780 if (bitset(H_EOH, chompheader(buf,
781 CHHDR_CHECK | CHHDR_USER,
797 df = collect_eoh(e, numhdrs, hdrslen);
799 e->e_flags |= EF_TOOBIG;
803 /* toss blank line */
804 if ((bp[0] == '\r' && bp[1] == '\n') ||
810 /* if not a blank separator, write it out */
811 if (!bitset(EF_TOOBIG, e->e_flags))
814 (void) sm_io_putc(df, SM_TIME_DEFAULT,
823 if ((sm_io_eof(fp) && SMTPMODE) || sm_io_error(fp))
828 errmsg = "unexpected close";
830 errmsg = sm_errstring(errno);
832 sm_dprintf("collect: premature EOM: %s\n", errmsg);
834 sm_syslog(LOG_WARNING, e->e_id,
835 "collect: premature EOM: %s", errmsg);
842 if (mstate != MS_BODY)
844 /* no body or discard, so we never opened the data file */
845 SM_ASSERT(df == NULL);
846 df = collect_eoh(e, numhdrs, hdrslen);
851 /* skip next few clauses */
854 else if (sm_io_flush(df, SM_TIME_DEFAULT) != 0 || sm_io_error(df))
856 dferror(df, "sm_io_flush||sm_io_error", e);
858 finis(true, true, ExitStat);
861 else if (SuperSafe == SAFE_NO ||
862 SuperSafe == SAFE_INTERACTIVE ||
863 (SuperSafe == SAFE_REALLY_POSTMILTER && SMTPMODE))
865 /* skip next few clauses */
867 /* Note: updfs() is not called in this case! */
869 else if (sm_io_setinfo(df, SM_BF_COMMIT, NULL) < 0 && errno != EINVAL)
871 int save_errno = errno;
873 if (save_errno == EEXIST)
879 dfile = queuename(e, DATAFL_LETTER);
880 if (stat(dfile, &st) < 0)
883 syserr("@collect: bfcommit(%s): already on disk, size=%ld",
884 dfile, (long) st.st_size);
885 dfd = sm_io_getinfo(df, SM_IO_WHAT_FD, NULL);
887 dumpfd(dfd, true, true);
890 dferror(df, "bfcommit", e);
892 finis(save_errno != EEXIST, true, ExitStat);
894 else if ((afd = sm_io_getinfo(df, SM_IO_WHAT_FD, NULL)) < 0)
896 dferror(df, "sm_io_getinfo", e);
898 finis(true, true, ExitStat);
901 else if (fsync(afd) < 0)
903 dferror(df, "fsync", e);
905 finis(true, true, ExitStat);
908 else if (sm_io_close(df, SM_TIME_DEFAULT) < 0)
910 dferror(df, "sm_io_close", e);
912 finis(true, true, ExitStat);
917 /* everything is happily flushed to disk */
920 /* remove from available space in filesystem */
921 updfs(e, 0, 1, "collect");
924 /* An EOF when running SMTP is an error */
926 if (inputerr && (OpMode == MD_SMTP || OpMode == MD_DAEMON))
932 problem = "unexpected close";
933 else if (sm_io_error(fp))
934 problem = "I/O error";
935 else if (0 != bare_lf)
936 problem = BARE_LF_MSG;
937 else if (0 != bare_cr)
938 problem = BARE_CR_MSG;
940 problem = "read timeout";
942 #define LOG_CLT ((NULL != RealHostName) ? RealHostName: "localhost")
943 #define CONN_ERR_TXT "collect: relay=%s, from=%s, info=%s%s%s%s"
944 #define CONN_ERR_CODE "421 4.4.1 "
945 #define CONN_LOG_FROM shortenstring(e->e_from.q_paddr, MAXSHORTSTR)
946 #define CONN_ERR_BARE (0 != bare_lf) ? BARE_LF_MSG : ((0 != bare_cr) ? BARE_CR_MSG : "")
947 #define CONN_ERR_WHERE(bare_xy) (BARE_IN_HDR==(bare_xy) ? "header" : \
948 (BARE_IN_BDY==(bare_xy) ? "body" : "header+body"))
950 #define HAS_BARE_XY (0 != (bare_lf | bare_cr))
951 #define CONN_ERR_ARGS LOG_CLT, CONN_LOG_FROM, problem, \
952 HAS_BARE_XY ? ", where=" : "", \
953 HAS_BARE_XY ? CONN_ERR_WHERE(bare_lf|bare_cr) : "", \
954 HAS_BARE_XY ? ", status=tempfail" : ""
956 if (LogLevel > 0 && (sm_io_eof(fp) || (0 != (bare_lf | bare_cr))))
957 sm_syslog(LOG_NOTICE, e->e_id,
958 CONN_ERR_TXT, CONN_ERR_ARGS);
959 if (0 != (bare_lf | bare_cr))
960 usrerr("421 4.5.0 %s", CONN_ERR_BARE);
961 else if (sm_io_eof(fp))
962 usrerr(CONN_ERR_CODE CONN_ERR_TXT, CONN_ERR_ARGS);
964 syserr(CONN_ERR_CODE CONN_ERR_TXT, CONN_ERR_ARGS);
967 /* don't return an error indication */
969 e->e_flags &= ~EF_FATALERRS;
970 e->e_flags |= EF_CLRQUEUE;
972 /* Don't send any message notification to sender */
973 for (q = e->e_sendqueue; q != NULL; q = q->q_next)
975 if (QS_IS_DEAD(q->q_state))
977 q->q_state = QS_FATALERR;
981 finis(true, true, ExitStat);
985 /* Log collection information. */
987 sm_dprintf("collect: e_id=%s, EF_LOGSENDER=%d, LogLevel=%d\n",
988 e->e_id, bitset(EF_LOGSENDER, e->e_flags), LogLevel);
989 if (bitset(EF_LOGSENDER, e->e_flags) && LogLevel > 4)
991 logsender(e, e->e_msgid);
992 e->e_flags &= ~EF_LOGSENDER;
995 #define LOG_BARE_XY(bare_xy, bare_xy_sp, bare_xy_msg) \
998 if ((0 != bare_xy) && LogLevel > 8) \
999 sm_syslog(LOG_NOTICE, e->e_id, \
1000 "collect: relay=%s, from=%s, info=%s, where=%s%s" \
1001 , LOG_CLT, CONN_LOG_FROM, bare_xy_msg \
1002 , CONN_ERR_WHERE(bare_xy) \
1003 , bare_xy_sp ? ", status=replaced" : "" \
1007 LOG_BARE_XY(bare_lf, BARE_LF_SP, BARE_LF_MSG);
1008 LOG_BARE_XY(bare_cr, BARE_CR_SP, BARE_CR_MSG);
1010 /* check for message too large */
1011 if (bitset(EF_TOOBIG, e->e_flags))
1013 e->e_flags |= EF_NO_BODY_RETN|EF_CLRQUEUE;
1014 if (!bitset(EF_FATALERRS, e->e_flags))
1016 e->e_status = "5.2.3";
1017 usrerrenh(e->e_status,
1018 "552 Message exceeds maximum fixed size (%ld)",
1021 sm_syslog(LOG_NOTICE, e->e_id,
1022 "message size (%ld) exceeds maximum (%ld)",
1023 PRT_NONNEGL(e->e_msgsize),
1028 /* check for illegal 8-bit data */
1031 e->e_flags |= EF_HAS8BIT;
1032 if (!bitset(MM_PASS8BIT|MM_MIME8BIT, MimeMode) &&
1033 !bitset(EF_IS_MIME, e->e_flags))
1035 e->e_status = "5.6.1";
1036 usrerrenh(e->e_status, "554 Eight bit data not allowed");
1041 /* if it claimed to be 8 bits, well, it lied.... */
1042 if (e->e_bodytype != NULL &&
1043 SM_STRCASEEQ(e->e_bodytype, "8bitmime"))
1044 e->e_bodytype = "7BIT";
1047 #if _FFR_REJECT_NUL_BYTE
1048 if (hasNUL && RejectNUL)
1050 e->e_status = "5.6.1";
1051 usrerrenh(e->e_status, "554 NUL byte not allowed");
1053 #endif /* _FFR_REJECT_NUL_BYTE */
1055 if (SuperSafe == SAFE_REALLY && !bitset(EF_FATALERRS, e->e_flags))
1057 char *dfname = queuename(e, DATAFL_LETTER);
1058 if ((e->e_dfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, dfname,
1059 SM_IO_RDONLY_B, NULL)) == NULL)
1061 /* we haven't acked receipt yet, so just chuck this */
1062 syserr("@Cannot reopen %s", dfname);
1063 finis(true, true, ExitStat);
1070 /* collect statistics */
1071 if (OpMode != MD_VERIFY)
1074 ** Recalculate e_msgpriority, it is done at in eatheader()
1075 ** which is called (in 8.12) after the header is collected,
1076 ** hence e_msgsize is (most likely) incorrect.
1079 e->e_msgpriority = e->e_msgsize
1080 - e->e_class * WkClassFact
1081 + e->e_nrcpts * WkRecipFact;
1082 markstats(e, (ADDRESS *) NULL, STATS_NORMAL);
1086 (void) set_tls_rd_tmo(old_rd_tmo);
1092 ** DFERROR -- signal error on writing the data file.
1094 ** Called by collect(). collect() always terminates the process
1095 ** immediately after calling dferror(), which means that the SMTP
1096 ** session will be terminated, which means that any error message
1097 ** issued by dferror must be a 421 error, as per RFC 821.
1100 ** df -- the file pointer for the data file.
1101 ** msg -- detailed message.
1102 ** e -- the current envelope.
1108 ** Gives an error message.
1109 ** Arranges for following output to go elsewhere.
1114 SM_FILE_T *volatile df;
1116 register ENVELOPE *e;
1120 dfname = queuename(e, DATAFL_LETTER);
1122 if (errno == ENOSPC)
1132 e->e_flags |= EF_NO_BODY_RETN;
1136 fstat64(sm_io_getinfo(df, SM_IO_WHAT_FD, NULL), &st)
1138 fstat(sm_io_getinfo(df, SM_IO_WHAT_FD, NULL), &st)
1142 (void) sm_io_reopen(SmFtStdio, SM_TIME_DEFAULT, dfname,
1143 SM_IO_WRONLY_B, NULL, df);
1144 if (st.st_size <= 0)
1145 (void) sm_io_fprintf(df, SM_TIME_DEFAULT,
1146 "\n*** Mail could not be accepted");
1148 (void) sm_io_fprintf(df, SM_TIME_DEFAULT,
1149 "\n*** Mail of at least %llu bytes could not be accepted\n",
1150 (ULONGLONG_T) st.st_size);
1151 (void) sm_io_fprintf(df, SM_TIME_DEFAULT,
1152 "*** at %s due to lack of disk space for temp file.\n",
1154 avail = freediskspace(qid_printqueue(e->e_qgrp, e->e_qdir),
1159 avail *= bsize / 1024;
1160 else if (bsize < 1024)
1161 avail /= 1024 / bsize;
1162 (void) sm_io_fprintf(df, SM_TIME_DEFAULT,
1163 "*** Currently, %ld kilobytes are available for mail temp files.\n",
1167 /* Wrong response code; should be 421. */
1168 e->e_status = "4.3.1";
1169 usrerrenh(e->e_status, "452 Out of disk space for temp file");
1171 syserr("421 4.3.1 Out of disk space for temp file");
1175 syserr("421 4.3.0 collect: Cannot write %s (%s, uid=%ld, gid=%ld)",
1176 dfname, msg, (long) geteuid(), (long) getegid());
1177 if (sm_io_reopen(SmFtStdio, SM_TIME_DEFAULT, SM_PATH_DEVNULL,
1178 SM_IO_WRONLY, NULL, df) == NULL)
1179 sm_syslog(LOG_ERR, e->e_id,
1180 "dferror: sm_io_reopen(\"/dev/null\") failed: %s",
1181 sm_errstring(errno));
1184 ** EATFROM -- chew up a UNIX style from line and process
1186 ** This does indeed make some assumptions about the format
1187 ** of UNIX messages.
1190 ** fm -- the from line.
1197 ** extracts what information it can from the header,
1198 ** such as the date.
1203 static char *DowList[] =
1205 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL
1208 static char *MonthList[] =
1210 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
1211 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
1218 register ENVELOPE *e;
1224 sm_dprintf("eatfrom(%s)\n", fm);
1226 /* find the date part */
1231 while (*p != '\0' && *p != ' ')
1237 /* no room for the date */
1240 if (!(isascii(*p) && isupper(*p)) ||
1241 p[3] != ' ' || p[13] != ':' || p[16] != ':')
1244 /* we have a possible date */
1245 for (dt = DowList; *dt != NULL; dt++)
1246 if (strncmp(*dt, p, 3) == 0)
1251 for (dt = MonthList; *dt != NULL; dt++)
1253 if (strncmp(*dt, &p[4], 3) == 0)
1264 /* we have found a date */
1265 (void) sm_strlcpy(buf, p, sizeof(buf));
1267 macdefine(&e->e_macro, A_TEMP, 'a', q);
1270 #endif /* ! NOTUNIX */