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