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