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