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