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