xref: /titanic_52/usr/src/cmd/mailx/receipt.c (revision faa2b6be2fc102adf9ed584fc1a667b4ddf50d78)
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 
23 /*
24  * Copyright 2014 Joyent, Inc.
25  */
26 
27 /*
28  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
29  * Use is subject to license terms.
30  */
31 
32 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
33 /*	  All Rights Reserved  	*/
34 
35 
36 /*
37  * University Copyright- Copyright (c) 1982, 1986, 1988
38  * The Regents of the University of California
39  * All Rights Reserved
40  *
41  * University Acknowledgment- Portions of this document are derived from
42  * software developed by the University of California, Berkeley, and its
43  * contributors.
44  */
45 
46 #include <err.h>
47 
48 #include "rcv.h"
49 
50 static int		icsubstr(char *s1, char *s2);
51 
52 void
53 receipt(struct message *mp)
54 {
55 	char	head[LINESIZE];
56 	char	buf[BUFSIZ];
57 	FILE	*pp, *fp;
58 	char	*mail, *s;
59 
60 
61 	if ((mail = value("sendmail")) == 0)
62 #ifdef SENDMAIL
63 		mail = SENDMAIL;
64 #else
65 		mail = MAIL;
66 #endif
67 	if (icsubstr(hfield("default-options", mp, addone), "/receipt")
68 	 || icsubstr(hfield(">to", mp, addto), "/receipt")) {
69 		snprintf(buf, sizeof (buf), "%s %s", mail, skin(nameof(mp)));
70 		if (pp = npopen(buf, "w")) {
71 			headline_t *hl;
72 
73 			if (headline_alloc(&hl) != 0) {
74 				err(1, "could not allocate memory");
75 			}
76 
77 			fp = setinput(mp);
78 			readline(fp, head);
79 			if (parse_headline(head, hl) != 0) {
80 				headline_reset(hl);
81 			}
82 			if (custr_len(hl->hl_date) > 0) {
83 				fprintf(pp, "Original-Date: %s\n",
84 				    custr_cstr(hl->hl_date));
85 			}
86 			if (s = hfield("message-id", mp, addone))
87 				fprintf(pp, "Original-Message-ID: %s\n", s);
88 			s = hfield("subject", mp, addone);
89 			fprintf(pp, "Subject: RR: %s\n", s ? s : "(none)");
90 			npclose(pp);
91 			headline_free(hl);
92 		}
93 	}
94 }
95 
96 static int
97 icsubstr(char *s1, char *s2)
98 {
99 	char	buf[LINESIZE];
100 
101 	if (s1 && s2) {
102 		istrcpy(buf, sizeof (buf), s1);
103 		return substr(buf, s2) != -1;
104 	} else
105 		return 0;
106 }
107