xref: /illumos-gate/usr/src/cmd/mail/ckdlivopts.c (revision 2a8bcb4e)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate /*
26*7c478bd9Sstevel@tonic-gate     NAME
27*7c478bd9Sstevel@tonic-gate 	ckdlivopts - check delivery notification options
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate     SYNOPSIS
30*7c478bd9Sstevel@tonic-gate 	int ckdlivopts(int tcopy_hdr, int *svopts)
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate     DESCRIPTION
33*7c478bd9Sstevel@tonic-gate 	Check if delivery notification requested for message being
34*7c478bd9Sstevel@tonic-gate 	processed. Returns specified options as combined from H_DEFOPTS,
35*7c478bd9Sstevel@tonic-gate 	H_TROPTS, & H_TCOPY lines.
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate 	(Positive notification options)
38*7c478bd9Sstevel@tonic-gate 		001 ==> /delivery requested
39*7c478bd9Sstevel@tonic-gate 		002 ==> /nodelivery requested
40*7c478bd9Sstevel@tonic-gate 	(Negative notification options)
41*7c478bd9Sstevel@tonic-gate 		010 ==> /report requested
42*7c478bd9Sstevel@tonic-gate 		020 ==> /return requested
43*7c478bd9Sstevel@tonic-gate 		040 ==> /ignore requested
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate 	Combinations are expected, i.e. - 011 ==> /delivery/report
46*7c478bd9Sstevel@tonic-gate 	If not specified, the assumed defaults are /nodelivery/return (rc=022)
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate 	The options discovered in the header are stored into svopts.
49*7c478bd9Sstevel@tonic-gate  */
50*7c478bd9Sstevel@tonic-gate #include "mail.h"
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate static void getopts();
53*7c478bd9Sstevel@tonic-gate static void mergeopts();
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate struct dlvopts {
56*7c478bd9Sstevel@tonic-gate 	int	deliv;
57*7c478bd9Sstevel@tonic-gate 	int	nodeliv;
58*7c478bd9Sstevel@tonic-gate 	int	rept;
59*7c478bd9Sstevel@tonic-gate 	int	rtrn;
60*7c478bd9Sstevel@tonic-gate 	int	ign;
61*7c478bd9Sstevel@tonic-gate };
62*7c478bd9Sstevel@tonic-gate 
ckdlivopts(tcopy_hdr,svopts)63*7c478bd9Sstevel@tonic-gate int ckdlivopts(tcopy_hdr, svopts)
64*7c478bd9Sstevel@tonic-gate int	tcopy_hdr;
65*7c478bd9Sstevel@tonic-gate int	*svopts;
66*7c478bd9Sstevel@tonic-gate {
67*7c478bd9Sstevel@tonic-gate 	static char	pn[] = "ckdlivopts";
68*7c478bd9Sstevel@tonic-gate 	struct	hdrs	*hp;
69*7c478bd9Sstevel@tonic-gate 	struct dlvopts	toopts, tropts, defopts;
70*7c478bd9Sstevel@tonic-gate 	int		rc;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	/* already done this once. no need to repeat..... */
73*7c478bd9Sstevel@tonic-gate 	if (svopts && *svopts != 0) {
74*7c478bd9Sstevel@tonic-gate 		Dout(pn, 0, "*svopts = o%o\n", *svopts);
75*7c478bd9Sstevel@tonic-gate 		return (*svopts);
76*7c478bd9Sstevel@tonic-gate 	}
77*7c478bd9Sstevel@tonic-gate 	memset((char *)&defopts, 0, sizeof(struct dlvopts));
78*7c478bd9Sstevel@tonic-gate 	if ((hp = hdrlines[H_DEFOPTS].head) != (struct hdrs *)NULL) {
79*7c478bd9Sstevel@tonic-gate 		Dout(pn, 3, "H_DEFOPTS line = '%s'\n", hp->value);
80*7c478bd9Sstevel@tonic-gate 		getopts(hp->value, &defopts);
81*7c478bd9Sstevel@tonic-gate 	}
82*7c478bd9Sstevel@tonic-gate 	memset((char *)&tropts, 0, sizeof(struct dlvopts));
83*7c478bd9Sstevel@tonic-gate 	if ((hp = hdrlines[H_TROPTS].head) != (struct hdrs *)NULL) {
84*7c478bd9Sstevel@tonic-gate 		Dout(pn, 3, "H_TROPTS line = '%s'\n", hp->value);
85*7c478bd9Sstevel@tonic-gate 		getopts(hp->value, &tropts);
86*7c478bd9Sstevel@tonic-gate 	}
87*7c478bd9Sstevel@tonic-gate 	memset((char *)&toopts, 0, sizeof(struct dlvopts));
88*7c478bd9Sstevel@tonic-gate 	if ((hp = hdrlines[tcopy_hdr].head) != (struct hdrs *)NULL) {
89*7c478bd9Sstevel@tonic-gate 		Dout(pn, 3,"H_TCOPY line = '%s'\n", hp->value);
90*7c478bd9Sstevel@tonic-gate 		getopts(hp->value, &toopts);
91*7c478bd9Sstevel@tonic-gate 	}
92*7c478bd9Sstevel@tonic-gate 	/* Combine options from different header lines. Precedence is */
93*7c478bd9Sstevel@tonic-gate 	/* toopts --> tropts --> defopts. Results left in defopts */
94*7c478bd9Sstevel@tonic-gate 	mergeopts(&tropts,&defopts);
95*7c478bd9Sstevel@tonic-gate 	mergeopts(&toopts,&defopts);
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	if (defopts.deliv)	rc = DELIVERY;
98*7c478bd9Sstevel@tonic-gate 	else			rc = NODELIVERY;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	if (defopts.rtrn)	rc += RETURN;
101*7c478bd9Sstevel@tonic-gate 	else if (defopts.rept)	rc += REPORT;
102*7c478bd9Sstevel@tonic-gate 	else if (defopts.ign)	rc += IGNORE;
103*7c478bd9Sstevel@tonic-gate 	else			rc += RETURN;
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	Dout(pn, 0,"returning = o%o\n", rc);
106*7c478bd9Sstevel@tonic-gate 	if (svopts)
107*7c478bd9Sstevel@tonic-gate 		*svopts = rc;
108*7c478bd9Sstevel@tonic-gate 	return (rc);
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate 
111*7c478bd9Sstevel@tonic-gate /*
112*7c478bd9Sstevel@tonic-gate  * Pick transport options off of header line.
113*7c478bd9Sstevel@tonic-gate  * If conflicting options found, use MOST demanding; i.e. - /delivery/return.
114*7c478bd9Sstevel@tonic-gate  */
getopts(s,optr)115*7c478bd9Sstevel@tonic-gate static void getopts(s, optr)
116*7c478bd9Sstevel@tonic-gate register char	*s;
117*7c478bd9Sstevel@tonic-gate register struct dlvopts *optr;
118*7c478bd9Sstevel@tonic-gate {
119*7c478bd9Sstevel@tonic-gate 	register char	*op;
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	for (op = strchr (s, '/'); op++; op = strchr(op, '/')) {
122*7c478bd9Sstevel@tonic-gate 		if (casncmp(op, "delivery", 7) == 0) {
123*7c478bd9Sstevel@tonic-gate 			optr->deliv = 1;
124*7c478bd9Sstevel@tonic-gate 			optr->nodeliv = 0;
125*7c478bd9Sstevel@tonic-gate 		} else if (casncmp(op, "nodelivery", 10) == 0) {
126*7c478bd9Sstevel@tonic-gate 			if (optr->deliv == 0) {
127*7c478bd9Sstevel@tonic-gate 				optr->nodeliv = 1;
128*7c478bd9Sstevel@tonic-gate 			}
129*7c478bd9Sstevel@tonic-gate 		} else if (casncmp(op, "report", 6) == 0) {
130*7c478bd9Sstevel@tonic-gate 			optr->ign = 0;
131*7c478bd9Sstevel@tonic-gate 			if (optr->rtrn == 0) {
132*7c478bd9Sstevel@tonic-gate 				optr->rept = 1;
133*7c478bd9Sstevel@tonic-gate 			}
134*7c478bd9Sstevel@tonic-gate 		} else if (casncmp(op, "return", 6) == 0) {
135*7c478bd9Sstevel@tonic-gate 			optr->rtrn = 1;
136*7c478bd9Sstevel@tonic-gate 			optr->rept = optr->ign = 0;
137*7c478bd9Sstevel@tonic-gate 		} else if (casncmp(op, "ignore", 6) == 0) {
138*7c478bd9Sstevel@tonic-gate 			optr->rept = 0;
139*7c478bd9Sstevel@tonic-gate 			if (optr->rtrn == 0) {
140*7c478bd9Sstevel@tonic-gate 				optr->ign = 1;
141*7c478bd9Sstevel@tonic-gate 			}
142*7c478bd9Sstevel@tonic-gate 		}
143*7c478bd9Sstevel@tonic-gate 	}
144*7c478bd9Sstevel@tonic-gate }
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate /*
147*7c478bd9Sstevel@tonic-gate  * Merge options between 2 sets. Higher set has precedence.
148*7c478bd9Sstevel@tonic-gate  * Results left in lower set.
149*7c478bd9Sstevel@tonic-gate  */
mergeopts(higher,lower)150*7c478bd9Sstevel@tonic-gate static void mergeopts(higher, lower)
151*7c478bd9Sstevel@tonic-gate register struct dlvopts *higher, *lower;
152*7c478bd9Sstevel@tonic-gate {
153*7c478bd9Sstevel@tonic-gate 	if (higher->deliv == 1) {
154*7c478bd9Sstevel@tonic-gate 		lower->deliv = 1;
155*7c478bd9Sstevel@tonic-gate 		lower->nodeliv = 0;
156*7c478bd9Sstevel@tonic-gate 	}
157*7c478bd9Sstevel@tonic-gate 	if (higher->nodeliv == 1) {
158*7c478bd9Sstevel@tonic-gate 		lower->nodeliv = 1;
159*7c478bd9Sstevel@tonic-gate 		lower->deliv = 0;
160*7c478bd9Sstevel@tonic-gate 	}
161*7c478bd9Sstevel@tonic-gate 	if (higher->rept == 1) {
162*7c478bd9Sstevel@tonic-gate 		lower->rept = 1;
163*7c478bd9Sstevel@tonic-gate 		lower->rtrn = lower->ign = 0;
164*7c478bd9Sstevel@tonic-gate 	}
165*7c478bd9Sstevel@tonic-gate 	if (higher->rtrn == 1) {
166*7c478bd9Sstevel@tonic-gate 		lower->rtrn = 1;
167*7c478bd9Sstevel@tonic-gate 		lower->rept = lower->ign = 0;
168*7c478bd9Sstevel@tonic-gate 	}
169*7c478bd9Sstevel@tonic-gate 	if (higher->ign == 1) {
170*7c478bd9Sstevel@tonic-gate 		lower->ign = 1;
171*7c478bd9Sstevel@tonic-gate 		lower->rept = lower->rtrn = 0;
172*7c478bd9Sstevel@tonic-gate 	}
173*7c478bd9Sstevel@tonic-gate }
174