8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / mailx / receipt.c
blob0b6b9296fcc212680047c29873ddaf0629652c40
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
24 * Copyright 2014 Joyent, Inc.
28 * Copyright 1998 Sun Microsystems, Inc. All rights reserved.
29 * Use is subject to license terms.
32 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
33 /* All Rights Reserved */
37 * University Copyright- Copyright (c) 1982, 1986, 1988
38 * The Regents of the University of California
39 * All Rights Reserved
41 * University Acknowledgment- Portions of this document are derived from
42 * software developed by the University of California, Berkeley, and its
43 * contributors.
46 #include <err.h>
48 #include "rcv.h"
50 static int icsubstr(char *s1, char *s2);
52 void
53 receipt(struct message *mp)
55 char head[LINESIZE];
56 char buf[BUFSIZ];
57 FILE *pp, *fp;
58 char *mail, *s;
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;
73 if (headline_alloc(&hl) != 0) {
74 err(1, "could not allocate memory");
77 fp = setinput(mp);
78 readline(fp, head);
79 if (parse_headline(head, hl) != 0) {
80 headline_reset(hl);
82 if (custr_len(hl->hl_date) > 0) {
83 fprintf(pp, "Original-Date: %s\n",
84 custr_cstr(hl->hl_date));
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);
96 static int
97 icsubstr(char *s1, char *s2)
99 char buf[LINESIZE];
101 if (s1 && s2) {
102 istrcpy(buf, sizeof (buf), s1);
103 return substr(buf, s2) != -1;
104 } else
105 return 0;