14632Seric # include "sendmail.h"
24632Seric # include <sys/stat.h>
36625Sglickman # include <ndir.h>
44634Seric # include <signal.h>
54632Seric # include <errno.h>
64632Seric 
75182Seric # ifndef QUEUE
8*7347Seric SCCSID(@(#)queue.c	3.20		07/02/82	(no queueing));
95182Seric # else QUEUE
104632Seric 
11*7347Seric SCCSID(@(#)queue.c	3.20		07/02/82);
125182Seric 
134632Seric /*
144632Seric **  QUEUEUP -- queue a message up for future transmission.
154632Seric **
164632Seric **	The queued message should already be in the correct place.
174632Seric **	This routine just outputs the control file as appropriate.
184632Seric **
194632Seric **	Parameters:
206980Seric **		e -- the envelope to queue up.
216999Seric **		queueall -- if TRUE, queue all addresses, rather than
226999Seric **			just those with the QQUEUEUP flag set.
234632Seric **
244632Seric **	Returns:
254632Seric **		none.
264632Seric **
274632Seric **	Side Effects:
284632Seric **		The current request (only unsatisfied addresses)
294632Seric **			are saved in a control file.
304632Seric */
314632Seric 
326999Seric queueup(e, queueall)
336980Seric 	register ENVELOPE *e;
346999Seric 	bool queueall;
354632Seric {
364632Seric 	char cf[MAXNAME];
376980Seric 	char buf[MAXNAME];
386980Seric 	register FILE *cfp;
394632Seric 	register HDR *h;
405007Seric 	register ADDRESS *q;
415199Seric 	extern char *mktemp();
425902Seric 	register int i;
434632Seric 
445037Seric 	/*
455037Seric 	**  Create control file.
465037Seric 	*/
474632Seric 
487009Seric 	(void) strcpy(cf, QueueDir);
497009Seric 	(void) strcat(cf, "/tfXXXXXX");
505037Seric 	(void) mktemp(cf);
516980Seric 	cfp = fopen(cf, "w");
526980Seric 	if (cfp == NULL)
534632Seric 	{
544632Seric 		syserr("queueup: cannot create control file %s", cf);
554632Seric 		return;
564632Seric 	}
577010Seric 	(void) chmod(cf, 0600);
584632Seric 
594632Seric # ifdef DEBUG
604632Seric 	if (Debug)
616980Seric 		printf("queueing in %s\n", cf);
624632Seric # endif DEBUG
634632Seric 
644632Seric 	/*
656980Seric 	**  If there is no data file yet, create one.
666980Seric 	*/
676980Seric 
686980Seric 	if (e->e_df == NULL)
696980Seric 	{
706980Seric 		register FILE *dfp;
716980Seric 
727009Seric 		(void) strcpy(buf, QueueDir);
737009Seric 		(void) strcat(buf, "/dfXXXXXX");
746980Seric 		e->e_df = newstr(mktemp(buf));
756980Seric 		dfp = fopen(e->e_df, "w");
766980Seric 		if (dfp == NULL)
776980Seric 		{
786980Seric 			syserr("queueup: cannot create %s", e->e_df);
797009Seric 			(void) fclose(cfp);
806980Seric 			return;
816980Seric 		}
827010Seric 		(void) chmod(e->e_df, 0600);
836980Seric 		(*e->e_putbody)(dfp, Mailer[1], FALSE);
847009Seric 		(void) fclose(dfp);
856980Seric 	}
866980Seric 
876980Seric 	/*
884632Seric 	**  Output future work requests.
894632Seric 	*/
904632Seric 
914632Seric 	/* output name of data file */
926980Seric 	fprintf(cfp, "D%s\n", e->e_df);
934632Seric 
944632Seric 	/* output name of sender */
956980Seric 	fprintf(cfp, "S%s\n", e->e_from.q_paddr);
964632Seric 
974632Seric 	/* output timeout */
986980Seric 	fprintf(cfp, "T%ld\n", TimeOut);
994632Seric 
1004634Seric 	/* output message priority */
1016980Seric 	fprintf(cfp, "P%ld\n", e->e_msgpriority);
1024634Seric 
1036980Seric 	/* output message class */
1046980Seric 	fprintf(cfp, "C%d\n", e->e_class);
1056980Seric 
1065902Seric 	/* output macro definitions */
1075902Seric 	for (i = 0; i < 128; i++)
1085902Seric 	{
1096980Seric 		register char *p = e->e_macro[i];
1105902Seric 
1115902Seric 		if (p != NULL && i != (int) 'b')
1126980Seric 			fprintf(cfp, "M%c%s\n", i, p);
1135902Seric 	}
1145902Seric 
1154632Seric 	/* output list of recipient addresses */
1166980Seric 	for (q = e->e_sendqueue; q != NULL; q = q->q_next)
1174632Seric 	{
1185037Seric # ifdef DEBUG
1195037Seric 		if (Debug > 0)
1205037Seric 		{
1215037Seric 			printf("queueing ");
1225037Seric 			printaddr(q, FALSE);
1235037Seric 		}
1245037Seric # endif DEBUG
1256999Seric 		if (queueall || bitset(QQUEUEUP, q->q_flags))
1266980Seric 			fprintf(cfp, "R%s\n", q->q_paddr);
1274632Seric 	}
1284632Seric 
1294632Seric 	/* output headers for this message */
1306980Seric 	for (h = e->e_header; h != NULL; h = h->h_link)
1314632Seric 	{
1324632Seric 		if (h->h_value == NULL || h->h_value[0] == '\0')
1334632Seric 			continue;
1346980Seric 		fprintf(cfp, "H");
1354632Seric 		if (h->h_mflags != 0 && bitset(H_CHECK|H_ACHECK, h->h_flags))
1366980Seric 			mfdecode(h->h_mflags, cfp);
1376980Seric 		fprintf(cfp, "%s: %s\n", h->h_field, h->h_value);
1384632Seric 	}
1394632Seric 
1404632Seric 	/*
1414632Seric 	**  Clean up.
1424632Seric 	*/
1434632Seric 
1446980Seric 	(void) fclose(cfp);
1456980Seric 	(void) strcpy(buf, QueueDir);
1466980Seric 	(void) strcat(buf, "/cfXXXXXX");
1476980Seric 	(void) mktemp(buf);
1486980Seric 	if (link(cf, buf) < 0)
1496980Seric 		syserr("cannot link(%s, %s), df=%s", cf, buf, e->e_df);
1506980Seric 	else
1517009Seric 		(void) unlink(cf);
1524632Seric }
1534632Seric /*
1544632Seric **  RUNQUEUE -- run the jobs in the queue.
1554632Seric **
1564632Seric **	Gets the stuff out of the queue in some presumably logical
1574632Seric **	order and processes them.
1584632Seric **
1594632Seric **	Parameters:
1604632Seric **		none.
1614632Seric **
1624632Seric **	Returns:
1634632Seric **		none.
1644632Seric **
1654632Seric **	Side Effects:
1664632Seric **		runs things in the mail queue.
1674632Seric */
1684632Seric 
1694639Seric bool	ReorderQueue;		/* if set, reorder the send queue */
1704639Seric int	QueuePid;		/* pid of child running queue */
1714634Seric 
1724639Seric runqueue(forkflag)
1734639Seric 	bool forkflag;
1744632Seric {
1754634Seric 	extern reordersig();
1764632Seric 
1774639Seric 	if (QueueIntvl != 0)
1784639Seric 	{
1794836Seric 		(void) signal(SIGALRM, reordersig);
1807009Seric 		(void) alarm(QueueIntvl);
1814639Seric 	}
1824639Seric 
1834639Seric 	if (forkflag)
1844639Seric 	{
1854639Seric 		QueuePid = dofork();
1864639Seric 		if (QueuePid > 0)
1874639Seric 		{
1884639Seric 			/* parent */
1894639Seric 			return;
1904639Seric 		}
1914639Seric 		else
1927009Seric 			(void) alarm(0);
1934639Seric 	}
1944639Seric 
1954634Seric 	for (;;)
1964634Seric 	{
1974634Seric 		/*
1984634Seric 		**  Order the existing work requests.
1994634Seric 		*/
2004632Seric 
2014634Seric 		orderq();
2024632Seric 
2034634Seric 		if (WorkQ == NULL)
2044634Seric 		{
2054634Seric 			/* no work?  well, maybe later */
2064634Seric 			if (QueueIntvl == 0)
2074634Seric 				break;
2084639Seric 			pause();
2094634Seric 			continue;
2104634Seric 		}
2114632Seric 
2124634Seric 		ReorderQueue = FALSE;
2134634Seric 
2144634Seric 		/*
2154634Seric 		**  Process them once at a time.
2164634Seric 		**	The queue could be reordered while we do this to take
2174634Seric 		**	new requests into account.  If so, the existing job
2184634Seric 		**	will be finished but the next thing taken off WorkQ
2194634Seric 		**	may be something else.
2204634Seric 		*/
2214634Seric 
2224634Seric 		while (WorkQ != NULL)
2234634Seric 		{
2244634Seric 			WORK *w = WorkQ;
2254634Seric 
2264634Seric 			WorkQ = WorkQ->w_next;
2274634Seric 			dowork(w);
2284634Seric 			free(w->w_name);
2294634Seric 			free((char *) w);
2304634Seric 			if (ReorderQueue)
2314634Seric 				break;
2324634Seric 		}
2334634Seric 
2344634Seric 		if (QueueIntvl == 0)
2354634Seric 			break;
2364632Seric 	}
2375978Seric 
2385978Seric 	/* no work to do -- just exit */
2395978Seric 	finis();
2404632Seric }
2414632Seric /*
2424634Seric **  REORDERSIG -- catch the alarm signal and tell sendmail to reorder queue.
2434634Seric **
2444634Seric **	Parameters:
2454634Seric **		none.
2464634Seric **
2474634Seric **	Returns:
2484634Seric **		none.
2494634Seric **
2504634Seric **	Side Effects:
2514634Seric **		sets the "reorder work queue" flag.
2524634Seric */
2534634Seric 
2544634Seric reordersig()
2554634Seric {
2564639Seric 	if (QueuePid == 0)
2574639Seric 	{
2584639Seric 		/* we are in a child doing queueing */
2594639Seric 		ReorderQueue = TRUE;
2604639Seric 	}
2614639Seric 	else
2624639Seric 	{
2634639Seric 		/* we are in a parent -- poke child or start new one */
2644639Seric 		if (kill(QueuePid, SIGALRM) < 0)
2654639Seric 		{
2664639Seric 			/* no child -- get zombie & start new one */
2674639Seric 			static int st;
2684639Seric 
2694836Seric 			(void) wait(&st);
2704639Seric 			QueuePid = dofork();
2714639Seric 			if (QueuePid == 0)
2724639Seric 			{
2734639Seric 				/* new child; run queue */
2744836Seric 				runqueue(FALSE);
2754639Seric 				finis();
2764639Seric 			}
2774639Seric 		}
2784639Seric 	}
2794639Seric 
2804639Seric 	/*
2814639Seric 	**  Arrange to get this signal again.
2824639Seric 	*/
2834639Seric 
2846065Seric 	(void) signal(SIGALRM, reordersig);
2857009Seric 	(void) alarm(QueueIntvl);
2864634Seric }
2874634Seric /*
2884632Seric **  ORDERQ -- order the work queue.
2894632Seric **
2904632Seric **	Parameters:
2914632Seric **		none.
2924632Seric **
2934632Seric **	Returns:
2944632Seric **		none.
2954632Seric **
2964632Seric **	Side Effects:
2974632Seric **		Sets WorkQ to the queue of available work, in order.
2984632Seric */
2994632Seric 
3004632Seric # define WLSIZE		120	/* max size of worklist per sort */
3014632Seric 
3024632Seric orderq()
3034632Seric {
3046625Sglickman 	register struct direct *d;
3054632Seric 	register WORK *w;
3064632Seric 	register WORK **wp;		/* parent of w */
3076625Sglickman 	DIR *f;
3084632Seric 	register int i;
3094632Seric 	WORK wlist[WLSIZE];
3104632Seric 	int wn = 0;
3114632Seric 	extern workcmpf();
3124632Seric 	extern char *QueueDir;
3134632Seric 
3144632Seric 	/* clear out old WorkQ */
3154632Seric 	for (w = WorkQ; w != NULL; )
3164632Seric 	{
3174632Seric 		register WORK *nw = w->w_next;
3184632Seric 
3194632Seric 		WorkQ = nw;
3204632Seric 		free(w->w_name);
3214632Seric 		free((char *) w);
3224632Seric 		w = nw;
3234632Seric 	}
3244632Seric 
3254632Seric 	/* open the queue directory */
3266625Sglickman 	f = opendir(QueueDir);
3274632Seric 	if (f == NULL)
3284632Seric 	{
3294632Seric 		syserr("orderq: cannot open %s", QueueDir);
3304632Seric 		return;
3314632Seric 	}
3324632Seric 
3334632Seric 	/*
3344632Seric 	**  Read the work directory.
3354632Seric 	*/
3364632Seric 
3376625Sglickman 	while (wn < WLSIZE && (d = readdir(f)) != NULL)
3384632Seric 	{
3394632Seric 		char cbuf[MAXNAME];
3404632Seric 		char lbuf[MAXNAME];
3414632Seric 		FILE *cf;
3424632Seric 		register char *p;
3434632Seric 
3444632Seric 		/* is this an interesting entry? */
3456625Sglickman 		if (d->d_name[0] != 'c')
3464632Seric 			continue;
3474632Seric 
3484632Seric 		/* yes -- find the control file location */
3497009Seric 		(void) strcpy(cbuf, QueueDir);
3507009Seric 		(void) strcat(cbuf, "/");
3514632Seric 		p = &cbuf[strlen(cbuf)];
3527009Seric 		(void) strcpy(p, d->d_name);
3534632Seric 
3544632Seric 		/* open control file */
3554632Seric 		cf = fopen(cbuf, "r");
3564632Seric 		if (cf == NULL)
3574632Seric 		{
3587055Seric 			/* this may be some random person sending hir msgs */
3597055Seric 			/* syserr("orderq: cannot open %s", cbuf); */
3607055Seric 			errno = 0;
3614632Seric 			continue;
3624632Seric 		}
3635037Seric 		wlist[wn].w_name = newstr(cbuf);
3644632Seric 
3654632Seric 		/* extract useful information */
3664632Seric 		while (fgets(lbuf, sizeof lbuf, cf) != NULL)
3674632Seric 		{
3684632Seric 			fixcrlf(lbuf, TRUE);
3694632Seric 
3704632Seric 			switch (lbuf[0])
3714632Seric 			{
3724632Seric 			  case 'P':		/* message priority */
3735037Seric 				(void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri);
3744632Seric 				break;
3754632Seric 			}
3764632Seric 		}
3774632Seric 		wn++;
3784632Seric 		(void) fclose(cf);
3794632Seric 	}
3806625Sglickman 	(void) closedir(f);
3814632Seric 
3824632Seric 	/*
3834632Seric 	**  Sort the work directory.
3844632Seric 	*/
3854632Seric 
3864632Seric 	qsort(wlist, wn, sizeof *wlist, workcmpf);
3874632Seric 
3884632Seric 	/*
3894632Seric 	**  Convert the work list into canonical form.
3904632Seric 	*/
3914632Seric 
3924632Seric 	wp = &WorkQ;
3934632Seric 	for (i = 0; i < wn; i++)
3944632Seric 	{
3954632Seric 		w = (WORK *) xalloc(sizeof *w);
3964632Seric 		w->w_name = wlist[i].w_name;
3974632Seric 		w->w_pri = wlist[i].w_pri;
3984632Seric 		w->w_next = NULL;
3994632Seric 		*wp = w;
4004632Seric 		wp = &w->w_next;
4014632Seric 	}
4024632Seric 
4034632Seric # ifdef DEBUG
4044632Seric 	if (Debug)
4054632Seric 	{
4064632Seric 		for (w = WorkQ; w != NULL; w = w->w_next)
4075037Seric 			printf("%32s: pri=%ld\n", w->w_name, w->w_pri);
4084632Seric 	}
4094632Seric # endif DEBUG
4104632Seric }
4114632Seric /*
4124632Seric **	WORKCMPF -- compare function for ordering work.
4134632Seric **
4144632Seric **	Parameters:
4154632Seric **		a -- the first argument.
4164632Seric **		b -- the second argument.
4174632Seric **
4184632Seric **	Returns:
4194632Seric **		-1 if a < b
4204632Seric **		0 if a == b
4214632Seric **		1 if a > b
4224632Seric **
4234632Seric **	Side Effects:
4244632Seric **		none.
4254632Seric */
4264632Seric 
4274632Seric # define PRIFACT	1800		/* bytes each priority point is worth */
4284632Seric 
4294632Seric workcmpf(a, b)
4305037Seric 	register WORK *a;
4315037Seric 	register WORK *b;
4324632Seric {
4335037Seric 	if (a->w_pri == b->w_pri)
4344632Seric 		return (0);
4355037Seric 	else if (a->w_pri > b->w_pri)
4364632Seric 		return (1);
4374632Seric 	else
4384632Seric 		return (-1);
4394632Seric }
4404632Seric /*
4414632Seric **  DOWORK -- do a work request.
4424632Seric **
4434632Seric **	Parameters:
4444632Seric **		w -- the work request to be satisfied.
4454632Seric **
4464632Seric **	Returns:
4474632Seric **		none.
4484632Seric **
4494632Seric **	Side Effects:
4504632Seric **		The work request is satisfied if possible.
4514632Seric */
4524632Seric 
4534632Seric dowork(w)
4544632Seric 	register WORK *w;
4554632Seric {
4564632Seric 	register int i;
4574632Seric 	auto int xstat;
4584632Seric 
4594632Seric # ifdef DEBUG
4604632Seric 	if (Debug)
4615037Seric 		printf("dowork: %s pri %ld\n", w->w_name, w->w_pri);
4624632Seric # endif DEBUG
4634632Seric 
4644632Seric 	/*
4654632Seric 	**  Fork for work.
4664632Seric 	*/
4674632Seric 
4684632Seric 	i = fork();
4694632Seric 	if (i < 0)
4704632Seric 	{
4714632Seric 		syserr("dowork: cannot fork");
4724632Seric 		return;
4734632Seric 	}
4744632Seric 
4754632Seric 	if (i == 0)
4764632Seric 	{
4776980Seric 		char buf[MAXNAME];
4786980Seric 
4794632Seric 		/*
4804632Seric 		**  CHILD
4816980Seric 		**	Change the name of the control file to avoid
4826980Seric 		**	duplicate deliveries.   Then run the file as
4836980Seric 		**	though we had just read it.
4844632Seric 		*/
4854632Seric 
486*7347Seric 		FatalErrors = FALSE;
4874632Seric 		QueueRun = TRUE;
4886991Seric 		MailBack = TRUE;
4896980Seric 		(void) strcpy(buf, QueueDir);
4906980Seric 		(void) strcat(buf, "/tfXXXXXX");
4916980Seric 		(void) mktemp(buf);
4926980Seric 		if (link(w->w_name, buf) < 0)
4936980Seric 		{
4946980Seric 			syserr("dowork: link(%s, %s)", w->w_name, buf);
4956980Seric 
4966980Seric 			/* it's ok to lie -- it will be run later */
4976980Seric 			exit(EX_OK);
4986980Seric 		}
4996980Seric 		(void) unlink(w->w_name);
5006980Seric 
5016980Seric 		/* create ourselves a transcript file */
5024634Seric 		openxscrpt();
5036980Seric 
5046980Seric 		/* do basic system initialization */
5054632Seric 		initsys();
5066980Seric 
5076980Seric 		/* read the queue control file */
5086980Seric 		readqf(buf);
5096980Seric 
5106980Seric 		/* do the delivery */
5117046Seric 		sendall(CurEnv, FALSE);
5126980Seric 
5136980Seric 		/* if still not sent, perhaps we should time out.... */
5144634Seric # ifdef DEBUG
5154634Seric 		if (Debug > 2)
5164634Seric 			printf("CurTime=%ld, TimeOut=%ld\n", CurTime, TimeOut);
5174634Seric # endif DEBUG
5186908Seric 		if (CurEnv->e_queueup && CurTime > TimeOut)
5194634Seric 			timeout(w);
5206980Seric 
5216980Seric 		/* get rid of the temporary file -- a new cf will be made */
5226980Seric 		(void) unlink(buf);
5236980Seric 
5246980Seric 		/* finish up and exit */
5254632Seric 		finis();
5264632Seric 	}
5274632Seric 
5284632Seric 	/*
5294632Seric 	**  Parent -- pick up results.
5304632Seric 	*/
5314632Seric 
5324632Seric 	errno = 0;
5334632Seric 	while ((i = wait(&xstat)) > 0 && errno != EINTR)
5344632Seric 	{
5354632Seric 		if (errno == EINTR)
5364632Seric 		{
5374632Seric 			errno = 0;
5384632Seric 		}
5394632Seric 	}
5404632Seric }
5414632Seric /*
5424632Seric **  READQF -- read queue file and set up environment.
5434632Seric **
5444632Seric **	Parameters:
5454632Seric **		cf -- name of queue control file.
5464632Seric **
5474632Seric **	Returns:
5484632Seric **		none.
5494632Seric **
5504632Seric **	Side Effects:
5514632Seric **		cf is read and created as the current job, as though
5524632Seric **		we had been invoked by argument.
5534632Seric */
5544632Seric 
5554632Seric readqf(cf)
5564632Seric 	char *cf;
5574632Seric {
5584632Seric 	register FILE *f;
5594632Seric 	char buf[MAXLINE];
5604632Seric 
5614632Seric 	/*
5624632Seric 	**  Open the file created by queueup.
5634632Seric 	*/
5644632Seric 
5654632Seric 	f = fopen(cf, "r");
5664632Seric 	if (f == NULL)
5674632Seric 	{
5684632Seric 		syserr("readqf: no cf file %s", cf);
5694632Seric 		return;
5704632Seric 	}
5714632Seric 
5724632Seric 	/*
5734632Seric 	**  Read and process the file.
5744632Seric 	*/
5754632Seric 
5767055Seric 	message(Arpa_Info, "Running %s", cf);
5774632Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5784632Seric 	{
5794632Seric 		fixcrlf(buf, TRUE);
5804632Seric 
5814632Seric 		switch (buf[0])
5824632Seric 		{
5834632Seric 		  case 'R':		/* specify recipient */
5846908Seric 			sendto(&buf[1], 1, (ADDRESS *) NULL, &CurEnv->e_sendqueue);
5854632Seric 			break;
5864632Seric 
5874632Seric 		  case 'H':		/* header */
5884632Seric 			(void) chompheader(&buf[1], FALSE);
5894632Seric 			break;
5904632Seric 
5914632Seric 		  case 'S':		/* sender */
5924634Seric 			setsender(newstr(&buf[1]));
5934632Seric 			break;
5944632Seric 
5954632Seric 		  case 'D':		/* data file name */
5966991Seric 			CurEnv->e_df = newstr(&buf[1]);
5976991Seric 			TempFile = fopen(CurEnv->e_df, "r");
5984632Seric 			if (TempFile == NULL)
5996991Seric 				syserr("readqf: cannot open %s", CurEnv->e_df);
6004632Seric 			break;
6014632Seric 
6024632Seric 		  case 'T':		/* timeout */
6034632Seric 			(void) sscanf(&buf[1], "%ld", &TimeOut);
6044632Seric 			break;
6054632Seric 
6064634Seric 		  case 'P':		/* message priority */
6076908Seric 			(void) sscanf(&buf[1], "%ld", &CurEnv->e_msgpriority);
6085037Seric 
6095037Seric 			/* make sure that big things get sent eventually */
6106908Seric 			CurEnv->e_msgpriority -= WKTIMEFACT;
6114634Seric 			break;
6124634Seric 
6136980Seric 		  case 'C':		/* message class */
6146980Seric 			(void) sscanf(&buf[1], "%hd", &CurEnv->e_class);
6156980Seric 			break;
6166980Seric 
6175902Seric 		  case 'M':		/* define macro */
6185902Seric 			define(buf[1], newstr(&buf[2]));
6195902Seric 			break;
6205902Seric 
6214632Seric 		  default:
6224632Seric 			syserr("readqf(%s): bad line \"%s\"", cf, buf);
6234632Seric 			break;
6244632Seric 		}
6254632Seric 	}
6264632Seric }
6274632Seric /*
6284632Seric **  TIMEOUT -- process timeout on queue file.
6294632Seric **
6304632Seric **	Parameters:
6314632Seric **		w -- pointer to work request that timed out.
6324632Seric **
6334632Seric **	Returns:
6344632Seric **		none.
6354632Seric **
6364632Seric **	Side Effects:
6374632Seric **		Returns a message to the sender saying that this
6384632Seric **		message has timed out.
6394632Seric */
6404632Seric 
6414632Seric timeout(w)
6424632Seric 	register WORK *w;
6434632Seric {
6444634Seric # ifdef DEBUG
6454634Seric 	if (Debug > 0)
6464634Seric 		printf("timeout(%s)\n", w->w_name);
6474634Seric # endif DEBUG
6486991Seric 	message(Arpa_Info, "Message has timed out");
6494634Seric 
6504634Seric 	/* return message to sender */
6516980Seric 	(void) returntosender("Cannot send mail for three days",
6526980Seric 			      &CurEnv->e_from, TRUE);
6534634Seric 
6544634Seric 	/* arrange to remove files from queue */
6556908Seric 	CurEnv->e_queueup = FALSE;
6564632Seric }
6575182Seric 
6585182Seric # endif QUEUE
659