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*7763Seric SCCSID(@(#)queue.c	3.31		08/15/82	(no queueing));
95182Seric # else QUEUE
104632Seric 
11*7763Seric SCCSID(@(#)queue.c	3.31		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];
37*7763Seric 	char buf[MAXLINE];
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 */
107*7763Seric 	/* I don't think this is needed any more.....
1085902Seric 	for (i = 0; i < 128; i++)
1095902Seric 	{
1106980Seric 		register char *p = e->e_macro[i];
1115902Seric 
1125902Seric 		if (p != NULL && i != (int) 'b')
1136980Seric 			fprintf(cfp, "M%c%s\n", i, p);
1145902Seric 	}
115*7763Seric 	.....  */
1165902Seric 
1174632Seric 	/* output list of recipient addresses */
1186980Seric 	for (q = e->e_sendqueue; q != NULL; q = q->q_next)
1194632Seric 	{
1205037Seric # ifdef DEBUG
1217677Seric 		if (tTd(40, 1))
1225037Seric 		{
1235037Seric 			printf("queueing ");
1245037Seric 			printaddr(q, FALSE);
1255037Seric 		}
1265037Seric # endif DEBUG
127*7763Seric 		if (queueall ? !bitset(QDONTSEND, q->q_flags) :
128*7763Seric 			       bitset(QQUEUEUP, q->q_flags))
1296980Seric 			fprintf(cfp, "R%s\n", q->q_paddr);
1304632Seric 	}
1314632Seric 
1324632Seric 	/* output headers for this message */
133*7763Seric 	define('g', "$f");
1346980Seric 	for (h = e->e_header; h != NULL; h = h->h_link)
1354632Seric 	{
1364632Seric 		if (h->h_value == NULL || h->h_value[0] == '\0')
1374632Seric 			continue;
1386980Seric 		fprintf(cfp, "H");
1394632Seric 		if (h->h_mflags != 0 && bitset(H_CHECK|H_ACHECK, h->h_flags))
1406980Seric 			mfdecode(h->h_mflags, cfp);
141*7763Seric 		fprintf(cfp, "%s: ", h->h_field);
142*7763Seric 		if (bitset(H_DEFAULT, h->h_flags))
143*7763Seric 		{
144*7763Seric 			(void) expand(h->h_value, buf, &buf[sizeof buf], e);
145*7763Seric 			fprintf(cfp, "%s\n", buf);
146*7763Seric 		}
147*7763Seric 		else
148*7763Seric 			fprintf(cfp, "%s\n", h->h_value);
1494632Seric 	}
1504632Seric 
1514632Seric 	/*
1524632Seric 	**  Clean up.
1534632Seric 	*/
1544632Seric 
1556980Seric 	(void) fclose(cfp);
1566980Seric 	(void) strcpy(buf, QueueDir);
1576980Seric 	(void) strcat(buf, "/cfXXXXXX");
1586980Seric 	(void) mktemp(buf);
1596980Seric 	if (link(cf, buf) < 0)
1606980Seric 		syserr("cannot link(%s, %s), df=%s", cf, buf, e->e_df);
1616980Seric 	else
1627009Seric 		(void) unlink(cf);
1637391Seric 
1647677Seric # ifdef LOG
1657677Seric 	/* save log info */
1667677Seric 	if (LogLevel > 9)
1677677Seric 		syslog(LOG_INFO, "%s queueup: cf=%s, df=%s\n", MsgId, buf, e->e_df);
1687677Seric # endif LOG
1697677Seric 
1707391Seric 	/* disconnect this temp file from the job */
1717391Seric 	e->e_df = NULL;
1724632Seric }
1734632Seric /*
1744632Seric **  RUNQUEUE -- run the jobs in the queue.
1754632Seric **
1764632Seric **	Gets the stuff out of the queue in some presumably logical
1774632Seric **	order and processes them.
1784632Seric **
1794632Seric **	Parameters:
1804632Seric **		none.
1814632Seric **
1824632Seric **	Returns:
1834632Seric **		none.
1844632Seric **
1854632Seric **	Side Effects:
1864632Seric **		runs things in the mail queue.
1874632Seric */
1884632Seric 
1894639Seric bool	ReorderQueue;		/* if set, reorder the send queue */
1904639Seric int	QueuePid;		/* pid of child running queue */
1914634Seric 
1924639Seric runqueue(forkflag)
1934639Seric 	bool forkflag;
1944632Seric {
1954634Seric 	extern reordersig();
1964632Seric 
1977466Seric 	/*
1987466Seric 	**  See if we want to go off and do other useful work.
1997466Seric 	*/
2004639Seric 
2014639Seric 	if (forkflag)
2024639Seric 	{
2034639Seric 		QueuePid = dofork();
2044639Seric 		if (QueuePid > 0)
2054639Seric 		{
2064639Seric 			/* parent */
2077690Seric 			if (QueueIntvl != 0)
2087690Seric 				setevent(QueueIntvl, reordersig, TRUE);
2094639Seric 			return;
2104639Seric 		}
2114639Seric 	}
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;
2824639Seric 	}
2834639Seric 	else
2844639Seric 	{
2857690Seric 		/*
2867690Seric 		**  In parent.  If the child still exists, we want
2877690Seric 		**  to do nothing.  If the child is gone, we will
2887690Seric 		**  start up a new one.
2897690Seric 		**  If the child exists, it is responsible for
2907690Seric 		**  doing a queue reorder.
2917690Seric 		**  This code really sucks.
2927690Seric 		*/
2937690Seric 
2944639Seric 		if (kill(QueuePid, SIGALRM) < 0)
2954639Seric 		{
2964639Seric 			/* no child -- get zombie & start new one */
2974639Seric 			static int st;
2984639Seric 
2994836Seric 			(void) wait(&st);
3007690Seric 			runqueue(TRUE);
3014639Seric 		}
3024639Seric 	}
3034639Seric 
3044639Seric 	/*
3054639Seric 	**  Arrange to get this signal again.
3064639Seric 	*/
3074639Seric 
3087690Seric 	setevent(QueueIntvl, reordersig, parent);
3094634Seric }
3104634Seric /*
3114632Seric **  ORDERQ -- order the work queue.
3124632Seric **
3134632Seric **	Parameters:
3144632Seric **		none.
3154632Seric **
3164632Seric **	Returns:
3174632Seric **		none.
3184632Seric **
3194632Seric **	Side Effects:
3204632Seric **		Sets WorkQ to the queue of available work, in order.
3214632Seric */
3224632Seric 
3234632Seric # define WLSIZE		120	/* max size of worklist per sort */
3244632Seric 
3254632Seric orderq()
3264632Seric {
3276625Sglickman 	register struct direct *d;
3284632Seric 	register WORK *w;
3294632Seric 	register WORK **wp;		/* parent of w */
3306625Sglickman 	DIR *f;
3314632Seric 	register int i;
3324632Seric 	WORK wlist[WLSIZE];
3334632Seric 	int wn = 0;
3344632Seric 	extern workcmpf();
3354632Seric 	extern char *QueueDir;
3364632Seric 
3374632Seric 	/* clear out old WorkQ */
3384632Seric 	for (w = WorkQ; w != NULL; )
3394632Seric 	{
3404632Seric 		register WORK *nw = w->w_next;
3414632Seric 
3424632Seric 		WorkQ = nw;
3434632Seric 		free(w->w_name);
3444632Seric 		free((char *) w);
3454632Seric 		w = nw;
3464632Seric 	}
3474632Seric 
3484632Seric 	/* open the queue directory */
3496625Sglickman 	f = opendir(QueueDir);
3504632Seric 	if (f == NULL)
3514632Seric 	{
3524632Seric 		syserr("orderq: cannot open %s", QueueDir);
3534632Seric 		return;
3544632Seric 	}
3554632Seric 
3564632Seric 	/*
3574632Seric 	**  Read the work directory.
3584632Seric 	*/
3594632Seric 
3606625Sglickman 	while (wn < WLSIZE && (d = readdir(f)) != NULL)
3614632Seric 	{
3624632Seric 		char cbuf[MAXNAME];
3634632Seric 		char lbuf[MAXNAME];
3644632Seric 		FILE *cf;
3654632Seric 		register char *p;
3664632Seric 
3674632Seric 		/* is this an interesting entry? */
3686625Sglickman 		if (d->d_name[0] != 'c')
3694632Seric 			continue;
3704632Seric 
3714632Seric 		/* yes -- find the control file location */
3727009Seric 		(void) strcpy(cbuf, QueueDir);
3737009Seric 		(void) strcat(cbuf, "/");
3744632Seric 		p = &cbuf[strlen(cbuf)];
3757009Seric 		(void) strcpy(p, d->d_name);
3764632Seric 
3774632Seric 		/* open control file */
3784632Seric 		cf = fopen(cbuf, "r");
3794632Seric 		if (cf == NULL)
3804632Seric 		{
3817055Seric 			/* this may be some random person sending hir msgs */
3827055Seric 			/* syserr("orderq: cannot open %s", cbuf); */
3837055Seric 			errno = 0;
3844632Seric 			continue;
3854632Seric 		}
3865037Seric 		wlist[wn].w_name = newstr(cbuf);
3874632Seric 
3884632Seric 		/* extract useful information */
3894632Seric 		while (fgets(lbuf, sizeof lbuf, cf) != NULL)
3904632Seric 		{
3914632Seric 			fixcrlf(lbuf, TRUE);
3924632Seric 
3934632Seric 			switch (lbuf[0])
3944632Seric 			{
3954632Seric 			  case 'P':		/* message priority */
3965037Seric 				(void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri);
3974632Seric 				break;
3984632Seric 			}
3994632Seric 		}
4004632Seric 		wn++;
4014632Seric 		(void) fclose(cf);
4024632Seric 	}
4036625Sglickman 	(void) closedir(f);
4044632Seric 
4054632Seric 	/*
4064632Seric 	**  Sort the work directory.
4074632Seric 	*/
4084632Seric 
4094632Seric 	qsort(wlist, wn, sizeof *wlist, workcmpf);
4104632Seric 
4114632Seric 	/*
4124632Seric 	**  Convert the work list into canonical form.
4134632Seric 	*/
4144632Seric 
4154632Seric 	wp = &WorkQ;
4164632Seric 	for (i = 0; i < wn; i++)
4174632Seric 	{
4184632Seric 		w = (WORK *) xalloc(sizeof *w);
4194632Seric 		w->w_name = wlist[i].w_name;
4204632Seric 		w->w_pri = wlist[i].w_pri;
4214632Seric 		w->w_next = NULL;
4224632Seric 		*wp = w;
4234632Seric 		wp = &w->w_next;
4244632Seric 	}
4254632Seric 
4264632Seric # ifdef DEBUG
4277677Seric 	if (tTd(40, 1))
4284632Seric 	{
4294632Seric 		for (w = WorkQ; w != NULL; w = w->w_next)
4305037Seric 			printf("%32s: pri=%ld\n", w->w_name, w->w_pri);
4314632Seric 	}
4324632Seric # endif DEBUG
4334632Seric }
4344632Seric /*
4357677Seric **  WORKCMPF -- compare function for ordering work.
4364632Seric **
4374632Seric **	Parameters:
4384632Seric **		a -- the first argument.
4394632Seric **		b -- the second argument.
4404632Seric **
4414632Seric **	Returns:
4424632Seric **		-1 if a < b
4434632Seric **		0 if a == b
4444632Seric **		1 if a > b
4454632Seric **
4464632Seric **	Side Effects:
4474632Seric **		none.
4484632Seric */
4494632Seric 
4504632Seric # define PRIFACT	1800		/* bytes each priority point is worth */
4514632Seric 
4524632Seric workcmpf(a, b)
4535037Seric 	register WORK *a;
4545037Seric 	register WORK *b;
4554632Seric {
4565037Seric 	if (a->w_pri == b->w_pri)
4574632Seric 		return (0);
4585037Seric 	else if (a->w_pri > b->w_pri)
4594632Seric 		return (1);
4604632Seric 	else
4614632Seric 		return (-1);
4624632Seric }
4634632Seric /*
4644632Seric **  DOWORK -- do a work request.
4654632Seric **
4664632Seric **	Parameters:
4674632Seric **		w -- the work request to be satisfied.
4684632Seric **
4694632Seric **	Returns:
4704632Seric **		none.
4714632Seric **
4724632Seric **	Side Effects:
4734632Seric **		The work request is satisfied if possible.
4744632Seric */
4754632Seric 
4764632Seric dowork(w)
4774632Seric 	register WORK *w;
4784632Seric {
4794632Seric 	register int i;
4804632Seric 	auto int xstat;
4814632Seric 
4824632Seric # ifdef DEBUG
4837677Seric 	if (tTd(40, 1))
4845037Seric 		printf("dowork: %s pri %ld\n", w->w_name, w->w_pri);
4854632Seric # endif DEBUG
4864632Seric 
4874632Seric 	/*
4884632Seric 	**  Fork for work.
4894632Seric 	*/
4904632Seric 
4914632Seric 	i = fork();
4924632Seric 	if (i < 0)
4934632Seric 	{
4944632Seric 		syserr("dowork: cannot fork");
4954632Seric 		return;
4964632Seric 	}
4974632Seric 
4984632Seric 	if (i == 0)
4994632Seric 	{
5006980Seric 		char buf[MAXNAME];
5016980Seric 
5024632Seric 		/*
5034632Seric 		**  CHILD
5046980Seric 		**	Change the name of the control file to avoid
5057350Seric 		**		duplicate deliveries.   Then run the file
5067350Seric 		**		as though we had just read it.
5077350Seric 		**	We save an idea of the temporary name so we
5087350Seric 		**		can recover on interrupt.
5094632Seric 		*/
5104632Seric 
511*7763Seric 		/* set basic modes, etc. */
5127356Seric 		(void) alarm(0);
5137347Seric 		FatalErrors = FALSE;
5144632Seric 		QueueRun = TRUE;
5156991Seric 		MailBack = TRUE;
516*7763Seric 
517*7763Seric 		/* don't use the headers from sendmail.cf... */
518*7763Seric 		CurEnv->e_header = NULL;
519*7763Seric 		chompheader("from: $q", TRUE);
520*7763Seric 
521*7763Seric 		/* create the link to the control file during processing */
5226980Seric 		(void) strcpy(buf, QueueDir);
5236980Seric 		(void) strcat(buf, "/tfXXXXXX");
5246980Seric 		(void) mktemp(buf);
5256980Seric 		if (link(w->w_name, buf) < 0)
5266980Seric 		{
5277683Seric 			/* this can happen normally; another queuer sneaks in */
5287683Seric 			/* syserr("dowork: link(%s, %s)", w->w_name, buf); */
5296980Seric 			exit(EX_OK);
5306980Seric 		}
5317350Seric 		ControlFile = newstr(buf);
5326980Seric 		(void) unlink(w->w_name);
5336980Seric 
5346980Seric 		/* create ourselves a transcript file */
5354634Seric 		openxscrpt();
5366980Seric 
5376980Seric 		/* do basic system initialization */
5384632Seric 		initsys();
5396980Seric 
5406980Seric 		/* read the queue control file */
5416980Seric 		readqf(buf);
5426980Seric 
5436980Seric 		/* do the delivery */
5447558Seric 		if (!FatalErrors)
5457558Seric 			sendall(CurEnv, FALSE);
5466980Seric 
5476980Seric 		/* if still not sent, perhaps we should time out.... */
5484634Seric # ifdef DEBUG
5497677Seric 		if (tTd(40, 3))
5504634Seric 			printf("CurTime=%ld, TimeOut=%ld\n", CurTime, TimeOut);
5514634Seric # endif DEBUG
5526908Seric 		if (CurEnv->e_queueup && CurTime > TimeOut)
5534634Seric 			timeout(w);
5546980Seric 
5556980Seric 		/* get rid of the temporary file -- a new cf will be made */
5567350Seric 		ControlFile = NULL;
5576980Seric 		(void) unlink(buf);
5586980Seric 
5596980Seric 		/* finish up and exit */
5604632Seric 		finis();
5614632Seric 	}
5624632Seric 
5634632Seric 	/*
5644632Seric 	**  Parent -- pick up results.
5654632Seric 	*/
5664632Seric 
5674632Seric 	errno = 0;
5684632Seric 	while ((i = wait(&xstat)) > 0 && errno != EINTR)
5694632Seric 	{
5704632Seric 		if (errno == EINTR)
5714632Seric 		{
5724632Seric 			errno = 0;
5734632Seric 		}
5744632Seric 	}
5754632Seric }
5764632Seric /*
5774632Seric **  READQF -- read queue file and set up environment.
5784632Seric **
5794632Seric **	Parameters:
5804632Seric **		cf -- name of queue control file.
5814632Seric **
5824632Seric **	Returns:
5834632Seric **		none.
5844632Seric **
5854632Seric **	Side Effects:
5864632Seric **		cf is read and created as the current job, as though
5874632Seric **		we had been invoked by argument.
5884632Seric */
5894632Seric 
5904632Seric readqf(cf)
5914632Seric 	char *cf;
5924632Seric {
5934632Seric 	register FILE *f;
5944632Seric 	char buf[MAXLINE];
5957753Seric 	register char *p;
5967753Seric 	register int i;
5974632Seric 
5984632Seric 	/*
5994632Seric 	**  Open the file created by queueup.
6004632Seric 	*/
6014632Seric 
6024632Seric 	f = fopen(cf, "r");
6034632Seric 	if (f == NULL)
6044632Seric 	{
6054632Seric 		syserr("readqf: no cf file %s", cf);
6064632Seric 		return;
6074632Seric 	}
6084632Seric 
6094632Seric 	/*
6104632Seric 	**  Read and process the file.
6114632Seric 	*/
6124632Seric 
6137356Seric 	if (Verbose)
6147356Seric 		printf("\nRunning %s\n", cf);
6157753Seric 	p = buf;
6167753Seric 	while (fgets(p, sizeof buf - (p - buf), f) != NULL)
6174632Seric 	{
6187753Seric 		/*
6197753Seric 		**  Collect any continuation lines...
6207753Seric 		*/
6214632Seric 
6227753Seric 		i = fgetc(f);
6237753Seric 		if (i != EOF)
6247753Seric 			ungetc(i, f);
6257753Seric 		if (i == ' ' || i == '\t')
6267753Seric 		{
6277753Seric 			p += strlen(p);
6287753Seric 			continue;
6297753Seric 		}
6307753Seric 		fixcrlf(p, TRUE);
6317753Seric 
6324632Seric 		switch (buf[0])
6334632Seric 		{
6344632Seric 		  case 'R':		/* specify recipient */
6356908Seric 			sendto(&buf[1], 1, (ADDRESS *) NULL, &CurEnv->e_sendqueue);
6364632Seric 			break;
6374632Seric 
6384632Seric 		  case 'H':		/* header */
6394632Seric 			(void) chompheader(&buf[1], FALSE);
6404632Seric 			break;
6414632Seric 
6424632Seric 		  case 'S':		/* sender */
6434634Seric 			setsender(newstr(&buf[1]));
6444632Seric 			break;
6454632Seric 
6464632Seric 		  case 'D':		/* data file name */
6476991Seric 			CurEnv->e_df = newstr(&buf[1]);
6486991Seric 			TempFile = fopen(CurEnv->e_df, "r");
6494632Seric 			if (TempFile == NULL)
6506991Seric 				syserr("readqf: cannot open %s", CurEnv->e_df);
6514632Seric 			break;
6524632Seric 
6534632Seric 		  case 'T':		/* timeout */
6544632Seric 			(void) sscanf(&buf[1], "%ld", &TimeOut);
6554632Seric 			break;
6564632Seric 
6574634Seric 		  case 'P':		/* message priority */
6586908Seric 			(void) sscanf(&buf[1], "%ld", &CurEnv->e_msgpriority);
6595037Seric 
6605037Seric 			/* make sure that big things get sent eventually */
6616908Seric 			CurEnv->e_msgpriority -= WKTIMEFACT;
6624634Seric 			break;
6634634Seric 
6646980Seric 		  case 'C':		/* message class */
6656980Seric 			(void) sscanf(&buf[1], "%hd", &CurEnv->e_class);
6666980Seric 			break;
6676980Seric 
6685902Seric 		  case 'M':		/* define macro */
6695902Seric 			define(buf[1], newstr(&buf[2]));
6705902Seric 			break;
6715902Seric 
6724632Seric 		  default:
6734632Seric 			syserr("readqf(%s): bad line \"%s\"", cf, buf);
6744632Seric 			break;
6754632Seric 		}
6764632Seric 	}
6774632Seric }
6784632Seric /*
6794632Seric **  TIMEOUT -- process timeout on queue file.
6804632Seric **
6814632Seric **	Parameters:
6824632Seric **		w -- pointer to work request that timed out.
6834632Seric **
6844632Seric **	Returns:
6854632Seric **		none.
6864632Seric **
6874632Seric **	Side Effects:
6884632Seric **		Returns a message to the sender saying that this
6894632Seric **		message has timed out.
6904632Seric */
6914632Seric 
6924632Seric timeout(w)
6934632Seric 	register WORK *w;
6944632Seric {
6957369Seric 	char buf[MAXLINE];
6967369Seric 	extern char *TextTimeOut;
6977369Seric 
6984634Seric # ifdef DEBUG
6997677Seric 	if (tTd(40, 3))
7004634Seric 		printf("timeout(%s)\n", w->w_name);
7014634Seric # endif DEBUG
7026991Seric 	message(Arpa_Info, "Message has timed out");
7034634Seric 
7044634Seric 	/* return message to sender */
7057369Seric 	(void) sprintf(buf, "Cannot send mail for %s", TextTimeOut);
7067369Seric 	(void) returntosender(buf, &CurEnv->e_from, TRUE);
7074634Seric 
7084634Seric 	/* arrange to remove files from queue */
7096908Seric 	CurEnv->e_queueup = FALSE;
7104632Seric }
7115182Seric 
7125182Seric # endif QUEUE
713