xref: /illumos-gate/usr/src/cmd/sendmail/src/envelope.c (revision 058561cb)
17c478bd9Sstevel@tonic-gate /*
2*058561cbSjbeck  * Copyright (c) 1998-2003, 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*058561cbSjbeck SM_RCSID("@(#)$Id: envelope.c,v 8.302 2006/11/10 23:12:52 ca Exp $")
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate /*
217c478bd9Sstevel@tonic-gate **  CLRSESSENVELOPE -- clear session oriented data in an envelope
227c478bd9Sstevel@tonic-gate **
237c478bd9Sstevel@tonic-gate **	Parameters:
247c478bd9Sstevel@tonic-gate **		e -- the envelope to clear.
257c478bd9Sstevel@tonic-gate **
267c478bd9Sstevel@tonic-gate **	Returns:
277c478bd9Sstevel@tonic-gate **		none.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate void
317c478bd9Sstevel@tonic-gate clrsessenvelope(e)
327c478bd9Sstevel@tonic-gate 	ENVELOPE *e;
337c478bd9Sstevel@tonic-gate {
347c478bd9Sstevel@tonic-gate #if SASL
357c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_type}"), "");
367c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_authen}"), "");
377c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_author}"), "");
387c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{auth_ssf}"), "");
397c478bd9Sstevel@tonic-gate #endif /* SASL */
407c478bd9Sstevel@tonic-gate #if STARTTLS
417c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cert_issuer}"), "");
427c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cert_subject}"), "");
437c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cipher_bits}"), "");
447c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cipher}"), "");
457c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{tls_version}"), "");
467c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{verify}"), "");
477c478bd9Sstevel@tonic-gate # if _FFR_TLS_1
487c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{alg_bits}"), "");
497c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cn_issuer}"), "");
507c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{cn_subject}"), "");
517c478bd9Sstevel@tonic-gate # endif /* _FFR_TLS_1 */
527c478bd9Sstevel@tonic-gate #endif /* STARTTLS */
537c478bd9Sstevel@tonic-gate }
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate **  NEWENVELOPE -- fill in a new envelope
577c478bd9Sstevel@tonic-gate **
587c478bd9Sstevel@tonic-gate **	Supports inheritance.
597c478bd9Sstevel@tonic-gate **
607c478bd9Sstevel@tonic-gate **	Parameters:
617c478bd9Sstevel@tonic-gate **		e -- the new envelope to fill in.
627c478bd9Sstevel@tonic-gate **		parent -- the envelope to be the parent of e.
637c478bd9Sstevel@tonic-gate **		rpool -- either NULL, or a pointer to a resource pool
647c478bd9Sstevel@tonic-gate **			from which envelope memory is allocated, and
657c478bd9Sstevel@tonic-gate **			to which envelope resources are attached.
667c478bd9Sstevel@tonic-gate **
677c478bd9Sstevel@tonic-gate **	Returns:
687c478bd9Sstevel@tonic-gate **		e.
697c478bd9Sstevel@tonic-gate **
707c478bd9Sstevel@tonic-gate **	Side Effects:
717c478bd9Sstevel@tonic-gate **		none.
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate ENVELOPE *
757c478bd9Sstevel@tonic-gate newenvelope(e, parent, rpool)
767c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
777c478bd9Sstevel@tonic-gate 	register ENVELOPE *parent;
787c478bd9Sstevel@tonic-gate 	SM_RPOOL_T *rpool;
797c478bd9Sstevel@tonic-gate {
8049218d4fSjbeck 	int sendmode;
8149218d4fSjbeck 
827c478bd9Sstevel@tonic-gate 	/*
837c478bd9Sstevel@tonic-gate 	**  This code used to read:
847c478bd9Sstevel@tonic-gate 	**	if (e == parent && e->e_parent != NULL)
857c478bd9Sstevel@tonic-gate 	**		parent = e->e_parent;
867c478bd9Sstevel@tonic-gate 	**  So if e == parent && e->e_parent == NULL then we would
877c478bd9Sstevel@tonic-gate 	**  set e->e_parent = e, which creates a loop in the e_parent chain.
887c478bd9Sstevel@tonic-gate 	**  This meant macvalue() could go into an infinite loop.
897c478bd9Sstevel@tonic-gate 	*/
907c478bd9Sstevel@tonic-gate 
9149218d4fSjbeck 	if (parent != NULL)
9249218d4fSjbeck 		sendmode = parent->e_sendmode;
9349218d4fSjbeck 	else
9449218d4fSjbeck 		sendmode = DM_NOTSET;
9549218d4fSjbeck 
967c478bd9Sstevel@tonic-gate 	if (e == parent)
977c478bd9Sstevel@tonic-gate 		parent = e->e_parent;
987c478bd9Sstevel@tonic-gate 	clearenvelope(e, true, rpool);
997c478bd9Sstevel@tonic-gate 	if (e == CurEnv)
1007c478bd9Sstevel@tonic-gate 		memmove((char *) &e->e_from,
1017c478bd9Sstevel@tonic-gate 			(char *) &NullAddress,
102*058561cbSjbeck 			sizeof(e->e_from));
1037c478bd9Sstevel@tonic-gate 	else
1047c478bd9Sstevel@tonic-gate 		memmove((char *) &e->e_from,
1057c478bd9Sstevel@tonic-gate 			(char *) &CurEnv->e_from,
106*058561cbSjbeck 			sizeof(e->e_from));
1077c478bd9Sstevel@tonic-gate 	e->e_parent = parent;
1087c478bd9Sstevel@tonic-gate 	assign_queueid(e);
1097c478bd9Sstevel@tonic-gate 	e->e_ctime = curtime();
1107c478bd9Sstevel@tonic-gate 	if (parent != NULL)
1117c478bd9Sstevel@tonic-gate 	{
1127c478bd9Sstevel@tonic-gate 		e->e_msgpriority = parent->e_msgsize;
1137c478bd9Sstevel@tonic-gate 		if (parent->e_quarmsg == NULL)
1147c478bd9Sstevel@tonic-gate 		{
1157c478bd9Sstevel@tonic-gate 			e->e_quarmsg = NULL;
1167c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM,
1177c478bd9Sstevel@tonic-gate 				  macid("{quarantine}"), "");
1187c478bd9Sstevel@tonic-gate 		}
1197c478bd9Sstevel@tonic-gate 		else
1207c478bd9Sstevel@tonic-gate 		{
1217c478bd9Sstevel@tonic-gate 			e->e_quarmsg = sm_rpool_strdup_x(rpool,
1227c478bd9Sstevel@tonic-gate 							 parent->e_quarmsg);
1237c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM,
1247c478bd9Sstevel@tonic-gate 				  macid("{quarantine}"), e->e_quarmsg);
1257c478bd9Sstevel@tonic-gate 		}
1267c478bd9Sstevel@tonic-gate 	}
1277c478bd9Sstevel@tonic-gate 	e->e_puthdr = putheader;
1287c478bd9Sstevel@tonic-gate 	e->e_putbody = putbody;
1297c478bd9Sstevel@tonic-gate 	if (CurEnv->e_xfp != NULL)
1307c478bd9Sstevel@tonic-gate 		(void) sm_io_flush(CurEnv->e_xfp, SM_TIME_DEFAULT);
13149218d4fSjbeck 	if (sendmode != DM_NOTSET)
13249218d4fSjbeck 		e->e_sendmode = sendmode;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	return e;
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate /* values for msg_timeout, see also IS_* below for usage (bit layout) */
1387c478bd9Sstevel@tonic-gate #define MSG_T_O		0x01	/* normal timeout */
1397c478bd9Sstevel@tonic-gate #define MSG_T_O_NOW	0x02	/* NOW timeout */
1407c478bd9Sstevel@tonic-gate #define MSG_NOT_BY	0x04	/* Deliver-By time exceeded, mode R */
1417c478bd9Sstevel@tonic-gate #define MSG_WARN	0x10	/* normal queue warning */
1427c478bd9Sstevel@tonic-gate #define MSG_WARN_BY	0x20	/* Deliver-By time exceeded, mode N */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #define IS_MSG_ERR(x)	(((x) & 0x0f) != 0)	/* return an error */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /* immediate return */
1477c478bd9Sstevel@tonic-gate #define IS_IMM_RET(x)	(((x) & (MSG_T_O_NOW|MSG_NOT_BY)) != 0)
1487c478bd9Sstevel@tonic-gate #define IS_MSG_WARN(x)	(((x) & 0xf0) != 0)	/* return a warning */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate **  DROPENVELOPE -- deallocate an envelope.
1527c478bd9Sstevel@tonic-gate **
1537c478bd9Sstevel@tonic-gate **	Parameters:
1547c478bd9Sstevel@tonic-gate **		e -- the envelope to deallocate.
1557c478bd9Sstevel@tonic-gate **		fulldrop -- if set, do return receipts.
1567c478bd9Sstevel@tonic-gate **		split -- if true, split by recipient if message is queued up
1577c478bd9Sstevel@tonic-gate **
1587c478bd9Sstevel@tonic-gate **	Returns:
1597c478bd9Sstevel@tonic-gate **		none.
1607c478bd9Sstevel@tonic-gate **
1617c478bd9Sstevel@tonic-gate **	Side Effects:
1627c478bd9Sstevel@tonic-gate **		housekeeping necessary to dispose of an envelope.
1637c478bd9Sstevel@tonic-gate **		Unlocks this queue file.
1647c478bd9Sstevel@tonic-gate */
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate void
1677c478bd9Sstevel@tonic-gate dropenvelope(e, fulldrop, split)
1687c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
1697c478bd9Sstevel@tonic-gate 	bool fulldrop;
1707c478bd9Sstevel@tonic-gate 	bool split;
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate 	bool panic = false;
1737c478bd9Sstevel@tonic-gate 	bool queueit = false;
1747c478bd9Sstevel@tonic-gate 	int msg_timeout = 0;
1757c478bd9Sstevel@tonic-gate 	bool failure_return = false;
1767c478bd9Sstevel@tonic-gate 	bool delay_return = false;
1777c478bd9Sstevel@tonic-gate 	bool success_return = false;
1787c478bd9Sstevel@tonic-gate 	bool pmnotify = bitset(EF_PM_NOTIFY, e->e_flags);
1797c478bd9Sstevel@tonic-gate 	bool done = false;
1807c478bd9Sstevel@tonic-gate 	register ADDRESS *q;
1817c478bd9Sstevel@tonic-gate 	char *id = e->e_id;
1827c478bd9Sstevel@tonic-gate 	time_t now;
1837c478bd9Sstevel@tonic-gate 	char buf[MAXLINE];
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (tTd(50, 1))
1867c478bd9Sstevel@tonic-gate 	{
1877c478bd9Sstevel@tonic-gate 		sm_dprintf("dropenvelope %p: id=", e);
1887c478bd9Sstevel@tonic-gate 		xputs(sm_debug_file(), e->e_id);
1897c478bd9Sstevel@tonic-gate 		sm_dprintf(", flags=");
1907c478bd9Sstevel@tonic-gate 		printenvflags(e);
1917c478bd9Sstevel@tonic-gate 		if (tTd(50, 10))
1927c478bd9Sstevel@tonic-gate 		{
1937c478bd9Sstevel@tonic-gate 			sm_dprintf("sendq=");
1947c478bd9Sstevel@tonic-gate 			printaddr(sm_debug_file(), e->e_sendqueue, true);
1957c478bd9Sstevel@tonic-gate 		}
1967c478bd9Sstevel@tonic-gate 	}
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	if (LogLevel > 84)
1997c478bd9Sstevel@tonic-gate 		sm_syslog(LOG_DEBUG, id,
2007c478bd9Sstevel@tonic-gate 			  "dropenvelope, e_flags=0x%lx, OpMode=%c, pid=%d",
2017c478bd9Sstevel@tonic-gate 			  e->e_flags, OpMode, (int) CurrentPid);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	/* we must have an id to remove disk files */
2047c478bd9Sstevel@tonic-gate 	if (id == NULL)
2057c478bd9Sstevel@tonic-gate 		return;
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	/* if verify-only mode, we can skip most of this */
2087c478bd9Sstevel@tonic-gate 	if (OpMode == MD_VERIFY)
2097c478bd9Sstevel@tonic-gate 		goto simpledrop;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	if (LogLevel > 4 && bitset(EF_LOGSENDER, e->e_flags))
2127c478bd9Sstevel@tonic-gate 		logsender(e, NULL);
2137c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_LOGSENDER;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	/* post statistics */
2167c478bd9Sstevel@tonic-gate 	poststats(StatFile);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/*
2197c478bd9Sstevel@tonic-gate 	**  Extract state information from dregs of send list.
2207c478bd9Sstevel@tonic-gate 	*/
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	now = curtime();
2237c478bd9Sstevel@tonic-gate 	if (now >= e->e_ctime + TimeOuts.to_q_return[e->e_timeoutclass])
2247c478bd9Sstevel@tonic-gate 		msg_timeout = MSG_T_O;
2257c478bd9Sstevel@tonic-gate 	if (IS_DLVR_RETURN(e) && e->e_deliver_by > 0 &&
2267c478bd9Sstevel@tonic-gate 	    now >= e->e_ctime + e->e_deliver_by &&
2277c478bd9Sstevel@tonic-gate 	    !bitset(EF_RESPONSE, e->e_flags))
2287c478bd9Sstevel@tonic-gate 	{
2297c478bd9Sstevel@tonic-gate 		msg_timeout = MSG_NOT_BY;
2307c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_FATALERRS|EF_CLRQUEUE;
2317c478bd9Sstevel@tonic-gate 	}
2327c478bd9Sstevel@tonic-gate 	else if (TimeOuts.to_q_return[e->e_timeoutclass] == NOW &&
2337c478bd9Sstevel@tonic-gate 		 !bitset(EF_RESPONSE, e->e_flags))
2347c478bd9Sstevel@tonic-gate 	{
2357c478bd9Sstevel@tonic-gate 		msg_timeout = MSG_T_O_NOW;
2367c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_FATALERRS|EF_CLRQUEUE;
2377c478bd9Sstevel@tonic-gate 	}
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_QUEUERUN;
2407c478bd9Sstevel@tonic-gate 	for (q = e->e_sendqueue; q != NULL; q = q->q_next)
2417c478bd9Sstevel@tonic-gate 	{
2427c478bd9Sstevel@tonic-gate 		if (QS_IS_UNDELIVERED(q->q_state))
2437c478bd9Sstevel@tonic-gate 			queueit = true;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 		/* see if a notification is needed */
2467c478bd9Sstevel@tonic-gate 		if (bitset(QPINGONFAILURE, q->q_flags) &&
2477c478bd9Sstevel@tonic-gate 		    ((IS_MSG_ERR(msg_timeout) &&
2487c478bd9Sstevel@tonic-gate 		      QS_IS_UNDELIVERED(q->q_state)) ||
2497c478bd9Sstevel@tonic-gate 		     QS_IS_BADADDR(q->q_state) ||
2507c478bd9Sstevel@tonic-gate 		     IS_IMM_RET(msg_timeout)))
2517c478bd9Sstevel@tonic-gate 		{
2527c478bd9Sstevel@tonic-gate 			failure_return = true;
2537c478bd9Sstevel@tonic-gate 			if (!done && q->q_owner == NULL &&
2547c478bd9Sstevel@tonic-gate 			    !emptyaddr(&e->e_from))
2557c478bd9Sstevel@tonic-gate 			{
2567c478bd9Sstevel@tonic-gate 				(void) sendtolist(e->e_from.q_paddr, NULLADDR,
2577c478bd9Sstevel@tonic-gate 						  &e->e_errorqueue, 0, e);
2587c478bd9Sstevel@tonic-gate 				done = true;
2597c478bd9Sstevel@tonic-gate 			}
2607c478bd9Sstevel@tonic-gate 		}
2617c478bd9Sstevel@tonic-gate 		else if ((bitset(QPINGONSUCCESS, q->q_flags) &&
2627c478bd9Sstevel@tonic-gate 			  ((QS_IS_SENT(q->q_state) &&
2637c478bd9Sstevel@tonic-gate 			    bitnset(M_LOCALMAILER, q->q_mailer->m_flags)) ||
2647c478bd9Sstevel@tonic-gate 			   bitset(QRELAYED|QEXPANDED|QDELIVERED, q->q_flags))) ||
2657c478bd9Sstevel@tonic-gate 			  bitset(QBYTRACE, q->q_flags) ||
2667c478bd9Sstevel@tonic-gate 			  bitset(QBYNRELAY, q->q_flags))
2677c478bd9Sstevel@tonic-gate 		{
2687c478bd9Sstevel@tonic-gate 			success_return = true;
2697c478bd9Sstevel@tonic-gate 		}
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	if (e->e_class < 0)
2737c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_NO_BODY_RETN;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	/*
2767c478bd9Sstevel@tonic-gate 	**  See if the message timed out.
2777c478bd9Sstevel@tonic-gate 	*/
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	if (!queueit)
2807c478bd9Sstevel@tonic-gate 		/* EMPTY */
2817c478bd9Sstevel@tonic-gate 		/* nothing to do */ ;
2827c478bd9Sstevel@tonic-gate 	else if (IS_MSG_ERR(msg_timeout))
2837c478bd9Sstevel@tonic-gate 	{
2847c478bd9Sstevel@tonic-gate 		if (failure_return)
2857c478bd9Sstevel@tonic-gate 		{
2867c478bd9Sstevel@tonic-gate 			if (msg_timeout == MSG_NOT_BY)
2877c478bd9Sstevel@tonic-gate 			{
288*058561cbSjbeck 				(void) sm_snprintf(buf, sizeof(buf),
2897c478bd9Sstevel@tonic-gate 					"delivery time expired %lds",
2907c478bd9Sstevel@tonic-gate 					e->e_deliver_by);
2917c478bd9Sstevel@tonic-gate 			}
2927c478bd9Sstevel@tonic-gate 			else
2937c478bd9Sstevel@tonic-gate 			{
294*058561cbSjbeck 				(void) sm_snprintf(buf, sizeof(buf),
2957c478bd9Sstevel@tonic-gate 					"Cannot send message for %s",
2967c478bd9Sstevel@tonic-gate 					pintvl(TimeOuts.to_q_return[e->e_timeoutclass],
2977c478bd9Sstevel@tonic-gate 						false));
2987c478bd9Sstevel@tonic-gate 			}
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 			/* don't free, allocated from e_rpool */
3017c478bd9Sstevel@tonic-gate 			e->e_message = sm_rpool_strdup_x(e->e_rpool, buf);
3027c478bd9Sstevel@tonic-gate 			message(buf);
3037c478bd9Sstevel@tonic-gate 			e->e_flags |= EF_CLRQUEUE;
3047c478bd9Sstevel@tonic-gate 		}
3057c478bd9Sstevel@tonic-gate 		if (msg_timeout == MSG_NOT_BY)
3067c478bd9Sstevel@tonic-gate 		{
3077c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
3087c478bd9Sstevel@tonic-gate 				"Delivery time (%lds) expired\n",
3097c478bd9Sstevel@tonic-gate 				e->e_deliver_by);
3107c478bd9Sstevel@tonic-gate 		}
3117c478bd9Sstevel@tonic-gate 		else
3127c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
3137c478bd9Sstevel@tonic-gate 				"Message could not be delivered for %s\n",
3147c478bd9Sstevel@tonic-gate 				pintvl(TimeOuts.to_q_return[e->e_timeoutclass],
3157c478bd9Sstevel@tonic-gate 					false));
3167c478bd9Sstevel@tonic-gate 		(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
3177c478bd9Sstevel@tonic-gate 			"Message will be deleted from queue\n");
3187c478bd9Sstevel@tonic-gate 		for (q = e->e_sendqueue; q != NULL; q = q->q_next)
3197c478bd9Sstevel@tonic-gate 		{
3207c478bd9Sstevel@tonic-gate 			if (QS_IS_UNDELIVERED(q->q_state))
3217c478bd9Sstevel@tonic-gate 			{
3227c478bd9Sstevel@tonic-gate 				q->q_state = QS_BADADDR;
3237c478bd9Sstevel@tonic-gate 				if (msg_timeout == MSG_NOT_BY)
3247c478bd9Sstevel@tonic-gate 					q->q_status = "5.4.7";
3257c478bd9Sstevel@tonic-gate 				else
3267c478bd9Sstevel@tonic-gate 					q->q_status = "4.4.7";
3277c478bd9Sstevel@tonic-gate 			}
3287c478bd9Sstevel@tonic-gate 		}
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate 	else
3317c478bd9Sstevel@tonic-gate 	{
3327c478bd9Sstevel@tonic-gate 		if (TimeOuts.to_q_warning[e->e_timeoutclass] > 0 &&
3337c478bd9Sstevel@tonic-gate 		    now >= e->e_ctime +
3347c478bd9Sstevel@tonic-gate 				TimeOuts.to_q_warning[e->e_timeoutclass])
3357c478bd9Sstevel@tonic-gate 			msg_timeout = MSG_WARN;
3367c478bd9Sstevel@tonic-gate 		else if (IS_DLVR_NOTIFY(e) &&
3377c478bd9Sstevel@tonic-gate 			 e->e_deliver_by > 0 &&
3387c478bd9Sstevel@tonic-gate 			 now >= e->e_ctime + e->e_deliver_by)
3397c478bd9Sstevel@tonic-gate 			msg_timeout = MSG_WARN_BY;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 		if (IS_MSG_WARN(msg_timeout))
3427c478bd9Sstevel@tonic-gate 		{
3437c478bd9Sstevel@tonic-gate 			if (!bitset(EF_WARNING|EF_RESPONSE, e->e_flags) &&
3447c478bd9Sstevel@tonic-gate 			    e->e_class >= 0 &&
3457c478bd9Sstevel@tonic-gate 			    e->e_from.q_paddr != NULL &&
3467c478bd9Sstevel@tonic-gate 			    strcmp(e->e_from.q_paddr, "<>") != 0 &&
3477c478bd9Sstevel@tonic-gate 			    sm_strncasecmp(e->e_from.q_paddr, "owner-", 6) != 0 &&
3487c478bd9Sstevel@tonic-gate 			    (strlen(e->e_from.q_paddr) <= 8 ||
3497c478bd9Sstevel@tonic-gate 			     sm_strcasecmp(&e->e_from.q_paddr[strlen(e->e_from.q_paddr) - 8],
3507c478bd9Sstevel@tonic-gate 					   "-request") != 0))
3517c478bd9Sstevel@tonic-gate 			{
3527c478bd9Sstevel@tonic-gate 				for (q = e->e_sendqueue; q != NULL;
3537c478bd9Sstevel@tonic-gate 				     q = q->q_next)
3547c478bd9Sstevel@tonic-gate 				{
3557c478bd9Sstevel@tonic-gate 					if (QS_IS_UNDELIVERED(q->q_state)
3567c478bd9Sstevel@tonic-gate #if _FFR_NODELAYDSN_ON_HOLD
3577c478bd9Sstevel@tonic-gate 					    && !bitnset(M_HOLD,
3587c478bd9Sstevel@tonic-gate 							q->q_mailer->m_flags)
3597c478bd9Sstevel@tonic-gate #endif /* _FFR_NODELAYDSN_ON_HOLD */
3607c478bd9Sstevel@tonic-gate 					   )
3617c478bd9Sstevel@tonic-gate 					{
3627c478bd9Sstevel@tonic-gate 						if (msg_timeout ==
3637c478bd9Sstevel@tonic-gate 						    MSG_WARN_BY &&
3647c478bd9Sstevel@tonic-gate 						    (bitset(QPINGONDELAY,
3657c478bd9Sstevel@tonic-gate 							    q->q_flags) ||
3667c478bd9Sstevel@tonic-gate 						    !bitset(QHASNOTIFY,
3677c478bd9Sstevel@tonic-gate 							    q->q_flags))
3687c478bd9Sstevel@tonic-gate 						   )
3697c478bd9Sstevel@tonic-gate 						{
3707c478bd9Sstevel@tonic-gate 							q->q_flags |= QBYNDELAY;
3717c478bd9Sstevel@tonic-gate 							delay_return = true;
3727c478bd9Sstevel@tonic-gate 						}
3737c478bd9Sstevel@tonic-gate 						if (bitset(QPINGONDELAY,
3747c478bd9Sstevel@tonic-gate 							   q->q_flags))
3757c478bd9Sstevel@tonic-gate 						{
3767c478bd9Sstevel@tonic-gate 							q->q_flags |= QDELAYED;
3777c478bd9Sstevel@tonic-gate 							delay_return = true;
3787c478bd9Sstevel@tonic-gate 						}
3797c478bd9Sstevel@tonic-gate 					}
3807c478bd9Sstevel@tonic-gate 				}
3817c478bd9Sstevel@tonic-gate 			}
3827c478bd9Sstevel@tonic-gate 			if (delay_return)
3837c478bd9Sstevel@tonic-gate 			{
3847c478bd9Sstevel@tonic-gate 				if (msg_timeout == MSG_WARN_BY)
3857c478bd9Sstevel@tonic-gate 				{
386*058561cbSjbeck 					(void) sm_snprintf(buf, sizeof(buf),
3877c478bd9Sstevel@tonic-gate 						"Warning: Delivery time (%lds) exceeded",
3887c478bd9Sstevel@tonic-gate 						e->e_deliver_by);
3897c478bd9Sstevel@tonic-gate 				}
3907c478bd9Sstevel@tonic-gate 				else
391*058561cbSjbeck 					(void) sm_snprintf(buf, sizeof(buf),
3927c478bd9Sstevel@tonic-gate 						"Warning: could not send message for past %s",
3937c478bd9Sstevel@tonic-gate 						pintvl(TimeOuts.to_q_warning[e->e_timeoutclass],
3947c478bd9Sstevel@tonic-gate 							false));
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 				/* don't free, allocated from e_rpool */
3977c478bd9Sstevel@tonic-gate 				e->e_message = sm_rpool_strdup_x(e->e_rpool,
3987c478bd9Sstevel@tonic-gate 								 buf);
3997c478bd9Sstevel@tonic-gate 				message(buf);
4007c478bd9Sstevel@tonic-gate 				e->e_flags |= EF_WARNING;
4017c478bd9Sstevel@tonic-gate 			}
4027c478bd9Sstevel@tonic-gate 			if (msg_timeout == MSG_WARN_BY)
4037c478bd9Sstevel@tonic-gate 			{
4047c478bd9Sstevel@tonic-gate 				(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4057c478bd9Sstevel@tonic-gate 					"Warning: Delivery time (%lds) exceeded\n",
4067c478bd9Sstevel@tonic-gate 					e->e_deliver_by);
4077c478bd9Sstevel@tonic-gate 			}
4087c478bd9Sstevel@tonic-gate 			else
4097c478bd9Sstevel@tonic-gate 				(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4107c478bd9Sstevel@tonic-gate 					"Warning: message still undelivered after %s\n",
4117c478bd9Sstevel@tonic-gate 					pintvl(TimeOuts.to_q_warning[e->e_timeoutclass],
4127c478bd9Sstevel@tonic-gate 					     false));
4137c478bd9Sstevel@tonic-gate 			(void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
4147c478bd9Sstevel@tonic-gate 				      "Will keep trying until message is %s old\n",
4157c478bd9Sstevel@tonic-gate 				      pintvl(TimeOuts.to_q_return[e->e_timeoutclass],
4167c478bd9Sstevel@tonic-gate 					     false));
4177c478bd9Sstevel@tonic-gate 		}
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 	if (tTd(50, 2))
4217c478bd9Sstevel@tonic-gate 		sm_dprintf("failure_return=%d delay_return=%d success_return=%d queueit=%d\n",
4227c478bd9Sstevel@tonic-gate 			failure_return, delay_return, success_return, queueit);
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	/*
4257c478bd9Sstevel@tonic-gate 	**  If we had some fatal error, but no addresses are marked as
4267c478bd9Sstevel@tonic-gate 	**  bad, mark them _all_ as bad.
4277c478bd9Sstevel@tonic-gate 	*/
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	if (bitset(EF_FATALERRS, e->e_flags) && !failure_return)
4307c478bd9Sstevel@tonic-gate 	{
4317c478bd9Sstevel@tonic-gate 		for (q = e->e_sendqueue; q != NULL; q = q->q_next)
4327c478bd9Sstevel@tonic-gate 		{
4337c478bd9Sstevel@tonic-gate 			if ((QS_IS_OK(q->q_state) ||
4347c478bd9Sstevel@tonic-gate 			     QS_IS_VERIFIED(q->q_state)) &&
4357c478bd9Sstevel@tonic-gate 			    bitset(QPINGONFAILURE, q->q_flags))
4367c478bd9Sstevel@tonic-gate 			{
4377c478bd9Sstevel@tonic-gate 				failure_return = true;
4387c478bd9Sstevel@tonic-gate 				q->q_state = QS_BADADDR;
4397c478bd9Sstevel@tonic-gate 			}
4407c478bd9Sstevel@tonic-gate 		}
4417c478bd9Sstevel@tonic-gate 	}
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	/*
4447c478bd9Sstevel@tonic-gate 	**  Send back return receipts as requested.
4457c478bd9Sstevel@tonic-gate 	*/
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	if (success_return && !failure_return && !delay_return && fulldrop &&
4487c478bd9Sstevel@tonic-gate 	    !bitset(PRIV_NORECEIPTS, PrivacyFlags) &&
4497c478bd9Sstevel@tonic-gate 	    strcmp(e->e_from.q_paddr, "<>") != 0)
4507c478bd9Sstevel@tonic-gate 	{
4517c478bd9Sstevel@tonic-gate 		auto ADDRESS *rlist = NULL;
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate 		if (tTd(50, 8))
4547c478bd9Sstevel@tonic-gate 			sm_dprintf("dropenvelope(%s): sending return receipt\n",
4557c478bd9Sstevel@tonic-gate 				id);
4567c478bd9Sstevel@tonic-gate 		e->e_flags |= EF_SENDRECEIPT;
4577c478bd9Sstevel@tonic-gate 		(void) sendtolist(e->e_from.q_paddr, NULLADDR, &rlist, 0, e);
4587c478bd9Sstevel@tonic-gate 		(void) returntosender("Return receipt", rlist, RTSF_NO_BODY, e);
4597c478bd9Sstevel@tonic-gate 	}
4607c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_SENDRECEIPT;
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	/*
4637c478bd9Sstevel@tonic-gate 	**  Arrange to send error messages if there are fatal errors.
4647c478bd9Sstevel@tonic-gate 	*/
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	if ((failure_return || delay_return) && e->e_errormode != EM_QUIET)
4677c478bd9Sstevel@tonic-gate 	{
4687c478bd9Sstevel@tonic-gate 		if (tTd(50, 8))
4697c478bd9Sstevel@tonic-gate 			sm_dprintf("dropenvelope(%s): saving mail\n", id);
4707c478bd9Sstevel@tonic-gate 		panic = savemail(e, !bitset(EF_NO_BODY_RETN, e->e_flags));
4717c478bd9Sstevel@tonic-gate 	}
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	/*
4747c478bd9Sstevel@tonic-gate 	**  Arrange to send warning messages to postmaster as requested.
4757c478bd9Sstevel@tonic-gate 	*/
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate 	if ((failure_return || pmnotify) &&
4787c478bd9Sstevel@tonic-gate 	    PostMasterCopy != NULL &&
4797c478bd9Sstevel@tonic-gate 	    !bitset(EF_RESPONSE, e->e_flags) &&
4807c478bd9Sstevel@tonic-gate 	    e->e_class >= 0)
4817c478bd9Sstevel@tonic-gate 	{
4827c478bd9Sstevel@tonic-gate 		auto ADDRESS *rlist = NULL;
4837c478bd9Sstevel@tonic-gate 		char pcopy[MAXNAME];
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 		if (failure_return)
4867c478bd9Sstevel@tonic-gate 		{
487*058561cbSjbeck 			expand(PostMasterCopy, pcopy, sizeof(pcopy), e);
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 			if (tTd(50, 8))
4907c478bd9Sstevel@tonic-gate 				sm_dprintf("dropenvelope(%s): sending postmaster copy to %s\n",
4917c478bd9Sstevel@tonic-gate 					id, pcopy);
4927c478bd9Sstevel@tonic-gate 			(void) sendtolist(pcopy, NULLADDR, &rlist, 0, e);
4937c478bd9Sstevel@tonic-gate 		}
4947c478bd9Sstevel@tonic-gate 		if (pmnotify)
4957c478bd9Sstevel@tonic-gate 			(void) sendtolist("postmaster", NULLADDR,
4967c478bd9Sstevel@tonic-gate 					  &rlist, 0, e);
4977c478bd9Sstevel@tonic-gate 		(void) returntosender(e->e_message, rlist,
4987c478bd9Sstevel@tonic-gate 				      RTSF_PM_BOUNCE|RTSF_NO_BODY, e);
4997c478bd9Sstevel@tonic-gate 	}
5007c478bd9Sstevel@tonic-gate 
5017c478bd9Sstevel@tonic-gate 	/*
5027c478bd9Sstevel@tonic-gate 	**  Instantiate or deinstantiate the queue.
5037c478bd9Sstevel@tonic-gate 	*/
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate simpledrop:
5067c478bd9Sstevel@tonic-gate 	if (tTd(50, 8))
5077c478bd9Sstevel@tonic-gate 		sm_dprintf("dropenvelope(%s): at simpledrop, queueit=%d\n",
5087c478bd9Sstevel@tonic-gate 			id, queueit);
5097c478bd9Sstevel@tonic-gate 	if (!queueit || bitset(EF_CLRQUEUE, e->e_flags))
5107c478bd9Sstevel@tonic-gate 	{
5117c478bd9Sstevel@tonic-gate 		if (tTd(50, 1))
5127c478bd9Sstevel@tonic-gate 		{
5137c478bd9Sstevel@tonic-gate 			sm_dprintf("\n===== Dropping queue files for %s... queueit=%d, e_flags=",
5147c478bd9Sstevel@tonic-gate 				e->e_id, queueit);
5157c478bd9Sstevel@tonic-gate 			printenvflags(e);
5167c478bd9Sstevel@tonic-gate 		}
5177c478bd9Sstevel@tonic-gate 		if (!panic)
5183ee0e492Sjbeck 		{
5193ee0e492Sjbeck 			if (e->e_dfp != NULL)
5203ee0e492Sjbeck 			{
5213ee0e492Sjbeck 				(void) sm_io_close(e->e_dfp, SM_TIME_DEFAULT);
5223ee0e492Sjbeck 				e->e_dfp = NULL;
5233ee0e492Sjbeck 			}
5247c478bd9Sstevel@tonic-gate 			(void) xunlink(queuename(e, DATAFL_LETTER));
5253ee0e492Sjbeck 		}
5267c478bd9Sstevel@tonic-gate 		if (panic && QueueMode == QM_LOST)
5277c478bd9Sstevel@tonic-gate 		{
5287c478bd9Sstevel@tonic-gate 			/*
5297c478bd9Sstevel@tonic-gate 			**  leave the Qf file behind as
5307c478bd9Sstevel@tonic-gate 			**  the delivery attempt failed.
5317c478bd9Sstevel@tonic-gate 			*/
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 			/* EMPTY */
5347c478bd9Sstevel@tonic-gate 		}
5357c478bd9Sstevel@tonic-gate 		else
5367c478bd9Sstevel@tonic-gate 		if (xunlink(queuename(e, ANYQFL_LETTER)) == 0)
5377c478bd9Sstevel@tonic-gate 		{
5387c478bd9Sstevel@tonic-gate 			/* add to available space in filesystem */
5397c478bd9Sstevel@tonic-gate 			updfs(e, -1, panic ? 0 : -1, "dropenvelope");
5407c478bd9Sstevel@tonic-gate 		}
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 		if (e->e_ntries > 0 && LogLevel > 9)
5437c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_INFO, id, "done; delay=%s, ntries=%d",
5447c478bd9Sstevel@tonic-gate 				  pintvl(curtime() - e->e_ctime, true),
5457c478bd9Sstevel@tonic-gate 				  e->e_ntries);
5467c478bd9Sstevel@tonic-gate 	}
5477c478bd9Sstevel@tonic-gate 	else if (queueit || !bitset(EF_INQUEUE, e->e_flags))
5487c478bd9Sstevel@tonic-gate 	{
5497c478bd9Sstevel@tonic-gate 		if (!split)
5507c478bd9Sstevel@tonic-gate 			queueup(e, false, true);
5517c478bd9Sstevel@tonic-gate 		else
5527c478bd9Sstevel@tonic-gate 		{
5537c478bd9Sstevel@tonic-gate 			ENVELOPE *oldsib;
5547c478bd9Sstevel@tonic-gate 			ENVELOPE *ee;
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 			/*
5577c478bd9Sstevel@tonic-gate 			**  Save old sibling and set it to NULL to avoid
5587c478bd9Sstevel@tonic-gate 			**  queueing up the same envelopes again.
5597c478bd9Sstevel@tonic-gate 			**  This requires that envelopes in that list have
5607c478bd9Sstevel@tonic-gate 			**  been take care of before (or at some other place).
5617c478bd9Sstevel@tonic-gate 			*/
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 			oldsib = e->e_sibling;
5647c478bd9Sstevel@tonic-gate 			e->e_sibling = NULL;
5657c478bd9Sstevel@tonic-gate 			if (!split_by_recipient(e) &&
5667c478bd9Sstevel@tonic-gate 			    bitset(EF_FATALERRS, e->e_flags))
5677c478bd9Sstevel@tonic-gate 			{
5687c478bd9Sstevel@tonic-gate 				syserr("!dropenvelope(%s): cannot commit data file %s, uid=%d",
5697c478bd9Sstevel@tonic-gate 					e->e_id, queuename(e, DATAFL_LETTER),
5707c478bd9Sstevel@tonic-gate 					(int) geteuid());
5717c478bd9Sstevel@tonic-gate 			}
5727c478bd9Sstevel@tonic-gate 			for (ee = e->e_sibling; ee != NULL; ee = ee->e_sibling)
5737c478bd9Sstevel@tonic-gate 				queueup(ee, false, true);
5747c478bd9Sstevel@tonic-gate 			queueup(e, false, true);
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 			/* clean up */
5777c478bd9Sstevel@tonic-gate 			for (ee = e->e_sibling; ee != NULL; ee = ee->e_sibling)
5787c478bd9Sstevel@tonic-gate 			{
5797c478bd9Sstevel@tonic-gate 				/* now unlock the job */
5807c478bd9Sstevel@tonic-gate 				if (tTd(50, 8))
5817c478bd9Sstevel@tonic-gate 					sm_dprintf("dropenvelope(%s): unlocking job\n",
5827c478bd9Sstevel@tonic-gate 						   ee->e_id);
5837c478bd9Sstevel@tonic-gate 				closexscript(ee);
5847c478bd9Sstevel@tonic-gate 				unlockqueue(ee);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 				/* this envelope is marked unused */
5877c478bd9Sstevel@tonic-gate 				if (ee->e_dfp != NULL)
5887c478bd9Sstevel@tonic-gate 				{
5897c478bd9Sstevel@tonic-gate 					(void) sm_io_close(ee->e_dfp,
5907c478bd9Sstevel@tonic-gate 							   SM_TIME_DEFAULT);
5917c478bd9Sstevel@tonic-gate 					ee->e_dfp = NULL;
5927c478bd9Sstevel@tonic-gate 				}
5937c478bd9Sstevel@tonic-gate 				ee->e_id = NULL;
5947c478bd9Sstevel@tonic-gate 				ee->e_flags &= ~EF_HAS_DF;
5957c478bd9Sstevel@tonic-gate 			}
5967c478bd9Sstevel@tonic-gate 			e->e_sibling = oldsib;
5977c478bd9Sstevel@tonic-gate 		}
5987c478bd9Sstevel@tonic-gate 	}
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 	/* now unlock the job */
6017c478bd9Sstevel@tonic-gate 	if (tTd(50, 8))
6027c478bd9Sstevel@tonic-gate 		sm_dprintf("dropenvelope(%s): unlocking job\n", id);
6037c478bd9Sstevel@tonic-gate 	closexscript(e);
6047c478bd9Sstevel@tonic-gate 	unlockqueue(e);
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 	/* make sure that this envelope is marked unused */
6077c478bd9Sstevel@tonic-gate 	if (e->e_dfp != NULL)
6087c478bd9Sstevel@tonic-gate 	{
6097c478bd9Sstevel@tonic-gate 		(void) sm_io_close(e->e_dfp, SM_TIME_DEFAULT);
6107c478bd9Sstevel@tonic-gate 		e->e_dfp = NULL;
6117c478bd9Sstevel@tonic-gate 	}
6127c478bd9Sstevel@tonic-gate 	e->e_id = NULL;
6137c478bd9Sstevel@tonic-gate 	e->e_flags &= ~EF_HAS_DF;
6147c478bd9Sstevel@tonic-gate }
6157c478bd9Sstevel@tonic-gate /*
6167c478bd9Sstevel@tonic-gate **  CLEARENVELOPE -- clear an envelope without unlocking
6177c478bd9Sstevel@tonic-gate **
6187c478bd9Sstevel@tonic-gate **	This is normally used by a child process to get a clean
6197c478bd9Sstevel@tonic-gate **	envelope without disturbing the parent.
6207c478bd9Sstevel@tonic-gate **
6217c478bd9Sstevel@tonic-gate **	Parameters:
6227c478bd9Sstevel@tonic-gate **		e -- the envelope to clear.
6237c478bd9Sstevel@tonic-gate **		fullclear - if set, the current envelope is total
6247c478bd9Sstevel@tonic-gate **			garbage and should be ignored; otherwise,
6257c478bd9Sstevel@tonic-gate **			release any resources it may indicate.
6267c478bd9Sstevel@tonic-gate **		rpool -- either NULL, or a pointer to a resource pool
6277c478bd9Sstevel@tonic-gate **			from which envelope memory is allocated, and
6287c478bd9Sstevel@tonic-gate **			to which envelope resources are attached.
6297c478bd9Sstevel@tonic-gate **
6307c478bd9Sstevel@tonic-gate **	Returns:
6317c478bd9Sstevel@tonic-gate **		none.
6327c478bd9Sstevel@tonic-gate **
6337c478bd9Sstevel@tonic-gate **	Side Effects:
6347c478bd9Sstevel@tonic-gate **		Closes files associated with the envelope.
6357c478bd9Sstevel@tonic-gate **		Marks the envelope as unallocated.
6367c478bd9Sstevel@tonic-gate */
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate void
6397c478bd9Sstevel@tonic-gate clearenvelope(e, fullclear, rpool)
6407c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
6417c478bd9Sstevel@tonic-gate 	bool fullclear;
6427c478bd9Sstevel@tonic-gate 	SM_RPOOL_T *rpool;
6437c478bd9Sstevel@tonic-gate {
6447c478bd9Sstevel@tonic-gate 	register HDR *bh;
6457c478bd9Sstevel@tonic-gate 	register HDR **nhp;
6467c478bd9Sstevel@tonic-gate 	extern ENVELOPE BlankEnvelope;
6477c478bd9Sstevel@tonic-gate 	char **p;
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 	if (!fullclear)
6507c478bd9Sstevel@tonic-gate 	{
6517c478bd9Sstevel@tonic-gate 		/* clear out any file information */
6527c478bd9Sstevel@tonic-gate 		if (e->e_xfp != NULL)
6537c478bd9Sstevel@tonic-gate 			(void) sm_io_close(e->e_xfp, SM_TIME_DEFAULT);
6547c478bd9Sstevel@tonic-gate 		if (e->e_dfp != NULL)
6557c478bd9Sstevel@tonic-gate 			(void) sm_io_close(e->e_dfp, SM_TIME_DEFAULT);
6567c478bd9Sstevel@tonic-gate 		e->e_xfp = e->e_dfp = NULL;
6577c478bd9Sstevel@tonic-gate 	}
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate 	/*
6607c478bd9Sstevel@tonic-gate 	**  Copy BlankEnvelope into *e.
6617c478bd9Sstevel@tonic-gate 	**  It is not safe to simply copy pointers to strings;
6627c478bd9Sstevel@tonic-gate 	**  the strings themselves must be copied (or set to NULL).
6637c478bd9Sstevel@tonic-gate 	**  The problem is that when we assign a new string value to
6647c478bd9Sstevel@tonic-gate 	**  a member of BlankEnvelope, we free the old string.
6657c478bd9Sstevel@tonic-gate 	**  We did not need to do this copying in sendmail 8.11 :-(
6667c478bd9Sstevel@tonic-gate 	**  and it is a potential performance hit.  Reference counted
6677c478bd9Sstevel@tonic-gate 	**  strings are one way out.
6687c478bd9Sstevel@tonic-gate 	*/
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate 	*e = BlankEnvelope;
6717c478bd9Sstevel@tonic-gate 	e->e_message = NULL;
6727c478bd9Sstevel@tonic-gate 	e->e_qfletter = '\0';
6737c478bd9Sstevel@tonic-gate 	e->e_quarmsg = NULL;
6747c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{quarantine}"), "");
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	/*
6777c478bd9Sstevel@tonic-gate 	**  Copy the macro table.
6787c478bd9Sstevel@tonic-gate 	**  We might be able to avoid this by zeroing the macro table
6797c478bd9Sstevel@tonic-gate 	**  and always searching BlankEnvelope.e_macro after e->e_macro
6807c478bd9Sstevel@tonic-gate 	**  in macvalue().
6817c478bd9Sstevel@tonic-gate 	*/
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	for (p = &e->e_macro.mac_table[0];
6847c478bd9Sstevel@tonic-gate 	     p <= &e->e_macro.mac_table[MAXMACROID];
6857c478bd9Sstevel@tonic-gate 	     ++p)
6867c478bd9Sstevel@tonic-gate 	{
6877c478bd9Sstevel@tonic-gate 		if (*p != NULL)
6887c478bd9Sstevel@tonic-gate 			*p = sm_rpool_strdup_x(rpool, *p);
6897c478bd9Sstevel@tonic-gate 	}
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 	/*
6927c478bd9Sstevel@tonic-gate 	**  XXX There are many strings in the envelope structure
6937c478bd9Sstevel@tonic-gate 	**  XXX that we are not attempting to copy here.
6947c478bd9Sstevel@tonic-gate 	**  XXX Investigate this further.
6957c478bd9Sstevel@tonic-gate 	*/
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate 	e->e_rpool = rpool;
6987c478bd9Sstevel@tonic-gate 	e->e_macro.mac_rpool = rpool;
6997c478bd9Sstevel@tonic-gate 	if (Verbose)
7007c478bd9Sstevel@tonic-gate 		set_delivery_mode(SM_DELIVER, e);
7017c478bd9Sstevel@tonic-gate 	bh = BlankEnvelope.e_header;
7027c478bd9Sstevel@tonic-gate 	nhp = &e->e_header;
7037c478bd9Sstevel@tonic-gate 	while (bh != NULL)
7047c478bd9Sstevel@tonic-gate 	{
705*058561cbSjbeck 		*nhp = (HDR *) sm_rpool_malloc_x(rpool, sizeof(*bh));
706*058561cbSjbeck 		memmove((char *) *nhp, (char *) bh, sizeof(*bh));
7077c478bd9Sstevel@tonic-gate 		bh = bh->h_link;
7087c478bd9Sstevel@tonic-gate 		nhp = &(*nhp)->h_link;
7097c478bd9Sstevel@tonic-gate 	}
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate /*
7127c478bd9Sstevel@tonic-gate **  INITSYS -- initialize instantiation of system
7137c478bd9Sstevel@tonic-gate **
7147c478bd9Sstevel@tonic-gate **	In Daemon mode, this is done in the child.
7157c478bd9Sstevel@tonic-gate **
7167c478bd9Sstevel@tonic-gate **	Parameters:
7177c478bd9Sstevel@tonic-gate **		e -- the envelope to use.
7187c478bd9Sstevel@tonic-gate **
7197c478bd9Sstevel@tonic-gate **	Returns:
7207c478bd9Sstevel@tonic-gate **		none.
7217c478bd9Sstevel@tonic-gate **
7227c478bd9Sstevel@tonic-gate **	Side Effects:
7237c478bd9Sstevel@tonic-gate **		Initializes the system macros, some global variables,
7247c478bd9Sstevel@tonic-gate **		etc.  In particular, the current time in various
7257c478bd9Sstevel@tonic-gate **		forms is set.
7267c478bd9Sstevel@tonic-gate */
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate void
7297c478bd9Sstevel@tonic-gate initsys(e)
7307c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
7317c478bd9Sstevel@tonic-gate {
7327c478bd9Sstevel@tonic-gate 	char buf[10];
7337c478bd9Sstevel@tonic-gate #ifdef TTYNAME
7347c478bd9Sstevel@tonic-gate 	static char ybuf[60];			/* holds tty id */
7357c478bd9Sstevel@tonic-gate 	register char *p;
7367c478bd9Sstevel@tonic-gate 	extern char *ttyname();
7377c478bd9Sstevel@tonic-gate #endif /* TTYNAME */
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate 	/*
7407c478bd9Sstevel@tonic-gate 	**  Give this envelope a reality.
7417c478bd9Sstevel@tonic-gate 	**	I.e., an id, a transcript, and a creation time.
7427c478bd9Sstevel@tonic-gate 	**  We don't select the queue until all of the recipients are known.
7437c478bd9Sstevel@tonic-gate 	*/
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 	openxscript(e);
7467c478bd9Sstevel@tonic-gate 	e->e_ctime = curtime();
7477c478bd9Sstevel@tonic-gate 	e->e_qfletter = '\0';
7487c478bd9Sstevel@tonic-gate 
7497c478bd9Sstevel@tonic-gate 	/*
7507c478bd9Sstevel@tonic-gate 	**  Set OutChannel to something useful if stdout isn't it.
7517c478bd9Sstevel@tonic-gate 	**	This arranges that any extra stuff the mailer produces
7527c478bd9Sstevel@tonic-gate 	**	gets sent back to the user on error (because it is
7537c478bd9Sstevel@tonic-gate 	**	tucked away in the transcript).
7547c478bd9Sstevel@tonic-gate 	*/
7557c478bd9Sstevel@tonic-gate 
7567c478bd9Sstevel@tonic-gate 	if (OpMode == MD_DAEMON && bitset(EF_QUEUERUN, e->e_flags) &&
7577c478bd9Sstevel@tonic-gate 	    e->e_xfp != NULL)
7587c478bd9Sstevel@tonic-gate 		OutChannel = e->e_xfp;
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 	/*
7617c478bd9Sstevel@tonic-gate 	**  Set up some basic system macros.
7627c478bd9Sstevel@tonic-gate 	*/
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 	/* process id */
765*058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%d", (int) CurrentPid);
7667c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'p', buf);
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 	/* hop count */
769*058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%d", e->e_hopcount);
7707c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'c', buf);
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate 	/* time as integer, unix time, arpa time */
7737c478bd9Sstevel@tonic-gate 	settime(e);
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 	/* Load average */
7767c478bd9Sstevel@tonic-gate 	sm_getla();
7777c478bd9Sstevel@tonic-gate 
7787c478bd9Sstevel@tonic-gate #ifdef TTYNAME
7797c478bd9Sstevel@tonic-gate 	/* tty name */
7807c478bd9Sstevel@tonic-gate 	if (macvalue('y', e) == NULL)
7817c478bd9Sstevel@tonic-gate 	{
7827c478bd9Sstevel@tonic-gate 		p = ttyname(2);
7837c478bd9Sstevel@tonic-gate 		if (p != NULL)
7847c478bd9Sstevel@tonic-gate 		{
7857c478bd9Sstevel@tonic-gate 			if (strrchr(p, '/') != NULL)
7867c478bd9Sstevel@tonic-gate 				p = strrchr(p, '/') + 1;
787*058561cbSjbeck 			(void) sm_strlcpy(ybuf, sizeof(ybuf), p);
7887c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM, 'y', ybuf);
7897c478bd9Sstevel@tonic-gate 		}
7907c478bd9Sstevel@tonic-gate 	}
7917c478bd9Sstevel@tonic-gate #endif /* TTYNAME */
7927c478bd9Sstevel@tonic-gate }
7937c478bd9Sstevel@tonic-gate /*
7947c478bd9Sstevel@tonic-gate **  SETTIME -- set the current time.
7957c478bd9Sstevel@tonic-gate **
7967c478bd9Sstevel@tonic-gate **	Parameters:
7977c478bd9Sstevel@tonic-gate **		e -- the envelope in which the macros should be set.
7987c478bd9Sstevel@tonic-gate **
7997c478bd9Sstevel@tonic-gate **	Returns:
8007c478bd9Sstevel@tonic-gate **		none.
8017c478bd9Sstevel@tonic-gate **
8027c478bd9Sstevel@tonic-gate **	Side Effects:
8037c478bd9Sstevel@tonic-gate **		Sets the various time macros -- $a, $b, $d, $t.
8047c478bd9Sstevel@tonic-gate */
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate void
8077c478bd9Sstevel@tonic-gate settime(e)
8087c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
8097c478bd9Sstevel@tonic-gate {
8107c478bd9Sstevel@tonic-gate 	register char *p;
8117c478bd9Sstevel@tonic-gate 	auto time_t now;
8127c478bd9Sstevel@tonic-gate 	char buf[30];
8137c478bd9Sstevel@tonic-gate 	register struct tm *tm;
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate 	now = curtime();
816*058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%ld", (long) now);
8177c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, macid("{time}"), buf);
8187c478bd9Sstevel@tonic-gate 	tm = gmtime(&now);
819*058561cbSjbeck 	(void) sm_snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d",
8207c478bd9Sstevel@tonic-gate 			   tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
8217c478bd9Sstevel@tonic-gate 			   tm->tm_hour, tm->tm_min);
8227c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 't', buf);
823*058561cbSjbeck 	(void) sm_strlcpy(buf, ctime(&now), sizeof(buf));
8247c478bd9Sstevel@tonic-gate 	p = strchr(buf, '\n');
8257c478bd9Sstevel@tonic-gate 	if (p != NULL)
8267c478bd9Sstevel@tonic-gate 		*p = '\0';
8277c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'd', buf);
8287c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_TEMP, 'b', arpadate(buf));
8297c478bd9Sstevel@tonic-gate 	if (macvalue('a', e) == NULL)
8307c478bd9Sstevel@tonic-gate 		macdefine(&e->e_macro, A_PERM, 'a', macvalue('b', e));
8317c478bd9Sstevel@tonic-gate }
8327c478bd9Sstevel@tonic-gate /*
8337c478bd9Sstevel@tonic-gate **  OPENXSCRIPT -- Open transcript file
8347c478bd9Sstevel@tonic-gate **
8357c478bd9Sstevel@tonic-gate **	Creates a transcript file for possible eventual mailing or
8367c478bd9Sstevel@tonic-gate **	sending back.
8377c478bd9Sstevel@tonic-gate **
8387c478bd9Sstevel@tonic-gate **	Parameters:
8397c478bd9Sstevel@tonic-gate **		e -- the envelope to create the transcript in/for.
8407c478bd9Sstevel@tonic-gate **
8417c478bd9Sstevel@tonic-gate **	Returns:
8427c478bd9Sstevel@tonic-gate **		none
8437c478bd9Sstevel@tonic-gate **
8447c478bd9Sstevel@tonic-gate **	Side Effects:
8457c478bd9Sstevel@tonic-gate **		Creates the transcript file.
8467c478bd9Sstevel@tonic-gate */
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate #ifndef O_APPEND
8497c478bd9Sstevel@tonic-gate # define O_APPEND	0
8507c478bd9Sstevel@tonic-gate #endif /* ! O_APPEND */
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate void
8537c478bd9Sstevel@tonic-gate openxscript(e)
8547c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
8557c478bd9Sstevel@tonic-gate {
8567c478bd9Sstevel@tonic-gate 	register char *p;
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 	if (e->e_xfp != NULL)
8597c478bd9Sstevel@tonic-gate 		return;
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate #if 0
8627c478bd9Sstevel@tonic-gate 	if (e->e_lockfp == NULL && bitset(EF_INQUEUE, e->e_flags))
8637c478bd9Sstevel@tonic-gate 		syserr("openxscript: job not locked");
8647c478bd9Sstevel@tonic-gate #endif /* 0 */
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate 	p = queuename(e, XSCRPT_LETTER);
8677c478bd9Sstevel@tonic-gate 	e->e_xfp = bfopen(p, FileMode, XscriptFileBufferSize,
8687c478bd9Sstevel@tonic-gate 			  SFF_NOTEXCL|SFF_OPENASROOT);
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 	if (e->e_xfp == NULL)
8717c478bd9Sstevel@tonic-gate 	{
8727c478bd9Sstevel@tonic-gate 		syserr("Can't create transcript file %s", p);
8737c478bd9Sstevel@tonic-gate 		e->e_xfp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
8747c478bd9Sstevel@tonic-gate 				      SM_PATH_DEVNULL, SM_IO_RDWR, NULL);
8757c478bd9Sstevel@tonic-gate 		if (e->e_xfp == NULL)
8767c478bd9Sstevel@tonic-gate 			syserr("!Can't open %s", SM_PATH_DEVNULL);
8777c478bd9Sstevel@tonic-gate 	}
8787c478bd9Sstevel@tonic-gate 	(void) sm_io_setvbuf(e->e_xfp, SM_TIME_DEFAULT, NULL, SM_IO_LBF, 0);
8797c478bd9Sstevel@tonic-gate 	if (tTd(46, 9))
8807c478bd9Sstevel@tonic-gate 	{
8817c478bd9Sstevel@tonic-gate 		sm_dprintf("openxscript(%s):\n  ", p);
8827c478bd9Sstevel@tonic-gate 		dumpfd(sm_io_getinfo(e->e_xfp, SM_IO_WHAT_FD, NULL), true,
8837c478bd9Sstevel@tonic-gate 		       false);
8847c478bd9Sstevel@tonic-gate 	}
8857c478bd9Sstevel@tonic-gate }
8867c478bd9Sstevel@tonic-gate /*
8877c478bd9Sstevel@tonic-gate **  CLOSEXSCRIPT -- close the transcript file.
8887c478bd9Sstevel@tonic-gate **
8897c478bd9Sstevel@tonic-gate **	Parameters:
8907c478bd9Sstevel@tonic-gate **		e -- the envelope containing the transcript to close.
8917c478bd9Sstevel@tonic-gate **
8927c478bd9Sstevel@tonic-gate **	Returns:
8937c478bd9Sstevel@tonic-gate **		none.
8947c478bd9Sstevel@tonic-gate **
8957c478bd9Sstevel@tonic-gate **	Side Effects:
8967c478bd9Sstevel@tonic-gate **		none.
8977c478bd9Sstevel@tonic-gate */
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate void
9007c478bd9Sstevel@tonic-gate closexscript(e)
9017c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
9027c478bd9Sstevel@tonic-gate {
9037c478bd9Sstevel@tonic-gate 	if (e->e_xfp == NULL)
9047c478bd9Sstevel@tonic-gate 		return;
9057c478bd9Sstevel@tonic-gate #if 0
9067c478bd9Sstevel@tonic-gate 	if (e->e_lockfp == NULL)
9077c478bd9Sstevel@tonic-gate 		syserr("closexscript: job not locked");
9087c478bd9Sstevel@tonic-gate #endif /* 0 */
9097c478bd9Sstevel@tonic-gate 	(void) sm_io_close(e->e_xfp, SM_TIME_DEFAULT);
9107c478bd9Sstevel@tonic-gate 	e->e_xfp = NULL;
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate /*
9137c478bd9Sstevel@tonic-gate **  SETSENDER -- set the person who this message is from
9147c478bd9Sstevel@tonic-gate **
9157c478bd9Sstevel@tonic-gate **	Under certain circumstances allow the user to say who
9167c478bd9Sstevel@tonic-gate **	s/he is (using -f or -r).  These are:
9177c478bd9Sstevel@tonic-gate **	1.  The user's uid is zero (root).
9187c478bd9Sstevel@tonic-gate **	2.  The user's login name is in an approved list (typically
9197c478bd9Sstevel@tonic-gate **	    from a network server).
9207c478bd9Sstevel@tonic-gate **	3.  The address the user is trying to claim has a
9217c478bd9Sstevel@tonic-gate **	    "!" character in it (since #2 doesn't do it for
9227c478bd9Sstevel@tonic-gate **	    us if we are dialing out for UUCP).
9237c478bd9Sstevel@tonic-gate **	A better check to replace #3 would be if the
9247c478bd9Sstevel@tonic-gate **	effective uid is "UUCP" -- this would require me
9257c478bd9Sstevel@tonic-gate **	to rewrite getpwent to "grab" uucp as it went by,
9267c478bd9Sstevel@tonic-gate **	make getname more nasty, do another passwd file
9277c478bd9Sstevel@tonic-gate **	scan, or compile the UID of "UUCP" into the code,
9287c478bd9Sstevel@tonic-gate **	all of which are reprehensible.
9297c478bd9Sstevel@tonic-gate **
9307c478bd9Sstevel@tonic-gate **	Assuming all of these fail, we figure out something
9317c478bd9Sstevel@tonic-gate **	ourselves.
9327c478bd9Sstevel@tonic-gate **
9337c478bd9Sstevel@tonic-gate **	Parameters:
9347c478bd9Sstevel@tonic-gate **		from -- the person we would like to believe this message
9357c478bd9Sstevel@tonic-gate **			is from, as specified on the command line.
9367c478bd9Sstevel@tonic-gate **		e -- the envelope in which we would like the sender set.
9377c478bd9Sstevel@tonic-gate **		delimptr -- if non-NULL, set to the location of the
9387c478bd9Sstevel@tonic-gate **			trailing delimiter.
9397c478bd9Sstevel@tonic-gate **		delimchar -- the character that will delimit the sender
9407c478bd9Sstevel@tonic-gate **			address.
9417c478bd9Sstevel@tonic-gate **		internal -- set if this address is coming from an internal
9427c478bd9Sstevel@tonic-gate **			source such as an owner alias.
9437c478bd9Sstevel@tonic-gate **
9447c478bd9Sstevel@tonic-gate **	Returns:
9457c478bd9Sstevel@tonic-gate **		none.
9467c478bd9Sstevel@tonic-gate **
9477c478bd9Sstevel@tonic-gate **	Side Effects:
9487c478bd9Sstevel@tonic-gate **		sets sendmail's notion of who the from person is.
9497c478bd9Sstevel@tonic-gate */
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate void
9527c478bd9Sstevel@tonic-gate setsender(from, e, delimptr, delimchar, internal)
9537c478bd9Sstevel@tonic-gate 	char *from;
9547c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
9557c478bd9Sstevel@tonic-gate 	char **delimptr;
9567c478bd9Sstevel@tonic-gate 	int delimchar;
9577c478bd9Sstevel@tonic-gate 	bool internal;
9587c478bd9Sstevel@tonic-gate {
9597c478bd9Sstevel@tonic-gate 	register char **pvp;
9607c478bd9Sstevel@tonic-gate 	char *realname = NULL;
9617c478bd9Sstevel@tonic-gate 	char *bp;
9627c478bd9Sstevel@tonic-gate 	char buf[MAXNAME + 2];
9637c478bd9Sstevel@tonic-gate 	char pvpbuf[PSBUFSIZE];
9647c478bd9Sstevel@tonic-gate 	extern char *FullName;
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate 	if (tTd(45, 1))
9677c478bd9Sstevel@tonic-gate 		sm_dprintf("setsender(%s)\n", from == NULL ? "" : from);
9687c478bd9Sstevel@tonic-gate 
9697c478bd9Sstevel@tonic-gate 	/* may be set from earlier calls */
9707c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, 'x', "");
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 	/*
9737c478bd9Sstevel@tonic-gate 	**  Figure out the real user executing us.
9747c478bd9Sstevel@tonic-gate 	**	Username can return errno != 0 on non-errors.
9757c478bd9Sstevel@tonic-gate 	*/
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate 	if (bitset(EF_QUEUERUN, e->e_flags) || OpMode == MD_SMTP ||
9787c478bd9Sstevel@tonic-gate 	    OpMode == MD_ARPAFTP || OpMode == MD_DAEMON)
9797c478bd9Sstevel@tonic-gate 		realname = from;
9807c478bd9Sstevel@tonic-gate 	if (realname == NULL || realname[0] == '\0')
9817c478bd9Sstevel@tonic-gate 		realname = username();
9827c478bd9Sstevel@tonic-gate 
9837c478bd9Sstevel@tonic-gate 	if (ConfigLevel < 2)
9847c478bd9Sstevel@tonic-gate 		SuprErrs = true;
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), "e s");
9877c478bd9Sstevel@tonic-gate 
9887c478bd9Sstevel@tonic-gate 	/* preset state for then clause in case from == NULL */
9897c478bd9Sstevel@tonic-gate 	e->e_from.q_state = QS_BADADDR;
9907c478bd9Sstevel@tonic-gate 	e->e_from.q_flags = 0;
9917c478bd9Sstevel@tonic-gate 	if (from == NULL ||
9927c478bd9Sstevel@tonic-gate 	    parseaddr(from, &e->e_from, RF_COPYALL|RF_SENDERADDR,
9937c478bd9Sstevel@tonic-gate 		      delimchar, delimptr, e, false) == NULL ||
9947c478bd9Sstevel@tonic-gate 	    QS_IS_BADADDR(e->e_from.q_state) ||
9957c478bd9Sstevel@tonic-gate 	    e->e_from.q_mailer == ProgMailer ||
9967c478bd9Sstevel@tonic-gate 	    e->e_from.q_mailer == FileMailer ||
9977c478bd9Sstevel@tonic-gate 	    e->e_from.q_mailer == InclMailer)
9987c478bd9Sstevel@tonic-gate 	{
9997c478bd9Sstevel@tonic-gate 		/* log garbage addresses for traceback */
10007c478bd9Sstevel@tonic-gate 		if (from != NULL && LogLevel > 2)
10017c478bd9Sstevel@tonic-gate 		{
10027c478bd9Sstevel@tonic-gate 			char *p;
10037c478bd9Sstevel@tonic-gate 			char ebuf[MAXNAME * 2 + 2];
10047c478bd9Sstevel@tonic-gate 
10057c478bd9Sstevel@tonic-gate 			p = macvalue('_', e);
10067c478bd9Sstevel@tonic-gate 			if (p == NULL)
10077c478bd9Sstevel@tonic-gate 			{
10087c478bd9Sstevel@tonic-gate 				char *host = RealHostName;
10097c478bd9Sstevel@tonic-gate 
10107c478bd9Sstevel@tonic-gate 				if (host == NULL)
10117c478bd9Sstevel@tonic-gate 					host = MyHostName;
1012*058561cbSjbeck 				(void) sm_snprintf(ebuf, sizeof(ebuf),
10137c478bd9Sstevel@tonic-gate 						   "%.*s@%.*s", MAXNAME,
10147c478bd9Sstevel@tonic-gate 						   realname, MAXNAME, host);
10157c478bd9Sstevel@tonic-gate 				p = ebuf;
10167c478bd9Sstevel@tonic-gate 			}
10177c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_NOTICE, e->e_id,
10187c478bd9Sstevel@tonic-gate 				  "setsender: %s: invalid or unparsable, received from %s",
10197c478bd9Sstevel@tonic-gate 				  shortenstring(from, 83), p);
10207c478bd9Sstevel@tonic-gate 		}
10217c478bd9Sstevel@tonic-gate 		if (from != NULL)
10227c478bd9Sstevel@tonic-gate 		{
10237c478bd9Sstevel@tonic-gate 			if (!QS_IS_BADADDR(e->e_from.q_state))
10247c478bd9Sstevel@tonic-gate 			{
10257c478bd9Sstevel@tonic-gate 				/* it was a bogus mailer in the from addr */
10267c478bd9Sstevel@tonic-gate 				e->e_status = "5.1.7";
10277c478bd9Sstevel@tonic-gate 				usrerrenh(e->e_status,
10287c478bd9Sstevel@tonic-gate 					  "553 Invalid sender address");
10297c478bd9Sstevel@tonic-gate 			}
10307c478bd9Sstevel@tonic-gate 			SuprErrs = true;
10317c478bd9Sstevel@tonic-gate 		}
10327c478bd9Sstevel@tonic-gate 		if (from == realname ||
10337c478bd9Sstevel@tonic-gate 		    parseaddr(from = realname,
10347c478bd9Sstevel@tonic-gate 			      &e->e_from, RF_COPYALL|RF_SENDERADDR, ' ',
10357c478bd9Sstevel@tonic-gate 			      NULL, e, false) == NULL)
10367c478bd9Sstevel@tonic-gate 		{
10377c478bd9Sstevel@tonic-gate 			char nbuf[100];
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate 			SuprErrs = true;
1040*058561cbSjbeck 			expand("\201n", nbuf, sizeof(nbuf), e);
10417c478bd9Sstevel@tonic-gate 			from = sm_rpool_strdup_x(e->e_rpool, nbuf);
10427c478bd9Sstevel@tonic-gate 			if (parseaddr(from, &e->e_from, RF_COPYALL, ' ',
10437c478bd9Sstevel@tonic-gate 				      NULL, e, false) == NULL &&
10447c478bd9Sstevel@tonic-gate 			    parseaddr(from = "postmaster", &e->e_from,
10457c478bd9Sstevel@tonic-gate 				      RF_COPYALL, ' ', NULL, e, false) == NULL)
10467c478bd9Sstevel@tonic-gate 				syserr("553 5.3.0 setsender: can't even parse postmaster!");
10477c478bd9Sstevel@tonic-gate 		}
10487c478bd9Sstevel@tonic-gate 	}
10497c478bd9Sstevel@tonic-gate 	else
10507c478bd9Sstevel@tonic-gate 		FromFlag = true;
10517c478bd9Sstevel@tonic-gate 	e->e_from.q_state = QS_SENDER;
10527c478bd9Sstevel@tonic-gate 	if (tTd(45, 5))
10537c478bd9Sstevel@tonic-gate 	{
10547c478bd9Sstevel@tonic-gate 		sm_dprintf("setsender: QS_SENDER ");
10557c478bd9Sstevel@tonic-gate 		printaddr(sm_debug_file(), &e->e_from, false);
10567c478bd9Sstevel@tonic-gate 	}
10577c478bd9Sstevel@tonic-gate 	SuprErrs = false;
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate #if USERDB
10607c478bd9Sstevel@tonic-gate 	if (bitnset(M_CHECKUDB, e->e_from.q_mailer->m_flags))
10617c478bd9Sstevel@tonic-gate 	{
10627c478bd9Sstevel@tonic-gate 		register char *p;
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate 		p = udbsender(e->e_from.q_user, e->e_rpool);
10657c478bd9Sstevel@tonic-gate 		if (p != NULL)
10667c478bd9Sstevel@tonic-gate 			from = p;
10677c478bd9Sstevel@tonic-gate 	}
10687c478bd9Sstevel@tonic-gate #endif /* USERDB */
10697c478bd9Sstevel@tonic-gate 
10707c478bd9Sstevel@tonic-gate 	if (bitnset(M_HASPWENT, e->e_from.q_mailer->m_flags))
10717c478bd9Sstevel@tonic-gate 	{
10727c478bd9Sstevel@tonic-gate 		SM_MBDB_T user;
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate 		if (!internal)
10757c478bd9Sstevel@tonic-gate 		{
10767c478bd9Sstevel@tonic-gate 			/* if the user already given fullname don't redefine */
10777c478bd9Sstevel@tonic-gate 			if (FullName == NULL)
10787c478bd9Sstevel@tonic-gate 				FullName = macvalue('x', e);
10797c478bd9Sstevel@tonic-gate 			if (FullName != NULL)
10807c478bd9Sstevel@tonic-gate 			{
10817c478bd9Sstevel@tonic-gate 				if (FullName[0] == '\0')
10827c478bd9Sstevel@tonic-gate 					FullName = NULL;
10837c478bd9Sstevel@tonic-gate 				else
10847c478bd9Sstevel@tonic-gate 					FullName = newstr(FullName);
10857c478bd9Sstevel@tonic-gate 			}
10867c478bd9Sstevel@tonic-gate 		}
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate 		if (e->e_from.q_user[0] != '\0' &&
10897c478bd9Sstevel@tonic-gate 		    sm_mbdb_lookup(e->e_from.q_user, &user) == EX_OK)
10907c478bd9Sstevel@tonic-gate 		{
10917c478bd9Sstevel@tonic-gate 			/*
10927c478bd9Sstevel@tonic-gate 			**  Process passwd file entry.
10937c478bd9Sstevel@tonic-gate 			*/
10947c478bd9Sstevel@tonic-gate 
10957c478bd9Sstevel@tonic-gate 			/* extract home directory */
10967c478bd9Sstevel@tonic-gate 			if (*user.mbdb_homedir == '\0')
10977c478bd9Sstevel@tonic-gate 				e->e_from.q_home = NULL;
10987c478bd9Sstevel@tonic-gate 			else if (strcmp(user.mbdb_homedir, "/") == 0)
10997c478bd9Sstevel@tonic-gate 				e->e_from.q_home = "";
11007c478bd9Sstevel@tonic-gate 			else
11017c478bd9Sstevel@tonic-gate 				e->e_from.q_home = sm_rpool_strdup_x(e->e_rpool,
11027c478bd9Sstevel@tonic-gate 							user.mbdb_homedir);
11037c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_PERM, 'z', e->e_from.q_home);
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 			/* extract user and group id */
11067c478bd9Sstevel@tonic-gate 			if (user.mbdb_uid != SM_NO_UID)
11077c478bd9Sstevel@tonic-gate 			{
11087c478bd9Sstevel@tonic-gate 				e->e_from.q_uid = user.mbdb_uid;
11097c478bd9Sstevel@tonic-gate 				e->e_from.q_gid = user.mbdb_gid;
11107c478bd9Sstevel@tonic-gate 				e->e_from.q_flags |= QGOODUID;
11117c478bd9Sstevel@tonic-gate 			}
11127c478bd9Sstevel@tonic-gate 
11137c478bd9Sstevel@tonic-gate 			/* extract full name from passwd file */
11147c478bd9Sstevel@tonic-gate 			if (FullName == NULL && !internal &&
11157c478bd9Sstevel@tonic-gate 			    user.mbdb_fullname[0] != '\0' &&
11167c478bd9Sstevel@tonic-gate 			    strcmp(user.mbdb_name, e->e_from.q_user) == 0)
11177c478bd9Sstevel@tonic-gate 			{
11187c478bd9Sstevel@tonic-gate 				FullName = newstr(user.mbdb_fullname);
11197c478bd9Sstevel@tonic-gate 			}
11207c478bd9Sstevel@tonic-gate 		}
11217c478bd9Sstevel@tonic-gate 		else
11227c478bd9Sstevel@tonic-gate 		{
11237c478bd9Sstevel@tonic-gate 			e->e_from.q_home = NULL;
11247c478bd9Sstevel@tonic-gate 		}
11257c478bd9Sstevel@tonic-gate 		if (FullName != NULL && !internal)
11267c478bd9Sstevel@tonic-gate 			macdefine(&e->e_macro, A_TEMP, 'x', FullName);
11277c478bd9Sstevel@tonic-gate 	}
11287c478bd9Sstevel@tonic-gate 	else if (!internal && OpMode != MD_DAEMON && OpMode != MD_SMTP)
11297c478bd9Sstevel@tonic-gate 	{
11307c478bd9Sstevel@tonic-gate 		if (e->e_from.q_home == NULL)
11317c478bd9Sstevel@tonic-gate 		{
11327c478bd9Sstevel@tonic-gate 			e->e_from.q_home = getenv("HOME");
11337c478bd9Sstevel@tonic-gate 			if (e->e_from.q_home != NULL)
11347c478bd9Sstevel@tonic-gate 			{
11357c478bd9Sstevel@tonic-gate 				if (*e->e_from.q_home == '\0')
11367c478bd9Sstevel@tonic-gate 					e->e_from.q_home = NULL;
11377c478bd9Sstevel@tonic-gate 				else if (strcmp(e->e_from.q_home, "/") == 0)
11387c478bd9Sstevel@tonic-gate 					e->e_from.q_home++;
11397c478bd9Sstevel@tonic-gate 			}
11407c478bd9Sstevel@tonic-gate 		}
11417c478bd9Sstevel@tonic-gate 		e->e_from.q_uid = RealUid;
11427c478bd9Sstevel@tonic-gate 		e->e_from.q_gid = RealGid;
11437c478bd9Sstevel@tonic-gate 		e->e_from.q_flags |= QGOODUID;
11447c478bd9Sstevel@tonic-gate 	}
11457c478bd9Sstevel@tonic-gate 
11467c478bd9Sstevel@tonic-gate 	/*
11477c478bd9Sstevel@tonic-gate 	**  Rewrite the from person to dispose of possible implicit
11487c478bd9Sstevel@tonic-gate 	**	links in the net.
11497c478bd9Sstevel@tonic-gate 	*/
11507c478bd9Sstevel@tonic-gate 
1151*058561cbSjbeck 	pvp = prescan(from, delimchar, pvpbuf, sizeof(pvpbuf), NULL,
1152*058561cbSjbeck 			IntTokenTab, false);
11537c478bd9Sstevel@tonic-gate 	if (pvp == NULL)
11547c478bd9Sstevel@tonic-gate 	{
11557c478bd9Sstevel@tonic-gate 		/* don't need to give error -- prescan did that already */
11567c478bd9Sstevel@tonic-gate 		if (LogLevel > 2)
11577c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_NOTICE, e->e_id,
11587c478bd9Sstevel@tonic-gate 				  "cannot prescan from (%s)",
11597c478bd9Sstevel@tonic-gate 				  shortenstring(from, MAXSHORTSTR));
11607c478bd9Sstevel@tonic-gate 		finis(true, true, ExitStat);
11617c478bd9Sstevel@tonic-gate 	}
11627c478bd9Sstevel@tonic-gate 	(void) REWRITE(pvp, 3, e);
11637c478bd9Sstevel@tonic-gate 	(void) REWRITE(pvp, 1, e);
11647c478bd9Sstevel@tonic-gate 	(void) REWRITE(pvp, 4, e);
11657c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), NULL);
11667c478bd9Sstevel@tonic-gate 	bp = buf + 1;
1167*058561cbSjbeck 	cataddr(pvp, NULL, bp, sizeof(buf) - 2, '\0', false);
11687c478bd9Sstevel@tonic-gate 	if (*bp == '@' && !bitnset(M_NOBRACKET, e->e_from.q_mailer->m_flags))
11697c478bd9Sstevel@tonic-gate 	{
11707c478bd9Sstevel@tonic-gate 		/* heuristic: route-addr: add angle brackets */
1171*058561cbSjbeck 		(void) sm_strlcat(bp, ">", sizeof(buf) - 1);
11727c478bd9Sstevel@tonic-gate 		*--bp = '<';
11737c478bd9Sstevel@tonic-gate 	}
11747c478bd9Sstevel@tonic-gate 	e->e_sender = sm_rpool_strdup_x(e->e_rpool, bp);
11757c478bd9Sstevel@tonic-gate 	macdefine(&e->e_macro, A_PERM, 'f', e->e_sender);
11767c478bd9Sstevel@tonic-gate 
11777c478bd9Sstevel@tonic-gate 	/* save the domain spec if this mailer wants it */
11787c478bd9Sstevel@tonic-gate 	if (e->e_from.q_mailer != NULL &&
11797c478bd9Sstevel@tonic-gate 	    bitnset(M_CANONICAL, e->e_from.q_mailer->m_flags))
11807c478bd9Sstevel@tonic-gate 	{
11817c478bd9Sstevel@tonic-gate 		char **lastat;
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 		/* get rid of any pesky angle brackets */
11847c478bd9Sstevel@tonic-gate 		macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), "e s");
11857c478bd9Sstevel@tonic-gate 		(void) REWRITE(pvp, 3, e);
11867c478bd9Sstevel@tonic-gate 		(void) REWRITE(pvp, 1, e);
11877c478bd9Sstevel@tonic-gate 		(void) REWRITE(pvp, 4, e);
11887c478bd9Sstevel@tonic-gate 		macdefine(&e->e_macro, A_PERM, macid("{addr_type}"), NULL);
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 		/* strip off to the last "@" sign */
11917c478bd9Sstevel@tonic-gate 		for (lastat = NULL; *pvp != NULL; pvp++)
11927c478bd9Sstevel@tonic-gate 		{
11937c478bd9Sstevel@tonic-gate 			if (strcmp(*pvp, "@") == 0)
11947c478bd9Sstevel@tonic-gate 				lastat = pvp;
11957c478bd9Sstevel@tonic-gate 		}
11967c478bd9Sstevel@tonic-gate 		if (lastat != NULL)
11977c478bd9Sstevel@tonic-gate 		{
11987c478bd9Sstevel@tonic-gate 			e->e_fromdomain = copyplist(lastat, true, e->e_rpool);
11997c478bd9Sstevel@tonic-gate 			if (tTd(45, 3))
12007c478bd9Sstevel@tonic-gate 			{
12017c478bd9Sstevel@tonic-gate 				sm_dprintf("Saving from domain: ");
12027c478bd9Sstevel@tonic-gate 				printav(sm_debug_file(), e->e_fromdomain);
12037c478bd9Sstevel@tonic-gate 			}
12047c478bd9Sstevel@tonic-gate 		}
12057c478bd9Sstevel@tonic-gate 	}
12067c478bd9Sstevel@tonic-gate }
12077c478bd9Sstevel@tonic-gate /*
12087c478bd9Sstevel@tonic-gate **  PRINTENVFLAGS -- print envelope flags for debugging
12097c478bd9Sstevel@tonic-gate **
12107c478bd9Sstevel@tonic-gate **	Parameters:
12117c478bd9Sstevel@tonic-gate **		e -- the envelope with the flags to be printed.
12127c478bd9Sstevel@tonic-gate **
12137c478bd9Sstevel@tonic-gate **	Returns:
12147c478bd9Sstevel@tonic-gate **		none.
12157c478bd9Sstevel@tonic-gate */
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate struct eflags
12187c478bd9Sstevel@tonic-gate {
12197c478bd9Sstevel@tonic-gate 	char		*ef_name;
12207c478bd9Sstevel@tonic-gate 	unsigned long	ef_bit;
12217c478bd9Sstevel@tonic-gate };
12227c478bd9Sstevel@tonic-gate 
12237c478bd9Sstevel@tonic-gate static struct eflags	EnvelopeFlags[] =
12247c478bd9Sstevel@tonic-gate {
12257c478bd9Sstevel@tonic-gate 	{ "OLDSTYLE",		EF_OLDSTYLE	},
12267c478bd9Sstevel@tonic-gate 	{ "INQUEUE",		EF_INQUEUE	},
12277c478bd9Sstevel@tonic-gate 	{ "NO_BODY_RETN",	EF_NO_BODY_RETN	},
12287c478bd9Sstevel@tonic-gate 	{ "CLRQUEUE",		EF_CLRQUEUE	},
12297c478bd9Sstevel@tonic-gate 	{ "SENDRECEIPT",	EF_SENDRECEIPT	},
12307c478bd9Sstevel@tonic-gate 	{ "FATALERRS",		EF_FATALERRS	},
12317c478bd9Sstevel@tonic-gate 	{ "DELETE_BCC",		EF_DELETE_BCC	},
12327c478bd9Sstevel@tonic-gate 	{ "RESPONSE",		EF_RESPONSE	},
12337c478bd9Sstevel@tonic-gate 	{ "RESENT",		EF_RESENT	},
12347c478bd9Sstevel@tonic-gate 	{ "VRFYONLY",		EF_VRFYONLY	},
12357c478bd9Sstevel@tonic-gate 	{ "WARNING",		EF_WARNING	},
12367c478bd9Sstevel@tonic-gate 	{ "QUEUERUN",		EF_QUEUERUN	},
12377c478bd9Sstevel@tonic-gate 	{ "GLOBALERRS",		EF_GLOBALERRS	},
12387c478bd9Sstevel@tonic-gate 	{ "PM_NOTIFY",		EF_PM_NOTIFY	},
12397c478bd9Sstevel@tonic-gate 	{ "METOO",		EF_METOO	},
12407c478bd9Sstevel@tonic-gate 	{ "LOGSENDER",		EF_LOGSENDER	},
12417c478bd9Sstevel@tonic-gate 	{ "NORECEIPT",		EF_NORECEIPT	},
12427c478bd9Sstevel@tonic-gate 	{ "HAS8BIT",		EF_HAS8BIT	},
12437c478bd9Sstevel@tonic-gate 	{ "NL_NOT_EOL",		EF_NL_NOT_EOL	},
12447c478bd9Sstevel@tonic-gate 	{ "CRLF_NOT_EOL",	EF_CRLF_NOT_EOL	},
12457c478bd9Sstevel@tonic-gate 	{ "RET_PARAM",		EF_RET_PARAM	},
12467c478bd9Sstevel@tonic-gate 	{ "HAS_DF",		EF_HAS_DF	},
12477c478bd9Sstevel@tonic-gate 	{ "IS_MIME",		EF_IS_MIME	},
12487c478bd9Sstevel@tonic-gate 	{ "DONT_MIME",		EF_DONT_MIME	},
12497c478bd9Sstevel@tonic-gate 	{ "DISCARD",		EF_DISCARD	},
12507c478bd9Sstevel@tonic-gate 	{ "TOOBIG",		EF_TOOBIG	},
12517c478bd9Sstevel@tonic-gate 	{ "SPLIT",		EF_SPLIT	},
12527c478bd9Sstevel@tonic-gate 	{ "UNSAFE",		EF_UNSAFE	},
12537c478bd9Sstevel@tonic-gate 	{ NULL,			0		}
12547c478bd9Sstevel@tonic-gate };
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate void
12577c478bd9Sstevel@tonic-gate printenvflags(e)
12587c478bd9Sstevel@tonic-gate 	register ENVELOPE *e;
12597c478bd9Sstevel@tonic-gate {
12607c478bd9Sstevel@tonic-gate 	register struct eflags *ef;
12617c478bd9Sstevel@tonic-gate 	bool first = true;
12627c478bd9Sstevel@tonic-gate 
12637c478bd9Sstevel@tonic-gate 	sm_dprintf("%lx", e->e_flags);
12647c478bd9Sstevel@tonic-gate 	for (ef = EnvelopeFlags; ef->ef_name != NULL; ef++)
12657c478bd9Sstevel@tonic-gate 	{
12667c478bd9Sstevel@tonic-gate 		if (!bitset(ef->ef_bit, e->e_flags))
12677c478bd9Sstevel@tonic-gate 			continue;
12687c478bd9Sstevel@tonic-gate 		if (first)
12697c478bd9Sstevel@tonic-gate 			sm_dprintf("<%s", ef->ef_name);
12707c478bd9Sstevel@tonic-gate 		else
12717c478bd9Sstevel@tonic-gate 			sm_dprintf(",%s", ef->ef_name);
12727c478bd9Sstevel@tonic-gate 		first = false;
12737c478bd9Sstevel@tonic-gate 	}
12747c478bd9Sstevel@tonic-gate 	if (!first)
12757c478bd9Sstevel@tonic-gate 		sm_dprintf(">\n");
12767c478bd9Sstevel@tonic-gate }
1277