1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988 Regents of the University of California.
4  * All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #ifndef lint
10 static char sccsid[] = "@(#)headers.c	6.4 (Berkeley) 01/18/93";
11 #endif /* not lint */
12 
13 # include <errno.h>
14 # include "sendmail.h"
15 
16 /*
17 **  CHOMPHEADER -- process and save a header line.
18 **
19 **	Called by collect and by readcf to deal with header lines.
20 **
21 **	Parameters:
22 **		line -- header as a text line.
23 **		def -- if set, this is a default value.
24 **		e -- the envelope including this header.
25 **
26 **	Returns:
27 **		flags for this header.
28 **
29 **	Side Effects:
30 **		The header is saved on the header list.
31 **		Contents of 'line' are destroyed.
32 */
33 
34 chompheader(line, def, e)
35 	char *line;
36 	bool def;
37 	register ENVELOPE *e;
38 {
39 	register char *p;
40 	register HDR *h;
41 	HDR **hp;
42 	char *fname;
43 	char *fvalue;
44 	struct hdrinfo *hi;
45 	bool cond = FALSE;
46 	BITMAP mopts;
47 
48 	if (tTd(31, 6))
49 		printf("chompheader: %s\n", line);
50 
51 	/* strip off options */
52 	clrbitmap(mopts);
53 	p = line;
54 	if (*p == '?')
55 	{
56 		/* have some */
57 		register char *q = strchr(p + 1, *p);
58 
59 		if (q != NULL)
60 		{
61 			*q++ = '\0';
62 			while (*++p != '\0')
63 				setbitn(*p, mopts);
64 			p = q;
65 		}
66 		else
67 			usrerr("chompheader: syntax error, line \"%s\"", line);
68 		cond = TRUE;
69 	}
70 
71 	/* find canonical name */
72 	fname = p;
73 	p = strchr(p, ':');
74 	if (p == NULL)
75 	{
76 		syserr("chompheader: syntax error, line \"%s\"", line);
77 		return (0);
78 	}
79 	fvalue = &p[1];
80 	while (isspace(*--p))
81 		continue;
82 	*++p = '\0';
83 	makelower(fname);
84 
85 	/* strip field value on front */
86 	if (*fvalue == ' ')
87 		fvalue++;
88 
89 	/* see if it is a known type */
90 	for (hi = HdrInfo; hi->hi_field != NULL; hi++)
91 	{
92 		if (strcmp(hi->hi_field, fname) == 0)
93 			break;
94 	}
95 
96 	/* see if this is a resent message */
97 	if (!def && bitset(H_RESENT, hi->hi_flags))
98 		e->e_flags |= EF_RESENT;
99 
100 	/* if this means "end of header" quit now */
101 	if (bitset(H_EOH, hi->hi_flags))
102 		return (hi->hi_flags);
103 
104 	/* drop explicit From: if same as what we would generate -- for MH */
105 	p = "resent-from";
106 	if (!bitset(EF_RESENT, e->e_flags))
107 		p += 7;
108 	if (!def && !QueueRun && strcmp(fname, p) == 0)
109 	{
110 		if (e->e_from.q_paddr != NULL &&
111 		    strcmp(fvalue, e->e_from.q_paddr) == 0)
112 			return (hi->hi_flags);
113 	}
114 
115 	/* delete default value for this header */
116 	for (hp = &e->e_header; (h = *hp) != NULL; hp = &h->h_link)
117 	{
118 		if (strcmp(fname, h->h_field) == 0 &&
119 		    bitset(H_DEFAULT, h->h_flags) &&
120 		    !bitset(H_FORCE, h->h_flags))
121 			h->h_value = NULL;
122 	}
123 
124 	/* create a new node */
125 	h = (HDR *) xalloc(sizeof *h);
126 	h->h_field = newstr(fname);
127 	h->h_value = NULL;
128 	h->h_link = NULL;
129 	bcopy((char *) mopts, (char *) h->h_mflags, sizeof mopts);
130 	*hp = h;
131 	h->h_flags = hi->hi_flags;
132 	if (def)
133 		h->h_flags |= H_DEFAULT;
134 	if (cond)
135 		h->h_flags |= H_CHECK;
136 	if (h->h_value != NULL)
137 		free((char *) h->h_value);
138 	h->h_value = newstr(fvalue);
139 
140 	/* hack to see if this is a new format message */
141 	if (!def && bitset(H_RCPT|H_FROM, h->h_flags) &&
142 	    (strchr(fvalue, ',') != NULL || strchr(fvalue, '(') != NULL ||
143 	     strchr(fvalue, '<') != NULL || strchr(fvalue, ';') != NULL))
144 	{
145 		e->e_flags &= ~EF_OLDSTYLE;
146 	}
147 
148 	return (h->h_flags);
149 }
150 /*
151 **  ADDHEADER -- add a header entry to the end of the queue.
152 **
153 **	This bypasses the special checking of chompheader.
154 **
155 **	Parameters:
156 **		field -- the name of the header field.
157 **		value -- the value of the field.  It must be lower-cased.
158 **		e -- the envelope to add them to.
159 **
160 **	Returns:
161 **		none.
162 **
163 **	Side Effects:
164 **		adds the field on the list of headers for this envelope.
165 */
166 
167 addheader(field, value, e)
168 	char *field;
169 	char *value;
170 	ENVELOPE *e;
171 {
172 	register HDR *h;
173 	register struct hdrinfo *hi;
174 	HDR **hp;
175 
176 	/* find info struct */
177 	for (hi = HdrInfo; hi->hi_field != NULL; hi++)
178 	{
179 		if (strcmp(field, hi->hi_field) == 0)
180 			break;
181 	}
182 
183 	/* find current place in list -- keep back pointer? */
184 	for (hp = &e->e_header; (h = *hp) != NULL; hp = &h->h_link)
185 	{
186 		if (strcmp(field, h->h_field) == 0)
187 			break;
188 	}
189 
190 	/* allocate space for new header */
191 	h = (HDR *) xalloc(sizeof *h);
192 	h->h_field = field;
193 	h->h_value = newstr(value);
194 	h->h_link = *hp;
195 	h->h_flags = hi->hi_flags | H_DEFAULT;
196 	clrbitmap(h->h_mflags);
197 	*hp = h;
198 }
199 /*
200 **  HVALUE -- return value of a header.
201 **
202 **	Only "real" fields (i.e., ones that have not been supplied
203 **	as a default) are used.
204 **
205 **	Parameters:
206 **		field -- the field name.
207 **		e -- the envelope containing the header.
208 **
209 **	Returns:
210 **		pointer to the value part.
211 **		NULL if not found.
212 **
213 **	Side Effects:
214 **		none.
215 */
216 
217 char *
218 hvalue(field, e)
219 	char *field;
220 	register ENVELOPE *e;
221 {
222 	register HDR *h;
223 
224 	for (h = e->e_header; h != NULL; h = h->h_link)
225 	{
226 		if (!bitset(H_DEFAULT, h->h_flags) && strcmp(h->h_field, field) == 0)
227 			return (h->h_value);
228 	}
229 	return (NULL);
230 }
231 /*
232 **  ISHEADER -- predicate telling if argument is a header.
233 **
234 **	A line is a header if it has a single word followed by
235 **	optional white space followed by a colon.
236 **
237 **	Parameters:
238 **		s -- string to check for possible headerness.
239 **
240 **	Returns:
241 **		TRUE if s is a header.
242 **		FALSE otherwise.
243 **
244 **	Side Effects:
245 **		none.
246 */
247 
248 bool
249 isheader(s)
250 	register char *s;
251 {
252 	while (*s > ' ' && *s != ':' && *s != '\0')
253 		s++;
254 
255 	/* following technically violates RFC822 */
256 	while (isspace(*s))
257 		s++;
258 
259 	return (*s == ':');
260 }
261 /*
262 **  EATHEADER -- run through the stored header and extract info.
263 **
264 **	Parameters:
265 **		e -- the envelope to process.
266 **
267 **	Returns:
268 **		none.
269 **
270 **	Side Effects:
271 **		Sets a bunch of global variables from information
272 **			in the collected header.
273 **		Aborts the message if the hop count is exceeded.
274 */
275 
276 eatheader(e)
277 	register ENVELOPE *e;
278 {
279 	register HDR *h;
280 	register char *p;
281 	int hopcnt = 0;
282 	char *msgid;
283 	char msgidbuf[MAXNAME];
284 
285 	if (tTd(32, 1))
286 		printf("----- collected header -----\n");
287 	msgid = "<none>";
288 	for (h = e->e_header; h != NULL; h = h->h_link)
289 	{
290 		extern char *capitalize();
291 
292 		if (tTd(32, 1))
293 			printf("%s: %s\n", capitalize(h->h_field), h->h_value);
294 
295 		/* count the number of times it has been processed */
296 		if (bitset(H_TRACE, h->h_flags))
297 			hopcnt++;
298 
299 		/* send to this person if we so desire */
300 		if (GrabTo && bitset(H_RCPT, h->h_flags) &&
301 		    !bitset(H_DEFAULT, h->h_flags) &&
302 		    (!bitset(EF_RESENT, e->e_flags) || bitset(H_RESENT, h->h_flags)))
303 		{
304 			sendtolist(h->h_value, (ADDRESS *) NULL,
305 				   &e->e_sendqueue, e);
306 		}
307 
308 		/* save the message-id for logging */
309 		if (!QueueRun && h->h_value != NULL &&
310 		    strcmp(h->h_field, "message-id") == 0)
311 		{
312 			msgid = h->h_value;
313 			if (bitset(H_DEFAULT, h->h_flags))
314 			{
315 				expand(msgid, msgidbuf,
316 					&msgidbuf[sizeof msgidbuf], e);
317 				msgid = msgidbuf;
318 			}
319 		}
320 
321 		/* see if this is a return-receipt header */
322 		if (bitset(H_RECEIPTTO, h->h_flags))
323 			e->e_receiptto = h->h_value;
324 
325 		/* see if this is an errors-to header */
326 		if (bitset(H_ERRORSTO, h->h_flags))
327 			sendtolist(h->h_value, (ADDRESS *) NULL, &e->e_errorqueue, e);
328 	}
329 	if (tTd(32, 1))
330 		printf("----------------------------\n");
331 
332 	/* store hop count */
333 	if (hopcnt > e->e_hopcount)
334 		e->e_hopcount = hopcnt;
335 
336 	/* message priority */
337 	p = hvalue("precedence", e);
338 	if (p != NULL)
339 		e->e_class = priencode(p);
340 	if (!QueueRun)
341 		e->e_msgpriority = e->e_msgsize
342 				 - e->e_class * WkClassFact
343 				 + e->e_nrcpts * WkRecipFact;
344 
345 	/* full name of from person */
346 	p = hvalue("full-name", e);
347 	if (p != NULL)
348 		define('x', p, e);
349 
350 	/* date message originated */
351 	p = hvalue("posted-date", e);
352 	if (p == NULL)
353 		p = hvalue("date", e);
354 	if (p != NULL)
355 	{
356 		extern char *arpatounix();
357 
358 		define('a', p, e);
359 		if ((p = arpatounix(p, e)) != NULL)
360 			define('d', newstr(p), e);
361 	}
362 
363 	/*
364 	**  Log collection information.
365 	*/
366 
367 # ifdef LOG
368 	if (!QueueRun && LogLevel > 1)
369 	{
370 		char *name;
371 		char hbuf[MAXNAME];
372 		char sbuf[MAXLINE];
373 
374 		if (RealHostName == NULL)
375 			name = "local";
376 		else if (RealHostName[0] == '[')
377 			name = RealHostName;
378 		else
379 		{
380 			extern char *inet_ntoa();
381 
382 			name = hbuf;
383 			(void)sprintf(hbuf, "%.80s (%s)",
384 			    RealHostName, inet_ntoa(RealHostAddr.sin_addr));
385 		}
386 
387 		/* some versions of syslog only take 5 printf args */
388 		sprintf(sbuf, "from=%.200s, size=%ld, class=%d, pri=%ld, nrcpts=%d, msgid=%.100s",
389 		    e->e_from.q_paddr, e->e_msgsize, e->e_class,
390 		    e->e_msgpriority, e->e_nrcpts, msgid);
391 		syslog(LOG_INFO, "%s: %s, received from %s\n",
392 		    e->e_id, sbuf, name);
393 	}
394 # endif /* LOG */
395 }
396 /*
397 **  PRIENCODE -- encode external priority names into internal values.
398 **
399 **	Parameters:
400 **		p -- priority in ascii.
401 **
402 **	Returns:
403 **		priority as a numeric level.
404 **
405 **	Side Effects:
406 **		none.
407 */
408 
409 priencode(p)
410 	char *p;
411 {
412 	register int i;
413 
414 	for (i = 0; i < NumPriorities; i++)
415 	{
416 		if (!strcasecmp(p, Priorities[i].pri_name))
417 			return (Priorities[i].pri_val);
418 	}
419 
420 	/* unknown priority */
421 	return (0);
422 }
423 /*
424 **  CRACKADDR -- parse an address and turn it into a macro
425 **
426 **	This doesn't actually parse the address -- it just extracts
427 **	it and replaces it with "$g".  The parse is totally ad hoc
428 **	and isn't even guaranteed to leave something syntactically
429 **	identical to what it started with.  However, it does leave
430 **	something semantically identical.
431 **
432 **	This algorithm has been cleaned up to handle a wider range
433 **	of cases -- notably quoted and backslash escaped strings.
434 **	This modification makes it substantially better at preserving
435 **	the original syntax.
436 **
437 **	Parameters:
438 **		addr -- the address to be cracked.
439 **
440 **	Returns:
441 **		a pointer to the new version.
442 **
443 **	Side Effects:
444 **		none.
445 **
446 **	Warning:
447 **		The return value is saved in local storage and should
448 **		be copied if it is to be reused.
449 */
450 
451 char *
452 crackaddr(addr)
453 	register char *addr;
454 {
455 	register char *p;
456 	register char c;
457 	int cmtlev;
458 	int realcmtlev;
459 	int anglelev, realanglelev;
460 	int copylev;
461 	bool qmode;
462 	bool realqmode;
463 	bool skipping;
464 	bool putgmac = FALSE;
465 	bool quoteit = FALSE;
466 	register char *bp;
467 	char *buflim;
468 	static char buf[MAXNAME];
469 
470 	if (tTd(33, 1))
471 		printf("crackaddr(%s)\n", addr);
472 
473 	/* strip leading spaces */
474 	while (*addr != '\0' && isspace(*addr))
475 		addr++;
476 
477 	/*
478 	**  Start by assuming we have no angle brackets.  This will be
479 	**  adjusted later if we find them.
480 	*/
481 
482 	bp = buf;
483 	buflim = &buf[sizeof buf - 5];
484 	p = addr;
485 	copylev = anglelev = realanglelev = cmtlev = realcmtlev = 0;
486 	qmode = realqmode = FALSE;
487 
488 	while ((c = *p++) != '\0')
489 	{
490 		/*
491 		**  If the buffer is overful, go into a special "skipping"
492 		**  mode that tries to keep legal syntax but doesn't actually
493 		**  output things.
494 		*/
495 
496 		skipping = bp >= buflim;
497 
498 		if (copylev > 0 && !skipping)
499 			*bp++ = c;
500 
501 		/* check for backslash escapes */
502 		if (c == '\\')
503 		{
504 			if ((c = *p++) == '\0')
505 			{
506 				/* too far */
507 				p--;
508 				goto putg;
509 			}
510 			if (copylev > 0 && !skipping)
511 				*bp++ = c;
512 			goto putg;
513 		}
514 
515 		/* check for quoted strings */
516 		if (c == '"')
517 		{
518 			qmode = !qmode;
519 			if (copylev > 0 && !skipping)
520 				realqmode = !realqmode;
521 			continue;
522 		}
523 		if (qmode)
524 			goto putg;
525 
526 		/* check for comments */
527 		if (c == '(')
528 		{
529 			cmtlev++;
530 
531 			/* allow space for closing paren */
532 			if (!skipping)
533 			{
534 				buflim--;
535 				realcmtlev++;
536 				if (copylev++ <= 0)
537 				{
538 					*bp++ = ' ';
539 					*bp++ = c;
540 				}
541 			}
542 		}
543 		if (cmtlev > 0)
544 		{
545 			if (c == ')')
546 			{
547 				cmtlev--;
548 				copylev--;
549 				if (!skipping)
550 				{
551 					realcmtlev--;
552 					buflim++;
553 				}
554 			}
555 			continue;
556 		}
557 		else if (c == ')')
558 		{
559 			/* syntax error: unmatched ) */
560 			if (!skipping)
561 				bp--;
562 		}
563 
564 
565 		/* check for characters that may have to be quoted */
566 		if (strchr(".'@,;:\\()", c) != NULL)
567 		{
568 			/*
569 			**  If these occur as the phrase part of a <>
570 			**  construct, but are not inside of () or already
571 			**  quoted, they will have to be quoted.  Note that
572 			**  now (but don't actually do the quoting).
573 			*/
574 
575 			if (cmtlev <= 0 && !qmode)
576 				quoteit = TRUE;
577 		}
578 
579 		/* check for angle brackets */
580 		if (c == '<')
581 		{
582 			register char *q;
583 
584 			/* oops -- have to change our mind */
585 			anglelev++;
586 			if (!skipping)
587 				realanglelev++;
588 
589 			bp = buf;
590 			if (quoteit)
591 			{
592 				*bp++ = '"';
593 
594 				/* back up over the '<' and any spaces */
595 				--p;
596 				while (isspace(*--p))
597 					continue;
598 				p++;
599 			}
600 			for (q = addr; q < p; )
601 			{
602 				c = *q++;
603 				if (bp < buflim)
604 				{
605 					if (quoteit && c == '"')
606 						*bp++ = '\\';
607 					*bp++ = c;
608 				}
609 			}
610 			if (quoteit)
611 			{
612 				*bp++ = '"';
613 				while ((c = *p++) != '<')
614 				{
615 					if (bp < buflim)
616 						*bp++ = c;
617 				}
618 				*bp++ = c;
619 			}
620 			copylev = 0;
621 			putgmac = quoteit = FALSE;
622 			continue;
623 		}
624 
625 		if (c == '>')
626 		{
627 			if (anglelev > 0)
628 			{
629 				anglelev--;
630 				if (!skipping)
631 				{
632 					realanglelev--;
633 					buflim++;
634 				}
635 			}
636 			else if (!skipping)
637 			{
638 				/* syntax error: unmatched > */
639 				if (copylev > 0)
640 					bp--;
641 				continue;
642 			}
643 			if (copylev++ <= 0)
644 				*bp++ = c;
645 			continue;
646 		}
647 
648 		/* must be a real address character */
649 	putg:
650 		if (copylev <= 0 && !putgmac)
651 		{
652 			*bp++ = '\001';
653 			*bp++ = 'g';
654 			putgmac = TRUE;
655 		}
656 	}
657 
658 	/* repair any syntactic damage */
659 	if (realqmode)
660 		*bp++ = '"';
661 	while (realcmtlev-- > 0)
662 		*bp++ = ')';
663 	while (realanglelev-- > 0)
664 		*bp++ = '>';
665 	*bp++ = '\0';
666 
667 	if (tTd(33, 1))
668 		printf("crackaddr=>`%s'\n", buf);
669 
670 	return (buf);
671 }
672 /*
673 **  PUTHEADER -- put the header part of a message from the in-core copy
674 **
675 **	Parameters:
676 **		fp -- file to put it on.
677 **		m -- mailer to use.
678 **		e -- envelope to use.
679 **
680 **	Returns:
681 **		none.
682 **
683 **	Side Effects:
684 **		none.
685 */
686 
687 /*
688  * Macro for fast max (not available in e.g. DG/UX, 386/ix).
689  */
690 #ifndef MAX
691 # define MAX(a,b) (((a)>(b))?(a):(b))
692 #endif
693 
694 putheader(fp, m, e)
695 	register FILE *fp;
696 	register MAILER *m;
697 	register ENVELOPE *e;
698 {
699 	char buf[MAX(MAXLINE,BUFSIZ)];
700 	register HDR *h;
701 	extern char *arpadate();
702 	extern char *capitalize();
703 	char obuf[MAXLINE];
704 
705 	for (h = e->e_header; h != NULL; h = h->h_link)
706 	{
707 		register char *p;
708 		extern bool bitintersect();
709 
710 		if (bitset(H_CHECK|H_ACHECK, h->h_flags) &&
711 		    !bitintersect(h->h_mflags, m->m_flags))
712 			continue;
713 
714 		/* handle Resent-... headers specially */
715 		if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags))
716 			continue;
717 
718 		p = h->h_value;
719 		if (bitset(H_DEFAULT, h->h_flags))
720 		{
721 			/* macro expand value if generated internally */
722 			expand(p, buf, &buf[sizeof buf], e);
723 			p = buf;
724 			if (p == NULL || *p == '\0')
725 				continue;
726 		}
727 
728 		if (bitset(H_FROM|H_RCPT, h->h_flags))
729 		{
730 			/* address field */
731 			bool oldstyle = bitset(EF_OLDSTYLE, e->e_flags);
732 
733 			if (bitset(H_FROM, h->h_flags))
734 				oldstyle = FALSE;
735 			commaize(h, p, fp, oldstyle, m, e);
736 		}
737 		else
738 		{
739 			/* vanilla header line */
740 			register char *nlp;
741 
742 			(void) sprintf(obuf, "%s: ", capitalize(h->h_field));
743 			while ((nlp = strchr(p, '\n')) != NULL)
744 			{
745 				*nlp = '\0';
746 				(void) strcat(obuf, p);
747 				*nlp = '\n';
748 				putline(obuf, fp, m);
749 				p = ++nlp;
750 				obuf[0] = '\0';
751 			}
752 			(void) strcat(obuf, p);
753 			putline(obuf, fp, m);
754 		}
755 	}
756 }
757 /*
758 **  COMMAIZE -- output a header field, making a comma-translated list.
759 **
760 **	Parameters:
761 **		h -- the header field to output.
762 **		p -- the value to put in it.
763 **		fp -- file to put it to.
764 **		oldstyle -- TRUE if this is an old style header.
765 **		m -- a pointer to the mailer descriptor.  If NULL,
766 **			don't transform the name at all.
767 **		e -- the envelope containing the message.
768 **
769 **	Returns:
770 **		none.
771 **
772 **	Side Effects:
773 **		outputs "p" to file "fp".
774 */
775 
776 commaize(h, p, fp, oldstyle, m, e)
777 	register HDR *h;
778 	register char *p;
779 	FILE *fp;
780 	bool oldstyle;
781 	register MAILER *m;
782 	register ENVELOPE *e;
783 {
784 	register char *obp;
785 	int opos;
786 	bool firstone = TRUE;
787 	char obuf[MAXLINE + 3];
788 
789 	/*
790 	**  Output the address list translated by the
791 	**  mailer and with commas.
792 	*/
793 
794 	if (tTd(14, 2))
795 		printf("commaize(%s: %s)\n", h->h_field, p);
796 
797 	obp = obuf;
798 	(void) sprintf(obp, "%s: ", capitalize(h->h_field));
799 	opos = strlen(h->h_field) + 2;
800 	obp += opos;
801 
802 	/*
803 	**  Run through the list of values.
804 	*/
805 
806 	while (*p != '\0')
807 	{
808 		register char *name;
809 		register int c;
810 		char savechar;
811 		extern char *remotename();
812 		extern char *DelimChar;		/* defined in prescan */
813 
814 		/*
815 		**  Find the end of the name.  New style names
816 		**  end with a comma, old style names end with
817 		**  a space character.  However, spaces do not
818 		**  necessarily delimit an old-style name -- at
819 		**  signs mean keep going.
820 		*/
821 
822 		/* find end of name */
823 		while (isspace(*p) || *p == ',')
824 			p++;
825 		name = p;
826 		for (;;)
827 		{
828 			char *oldp;
829 			char pvpbuf[PSBUFSIZE];
830 			extern bool isatword();
831 			extern char **prescan();
832 
833 			(void) prescan(p, oldstyle ? ' ' : ',', pvpbuf);
834 			p = DelimChar;
835 
836 			/* look to see if we have an at sign */
837 			oldp = p;
838 			while (*p != '\0' && isspace(*p))
839 				p++;
840 
841 			if (*p != '@' && !isatword(p))
842 			{
843 				p = oldp;
844 				break;
845 			}
846 			p += *p == '@' ? 1 : 2;
847 			while (*p != '\0' && isspace(*p))
848 				p++;
849 		}
850 		/* at the end of one complete name */
851 
852 		/* strip off trailing white space */
853 		while (p >= name && (isspace(*p) || *p == ',' || *p == '\0'))
854 			p--;
855 		if (++p == name)
856 			continue;
857 		savechar = *p;
858 		*p = '\0';
859 
860 		/* translate the name to be relative */
861 		name = remotename(name, m, bitset(H_FROM, h->h_flags), FALSE, e);
862 		if (*name == '\0')
863 		{
864 			*p = savechar;
865 			continue;
866 		}
867 
868 		/* output the name with nice formatting */
869 		opos += strlen(name);
870 		if (!firstone)
871 			opos += 2;
872 		if (opos > 78 && !firstone)
873 		{
874 			(void) strcpy(obp, ",\n");
875 			putline(obuf, fp, m);
876 			obp = obuf;
877 			(void) sprintf(obp, "        ");
878 			opos = strlen(obp);
879 			obp += opos;
880 			opos += strlen(name);
881 		}
882 		else if (!firstone)
883 		{
884 			(void) sprintf(obp, ", ");
885 			obp += 2;
886 		}
887 
888 		/* strip off quote bits as we output */
889 		while ((c = *name++) != '\0' && obp < &obuf[MAXLINE])
890 		{
891 			if (bitnset(M_7BITS, m->m_flags))
892 				c &= 0177;
893 			*obp++ = c;
894 		}
895 		firstone = FALSE;
896 		*p = savechar;
897 	}
898 	(void) strcpy(obp, "\n");
899 	putline(obuf, fp, m);
900 }
901 /*
902 **  ISATWORD -- tell if the word we are pointing to is "at".
903 **
904 **	Parameters:
905 **		p -- word to check.
906 **
907 **	Returns:
908 **		TRUE -- if p is the word at.
909 **		FALSE -- otherwise.
910 **
911 **	Side Effects:
912 **		none.
913 */
914 
915 bool
916 isatword(p)
917 	register char *p;
918 {
919 	extern char lower();
920 
921 	if (lower(p[0]) == 'a' && lower(p[1]) == 't' &&
922 	    p[2] != '\0' && isspace(p[2]))
923 		return (TRUE);
924 	return (FALSE);
925 }
926