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*7886Seric SCCSID(@(#)queue.c	3.39		08/25/82	(no queueing));
95182Seric # else QUEUE
104632Seric 
11*7886Seric SCCSID(@(#)queue.c	3.39		08/25/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 {
367812Seric 	char *tf;
377812Seric 	char *qf;
387763Seric 	char buf[MAXLINE];
397812Seric 	register FILE *tfp;
404632Seric 	register HDR *h;
415007Seric 	register ADDRESS *q;
425902Seric 	register int i;
434632Seric 
445037Seric 	/*
455037Seric 	**  Create control file.
465037Seric 	*/
474632Seric 
487812Seric 	tf = newstr(queuename(e, 't'));
497812Seric 	tfp = fopen(tf, "w");
507812Seric 	if (tfp == NULL)
514632Seric 	{
527812Seric 		syserr("queueup: cannot create temp file %s", tf);
534632Seric 		return;
544632Seric 	}
557812Seric 	(void) chmod(tf, 0600);
564632Seric 
574632Seric # ifdef DEBUG
587677Seric 	if (tTd(40, 1))
597812Seric 		printf("queueing in %s\n", tf);
604632Seric # endif DEBUG
614632Seric 
624632Seric 	/*
636980Seric 	**  If there is no data file yet, create one.
646980Seric 	*/
656980Seric 
666980Seric 	if (e->e_df == NULL)
676980Seric 	{
686980Seric 		register FILE *dfp;
696980Seric 
707812Seric 		e->e_df = newstr(queuename(e, 'd'));
716980Seric 		dfp = fopen(e->e_df, "w");
726980Seric 		if (dfp == NULL)
736980Seric 		{
746980Seric 			syserr("queueup: cannot create %s", e->e_df);
757812Seric 			(void) fclose(tfp);
766980Seric 			return;
776980Seric 		}
787010Seric 		(void) chmod(e->e_df, 0600);
796980Seric 		(*e->e_putbody)(dfp, Mailer[1], FALSE);
807009Seric 		(void) fclose(dfp);
816980Seric 	}
826980Seric 
836980Seric 	/*
844632Seric 	**  Output future work requests.
854632Seric 	*/
864632Seric 
874632Seric 	/* output name of data file */
887812Seric 	fprintf(tfp, "D%s\n", e->e_df);
894632Seric 
904632Seric 	/* output name of sender */
917812Seric 	fprintf(tfp, "S%s\n", e->e_from.q_paddr);
924632Seric 
937860Seric 	/* output creation time */
947860Seric 	fprintf(tfp, "T%ld\n", e->e_ctime);
954632Seric 
964634Seric 	/* output message priority */
977812Seric 	fprintf(tfp, "P%ld\n", e->e_msgpriority);
984634Seric 
996980Seric 	/* output message class */
1007812Seric 	fprintf(tfp, "C%d\n", e->e_class);
1016980Seric 
1025902Seric 	/* output macro definitions */
1037763Seric 	/* I don't think this is needed any more.....
1045902Seric 	for (i = 0; i < 128; i++)
1055902Seric 	{
1066980Seric 		register char *p = e->e_macro[i];
1075902Seric 
1085902Seric 		if (p != NULL && i != (int) 'b')
1097812Seric 			fprintf(tfp, "M%c%s\n", i, p);
1105902Seric 	}
1117763Seric 	.....  */
1125902Seric 
1134632Seric 	/* output list of recipient addresses */
1146980Seric 	for (q = e->e_sendqueue; q != NULL; q = q->q_next)
1154632Seric 	{
1165037Seric # ifdef DEBUG
1177677Seric 		if (tTd(40, 1))
1185037Seric 		{
1195037Seric 			printf("queueing ");
1205037Seric 			printaddr(q, FALSE);
1215037Seric 		}
1225037Seric # endif DEBUG
1237763Seric 		if (queueall ? !bitset(QDONTSEND, q->q_flags) :
1247763Seric 			       bitset(QQUEUEUP, q->q_flags))
1257812Seric 			fprintf(tfp, "R%s\n", q->q_paddr);
1264632Seric 	}
1274632Seric 
1284632Seric 	/* output headers for this message */
1297763Seric 	define('g', "$f");
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;
1347812Seric 		fprintf(tfp, "H");
1354632Seric 		if (h->h_mflags != 0 && bitset(H_CHECK|H_ACHECK, h->h_flags))
1367812Seric 			mfdecode(h->h_mflags, tfp);
1377812Seric 		fprintf(tfp, "%s: ", h->h_field);
1387763Seric 		if (bitset(H_DEFAULT, h->h_flags))
1397763Seric 		{
1407763Seric 			(void) expand(h->h_value, buf, &buf[sizeof buf], e);
1417812Seric 			fprintf(tfp, "%s\n", buf);
1427763Seric 		}
1437763Seric 		else
1447812Seric 			fprintf(tfp, "%s\n", h->h_value);
1454632Seric 	}
1464632Seric 
1474632Seric 	/*
1484632Seric 	**  Clean up.
1494632Seric 	*/
1504632Seric 
1517812Seric 	(void) fclose(tfp);
1527812Seric 	qf = queuename(e, 'q');
1537812Seric 	(void) unlink(qf);
1547812Seric 	if (link(tf, qf) < 0)
1557812Seric 		syserr("cannot link(%s, %s), df=%s", tf, qf, e->e_df);
1566980Seric 	else
1577812Seric 		(void) unlink(tf);
1587812Seric 	e->e_qf = NULL;
1597391Seric 
1607677Seric # ifdef LOG
1617677Seric 	/* save log info */
1627878Seric 	if (LogLevel > 15)
1637878Seric 		syslog(LOG_DEBUG, "%s: queueup, qf=%s, df=%s\n", e->e_id, qf, e->e_df);
1647677Seric # endif LOG
1657677Seric 
1667391Seric 	/* disconnect this temp file from the job */
1677391Seric 	e->e_df = NULL;
1684632Seric }
1694632Seric /*
1704632Seric **  RUNQUEUE -- run the jobs in the queue.
1714632Seric **
1724632Seric **	Gets the stuff out of the queue in some presumably logical
1734632Seric **	order and processes them.
1744632Seric **
1754632Seric **	Parameters:
1764632Seric **		none.
1774632Seric **
1784632Seric **	Returns:
1794632Seric **		none.
1804632Seric **
1814632Seric **	Side Effects:
1824632Seric **		runs things in the mail queue.
1834632Seric */
1844632Seric 
1854639Seric bool	ReorderQueue;		/* if set, reorder the send queue */
1864639Seric int	QueuePid;		/* pid of child running queue */
1874634Seric 
1884639Seric runqueue(forkflag)
1894639Seric 	bool forkflag;
1904632Seric {
1914634Seric 	extern reordersig();
1924632Seric 
1937466Seric 	/*
1947466Seric 	**  See if we want to go off and do other useful work.
1957466Seric 	*/
1964639Seric 
1974639Seric 	if (forkflag)
1984639Seric 	{
1994639Seric 		QueuePid = dofork();
2004639Seric 		if (QueuePid > 0)
2014639Seric 		{
2024639Seric 			/* parent */
2037690Seric 			if (QueueIntvl != 0)
2047690Seric 				setevent(QueueIntvl, reordersig, TRUE);
2054639Seric 			return;
2064639Seric 		}
2074639Seric 	}
2087876Seric # ifdef LOG
2097876Seric 	if (LogLevel > 11)
2107876Seric 		syslog(LOG_DEBUG, "runqueue, pid=%d", getpid());
2117876Seric # endif LOG
2124639Seric 
2137466Seric 	/*
2147466Seric 	**  Start making passes through the queue.
2157466Seric 	**	First, read and sort the entire queue.
2167466Seric 	**	Then, process the work in that order.
2177466Seric 	**		But if you take too long, start over.
2187466Seric 	**	There is a race condition at the end -- we could get
2197466Seric 	**		a reorder signal after finishing the queue.
2207466Seric 	**		In this case we will hang for one more queue
2217466Seric 	**		interval -- clearly a botch, but rare and
2227466Seric 	**		relatively innocuous.
2237466Seric 	*/
2247466Seric 
2254634Seric 	for (;;)
2264634Seric 	{
2277466Seric 		/* order the existing work requests */
2284634Seric 		orderq();
2297690Seric 
2307690Seric 		/* arrange to reorder later */
2314634Seric 		ReorderQueue = FALSE;
2327690Seric 		if (QueueIntvl != 0)
2337690Seric 			setevent(QueueIntvl, reordersig, FALSE);
2344634Seric 
2357466Seric 		/* process them once at a time */
2364634Seric 		while (WorkQ != NULL)
2374634Seric 		{
2384634Seric 			WORK *w = WorkQ;
2394634Seric 
2404634Seric 			WorkQ = WorkQ->w_next;
2414634Seric 			dowork(w);
2424634Seric 			free(w->w_name);
2434634Seric 			free((char *) w);
2444634Seric 			if (ReorderQueue)
2454634Seric 				break;
2464634Seric 		}
2474634Seric 
2487466Seric 		/* if we are just doing one pass, then we are done */
2494634Seric 		if (QueueIntvl == 0)
2507690Seric 			finis();
2517466Seric 
2527466Seric 		/* wait for work -- note (harmless) race condition here */
2537690Seric 		while (!ReorderQueue)
2547690Seric 		{
2557690Seric 			if (forkflag)
2567690Seric 				finis();
2577466Seric 			pause();
2587690Seric 		}
2594632Seric 	}
2604632Seric }
2614632Seric /*
2627690Seric **  REORDERSIG -- catch the reorder signal and tell sendmail to reorder queue.
2634634Seric **
2644634Seric **	Parameters:
2657690Seric **		parent -- if set, called from parent (i.e., not
2667690Seric **			really doing the work).
2674634Seric **
2684634Seric **	Returns:
2694634Seric **		none.
2704634Seric **
2714634Seric **	Side Effects:
2724634Seric **		sets the "reorder work queue" flag.
2734634Seric */
2744634Seric 
2757690Seric reordersig(parent)
2767690Seric 	bool parent;
2774634Seric {
2787690Seric 	if (!parent)
2794639Seric 	{
2804639Seric 		/* we are in a child doing queueing */
2814639Seric 		ReorderQueue = TRUE;
2827881Seric 
2837881Seric 		/* arrange to get this signal again */
2847881Seric 		setevent(QueueIntvl, reordersig, FALSE);
2854639Seric 	}
2864639Seric 	else
2874639Seric 	{
2887690Seric 		/*
2897690Seric 		**  In parent.  If the child still exists, we want
2907690Seric 		**  to do nothing.  If the child is gone, we will
2917690Seric 		**  start up a new one.
2927690Seric 		**  If the child exists, it is responsible for
2937690Seric 		**  doing a queue reorder.
2947690Seric 		**  This code really sucks.
2957690Seric 		*/
2967690Seric 
2974639Seric 		if (kill(QueuePid, SIGALRM) < 0)
2984639Seric 		{
2994639Seric 			/* no child -- get zombie & start new one */
3004639Seric 			static int st;
3014639Seric 
3024836Seric 			(void) wait(&st);
3037690Seric 			runqueue(TRUE);
3044639Seric 		}
3057881Seric 		else
3067881Seric 			setevent(QueueIntvl, reordersig, TRUE);
3074639Seric 	}
3084634Seric }
3094634Seric /*
3104632Seric **  ORDERQ -- order the work queue.
3114632Seric **
3124632Seric **	Parameters:
3134632Seric **		none.
3144632Seric **
3154632Seric **	Returns:
3164632Seric **		none.
3174632Seric **
3184632Seric **	Side Effects:
3194632Seric **		Sets WorkQ to the queue of available work, in order.
3204632Seric */
3214632Seric 
3224632Seric # define WLSIZE		120	/* max size of worklist per sort */
3234632Seric 
3244632Seric orderq()
3254632Seric {
3266625Sglickman 	register struct direct *d;
3274632Seric 	register WORK *w;
3284632Seric 	register WORK **wp;		/* parent of w */
3296625Sglickman 	DIR *f;
3304632Seric 	register int i;
3314632Seric 	WORK wlist[WLSIZE];
3324632Seric 	int wn = 0;
3334632Seric 	extern workcmpf();
3344632Seric 	extern char *QueueDir;
3354632Seric 
3364632Seric 	/* clear out old WorkQ */
3374632Seric 	for (w = WorkQ; w != NULL; )
3384632Seric 	{
3394632Seric 		register WORK *nw = w->w_next;
3404632Seric 
3414632Seric 		WorkQ = nw;
3424632Seric 		free(w->w_name);
3434632Seric 		free((char *) w);
3444632Seric 		w = nw;
3454632Seric 	}
3464632Seric 
3474632Seric 	/* open the queue directory */
3486625Sglickman 	f = opendir(QueueDir);
3494632Seric 	if (f == NULL)
3504632Seric 	{
3514632Seric 		syserr("orderq: cannot open %s", QueueDir);
3524632Seric 		return;
3534632Seric 	}
3544632Seric 
3554632Seric 	/*
3564632Seric 	**  Read the work directory.
3574632Seric 	*/
3584632Seric 
3596625Sglickman 	while (wn < WLSIZE && (d = readdir(f)) != NULL)
3604632Seric 	{
3614632Seric 		char cbuf[MAXNAME];
3624632Seric 		char lbuf[MAXNAME];
3634632Seric 		FILE *cf;
3644632Seric 		register char *p;
3654632Seric 
3664632Seric 		/* is this an interesting entry? */
3677812Seric 		if (d->d_name[0] != 'q' || d->d_name[1] != 'f')
3684632Seric 			continue;
3694632Seric 
3704632Seric 		/* yes -- find the control file location */
3717009Seric 		(void) strcpy(cbuf, QueueDir);
3727009Seric 		(void) strcat(cbuf, "/");
3734632Seric 		p = &cbuf[strlen(cbuf)];
3747009Seric 		(void) strcpy(p, d->d_name);
3754632Seric 
3764632Seric 		/* open control file */
3774632Seric 		cf = fopen(cbuf, "r");
3784632Seric 		if (cf == NULL)
3794632Seric 		{
3807055Seric 			/* this may be some random person sending hir msgs */
3817055Seric 			/* syserr("orderq: cannot open %s", cbuf); */
3827055Seric 			errno = 0;
3834632Seric 			continue;
3844632Seric 		}
3855037Seric 		wlist[wn].w_name = newstr(cbuf);
3864632Seric 
3874632Seric 		/* extract useful information */
3884632Seric 		while (fgets(lbuf, sizeof lbuf, cf) != NULL)
3894632Seric 		{
3904632Seric 			fixcrlf(lbuf, TRUE);
3914632Seric 
3924632Seric 			switch (lbuf[0])
3934632Seric 			{
3944632Seric 			  case 'P':		/* message priority */
3955037Seric 				(void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri);
3964632Seric 				break;
3974632Seric 			}
3984632Seric 		}
3994632Seric 		wn++;
4004632Seric 		(void) fclose(cf);
4014632Seric 	}
4026625Sglickman 	(void) closedir(f);
4034632Seric 
4044632Seric 	/*
4054632Seric 	**  Sort the work directory.
4064632Seric 	*/
4074632Seric 
4084632Seric 	qsort(wlist, wn, sizeof *wlist, workcmpf);
4094632Seric 
4104632Seric 	/*
4114632Seric 	**  Convert the work list into canonical form.
4124632Seric 	*/
4134632Seric 
4144632Seric 	wp = &WorkQ;
4154632Seric 	for (i = 0; i < wn; i++)
4164632Seric 	{
4174632Seric 		w = (WORK *) xalloc(sizeof *w);
4184632Seric 		w->w_name = wlist[i].w_name;
4194632Seric 		w->w_pri = wlist[i].w_pri;
4204632Seric 		w->w_next = NULL;
4214632Seric 		*wp = w;
4224632Seric 		wp = &w->w_next;
4234632Seric 	}
4244632Seric 
4254632Seric # ifdef DEBUG
4267677Seric 	if (tTd(40, 1))
4274632Seric 	{
4284632Seric 		for (w = WorkQ; w != NULL; w = w->w_next)
4295037Seric 			printf("%32s: pri=%ld\n", w->w_name, w->w_pri);
4304632Seric 	}
4314632Seric # endif DEBUG
4324632Seric }
4334632Seric /*
4347677Seric **  WORKCMPF -- compare function for ordering work.
4354632Seric **
4364632Seric **	Parameters:
4374632Seric **		a -- the first argument.
4384632Seric **		b -- the second argument.
4394632Seric **
4404632Seric **	Returns:
4414632Seric **		-1 if a < b
4424632Seric **		0 if a == b
4434632Seric **		1 if a > b
4444632Seric **
4454632Seric **	Side Effects:
4464632Seric **		none.
4474632Seric */
4484632Seric 
4494632Seric # define PRIFACT	1800		/* bytes each priority point is worth */
4504632Seric 
4514632Seric workcmpf(a, b)
4525037Seric 	register WORK *a;
4535037Seric 	register WORK *b;
4544632Seric {
4555037Seric 	if (a->w_pri == b->w_pri)
4564632Seric 		return (0);
4575037Seric 	else if (a->w_pri > b->w_pri)
4584632Seric 		return (1);
4594632Seric 	else
4604632Seric 		return (-1);
4614632Seric }
4624632Seric /*
4634632Seric **  DOWORK -- do a work request.
4644632Seric **
4654632Seric **	Parameters:
4664632Seric **		w -- the work request to be satisfied.
4674632Seric **
4684632Seric **	Returns:
4694632Seric **		none.
4704632Seric **
4714632Seric **	Side Effects:
4724632Seric **		The work request is satisfied if possible.
4734632Seric */
4744632Seric 
4754632Seric dowork(w)
4764632Seric 	register WORK *w;
4774632Seric {
4784632Seric 	register int i;
4794632Seric 	auto int xstat;
4804632Seric 
4814632Seric # ifdef DEBUG
4827677Seric 	if (tTd(40, 1))
4835037Seric 		printf("dowork: %s pri %ld\n", w->w_name, w->w_pri);
4844632Seric # endif DEBUG
4854632Seric 
4864632Seric 	/*
4874632Seric 	**  Fork for work.
4884632Seric 	*/
4894632Seric 
4904632Seric 	i = fork();
4914632Seric 	if (i < 0)
4924632Seric 	{
4934632Seric 		syserr("dowork: cannot fork");
4944632Seric 		return;
4954632Seric 	}
4964632Seric 
4974632Seric 	if (i == 0)
4984632Seric 	{
4996980Seric 		char buf[MAXNAME];
5006980Seric 
5014632Seric 		/*
5024632Seric 		**  CHILD
5036980Seric 		**	Change the name of the control file to avoid
5047350Seric 		**		duplicate deliveries.   Then run the file
5057350Seric 		**		as though we had just read it.
5067350Seric 		**	We save an idea of the temporary name so we
5077350Seric 		**		can recover on interrupt.
5084632Seric 		*/
5094632Seric 
5107763Seric 		/* set basic modes, etc. */
5117356Seric 		(void) alarm(0);
5127347Seric 		FatalErrors = FALSE;
5134632Seric 		QueueRun = TRUE;
5146991Seric 		MailBack = TRUE;
5157812Seric 		CurEnv->e_qf = w->w_name;
5167812Seric 		CurEnv->e_id = &w->w_name[strlen(QueueDir) + 3];
5177876Seric # ifdef LOG
5187876Seric 		if (LogLevel > 11)
5197881Seric 			syslog(LOG_DEBUG, "%s: dowork, pid=%d", CurEnv->e_id,
5207881Seric 			       getpid());
5217876Seric # endif LOG
5227763Seric 
5237763Seric 		/* don't use the headers from sendmail.cf... */
5247763Seric 		CurEnv->e_header = NULL;
5257763Seric 		chompheader("from: $q", TRUE);
5267763Seric 
5277763Seric 		/* create the link to the control file during processing */
5287812Seric 		if (link(w->w_name, queuename(CurEnv, 'l')) < 0)
5296980Seric 		{
5307812Seric 			/* being processed by another queuer */
5317881Seric # ifdef LOG
5327881Seric 			if (LogLevel > 4)
5337881Seric 				syslog(LOG_DEBUG, "%s: locked", CurEnv->e_id);
5347881Seric # endif LOG
5356980Seric 			exit(EX_OK);
5366980Seric 		}
5376980Seric 
5386980Seric 		/* create ourselves a transcript file */
5394634Seric 		openxscrpt();
5406980Seric 
5416980Seric 		/* do basic system initialization */
5424632Seric 		initsys();
5436980Seric 
5446980Seric 		/* read the queue control file */
5457812Seric 		readqf(CurEnv->e_qf);
5467781Seric 		eatheader();
5476980Seric 
5486980Seric 		/* do the delivery */
5497558Seric 		if (!FatalErrors)
5507558Seric 			sendall(CurEnv, FALSE);
5516980Seric 
5526980Seric 		/* if still not sent, perhaps we should time out.... */
5534634Seric # ifdef DEBUG
5547677Seric 		if (tTd(40, 3))
555*7886Seric 			printf("curtime=%ld, TimeOut=%ld\n", curtime(),
5567860Seric 					     CurEnv->e_ctime + TimeOut);
5574634Seric # endif DEBUG
558*7886Seric 		if (CurEnv->e_queueup && curtime() > CurEnv->e_ctime + TimeOut)
5594634Seric 			timeout(w);
5606980Seric 
5616980Seric 		/* finish up and exit */
5624632Seric 		finis();
5634632Seric 	}
5644632Seric 
5654632Seric 	/*
5664632Seric 	**  Parent -- pick up results.
5674632Seric 	*/
5684632Seric 
5694632Seric 	errno = 0;
5704632Seric 	while ((i = wait(&xstat)) > 0 && errno != EINTR)
5714632Seric 	{
5724632Seric 		if (errno == EINTR)
5734632Seric 		{
5744632Seric 			errno = 0;
5754632Seric 		}
5764632Seric 	}
5774632Seric }
5784632Seric /*
5794632Seric **  READQF -- read queue file and set up environment.
5804632Seric **
5814632Seric **	Parameters:
5824632Seric **		cf -- name of queue control file.
5834632Seric **
5844632Seric **	Returns:
5854632Seric **		none.
5864632Seric **
5874632Seric **	Side Effects:
5884632Seric **		cf is read and created as the current job, as though
5894632Seric **		we had been invoked by argument.
5904632Seric */
5914632Seric 
5924632Seric readqf(cf)
5934632Seric 	char *cf;
5944632Seric {
5954632Seric 	register FILE *f;
5967785Seric 	char buf[MAXFIELD];
5977753Seric 	register char *p;
5987753Seric 	register int i;
5994632Seric 
6004632Seric 	/*
6014632Seric 	**  Open the file created by queueup.
6024632Seric 	*/
6034632Seric 
6044632Seric 	f = fopen(cf, "r");
6054632Seric 	if (f == NULL)
6064632Seric 	{
6074632Seric 		syserr("readqf: no cf file %s", cf);
6084632Seric 		return;
6094632Seric 	}
6104632Seric 
6114632Seric 	/*
6124632Seric 	**  Read and process the file.
6134632Seric 	*/
6144632Seric 
6157356Seric 	if (Verbose)
6167356Seric 		printf("\nRunning %s\n", cf);
6177785Seric 	while (fgetfolded(buf, sizeof buf, f) != NULL)
6184632Seric 	{
6194632Seric 		switch (buf[0])
6204632Seric 		{
6214632Seric 		  case 'R':		/* specify recipient */
6226908Seric 			sendto(&buf[1], 1, (ADDRESS *) NULL, &CurEnv->e_sendqueue);
6234632Seric 			break;
6244632Seric 
6254632Seric 		  case 'H':		/* header */
6264632Seric 			(void) chompheader(&buf[1], FALSE);
6274632Seric 			break;
6284632Seric 
6294632Seric 		  case 'S':		/* sender */
6304634Seric 			setsender(newstr(&buf[1]));
6314632Seric 			break;
6324632Seric 
6334632Seric 		  case 'D':		/* data file name */
6346991Seric 			CurEnv->e_df = newstr(&buf[1]);
6356991Seric 			TempFile = fopen(CurEnv->e_df, "r");
6364632Seric 			if (TempFile == NULL)
6376991Seric 				syserr("readqf: cannot open %s", CurEnv->e_df);
6384632Seric 			break;
6394632Seric 
6407860Seric 		  case 'T':		/* init time */
6417860Seric 			(void) sscanf(&buf[1], "%ld", &CurEnv->e_ctime);
6424632Seric 			break;
6434632Seric 
6444634Seric 		  case 'P':		/* message priority */
6456908Seric 			(void) sscanf(&buf[1], "%ld", &CurEnv->e_msgpriority);
6465037Seric 
6475037Seric 			/* make sure that big things get sent eventually */
6486908Seric 			CurEnv->e_msgpriority -= WKTIMEFACT;
6494634Seric 			break;
6504634Seric 
6516980Seric 		  case 'C':		/* message class */
6526980Seric 			(void) sscanf(&buf[1], "%hd", &CurEnv->e_class);
6536980Seric 			break;
6546980Seric 
6555902Seric 		  case 'M':		/* define macro */
6565902Seric 			define(buf[1], newstr(&buf[2]));
6575902Seric 			break;
6585902Seric 
6594632Seric 		  default:
6604632Seric 			syserr("readqf(%s): bad line \"%s\"", cf, buf);
6614632Seric 			break;
6624632Seric 		}
6634632Seric 	}
6644632Seric }
6654632Seric /*
6664632Seric **  TIMEOUT -- process timeout on queue file.
6674632Seric **
6684632Seric **	Parameters:
6694632Seric **		w -- pointer to work request that timed out.
6704632Seric **
6714632Seric **	Returns:
6724632Seric **		none.
6734632Seric **
6744632Seric **	Side Effects:
6754632Seric **		Returns a message to the sender saying that this
6764632Seric **		message has timed out.
6774632Seric */
6784632Seric 
6794632Seric timeout(w)
6804632Seric 	register WORK *w;
6814632Seric {
6827369Seric 	char buf[MAXLINE];
6837860Seric 	extern char *pintvl();
6847369Seric 
6854634Seric # ifdef DEBUG
6867677Seric 	if (tTd(40, 3))
6874634Seric 		printf("timeout(%s)\n", w->w_name);
6884634Seric # endif DEBUG
6896991Seric 	message(Arpa_Info, "Message has timed out");
6904634Seric 
6914634Seric 	/* return message to sender */
6927860Seric 	(void) sprintf(buf, "Cannot send mail for %s", pintvl(TimeOut, FALSE));
6937369Seric 	(void) returntosender(buf, &CurEnv->e_from, TRUE);
6944634Seric 
6954634Seric 	/* arrange to remove files from queue */
6967860Seric 	CurEnv->e_dontqueue = TRUE;
6974632Seric }
6985182Seric 
6995182Seric # endif QUEUE
700