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