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*7466Seric SCCSID(@(#)queue.c	3.25		07/20/82	(no queueing));
95182Seric # else QUEUE
104632Seric 
11*7466Seric SCCSID(@(#)queue.c	3.25		07/20/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);
1527391Seric 
1537391Seric 	/* disconnect this temp file from the job */
1547391Seric 	e->e_df = NULL;
1554632Seric }
1564632Seric /*
1574632Seric **  RUNQUEUE -- run the jobs in the queue.
1584632Seric **
1594632Seric **	Gets the stuff out of the queue in some presumably logical
1604632Seric **	order and processes them.
1614632Seric **
1624632Seric **	Parameters:
1634632Seric **		none.
1644632Seric **
1654632Seric **	Returns:
1664632Seric **		none.
1674632Seric **
1684632Seric **	Side Effects:
1694632Seric **		runs things in the mail queue.
1704632Seric */
1714632Seric 
1724639Seric bool	ReorderQueue;		/* if set, reorder the send queue */
1734639Seric int	QueuePid;		/* pid of child running queue */
1744634Seric 
1754639Seric runqueue(forkflag)
1764639Seric 	bool forkflag;
1774632Seric {
1784634Seric 	extern reordersig();
1794632Seric 
180*7466Seric 	/*
181*7466Seric 	**  See if we want to go off and do other useful work.
182*7466Seric 	*/
1834639Seric 
1844639Seric 	if (forkflag)
1854639Seric 	{
1864639Seric 		QueuePid = dofork();
1874639Seric 		if (QueuePid > 0)
1884639Seric 		{
1894639Seric 			/* parent */
1904639Seric 			return;
1914639Seric 		}
1924639Seric 		else
1937009Seric 			(void) alarm(0);
1944639Seric 	}
1954639Seric 
196*7466Seric 	/*
197*7466Seric 	**  Arrange to reorder the queue at polite intervals.
198*7466Seric 	*/
199*7466Seric 
200*7466Seric 	if (QueueIntvl != 0)
201*7466Seric 	{
202*7466Seric 		(void) signal(SIGALRM, reordersig);
203*7466Seric 		(void) alarm(QueueIntvl);
204*7466Seric 	}
205*7466Seric 
206*7466Seric 	/*
207*7466Seric 	**  Start making passes through the queue.
208*7466Seric 	**	First, read and sort the entire queue.
209*7466Seric 	**	Then, process the work in that order.
210*7466Seric 	**		But if you take too long, start over.
211*7466Seric 	**	There is a race condition at the end -- we could get
212*7466Seric 	**		a reorder signal after finishing the queue.
213*7466Seric 	**		In this case we will hang for one more queue
214*7466Seric 	**		interval -- clearly a botch, but rare and
215*7466Seric 	**		relatively innocuous.
216*7466Seric 	*/
217*7466Seric 
2184634Seric 	for (;;)
2194634Seric 	{
220*7466Seric 		/* order the existing work requests */
2214634Seric 		orderq();
2224634Seric 		ReorderQueue = FALSE;
2234634Seric 
224*7466Seric 		/* 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 
237*7466Seric 		/* if we are just doing one pass, then we are done */
2384634Seric 		if (QueueIntvl == 0)
2394634Seric 			break;
240*7466Seric 
241*7466Seric 		/* wait for work -- note (harmless) race condition here */
242*7466Seric 		if (!ReorderQueue)
243*7466Seric 			pause();
2444632Seric 	}
2455978Seric 
2465978Seric 	/* no work to do -- just exit */
2475978Seric 	finis();
2484632Seric }
2494632Seric /*
2504634Seric **  REORDERSIG -- catch the alarm signal and tell sendmail to reorder queue.
2514634Seric **
2524634Seric **	Parameters:
2534634Seric **		none.
2544634Seric **
2554634Seric **	Returns:
2564634Seric **		none.
2574634Seric **
2584634Seric **	Side Effects:
2594634Seric **		sets the "reorder work queue" flag.
2604634Seric */
2614634Seric 
2624634Seric reordersig()
2634634Seric {
2644639Seric 	if (QueuePid == 0)
2654639Seric 	{
2664639Seric 		/* we are in a child doing queueing */
2674639Seric 		ReorderQueue = TRUE;
2684639Seric 	}
2694639Seric 	else
2704639Seric 	{
2714639Seric 		/* we are in a parent -- poke child or start new one */
2724639Seric 		if (kill(QueuePid, SIGALRM) < 0)
2734639Seric 		{
2744639Seric 			/* no child -- get zombie & start new one */
2754639Seric 			static int st;
2764639Seric 
2774836Seric 			(void) wait(&st);
2784639Seric 			QueuePid = dofork();
2794639Seric 			if (QueuePid == 0)
2804639Seric 			{
2814639Seric 				/* new child; run queue */
2824836Seric 				runqueue(FALSE);
2834639Seric 				finis();
2844639Seric 			}
2854639Seric 		}
2864639Seric 	}
2874639Seric 
2884639Seric 	/*
2894639Seric 	**  Arrange to get this signal again.
2904639Seric 	*/
2914639Seric 
2926065Seric 	(void) signal(SIGALRM, reordersig);
2937009Seric 	(void) alarm(QueueIntvl);
2944634Seric }
2954634Seric /*
2964632Seric **  ORDERQ -- order the work queue.
2974632Seric **
2984632Seric **	Parameters:
2994632Seric **		none.
3004632Seric **
3014632Seric **	Returns:
3024632Seric **		none.
3034632Seric **
3044632Seric **	Side Effects:
3054632Seric **		Sets WorkQ to the queue of available work, in order.
3064632Seric */
3074632Seric 
3084632Seric # define WLSIZE		120	/* max size of worklist per sort */
3094632Seric 
3104632Seric orderq()
3114632Seric {
3126625Sglickman 	register struct direct *d;
3134632Seric 	register WORK *w;
3144632Seric 	register WORK **wp;		/* parent of w */
3156625Sglickman 	DIR *f;
3164632Seric 	register int i;
3174632Seric 	WORK wlist[WLSIZE];
3184632Seric 	int wn = 0;
3194632Seric 	extern workcmpf();
3204632Seric 	extern char *QueueDir;
3214632Seric 
3224632Seric 	/* clear out old WorkQ */
3234632Seric 	for (w = WorkQ; w != NULL; )
3244632Seric 	{
3254632Seric 		register WORK *nw = w->w_next;
3264632Seric 
3274632Seric 		WorkQ = nw;
3284632Seric 		free(w->w_name);
3294632Seric 		free((char *) w);
3304632Seric 		w = nw;
3314632Seric 	}
3324632Seric 
3334632Seric 	/* open the queue directory */
3346625Sglickman 	f = opendir(QueueDir);
3354632Seric 	if (f == NULL)
3364632Seric 	{
3374632Seric 		syserr("orderq: cannot open %s", QueueDir);
3384632Seric 		return;
3394632Seric 	}
3404632Seric 
3414632Seric 	/*
3424632Seric 	**  Read the work directory.
3434632Seric 	*/
3444632Seric 
3456625Sglickman 	while (wn < WLSIZE && (d = readdir(f)) != NULL)
3464632Seric 	{
3474632Seric 		char cbuf[MAXNAME];
3484632Seric 		char lbuf[MAXNAME];
3494632Seric 		FILE *cf;
3504632Seric 		register char *p;
3514632Seric 
3524632Seric 		/* is this an interesting entry? */
3536625Sglickman 		if (d->d_name[0] != 'c')
3544632Seric 			continue;
3554632Seric 
3564632Seric 		/* yes -- find the control file location */
3577009Seric 		(void) strcpy(cbuf, QueueDir);
3587009Seric 		(void) strcat(cbuf, "/");
3594632Seric 		p = &cbuf[strlen(cbuf)];
3607009Seric 		(void) strcpy(p, d->d_name);
3614632Seric 
3624632Seric 		/* open control file */
3634632Seric 		cf = fopen(cbuf, "r");
3644632Seric 		if (cf == NULL)
3654632Seric 		{
3667055Seric 			/* this may be some random person sending hir msgs */
3677055Seric 			/* syserr("orderq: cannot open %s", cbuf); */
3687055Seric 			errno = 0;
3694632Seric 			continue;
3704632Seric 		}
3715037Seric 		wlist[wn].w_name = newstr(cbuf);
3724632Seric 
3734632Seric 		/* extract useful information */
3744632Seric 		while (fgets(lbuf, sizeof lbuf, cf) != NULL)
3754632Seric 		{
3764632Seric 			fixcrlf(lbuf, TRUE);
3774632Seric 
3784632Seric 			switch (lbuf[0])
3794632Seric 			{
3804632Seric 			  case 'P':		/* message priority */
3815037Seric 				(void) sscanf(&lbuf[1], "%ld", &wlist[wn].w_pri);
3824632Seric 				break;
3834632Seric 			}
3844632Seric 		}
3854632Seric 		wn++;
3864632Seric 		(void) fclose(cf);
3874632Seric 	}
3886625Sglickman 	(void) closedir(f);
3894632Seric 
3904632Seric 	/*
3914632Seric 	**  Sort the work directory.
3924632Seric 	*/
3934632Seric 
3944632Seric 	qsort(wlist, wn, sizeof *wlist, workcmpf);
3954632Seric 
3964632Seric 	/*
3974632Seric 	**  Convert the work list into canonical form.
3984632Seric 	*/
3994632Seric 
4004632Seric 	wp = &WorkQ;
4014632Seric 	for (i = 0; i < wn; i++)
4024632Seric 	{
4034632Seric 		w = (WORK *) xalloc(sizeof *w);
4044632Seric 		w->w_name = wlist[i].w_name;
4054632Seric 		w->w_pri = wlist[i].w_pri;
4064632Seric 		w->w_next = NULL;
4074632Seric 		*wp = w;
4084632Seric 		wp = &w->w_next;
4094632Seric 	}
4104632Seric 
4114632Seric # ifdef DEBUG
4124632Seric 	if (Debug)
4134632Seric 	{
4144632Seric 		for (w = WorkQ; w != NULL; w = w->w_next)
4155037Seric 			printf("%32s: pri=%ld\n", w->w_name, w->w_pri);
4164632Seric 	}
4174632Seric # endif DEBUG
4184632Seric }
4194632Seric /*
4204632Seric **	WORKCMPF -- compare function for ordering work.
4214632Seric **
4224632Seric **	Parameters:
4234632Seric **		a -- the first argument.
4244632Seric **		b -- the second argument.
4254632Seric **
4264632Seric **	Returns:
4274632Seric **		-1 if a < b
4284632Seric **		0 if a == b
4294632Seric **		1 if a > b
4304632Seric **
4314632Seric **	Side Effects:
4324632Seric **		none.
4334632Seric */
4344632Seric 
4354632Seric # define PRIFACT	1800		/* bytes each priority point is worth */
4364632Seric 
4374632Seric workcmpf(a, b)
4385037Seric 	register WORK *a;
4395037Seric 	register WORK *b;
4404632Seric {
4415037Seric 	if (a->w_pri == b->w_pri)
4424632Seric 		return (0);
4435037Seric 	else if (a->w_pri > b->w_pri)
4444632Seric 		return (1);
4454632Seric 	else
4464632Seric 		return (-1);
4474632Seric }
4484632Seric /*
4494632Seric **  DOWORK -- do a work request.
4504632Seric **
4514632Seric **	Parameters:
4524632Seric **		w -- the work request to be satisfied.
4534632Seric **
4544632Seric **	Returns:
4554632Seric **		none.
4564632Seric **
4574632Seric **	Side Effects:
4584632Seric **		The work request is satisfied if possible.
4594632Seric */
4604632Seric 
4614632Seric dowork(w)
4624632Seric 	register WORK *w;
4634632Seric {
4644632Seric 	register int i;
4654632Seric 	auto int xstat;
4664632Seric 
4674632Seric # ifdef DEBUG
4684632Seric 	if (Debug)
4695037Seric 		printf("dowork: %s pri %ld\n", w->w_name, w->w_pri);
4704632Seric # endif DEBUG
4714632Seric 
4724632Seric 	/*
4734632Seric 	**  Fork for work.
4744632Seric 	*/
4754632Seric 
4764632Seric 	i = fork();
4774632Seric 	if (i < 0)
4784632Seric 	{
4794632Seric 		syserr("dowork: cannot fork");
4804632Seric 		return;
4814632Seric 	}
4824632Seric 
4834632Seric 	if (i == 0)
4844632Seric 	{
4856980Seric 		char buf[MAXNAME];
4866980Seric 
4874632Seric 		/*
4884632Seric 		**  CHILD
4896980Seric 		**	Change the name of the control file to avoid
4907350Seric 		**		duplicate deliveries.   Then run the file
4917350Seric 		**		as though we had just read it.
4927350Seric 		**	We save an idea of the temporary name so we
4937350Seric 		**		can recover on interrupt.
4944632Seric 		*/
4954632Seric 
4967356Seric 		(void) alarm(0);
4977347Seric 		FatalErrors = FALSE;
4984632Seric 		QueueRun = TRUE;
4996991Seric 		MailBack = TRUE;
5006980Seric 		(void) strcpy(buf, QueueDir);
5016980Seric 		(void) strcat(buf, "/tfXXXXXX");
5026980Seric 		(void) mktemp(buf);
5036980Seric 		if (link(w->w_name, buf) < 0)
5046980Seric 		{
5056980Seric 			syserr("dowork: link(%s, %s)", w->w_name, buf);
5066980Seric 
5076980Seric 			/* it's ok to lie -- it will be run later */
5086980Seric 			exit(EX_OK);
5096980Seric 		}
5107350Seric 		ControlFile = newstr(buf);
5116980Seric 		(void) unlink(w->w_name);
5126980Seric 
5136980Seric 		/* create ourselves a transcript file */
5144634Seric 		openxscrpt();
5156980Seric 
5166980Seric 		/* do basic system initialization */
5174632Seric 		initsys();
5186980Seric 
5196980Seric 		/* read the queue control file */
5206980Seric 		readqf(buf);
5216980Seric 
5226980Seric 		/* do the delivery */
5237046Seric 		sendall(CurEnv, FALSE);
5246980Seric 
5256980Seric 		/* if still not sent, perhaps we should time out.... */
5264634Seric # ifdef DEBUG
5274634Seric 		if (Debug > 2)
5284634Seric 			printf("CurTime=%ld, TimeOut=%ld\n", CurTime, TimeOut);
5294634Seric # endif DEBUG
5306908Seric 		if (CurEnv->e_queueup && CurTime > TimeOut)
5314634Seric 			timeout(w);
5326980Seric 
5336980Seric 		/* get rid of the temporary file -- a new cf will be made */
5347350Seric 		ControlFile = NULL;
5356980Seric 		(void) unlink(buf);
5366980Seric 
5376980Seric 		/* finish up and exit */
5384632Seric 		finis();
5394632Seric 	}
5404632Seric 
5414632Seric 	/*
5424632Seric 	**  Parent -- pick up results.
5434632Seric 	*/
5444632Seric 
5454632Seric 	errno = 0;
5464632Seric 	while ((i = wait(&xstat)) > 0 && errno != EINTR)
5474632Seric 	{
5484632Seric 		if (errno == EINTR)
5494632Seric 		{
5504632Seric 			errno = 0;
5514632Seric 		}
5524632Seric 	}
5534632Seric }
5544632Seric /*
5554632Seric **  READQF -- read queue file and set up environment.
5564632Seric **
5574632Seric **	Parameters:
5584632Seric **		cf -- name of queue control file.
5594632Seric **
5604632Seric **	Returns:
5614632Seric **		none.
5624632Seric **
5634632Seric **	Side Effects:
5644632Seric **		cf is read and created as the current job, as though
5654632Seric **		we had been invoked by argument.
5664632Seric */
5674632Seric 
5684632Seric readqf(cf)
5694632Seric 	char *cf;
5704632Seric {
5714632Seric 	register FILE *f;
5724632Seric 	char buf[MAXLINE];
5734632Seric 
5744632Seric 	/*
5754632Seric 	**  Open the file created by queueup.
5764632Seric 	*/
5774632Seric 
5784632Seric 	f = fopen(cf, "r");
5794632Seric 	if (f == NULL)
5804632Seric 	{
5814632Seric 		syserr("readqf: no cf file %s", cf);
5824632Seric 		return;
5834632Seric 	}
5844632Seric 
5854632Seric 	/*
5864632Seric 	**  Read and process the file.
5874632Seric 	*/
5884632Seric 
5897356Seric 	if (Verbose)
5907356Seric 		printf("\nRunning %s\n", cf);
5914632Seric 	while (fgets(buf, sizeof buf, f) != NULL)
5924632Seric 	{
5934632Seric 		fixcrlf(buf, TRUE);
5944632Seric 
5954632Seric 		switch (buf[0])
5964632Seric 		{
5974632Seric 		  case 'R':		/* specify recipient */
5986908Seric 			sendto(&buf[1], 1, (ADDRESS *) NULL, &CurEnv->e_sendqueue);
5994632Seric 			break;
6004632Seric 
6014632Seric 		  case 'H':		/* header */
6024632Seric 			(void) chompheader(&buf[1], FALSE);
6034632Seric 			break;
6044632Seric 
6054632Seric 		  case 'S':		/* sender */
6064634Seric 			setsender(newstr(&buf[1]));
6074632Seric 			break;
6084632Seric 
6094632Seric 		  case 'D':		/* data file name */
6106991Seric 			CurEnv->e_df = newstr(&buf[1]);
6116991Seric 			TempFile = fopen(CurEnv->e_df, "r");
6124632Seric 			if (TempFile == NULL)
6136991Seric 				syserr("readqf: cannot open %s", CurEnv->e_df);
6144632Seric 			break;
6154632Seric 
6164632Seric 		  case 'T':		/* timeout */
6174632Seric 			(void) sscanf(&buf[1], "%ld", &TimeOut);
6184632Seric 			break;
6194632Seric 
6204634Seric 		  case 'P':		/* message priority */
6216908Seric 			(void) sscanf(&buf[1], "%ld", &CurEnv->e_msgpriority);
6225037Seric 
6235037Seric 			/* make sure that big things get sent eventually */
6246908Seric 			CurEnv->e_msgpriority -= WKTIMEFACT;
6254634Seric 			break;
6264634Seric 
6276980Seric 		  case 'C':		/* message class */
6286980Seric 			(void) sscanf(&buf[1], "%hd", &CurEnv->e_class);
6296980Seric 			break;
6306980Seric 
6315902Seric 		  case 'M':		/* define macro */
6325902Seric 			define(buf[1], newstr(&buf[2]));
6335902Seric 			break;
6345902Seric 
6354632Seric 		  default:
6364632Seric 			syserr("readqf(%s): bad line \"%s\"", cf, buf);
6374632Seric 			break;
6384632Seric 		}
6394632Seric 	}
6404632Seric }
6414632Seric /*
6424632Seric **  TIMEOUT -- process timeout on queue file.
6434632Seric **
6444632Seric **	Parameters:
6454632Seric **		w -- pointer to work request that timed out.
6464632Seric **
6474632Seric **	Returns:
6484632Seric **		none.
6494632Seric **
6504632Seric **	Side Effects:
6514632Seric **		Returns a message to the sender saying that this
6524632Seric **		message has timed out.
6534632Seric */
6544632Seric 
6554632Seric timeout(w)
6564632Seric 	register WORK *w;
6574632Seric {
6587369Seric 	char buf[MAXLINE];
6597369Seric 	extern char *TextTimeOut;
6607369Seric 
6614634Seric # ifdef DEBUG
6624634Seric 	if (Debug > 0)
6634634Seric 		printf("timeout(%s)\n", w->w_name);
6644634Seric # endif DEBUG
6656991Seric 	message(Arpa_Info, "Message has timed out");
6664634Seric 
6674634Seric 	/* return message to sender */
6687369Seric 	(void) sprintf(buf, "Cannot send mail for %s", TextTimeOut);
6697369Seric 	(void) returntosender(buf, &CurEnv->e_from, TRUE);
6704634Seric 
6714634Seric 	/* arrange to remove files from queue */
6726908Seric 	CurEnv->e_queueup = FALSE;
6734632Seric }
6745182Seric 
6755182Seric # endif QUEUE
676