xref: /titanic_52/usr/src/cmd/mail/poplist.c (revision 88447a05f537aabe9a1bc3d5313f22581ec992a7)
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 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI" 	/* SVr4.0 2.	*/
27 #include "mail.h"
28 /*
29  * Remove an entry from its linked list and free any malloc'd memory..
30  */
31 void poplist (hdrtype, where)
32 register int	hdrtype;
33 register int	where;
34 {
35 	struct	hdrs	*hdr2rm, *cont2rm, *nextcont;
36 
37 	/* Remove first/last entry from list */
38 
39 	hdr2rm = (where == HEAD ?
40 			hdrlines[hdrtype].head : hdrlines[hdrtype].tail);
41 
42 	if (hdr2rm == (struct hdrs *)NULL) {
43 		return;
44 	}
45 	if (where == HEAD) {
46 		if (hdr2rm->next == (struct hdrs *)NULL) {
47 			/* Only 1 entry in list */
48 			hdrlines[hdrtype].head = hdrlines[hdrtype].tail =
49 							(struct hdrs *)NULL;
50 		} else {
51 			hdrlines[hdrtype].head = hdr2rm->next;
52 			hdr2rm->next->prev = (struct hdrs *)NULL;
53 		}
54 	} else {
55 		if (hdr2rm->prev == (struct hdrs *)NULL) {
56 			/* Only 1 entry in list */
57 			hdrlines[hdrtype].head = hdrlines[hdrtype].tail =
58 							(struct hdrs *)NULL;
59 		} else {
60 			hdrlines[hdrtype].tail = hdr2rm->prev;
61 			hdr2rm->prev->next = (struct hdrs *)NULL;
62 		}
63 	}
64 	/* Keep track of total bytes added to message due to    */
65 	/* selected lines in case non-delivery                  */
66 	/* notification needs to be sent. (See also copylet())  */
67 	if (hdrtype == H_AFWDFROM) {
68 	    affbytecnt -=
69 		(strlen(header[H_AFWDFROM].tag) + strlen(hdr2rm->value) + 2);
70 	    affcnt--;
71 	}
72 	if (hdrtype == H_RECEIVED) {
73 	    rcvbytecnt -=
74 		(strlen(header[H_RECEIVED].tag) + strlen(hdr2rm->value) + 2);
75 	}
76 
77 	cont2rm = hdr2rm->cont;
78 	while (cont2rm != (struct hdrs *)NULL) {
79 		nextcont = cont2rm->next;
80 		if (hdrtype == H_AFWDFROM) {
81 		    affbytecnt -= (strlen(cont2rm->value) + 1);
82 		    affcnt--;
83 		}
84 		if (hdrtype == H_RECEIVED) {
85 		    rcvbytecnt -= (strlen(cont2rm->value) + 1);
86 		}
87 		free ((char *)cont2rm);
88 		cont2rm = nextcont;
89 	}
90 	free ((char *)hdr2rm);
91 }
92