xref: /illumos-gate/usr/src/cmd/mail/savehdrs.c (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 #include "mail.h"
26 /*
27  * Save info on each header line for possible generation
28  * of MTA positive or negative delivery notification
29  */
30 void
31 savehdrs(s, hdrtype)
32 char *s;
33 int hdrtype;
34 {
35 	char		*q;
36 	int		rf;
37 	char		delim = ':';
38 	char		tbuf[HDRSIZ];
39 	static int	last_hdrtype = -1;
40 
41 	if (hdrtype > H_CONT) {
42 		return;
43 	}
44 	if (hdrtype == H_CONT) {
45 		trimnl(s);
46 		pushlist(last_hdrtype, TAIL, s, TRUE);
47 		return;
48 	}
49 
50 	last_hdrtype = hdrtype;
51 
52 	if ((hdrtype == H_FROM) || (hdrtype == H_FROM1)) {
53 		delim = ' ';
54 	} else {
55 		if (fnuhdrtype == 0) {
56 			/* Save type of first non-UNIX header line */
57 			fnuhdrtype = hdrtype;
58 		}
59 	}
60 	switch (hdrtype) {
61 	    case H_FROM1:
62 		/* If first ">From " line, check for '...remote from...' */
63 		if (hdrlines[H_FROM1].head == (struct hdrs *)NULL) {
64 			if ((rf = substr(s, " remote from ")) >= 0) {
65 				trimnl(s + rf);
66 				(void) snprintf(tbuf, sizeof (tbuf),
67 				    "from %s by %s%s; %s",
68 				    s+rf+13, thissys, maildomain(),
69 				    RFC822datestring);
70 				pushlist(H_RECEIVED, HEAD, tbuf, FALSE);
71 			}
72 		}
73 		break;
74 
75 	    /* Remember that these header line type were in orig. msg.  */
76 	    case H_AFWDFROM:
77 		orig_aff++;
78 		break;
79 	    case H_RECEIVED:
80 		orig_rcv++;
81 		break;
82 	    case H_TCOPY:
83 		orig_tcopy++;
84 		break;
85 	}
86 	q = strchr(s, delim) + 1;
87 	q = skipspace(q);
88 	trimnl(q);
89 	if ((hdrtype == H_UAID) || (hdrtype == H_MTSID)) {
90 		/* Check for enclosing '<' & '>', and remove if found */
91 		/* gendeliv() will replace them if necessary */
92 		if ((*q == '<') && (*(q+strlen(q)-1) == '>')) {
93 			q++;
94 			*(q+strlen(q)-1) = '\0';
95 		}
96 	}
97 
98 	pushlist(hdrtype, TAIL, q, FALSE);
99 }
100