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*7677Seric SCCSID(@(#)queue.c	3.27		08/08/82	(no queueing));
95182Seric # else QUEUE
104632Seric 
11*7677Seric SCCSID(@(#)queue.c	3.27		08/08/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
60*7677Seric 	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
119*7677Seric 		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 
153*7677Seric # ifdef LOG
154*7677Seric 	/* save log info */
155*7677Seric 	if (LogLevel > 9)
156*7677Seric 		syslog(LOG_INFO, "%s queueup: cf=%s, df=%s\n", MsgId, buf, e->e_df);
157*7677Seric # endif LOG
158*7677Seric 
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 */
1964639Seric 			return;
1974639Seric 		}
1984639Seric 		else
1997009Seric 			(void) alarm(0);
2004639Seric 	}
2014639Seric 
2027466Seric 	/*
2037466Seric 	**  Arrange to reorder the queue at polite intervals.
2047466Seric 	*/
2057466Seric 
2067466Seric 	if (QueueIntvl != 0)
2077466Seric 	{
2087466Seric 		(void) signal(SIGALRM, reordersig);
2097466Seric 		(void) alarm(QueueIntvl);
2107466Seric 	}
2117466Seric 
2127466Seric 	/*
2137466Seric 	**  Start making passes through the queue.
2147466Seric 	**	First, read and sort the entire queue.
2157466Seric 	**	Then, process the work in that order.
2167466Seric 	**		But if you take too long, start over.
2177466Seric 	**	There is a race condition at the end -- we could get
2187466Seric 	**		a reorder signal after finishing the queue.
2197466Seric 	**		In this case we will hang for one more queue
2207466Seric 	**		interval -- clearly a botch, but rare and
2217466Seric 	**		relatively innocuous.
2227466Seric 	*/
2237466Seric 
2244634Seric 	for (;;)
2254634Seric 	{
2267466Seric 		/* order the existing work requests */
2274634Seric 		orderq();
2284634Seric 		ReorderQueue = FALSE;
2294634Seric 
2307466Seric 		/* process them once at a time */
2314634Seric 		while (WorkQ != NULL)
2324634Seric 		{
2334634Seric 			WORK *w = WorkQ;
2344634Seric 
2354634Seric 			WorkQ = WorkQ->w_next;
2364634Seric 			dowork(w);
2374634Seric 			free(w->w_name);
2384634Seric 			free((char *) w);
2394634Seric 			if (ReorderQueue)
2404634Seric 				break;
2414634Seric 		}
2424634Seric 
2437466Seric 		/* if we are just doing one pass, then we are done */
2444634Seric 		if (QueueIntvl == 0)
2454634Seric 			break;
2467466Seric 
2477466Seric 		/* wait for work -- note (harmless) race condition here */
2487466Seric 		if (!ReorderQueue)
2497466Seric 			pause();
2504632Seric 	}
2515978Seric 
2525978Seric 	/* no work to do -- just exit */
2535978Seric 	finis();
2544632Seric }
2554632Seric /*
2564634Seric **  REORDERSIG -- catch the alarm signal and tell sendmail to reorder queue.
2574634Seric **
2584634Seric **	Parameters:
2594634Seric **		none.
2604634Seric **
2614634Seric **	Returns:
2624634Seric **		none.
2634634Seric **
2644634Seric **	Side Effects:
2654634Seric **		sets the "reorder work queue" flag.
2664634Seric */
2674634Seric 
2684634Seric reordersig()
2694634Seric {
2704639Seric 	if (QueuePid == 0)
2714639Seric 	{
2724639Seric 		/* we are in a child doing queueing */
2734639Seric 		ReorderQueue = TRUE;
2744639Seric 	}
2754639Seric 	else
2764639Seric 	{
2774639Seric 		/* we are in a parent -- poke child or start new one */
2784639Seric 		if (kill(QueuePid, SIGALRM) < 0)
2794639Seric 		{
2804639Seric 			/* no child -- get zombie & start new one */
2814639Seric 			static int st;
2824639Seric 
2834836Seric 			(void) wait(&st);
2844639Seric 			QueuePid = dofork();
2854639Seric 			if (QueuePid == 0)
2864639Seric 			{
2874639Seric 				/* new child; run queue */
2884836Seric 				runqueue(FALSE);
2894639Seric 				finis();
2904639Seric 			}
2914639Seric 		}
2924639Seric 	}
2934639Seric 
2944639Seric 	/*
2954639Seric 	**  Arrange to get this signal again.
2964639Seric 	*/
2974639Seric 
2986065Seric 	(void) signal(SIGALRM, reordersig);
2997009Seric 	(void) alarm(QueueIntvl);
3004634Seric }
3014634Seric /*
3024632Seric **  ORDERQ -- order the work queue.
3034632Seric **
3044632Seric **	Parameters:
3054632Seric **		none.
3064632Seric **
3074632Seric **	Returns:
3084632Seric **		none.
3094632Seric **
3104632Seric **	Side Effects:
3114632Seric **		Sets WorkQ to the queue of available work, in order.
3124632Seric */
3134632Seric 
3144632Seric # define WLSIZE		120	/* max size of worklist per sort */
3154632Seric 
3164632Seric orderq()
3174632Seric {
3186625Sglickman 	register struct direct *d;
3194632Seric 	register WORK *w;
3204632Seric 	register WORK **wp;		/* parent of w */
3216625Sglickman 	DIR *f;
3224632Seric 	register int i;
3234632Seric 	WORK wlist[WLSIZE];
3244632Seric 	int wn = 0;
3254632Seric 	extern workcmpf();
3264632Seric 	extern char *QueueDir;
3274632Seric 
3284632Seric 	/* clear out old WorkQ */
3294632Seric 	for (w = WorkQ; w != NULL; )
3304632Seric 	{
3314632Seric 		register WORK *nw = w->w_next;
3324632Seric 
3334632Seric 		WorkQ = nw;
3344632Seric 		free(w->w_name);
3354632Seric 		free((char *) w);
3364632Seric 		w = nw;
3374632Seric 	}
3384632Seric 
3394632Seric 	/* open the queue directory */
3406625Sglickman 	f = opendir(QueueDir);
3414632Seric 	if (f == NULL)
3424632Seric 	{
3434632Seric 		syserr("orderq: cannot open %s", QueueDir);
3444632Seric 		return;
3454632Seric 	}
3464632Seric 
3474632Seric 	/*
3484632Seric 	**  Read the work directory.
3494632Seric 	*/
3504632Seric 
3516625Sglickman 	while (wn < WLSIZE && (d = readdir(f)) != NULL)
3524632Seric 	{
3534632Seric 		char cbuf[MAXNAME];
3544632Seric 		char lbuf[MAXNAME];
3554632Seric 		FILE *cf;
3564632Seric 		register char *p;
3574632Seric 
3584632Seric 		/* is this an interesting entry? */
3596625Sglickman 		if (d->d_name[0] != 'c')
3604632Seric 			continue;
3614632Seric 
3624632Seric 		/* yes -- find the control file location */
3637009Seric 		(void) strcpy(cbuf, QueueDir);
3647009Seric 		(void) strcat(cbuf, "/");
3654632Seric 		p = &cbuf[strlen(cbuf)];
3667009Seric 		(void) strcpy(p, d->d_name);
3674632Seric 
3684632Seric 		/* open control file */
3694632Seric 		cf = fopen(cbuf, "r");
3704632Seric 		if (cf == NULL)
3714632Seric 		{
3727055Seric 			/* this may be some random person sending hir msgs */
3737055Seric 			/* syserr("orderq: cannot open %s", cbuf); */
3747055Seric 			errno = 0;
3754632Seric 			continue;
3764632Seric 		}
3775037Seric 		wlist[wn].w_name = newstr(cbuf);
3784632Seric 
3794632Seric 		/* extract useful information */
3804632Seric 		while (fgets(lbuf, sizeof lbuf, cf) != NULL)
3814632Seric 		{
3824632Seric 			fixcrlf(lbuf, TRUE);
3834632Seric 
3844632Seric 			switch (lbuf[0])
3854632Seric 			{
3864632Seric 			  case 'P':		/* message priority */
3875037Seric 				(void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri);
3884632Seric 				break;
3894632Seric 			}
3904632Seric 		}
3914632Seric 		wn++;
3924632Seric 		(void) fclose(cf);
3934632Seric 	}
3946625Sglickman 	(void) closedir(f);
3954632Seric 
3964632Seric 	/*
3974632Seric 	**  Sort the work directory.
3984632Seric 	*/
3994632Seric 
4004632Seric 	qsort(wlist, wn, sizeof *wlist, workcmpf);
4014632Seric 
4024632Seric 	/*
4034632Seric 	**  Convert the work list into canonical form.
4044632Seric 	*/
4054632Seric 
4064632Seric 	wp = &WorkQ;
4074632Seric 	for (i = 0; i < wn; i++)
4084632Seric 	{
4094632Seric 		w = (WORK *) xalloc(sizeof *w);
4104632Seric 		w->w_name = wlist[i].w_name;
4114632Seric 		w->w_pri = wlist[i].w_pri;
4124632Seric 		w->w_next = NULL;
4134632Seric 		*wp = w;
4144632Seric 		wp = &w->w_next;
4154632Seric 	}
4164632Seric 
4174632Seric # ifdef DEBUG
418*7677Seric 	if (tTd(40, 1))
4194632Seric 	{
4204632Seric 		for (w = WorkQ; w != NULL; w = w->w_next)
4215037Seric 			printf("%32s: pri=%ld\n", w->w_name, w->w_pri);
4224632Seric 	}
4234632Seric # endif DEBUG
4244632Seric }
4254632Seric /*
426*7677Seric **  WORKCMPF -- compare function for ordering work.
4274632Seric **
4284632Seric **	Parameters:
4294632Seric **		a -- the first argument.
4304632Seric **		b -- the second argument.
4314632Seric **
4324632Seric **	Returns:
4334632Seric **		-1 if a < b
4344632Seric **		0 if a == b
4354632Seric **		1 if a > b
4364632Seric **
4374632Seric **	Side Effects:
4384632Seric **		none.
4394632Seric */
4404632Seric 
4414632Seric # define PRIFACT	1800		/* bytes each priority point is worth */
4424632Seric 
4434632Seric workcmpf(a, b)
4445037Seric 	register WORK *a;
4455037Seric 	register WORK *b;
4464632Seric {
4475037Seric 	if (a->w_pri == b->w_pri)
4484632Seric 		return (0);
4495037Seric 	else if (a->w_pri > b->w_pri)
4504632Seric 		return (1);
4514632Seric 	else
4524632Seric 		return (-1);
4534632Seric }
4544632Seric /*
4554632Seric **  DOWORK -- do a work request.
4564632Seric **
4574632Seric **	Parameters:
4584632Seric **		w -- the work request to be satisfied.
4594632Seric **
4604632Seric **	Returns:
4614632Seric **		none.
4624632Seric **
4634632Seric **	Side Effects:
4644632Seric **		The work request is satisfied if possible.
4654632Seric */
4664632Seric 
4674632Seric dowork(w)
4684632Seric 	register WORK *w;
4694632Seric {
4704632Seric 	register int i;
4714632Seric 	auto int xstat;
4724632Seric 
4734632Seric # ifdef DEBUG
474*7677Seric 	if (tTd(40, 1))
4755037Seric 		printf("dowork: %s pri %ld\n", w->w_name, w->w_pri);
4764632Seric # endif DEBUG
4774632Seric 
4784632Seric 	/*
4794632Seric 	**  Fork for work.
4804632Seric 	*/
4814632Seric 
4824632Seric 	i = fork();
4834632Seric 	if (i < 0)
4844632Seric 	{
4854632Seric 		syserr("dowork: cannot fork");
4864632Seric 		return;
4874632Seric 	}
4884632Seric 
4894632Seric 	if (i == 0)
4904632Seric 	{
4916980Seric 		char buf[MAXNAME];
4926980Seric 
4934632Seric 		/*
4944632Seric 		**  CHILD
4956980Seric 		**	Change the name of the control file to avoid
4967350Seric 		**		duplicate deliveries.   Then run the file
4977350Seric 		**		as though we had just read it.
4987350Seric 		**	We save an idea of the temporary name so we
4997350Seric 		**		can recover on interrupt.
5004632Seric 		*/
5014632Seric 
5027356Seric 		(void) alarm(0);
5037347Seric 		FatalErrors = FALSE;
5044632Seric 		QueueRun = TRUE;
5056991Seric 		MailBack = TRUE;
5066980Seric 		(void) strcpy(buf, QueueDir);
5076980Seric 		(void) strcat(buf, "/tfXXXXXX");
5086980Seric 		(void) mktemp(buf);
5096980Seric 		if (link(w->w_name, buf) < 0)
5106980Seric 		{
5116980Seric 			syserr("dowork: link(%s, %s)", w->w_name, buf);
5126980Seric 
5136980Seric 			/* it's ok to lie -- it will be run later */
5146980Seric 			exit(EX_OK);
5156980Seric 		}
5167350Seric 		ControlFile = newstr(buf);
5176980Seric 		(void) unlink(w->w_name);
5186980Seric 
5196980Seric 		/* create ourselves a transcript file */
5204634Seric 		openxscrpt();
5216980Seric 
5226980Seric 		/* do basic system initialization */
5234632Seric 		initsys();
5246980Seric 
5256980Seric 		/* read the queue control file */
5266980Seric 		readqf(buf);
5276980Seric 
5286980Seric 		/* do the delivery */
5297558Seric 		if (!FatalErrors)
5307558Seric 			sendall(CurEnv, FALSE);
5316980Seric 
5326980Seric 		/* if still not sent, perhaps we should time out.... */
5334634Seric # ifdef DEBUG
534*7677Seric 		if (tTd(40, 3))
5354634Seric 			printf("CurTime=%ld, TimeOut=%ld\n", CurTime, TimeOut);
5364634Seric # endif DEBUG
5376908Seric 		if (CurEnv->e_queueup && CurTime > TimeOut)
5384634Seric 			timeout(w);
5396980Seric 
5406980Seric 		/* get rid of the temporary file -- a new cf will be made */
5417350Seric 		ControlFile = NULL;
5426980Seric 		(void) unlink(buf);
5436980Seric 
5446980Seric 		/* finish up and exit */
5454632Seric 		finis();
5464632Seric 	}
5474632Seric 
5484632Seric 	/*
5494632Seric 	**  Parent -- pick up results.
5504632Seric 	*/
5514632Seric 
5524632Seric 	errno = 0;
5534632Seric 	while ((i = wait(&xstat)) > 0 && errno != EINTR)
5544632Seric 	{
5554632Seric 		if (errno == EINTR)
5564632Seric 		{
5574632Seric 			errno = 0;
5584632Seric 		}
5594632Seric 	}
5604632Seric }
5614632Seric /*
5624632Seric **  READQF -- read queue file and set up environment.
5634632Seric **
5644632Seric **	Parameters:
5654632Seric **		cf -- name of queue control file.
5664632Seric **
5674632Seric **	Returns:
5684632Seric **		none.
5694632Seric **
5704632Seric **	Side Effects:
5714632Seric **		cf is read and created as the current job, as though
5724632Seric **		we had been invoked by argument.
5734632Seric */
5744632Seric 
5754632Seric readqf(cf)
5764632Seric 	char *cf;
5774632Seric {
5784632Seric 	register FILE *f;
5794632Seric 	char buf[MAXLINE];
5804632Seric 
5814632Seric 	/*
5824632Seric 	**  Open the file created by queueup.
5834632Seric 	*/
5844632Seric 
5854632Seric 	f = fopen(cf, "r");
5864632Seric 	if (f == NULL)
5874632Seric 	{
5884632Seric 		syserr("readqf: no cf file %s", cf);
5894632Seric 		return;
5904632Seric 	}
5914632Seric 
5924632Seric 	/*
5934632Seric 	**  Read and process the file.
5944632Seric 	*/
5954632Seric 
5967356Seric 	if (Verbose)
5977356Seric 		printf("\nRunning %s\n", cf);
5984632Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5994632Seric 	{
6004632Seric 		fixcrlf(buf, TRUE);
6014632Seric 
6024632Seric 		switch (buf[0])
6034632Seric 		{
6044632Seric 		  case 'R':		/* specify recipient */
6056908Seric 			sendto(&buf[1], 1, (ADDRESS *) NULL, &CurEnv->e_sendqueue);
6064632Seric 			break;
6074632Seric 
6084632Seric 		  case 'H':		/* header */
6094632Seric 			(void) chompheader(&buf[1], FALSE);
6104632Seric 			break;
6114632Seric 
6124632Seric 		  case 'S':		/* sender */
6134634Seric 			setsender(newstr(&buf[1]));
6144632Seric 			break;
6154632Seric 
6164632Seric 		  case 'D':		/* data file name */
6176991Seric 			CurEnv->e_df = newstr(&buf[1]);
6186991Seric 			TempFile = fopen(CurEnv->e_df, "r");
6194632Seric 			if (TempFile == NULL)
6206991Seric 				syserr("readqf: cannot open %s", CurEnv->e_df);
6214632Seric 			break;
6224632Seric 
6234632Seric 		  case 'T':		/* timeout */
6244632Seric 			(void) sscanf(&buf[1], "%ld", &TimeOut);
6254632Seric 			break;
6264632Seric 
6274634Seric 		  case 'P':		/* message priority */
6286908Seric 			(void) sscanf(&buf[1], "%ld", &CurEnv->e_msgpriority);
6295037Seric 
6305037Seric 			/* make sure that big things get sent eventually */
6316908Seric 			CurEnv->e_msgpriority -= WKTIMEFACT;
6324634Seric 			break;
6334634Seric 
6346980Seric 		  case 'C':		/* message class */
6356980Seric 			(void) sscanf(&buf[1], "%hd", &CurEnv->e_class);
6366980Seric 			break;
6376980Seric 
6385902Seric 		  case 'M':		/* define macro */
6395902Seric 			define(buf[1], newstr(&buf[2]));
6405902Seric 			break;
6415902Seric 
6424632Seric 		  default:
6434632Seric 			syserr("readqf(%s): bad line \"%s\"", cf, buf);
6444632Seric 			break;
6454632Seric 		}
6464632Seric 	}
6474632Seric }
6484632Seric /*
6494632Seric **  TIMEOUT -- process timeout on queue file.
6504632Seric **
6514632Seric **	Parameters:
6524632Seric **		w -- pointer to work request that timed out.
6534632Seric **
6544632Seric **	Returns:
6554632Seric **		none.
6564632Seric **
6574632Seric **	Side Effects:
6584632Seric **		Returns a message to the sender saying that this
6594632Seric **		message has timed out.
6604632Seric */
6614632Seric 
6624632Seric timeout(w)
6634632Seric 	register WORK *w;
6644632Seric {
6657369Seric 	char buf[MAXLINE];
6667369Seric 	extern char *TextTimeOut;
6677369Seric 
6684634Seric # ifdef DEBUG
669*7677Seric 	if (tTd(40, 3))
6704634Seric 		printf("timeout(%s)\n", w->w_name);
6714634Seric # endif DEBUG
6726991Seric 	message(Arpa_Info, "Message has timed out");
6734634Seric 
6744634Seric 	/* return message to sender */
6757369Seric 	(void) sprintf(buf, "Cannot send mail for %s", TextTimeOut);
6767369Seric 	(void) returntosender(buf, &CurEnv->e_from, TRUE);
6774634Seric 
6784634Seric 	/* arrange to remove files from queue */
6796908Seric 	CurEnv->e_queueup = FALSE;
6804632Seric }
6815182Seric 
6825182Seric # endif QUEUE
683