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

Contents of /imapfilter/destroy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Fri Feb 13 12:17:15 2004 UTC (20 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.4: +43 -43 lines
File MIME type: text/plain
Stylistic changes.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26