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*7753Seric SCCSID(@(#)queue.c	3.30		08/15/82	(no queueing));
95182Seric # else QUEUE
104632Seric 
11*7753Seric SCCSID(@(#)queue.c	3.30		08/15/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
607677Seric 	if (tTd(40, 1))
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
1197677Seric 		if (tTd(40, 1))
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);
1527391Seric 
1537677Seric # ifdef LOG
1547677Seric 	/* save log info */
1557677Seric 	if (LogLevel > 9)
1567677Seric 		syslog(LOG_INFO, "%s queueup: cf=%s, df=%s\n", MsgId, buf, e->e_df);
1577677Seric # endif LOG
1587677Seric 
1597391Seric 	/* disconnect this temp file from the job */
1607391Seric 	e->e_df = NULL;
1614632Seric }
1624632Seric /*
1634632Seric **  RUNQUEUE -- run the jobs in the queue.
1644632Seric **
1654632Seric **	Gets the stuff out of the queue in some presumably logical
1664632Seric **	order and processes them.
1674632Seric **
1684632Seric **	Parameters:
1694632Seric **		none.
1704632Seric **
1714632Seric **	Returns:
1724632Seric **		none.
1734632Seric **
1744632Seric **	Side Effects:
1754632Seric **		runs things in the mail queue.
1764632Seric */
1774632Seric 
1784639Seric bool	ReorderQueue;		/* if set, reorder the send queue */
1794639Seric int	QueuePid;		/* pid of child running queue */
1804634Seric 
1814639Seric runqueue(forkflag)
1824639Seric 	bool forkflag;
1834632Seric {
1844634Seric 	extern reordersig();
1854632Seric 
1867466Seric 	/*
1877466Seric 	**  See if we want to go off and do other useful work.
1887466Seric 	*/
1894639Seric 
1904639Seric 	if (forkflag)
1914639Seric 	{
1924639Seric 		QueuePid = dofork();
1934639Seric 		if (QueuePid > 0)
1944639Seric 		{
1954639Seric 			/* parent */
1967690Seric 			if (QueueIntvl != 0)
1977690Seric 				setevent(QueueIntvl, reordersig, TRUE);
1984639Seric 			return;
1994639Seric 		}
2004639Seric 	}
2014639Seric 
2027466Seric 	/*
2037466Seric 	**  Start making passes through the queue.
2047466Seric 	**	First, read and sort the entire queue.
2057466Seric 	**	Then, process the work in that order.
2067466Seric 	**		But if you take too long, start over.
2077466Seric 	**	There is a race condition at the end -- we could get
2087466Seric 	**		a reorder signal after finishing the queue.
2097466Seric 	**		In this case we will hang for one more queue
2107466Seric 	**		interval -- clearly a botch, but rare and
2117466Seric 	**		relatively innocuous.
2127466Seric 	*/
2137466Seric 
2144634Seric 	for (;;)
2154634Seric 	{
2167466Seric 		/* order the existing work requests */
2174634Seric 		orderq();
2187690Seric 
2197690Seric 		/* arrange to reorder later */
2204634Seric 		ReorderQueue = FALSE;
2217690Seric 		if (QueueIntvl != 0)
2227690Seric 			setevent(QueueIntvl, reordersig, FALSE);
2234634Seric 
2247466Seric 		/* process them once at a time */
2254634Seric 		while (WorkQ != NULL)
2264634Seric 		{
2274634Seric 			WORK *w = WorkQ;
2284634Seric 
2294634Seric 			WorkQ = WorkQ->w_next;
2304634Seric 			dowork(w);
2314634Seric 			free(w->w_name);
2324634Seric 			free((char *) w);
2334634Seric 			if (ReorderQueue)
2344634Seric 				break;
2354634Seric 		}
2364634Seric 
2377466Seric 		/* if we are just doing one pass, then we are done */
2384634Seric 		if (QueueIntvl == 0)
2397690Seric 			finis();
2407466Seric 
2417466Seric 		/* wait for work -- note (harmless) race condition here */
2427690Seric 		while (!ReorderQueue)
2437690Seric 		{
2447690Seric 			if (forkflag)
2457690Seric 				finis();
2467466Seric 			pause();
2477690Seric 		}
2484632Seric 	}
2494632Seric }
2504632Seric /*
2517690Seric **  REORDERSIG -- catch the reorder signal and tell sendmail to reorder queue.
2524634Seric **
2534634Seric **	Parameters:
2547690Seric **		parent -- if set, called from parent (i.e., not
2557690Seric **			really doing the work).
2564634Seric **
2574634Seric **	Returns:
2584634Seric **		none.
2594634Seric **
2604634Seric **	Side Effects:
2614634Seric **		sets the "reorder work queue" flag.
2624634Seric */
2634634Seric 
2647690Seric reordersig(parent)
2657690Seric 	bool parent;
2664634Seric {
2677690Seric 	if (!parent)
2684639Seric 	{
2694639Seric 		/* we are in a child doing queueing */
2704639Seric 		ReorderQueue = TRUE;
2714639Seric 	}
2724639Seric 	else
2734639Seric 	{
2747690Seric 		/*
2757690Seric 		**  In parent.  If the child still exists, we want
2767690Seric 		**  to do nothing.  If the child is gone, we will
2777690Seric 		**  start up a new one.
2787690Seric 		**  If the child exists, it is responsible for
2797690Seric 		**  doing a queue reorder.
2807690Seric 		**  This code really sucks.
2817690Seric 		*/
2827690Seric 
2834639Seric 		if (kill(QueuePid, SIGALRM) < 0)
2844639Seric 		{
2854639Seric 			/* no child -- get zombie & start new one */
2864639Seric 			static int st;
2874639Seric 
2884836Seric 			(void) wait(&st);
2897690Seric 			runqueue(TRUE);
2904639Seric 		}
2914639Seric 	}
2924639Seric 
2934639Seric 	/*
2944639Seric 	**  Arrange to get this signal again.
2954639Seric 	*/
2964639Seric 
2977690Seric 	setevent(QueueIntvl, reordersig, parent);
2984634Seric }
2994634Seric /*
3004632Seric **  ORDERQ -- order the work queue.
3014632Seric **
3024632Seric **	Parameters:
3034632Seric **		none.
3044632Seric **
3054632Seric **	Returns:
3064632Seric **		none.
3074632Seric **
3084632Seric **	Side Effects:
3094632Seric **		Sets WorkQ to the queue of available work, in order.
3104632Seric */
3114632Seric 
3124632Seric # define WLSIZE		120	/* max size of worklist per sort */
3134632Seric 
3144632Seric orderq()
3154632Seric {
3166625Sglickman 	register struct direct *d;
3174632Seric 	register WORK *w;
3184632Seric 	register WORK **wp;		/* parent of w */
3196625Sglickman 	DIR *f;
3204632Seric 	register int i;
3214632Seric 	WORK wlist[WLSIZE];
3224632Seric 	int wn = 0;
3234632Seric 	extern workcmpf();
3244632Seric 	extern char *QueueDir;
3254632Seric 
3264632Seric 	/* clear out old WorkQ */
3274632Seric 	for (w = WorkQ; w != NULL; )
3284632Seric 	{
3294632Seric 		register WORK *nw = w->w_next;
3304632Seric 
3314632Seric 		WorkQ = nw;
3324632Seric 		free(w->w_name);
3334632Seric 		free((char *) w);
3344632Seric 		w = nw;
3354632Seric 	}
3364632Seric 
3374632Seric 	/* open the queue directory */
3386625Sglickman 	f = opendir(QueueDir);
3394632Seric 	if (f == NULL)
3404632Seric 	{
3414632Seric 		syserr("orderq: cannot open %s", QueueDir);
3424632Seric 		return;
3434632Seric 	}
3444632Seric 
3454632Seric 	/*
3464632Seric 	**  Read the work directory.
3474632Seric 	*/
3484632Seric 
3496625Sglickman 	while (wn < WLSIZE && (d = readdir(f)) != NULL)
3504632Seric 	{
3514632Seric 		char cbuf[MAXNAME];
3524632Seric 		char lbuf[MAXNAME];
3534632Seric 		FILE *cf;
3544632Seric 		register char *p;
3554632Seric 
3564632Seric 		/* is this an interesting entry? */
3576625Sglickman 		if (d->d_name[0] != 'c')
3584632Seric 			continue;
3594632Seric 
3604632Seric 		/* yes -- find the control file location */
3617009Seric 		(void) strcpy(cbuf, QueueDir);
3627009Seric 		(void) strcat(cbuf, "/");
3634632Seric 		p = &cbuf[strlen(cbuf)];
3647009Seric 		(void) strcpy(p, d->d_name);
3654632Seric 
3664632Seric 		/* open control file */
3674632Seric 		cf = fopen(cbuf, "r");
3684632Seric 		if (cf == NULL)
3694632Seric 		{
3707055Seric 			/* this may be some random person sending hir msgs */
3717055Seric 			/* syserr("orderq: cannot open %s", cbuf); */
3727055Seric 			errno = 0;
3734632Seric 			continue;
3744632Seric 		}
3755037Seric 		wlist[wn].w_name = newstr(cbuf);
3764632Seric 
3774632Seric 		/* extract useful information */
3784632Seric 		while (fgets(lbuf, sizeof lbuf, cf) != NULL)
3794632Seric 		{
3804632Seric 			fixcrlf(lbuf, TRUE);
3814632Seric 
3824632Seric 			switch (lbuf[0])
3834632Seric 			{
3844632Seric 			  case 'P':		/* message priority */
3855037Seric 				(void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri);
3864632Seric 				break;
3874632Seric 			}
3884632Seric 		}
3894632Seric 		wn++;
3904632Seric 		(void) fclose(cf);
3914632Seric 	}
3926625Sglickman 	(void) closedir(f);
3934632Seric 
3944632Seric 	/*
3954632Seric 	**  Sort the work directory.
3964632Seric 	*/
3974632Seric 
3984632Seric 	qsort(wlist, wn, sizeof *wlist, workcmpf);
3994632Seric 
4004632Seric 	/*
4014632Seric 	**  Convert the work list into canonical form.
4024632Seric 	*/
4034632Seric 
4044632Seric 	wp = &WorkQ;
4054632Seric 	for (i = 0; i < wn; i++)
4064632Seric 	{
4074632Seric 		w = (WORK *) xalloc(sizeof *w);
4084632Seric 		w->w_name = wlist[i].w_name;
4094632Seric 		w->w_pri = wlist[i].w_pri;
4104632Seric 		w->w_next = NULL;
4114632Seric 		*wp = w;
4124632Seric 		wp = &w->w_next;
4134632Seric 	}
4144632Seric 
4154632Seric # ifdef DEBUG
4167677Seric 	if (tTd(40, 1))
4174632Seric 	{
4184632Seric 		for (w = WorkQ; w != NULL; w = w->w_next)
4195037Seric 			printf("%32s: pri=%ld\n", w->w_name, w->w_pri);
4204632Seric 	}
4214632Seric # endif DEBUG
4224632Seric }
4234632Seric /*
4247677Seric **  WORKCMPF -- compare function for ordering work.
4254632Seric **
4264632Seric **	Parameters:
4274632Seric **		a -- the first argument.
4284632Seric **		b -- the second argument.
4294632Seric **
4304632Seric **	Returns:
4314632Seric **		-1 if a < b
4324632Seric **		0 if a == b
4334632Seric **		1 if a > b
4344632Seric **
4354632Seric **	Side Effects:
4364632Seric **		none.
4374632Seric */
4384632Seric 
4394632Seric # define PRIFACT	1800		/* bytes each priority point is worth */
4404632Seric 
4414632Seric workcmpf(a, b)
4425037Seric 	register WORK *a;
4435037Seric 	register WORK *b;
4444632Seric {
4455037Seric 	if (a->w_pri == b->w_pri)
4464632Seric 		return (0);
4475037Seric 	else if (a->w_pri > b->w_pri)
4484632Seric 		return (1);
4494632Seric 	else
4504632Seric 		return (-1);
4514632Seric }
4524632Seric /*
4534632Seric **  DOWORK -- do a work request.
4544632Seric **
4554632Seric **	Parameters:
4564632Seric **		w -- the work request to be satisfied.
4574632Seric **
4584632Seric **	Returns:
4594632Seric **		none.
4604632Seric **
4614632Seric **	Side Effects:
4624632Seric **		The work request is satisfied if possible.
4634632Seric */
4644632Seric 
4654632Seric dowork(w)
4664632Seric 	register WORK *w;
4674632Seric {
4684632Seric 	register int i;
4694632Seric 	auto int xstat;
4704632Seric 
4714632Seric # ifdef DEBUG
4727677Seric 	if (tTd(40, 1))
4735037Seric 		printf("dowork: %s pri %ld\n", w->w_name, w->w_pri);
4744632Seric # endif DEBUG
4754632Seric 
4764632Seric 	/*
4774632Seric 	**  Fork for work.
4784632Seric 	*/
4794632Seric 
4804632Seric 	i = fork();
4814632Seric 	if (i < 0)
4824632Seric 	{
4834632Seric 		syserr("dowork: cannot fork");
4844632Seric 		return;
4854632Seric 	}
4864632Seric 
4874632Seric 	if (i == 0)
4884632Seric 	{
4896980Seric 		char buf[MAXNAME];
4906980Seric 
4914632Seric 		/*
4924632Seric 		**  CHILD
4936980Seric 		**	Change the name of the control file to avoid
4947350Seric 		**		duplicate deliveries.   Then run the file
4957350Seric 		**		as though we had just read it.
4967350Seric 		**	We save an idea of the temporary name so we
4977350Seric 		**		can recover on interrupt.
4984632Seric 		*/
4994632Seric 
5007356Seric 		(void) alarm(0);
5017347Seric 		FatalErrors = FALSE;
5024632Seric 		QueueRun = TRUE;
5036991Seric 		MailBack = TRUE;
5046980Seric 		(void) strcpy(buf, QueueDir);
5056980Seric 		(void) strcat(buf, "/tfXXXXXX");
5066980Seric 		(void) mktemp(buf);
5076980Seric 		if (link(w->w_name, buf) < 0)
5086980Seric 		{
5097683Seric 			/* this can happen normally; another queuer sneaks in */
5107683Seric 			/* syserr("dowork: link(%s, %s)", w->w_name, buf); */
5116980Seric 			exit(EX_OK);
5126980Seric 		}
5137350Seric 		ControlFile = newstr(buf);
5146980Seric 		(void) unlink(w->w_name);
5156980Seric 
5166980Seric 		/* create ourselves a transcript file */
5174634Seric 		openxscrpt();
5186980Seric 
5196980Seric 		/* do basic system initialization */
5204632Seric 		initsys();
5216980Seric 
5226980Seric 		/* read the queue control file */
5236980Seric 		readqf(buf);
5246980Seric 
5256980Seric 		/* do the delivery */
5267558Seric 		if (!FatalErrors)
5277558Seric 			sendall(CurEnv, FALSE);
5286980Seric 
5296980Seric 		/* if still not sent, perhaps we should time out.... */
5304634Seric # ifdef DEBUG
5317677Seric 		if (tTd(40, 3))
5324634Seric 			printf("CurTime=%ld, TimeOut=%ld\n", CurTime, TimeOut);
5334634Seric # endif DEBUG
5346908Seric 		if (CurEnv->e_queueup && CurTime > TimeOut)
5354634Seric 			timeout(w);
5366980Seric 
5376980Seric 		/* get rid of the temporary file -- a new cf will be made */
5387350Seric 		ControlFile = NULL;
5396980Seric 		(void) unlink(buf);
5406980Seric 
5416980Seric 		/* finish up and exit */
5424632Seric 		finis();
5434632Seric 	}
5444632Seric 
5454632Seric 	/*
5464632Seric 	**  Parent -- pick up results.
5474632Seric 	*/
5484632Seric 
5494632Seric 	errno = 0;
5504632Seric 	while ((i = wait(&xstat)) > 0 && errno != EINTR)
5514632Seric 	{
5524632Seric 		if (errno == EINTR)
5534632Seric 		{
5544632Seric 			errno = 0;
5554632Seric 		}
5564632Seric 	}
5574632Seric }
5584632Seric /*
5594632Seric **  READQF -- read queue file and set up environment.
5604632Seric **
5614632Seric **	Parameters:
5624632Seric **		cf -- name of queue control file.
5634632Seric **
5644632Seric **	Returns:
5654632Seric **		none.
5664632Seric **
5674632Seric **	Side Effects:
5684632Seric **		cf is read and created as the current job, as though
5694632Seric **		we had been invoked by argument.
5704632Seric */
5714632Seric 
5724632Seric readqf(cf)
5734632Seric 	char *cf;
5744632Seric {
5754632Seric 	register FILE *f;
5764632Seric 	char buf[MAXLINE];
577*7753Seric 	register char *p;
578*7753Seric 	register int i;
5794632Seric 
5804632Seric 	/*
5814632Seric 	**  Open the file created by queueup.
5824632Seric 	*/
5834632Seric 
5844632Seric 	f = fopen(cf, "r");
5854632Seric 	if (f == NULL)
5864632Seric 	{
5874632Seric 		syserr("readqf: no cf file %s", cf);
5884632Seric 		return;
5894632Seric 	}
5904632Seric 
5914632Seric 	/*
5924632Seric 	**  Read and process the file.
5934632Seric 	*/
5944632Seric 
5957356Seric 	if (Verbose)
5967356Seric 		printf("\nRunning %s\n", cf);
597*7753Seric 	p = buf;
598*7753Seric 	while (fgets(p, sizeof buf - (p - buf), f) != NULL)
5994632Seric 	{
600*7753Seric 		/*
601*7753Seric 		**  Collect any continuation lines...
602*7753Seric 		*/
6034632Seric 
604*7753Seric 		i = fgetc(f);
605*7753Seric 		if (i != EOF)
606*7753Seric 			ungetc(i, f);
607*7753Seric 		if (i == ' ' || i == '\t')
608*7753Seric 		{
609*7753Seric 			p += strlen(p);
610*7753Seric 			continue;
611*7753Seric 		}
612*7753Seric 		fixcrlf(p, TRUE);
613*7753Seric 
6144632Seric 		switch (buf[0])
6154632Seric 		{
6164632Seric 		  case 'R':		/* specify recipient */
6176908Seric 			sendto(&buf[1], 1, (ADDRESS *) NULL, &CurEnv->e_sendqueue);
6184632Seric 			break;
6194632Seric 
6204632Seric 		  case 'H':		/* header */
6214632Seric 			(void) chompheader(&buf[1], FALSE);
6224632Seric 			break;
6234632Seric 
6244632Seric 		  case 'S':		/* sender */
6254634Seric 			setsender(newstr(&buf[1]));
6264632Seric 			break;
6274632Seric 
6284632Seric 		  case 'D':		/* data file name */
6296991Seric 			CurEnv->e_df = newstr(&buf[1]);
6306991Seric 			TempFile = fopen(CurEnv->e_df, "r");
6314632Seric 			if (TempFile == NULL)
6326991Seric 				syserr("readqf: cannot open %s", CurEnv->e_df);
6334632Seric 			break;
6344632Seric 
6354632Seric 		  case 'T':		/* timeout */
6364632Seric 			(void) sscanf(&buf[1], "%ld", &TimeOut);
6374632Seric 			break;
6384632Seric 
6394634Seric 		  case 'P':		/* message priority */
6406908Seric 			(void) sscanf(&buf[1], "%ld", &CurEnv->e_msgpriority);
6415037Seric 
6425037Seric 			/* make sure that big things get sent eventually */
6436908Seric 			CurEnv->e_msgpriority -= WKTIMEFACT;
6444634Seric 			break;
6454634Seric 
6466980Seric 		  case 'C':		/* message class */
6476980Seric 			(void) sscanf(&buf[1], "%hd", &CurEnv->e_class);
6486980Seric 			break;
6496980Seric 
6505902Seric 		  case 'M':		/* define macro */
6515902Seric 			define(buf[1], newstr(&buf[2]));
6525902Seric 			break;
6535902Seric 
6544632Seric 		  default:
6554632Seric 			syserr("readqf(%s): bad line \"%s\"", cf, buf);
6564632Seric 			break;
6574632Seric 		}
6584632Seric 	}
6594632Seric }
6604632Seric /*
6614632Seric **  TIMEOUT -- process timeout on queue file.
6624632Seric **
6634632Seric **	Parameters:
6644632Seric **		w -- pointer to work request that timed out.
6654632Seric **
6664632Seric **	Returns:
6674632Seric **		none.
6684632Seric **
6694632Seric **	Side Effects:
6704632Seric **		Returns a message to the sender saying that this
6714632Seric **		message has timed out.
6724632Seric */
6734632Seric 
6744632Seric timeout(w)
6754632Seric 	register WORK *w;
6764632Seric {
6777369Seric 	char buf[MAXLINE];
6787369Seric 	extern char *TextTimeOut;
6797369Seric 
6804634Seric # ifdef DEBUG
6817677Seric 	if (tTd(40, 3))
6824634Seric 		printf("timeout(%s)\n", w->w_name);
6834634Seric # endif DEBUG
6846991Seric 	message(Arpa_Info, "Message has timed out");
6854634Seric 
6864634Seric 	/* return message to sender */
6877369Seric 	(void) sprintf(buf, "Cannot send mail for %s", TextTimeOut);
6887369Seric 	(void) returntosender(buf, &CurEnv->e_from, TRUE);
6894634Seric 
6904634Seric 	/* arrange to remove files from queue */
6916908Seric 	CurEnv->e_queueup = FALSE;
6924632Seric }
6935182Seric 
6945182Seric # endif QUEUE
695