xref: /titanic_50/usr/src/cmd/mail/savehdrs.c (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
26 
27 #include "mail.h"
28 /*
29  * Save info on each header line for possible generation
30  * of MTA positive or negative delivery notification
31  */
32 void
33 savehdrs(s, hdrtype)
34 char *s;
35 int hdrtype;
36 {
37 	char		*q;
38 	int		rf;
39 	char		delim = ':';
40 	char		tbuf[HDRSIZ];
41 	static int	last_hdrtype = -1;
42 
43 	if (hdrtype > H_CONT) {
44 		return;
45 	}
46 	if (hdrtype == H_CONT) {
47 		trimnl(s);
48 		pushlist(last_hdrtype, TAIL, s, TRUE);
49 		return;
50 	}
51 
52 	last_hdrtype = hdrtype;
53 
54 	if ((hdrtype == H_FROM) || (hdrtype == H_FROM1)) {
55 		delim = ' ';
56 	} else {
57 		if (fnuhdrtype == 0) {
58 			/* Save type of first non-UNIX header line */
59 			fnuhdrtype = hdrtype;
60 		}
61 	}
62 	switch (hdrtype) {
63 	    case H_FROM1:
64 		/* If first ">From " line, check for '...remote from...' */
65 		if (hdrlines[H_FROM1].head == (struct hdrs *)NULL) {
66 			if ((rf = substr(s, " remote from ")) >= 0) {
67 				trimnl(s + rf);
68 				(void) snprintf(tbuf, sizeof (tbuf),
69 				    "from %s by %s%s; %s",
70 				    s+rf+13, thissys, maildomain(),
71 				    RFC822datestring);
72 				pushlist(H_RECEIVED, HEAD, tbuf, FALSE);
73 			}
74 		}
75 		break;
76 
77 	    /* Remember that these header line type were in orig. msg.  */
78 	    case H_AFWDFROM:
79 		orig_aff++;
80 		break;
81 	    case H_RECEIVED:
82 		orig_rcv++;
83 		break;
84 	    case H_TCOPY:
85 		orig_tcopy++;
86 		break;
87 	}
88 	q = strchr(s, delim) + 1;
89 	q = skipspace(q);
90 	trimnl(q);
91 	if ((hdrtype == H_UAID) || (hdrtype == H_MTSID)) {
92 		/* Check for enclosing '<' & '>', and remove if found */
93 		/* gendeliv() will replace them if necessary */
94 		if ((*q == '<') && (*(q+strlen(q)-1) == '>')) {
95 			q++;
96 			*(q+strlen(q)-1) = '\0';
97 		}
98 	}
99 
100 	pushlist(hdrtype, TAIL, q, FALSE);
101 }
102