/[imapfilter]/imapfilter/destroy.c
ViewVC logotype

Contents of /imapfilter/destroy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Sat Feb 14 19:14:43 2004 UTC (20 years, 1 month ago) by lefcha
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +2 -2 lines
File MIME type: text/plain
Indentation.

1 #include <stdio.h>
2
3 #include "config.h"
4 #include "imapfilter.h"
5 #include "account.h"
6 #include "filter.h"
7
8
9 extern account_t *accounts;
10 extern mboxgrp_t *mboxgrps;
11 extern filter_t *filters;
12
13 extern account_t *curacct;
14 extern filter_t *curfltr;
15
16
17 void destroy_mboxgrps(mboxgrp_t * g);
18 void destroy_mboxes(mbox_t * m);
19 void destroy_accounts(account_t * a);
20 void destroy_filters(filter_t * f);
21 void destroy_masks(mask_t * k);
22
23
24 /*
25 * Free allocated memory of all data structures.
26 */
27 void
28 destroy_all(void)
29 {
30
31 destroy_accounts(accounts);
32 accounts = NULL;
33 curacct = NULL;
34 destroy_filters(filters);
35 filters = NULL;
36 curfltr = NULL;
37 destroy_mboxgrps(mboxgrps);
38 mboxgrps = NULL;
39 }
40
41
42 /*
43 * Free allocated memory of data structures that are not needed anymore.
44 */
45 void
46 destroy_unneeded(void)
47 {
48
49 destroy_mboxgrps(mboxgrps);
50 mboxgrps = NULL;
51 }
52
53
54 /*
55 * Go through the mailbox-group tree, and free the allocated memory of each
56 * node.
57 */
58 void
59 destroy_mboxgrps(mboxgrp_t * g)
60 {
61
62 if (g == NULL)
63 return;
64
65 if (g->left != NULL) {
66 destroy_mboxgrps(g->left);
67 g->left = NULL;
68 }
69 if (g->right != NULL) {
70 destroy_mboxgrps(g->right);
71 g->right = NULL;
72 }
73 debug("deleting folder: '%s'\n", g->key);
74
75 xfree(g);
76 }
77
78
79 /*
80 * Go through the mailbox linked list of the account and free the allocated
81 * memory of each node.
82 */
83 void
84 destroy_mboxes(mbox_t * m)
85 {
86 mbox_t *p, *t;
87
88 for (p = m; p != NULL; p = t) {
89 t = p->next;
90 debug("deleting mbox: '%s'\n", p->name);
91 xfree(p);
92 }
93 }
94
95
96 /*
97 * Go through the accounts' linked list and free the allocated memory of
98 * each node.
99 */
100 void
101 destroy_accounts(account_t * a)
102 {
103 account_t *p, *t;
104
105 for (p = a; p != NULL; p = t) {
106 t = p->next;
107 debug("deleting account: '%s'\n", p->key);
108 destroy_mboxes(p->mboxes);
109 sfree(p->pass);
110 xfree(p);
111 }
112 }
113
114
115 /*
116 * Go through the filters' tree and free the allocated memory of each node.
117 */
118 void
119 destroy_filters(filter_t * f)
120 {
121
122 if (f == NULL)
123 return;
124
125 if (f->left != NULL) {
126 destroy_filters(f->left);
127 f->left = NULL;
128 }
129 if (f->right != NULL) {
130 destroy_filters(f->right);
131 f->right = NULL;
132 }
133 debug("deleting filter: '%s'\n", f->key);
134 destroy_masks(f->masks);
135 xfree(f);
136 }
137
138
139 /*
140 * Go through the masks' linked list and free the allocated memory of each
141 * node.
142 */
143 void
144 destroy_masks(mask_t * k)
145 {
146 mask_t *p, *t;
147
148 for (p = k; p != NULL; p = t) {
149 t = p->next;
150 debug("deleting mask: '%s'\n", p->body);
151 xfree(p);
152 }
153 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26