comparison src/message.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children 71ce3a1568e9
comparison
equal deleted inserted replaced
9:31cc8a89cb74 10:26e34ae9a3e3
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */ 17 */
18 18
19 #include "masqmail.h" 19 #include "masqmail.h"
20 20
21 message *create_message() 21 message*
22 { 22 create_message()
23 message *msg = (message *)g_malloc(sizeof(message)); 23 {
24 if(msg){ 24 message *msg = (message *) g_malloc(sizeof(message));
25 memset(msg, 0, sizeof(message)); 25 if (msg) {
26 msg->data_size = -1; 26 memset(msg, 0, sizeof(message));
27 } 27 msg->data_size = -1;
28 return msg; 28 }
29 } 29 return msg;
30 30 }
31 gint msg_calc_size(message *msg, gboolean is_smtp) 31
32 { 32 gint
33 GList *node; 33 msg_calc_size(message * msg, gboolean is_smtp)
34 gint l_cnt = 0, c_cnt = 0; 34 {
35 35 GList *node;
36 /* header size */ 36 gint l_cnt = 0, c_cnt = 0;
37 if(msg->hdr_list){ 37
38 for(node = g_list_first(msg->hdr_list); node; node = g_list_next(node)){ 38 /* header size */
39 if(node->data){ 39 if (msg->hdr_list) {
40 header *hdr = (header *)(node->data); 40 for (node = g_list_first(msg->hdr_list); node; node = g_list_next(node)) {
41 if(hdr->header){ 41 if (node->data) {
42 char *p = hdr->header; 42 header *hdr = (header *) (node->data);
43 while(*p){ 43 if (hdr->header) {
44 if(*p++ == '\n') l_cnt++; 44 char *p = hdr->header;
45 c_cnt++; 45 while (*p) {
46 } 46 if (*p++ == '\n')
47 } 47 l_cnt++;
48 } 48 c_cnt++;
49 } 49 }
50 } 50 }
51 51 }
52 /* empty line separating headers from data: */ 52 }
53 c_cnt++; 53 }
54 l_cnt++; 54
55 55 /* empty line separating headers from data: */
56 /* data size */ 56 c_cnt++;
57 if(msg->data_list){ 57 l_cnt++;
58 for(node = g_list_first(msg->data_list); node; node = g_list_next(node)){ 58
59 if(node->data){ 59 /* data size */
60 char *p = node->data; 60 if (msg->data_list) {
61 while(*p){ 61 for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
62 if(*p++ == '\n') l_cnt++; 62 if (node->data) {
63 c_cnt++; 63 char *p = node->data;
64 } 64 while (*p) {
65 } 65 if (*p++ == '\n')
66 } 66 l_cnt++;
67 } 67 c_cnt++;
68 68 }
69 return is_smtp ? c_cnt + l_cnt : c_cnt; 69 }
70 } 70 }
71 71 }
72 void msg_free_data(message *msg) 72
73 { 73 return is_smtp ? c_cnt + l_cnt : c_cnt;
74 GList *node; 74 }
75 75
76 if(msg->data_list){ 76 void
77 for(node = g_list_first(msg->data_list); node; node = g_list_next(node)){ 77 msg_free_data(message * msg)
78 if(node->data) 78 {
79 g_free(node->data); 79 GList *node;
80 } 80
81 g_list_free(msg->data_list); 81 if (msg->data_list) {
82 msg->data_list = NULL; 82 for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
83 } 83 if (node->data)
84 } 84 g_free(node->data);
85 85 }
86 void destroy_message(message *msg) 86 g_list_free(msg->data_list);
87 { 87 msg->data_list = NULL;
88 GList *node; 88 }
89 89 }
90 if(msg->uid) g_free(msg->uid); 90
91 if(msg->ident) g_free(msg->ident); 91 void
92 if(msg->return_path) g_free(msg->return_path); 92 destroy_message(message * msg)
93 93 {
94 if(msg->rcpt_list){ 94 GList *node;
95 for(node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)){ 95
96 if(node->data) 96 if (msg->uid)
97 g_free(node->data); 97 g_free(msg->uid);
98 } 98 if (msg->ident)
99 g_list_free(msg->rcpt_list); 99 g_free(msg->ident);
100 } 100 if (msg->return_path)
101 if(msg->hdr_list){ 101 g_free(msg->return_path);
102 for(node = g_list_first(msg->hdr_list); node; node = g_list_next(node)){ 102
103 if(node->data){ 103 if (msg->rcpt_list) {
104 header *hdr = (header *)(node->data); 104 for (node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)) {
105 if(hdr->header) 105 if (node->data)
106 g_free(hdr->header); 106 g_free(node->data);
107 g_free(node->data); 107 }
108 } 108 g_list_free(msg->rcpt_list);
109 } 109 }
110 g_list_free(msg->hdr_list); 110 if (msg->hdr_list) {
111 } 111 for (node = g_list_first(msg->hdr_list); node; node = g_list_next(node)) {
112 112 if (node->data) {
113 if(msg->full_sender_name) 113 header *hdr = (header *) (node->data);
114 g_free(msg->full_sender_name); 114 if (hdr->header)
115 115 g_free(hdr->header);
116 msg_free_data(msg); 116 g_free(node->data);
117 117 }
118 g_free(msg); 118 }
119 } 119 g_list_free(msg->hdr_list);
120 120 }
121 void destroy_msg_list(GList *msg_list) 121
122 { 122 if (msg->full_sender_name)
123 GList *msg_node; 123 g_free(msg->full_sender_name);
124 124
125 foreach(msg_list, msg_node){ 125 msg_free_data(msg);
126 message *msg = (message *)(msg_node->data); 126
127 destroy_message(msg); 127 g_free(msg);
128 } 128 }
129 g_list_free(msg_list); 129
130 } 130 void
131 131 destroy_msg_list(GList * msg_list)
132 msg_out *create_msg_out(message *msg) 132 {
133 { 133 GList *msg_node;
134 msg_out *msgout = NULL; 134
135 135 foreach(msg_list, msg_node) {
136 msgout = g_malloc(sizeof(msg_out)); 136 message *msg = (message *) (msg_node->data);
137 if(msgout){ 137 destroy_message(msg);
138 msgout->msg = msg; 138 }
139 msgout->return_path = NULL; 139 g_list_free(msg_list);
140 msgout->rcpt_list = NULL; 140 }
141 141
142 msgout->hdr_list = NULL; 142 msg_out*
143 msgout->xtra_hdr_list = NULL; 143 create_msg_out(message * msg)
144 } 144 {
145 return msgout; 145 msg_out *msgout = NULL;
146 } 146
147 147 msgout = g_malloc(sizeof(msg_out));
148 msg_out *clone_msg_out(msg_out *msgout_orig) 148 if (msgout) {
149 { 149 msgout->msg = msg;
150 if(msgout_orig){ 150 msgout->return_path = NULL;
151 msg_out *msgout = create_msg_out(msgout_orig->msg); 151 msgout->rcpt_list = NULL;
152 if(msgout){ 152
153 msgout->msg = msgout_orig->msg; 153 msgout->hdr_list = NULL;
154 if(msgout_orig->return_path) 154 msgout->xtra_hdr_list = NULL;
155 msgout->return_path = copy_address(msgout_orig->return_path); 155 }
156 if(msgout_orig->hdr_list) 156 return msgout;
157 msgout->hdr_list = g_list_copy(msgout_orig->hdr_list); 157 }
158 /* FIXME: if this lives longer than the original 158
159 and we access one of the xtra hdrs, we will segfault 159 msg_out*
160 or cause some weird bugs: */ 160 clone_msg_out(msg_out * msgout_orig)
161 msgout->xtra_hdr_list = NULL; 161 {
162 if(msgout_orig->rcpt_list) 162 if (msgout_orig) {
163 msgout->rcpt_list = g_list_copy(msgout_orig->rcpt_list); 163 msg_out *msgout = create_msg_out(msgout_orig->msg);
164 } 164 if (msgout) {
165 return msgout; 165 msgout->msg = msgout_orig->msg;
166 } 166 if (msgout_orig->return_path)
167 return NULL; 167 msgout->return_path = copy_address(msgout_orig->return_path);
168 } 168 if (msgout_orig->hdr_list)
169 169 msgout->hdr_list = g_list_copy(msgout_orig->hdr_list);
170 GList *create_msg_out_list(GList *msg_list) 170 /* FIXME: if this lives longer than the original
171 { 171 and we access one of the xtra hdrs, we will segfault
172 GList *msgout_list = NULL; 172 or cause some weird bugs: */
173 GList *msg_node; 173 msgout->xtra_hdr_list = NULL;
174 174 if (msgout_orig->rcpt_list)
175 foreach(msg_list, msg_node){ 175 msgout->rcpt_list = g_list_copy(msgout_orig->rcpt_list);
176 message *msg = (message *)(msg_node->data); 176 }
177 msgout_list = g_list_append(msgout_list, create_msg_out(msg)); 177 return msgout;
178 } 178 }
179 return msgout_list; 179 return NULL;
180 } 180 }
181 181
182 void destroy_msg_out(msg_out *msgout) 182 GList*
183 { 183 create_msg_out_list(GList * msg_list)
184 if(msgout){ 184 {
185 if(msgout->return_path) 185 GList *msgout_list = NULL;
186 destroy_address(msgout->return_path); 186 GList *msg_node;
187 if(msgout->hdr_list) 187
188 g_list_free(msgout->hdr_list); 188 foreach(msg_list, msg_node) {
189 if(msgout->xtra_hdr_list){ 189 message *msg = (message *) (msg_node->data);
190 GList *hdr_node; 190 msgout_list = g_list_append(msgout_list, create_msg_out(msg));
191 foreach(msgout->xtra_hdr_list, hdr_node){ 191 }
192 header *hdr = (header *)(hdr_node->data); 192 return msgout_list;
193 destroy_header(hdr); 193 }
194 } 194
195 g_list_free(msgout->xtra_hdr_list); 195 void
196 } 196 destroy_msg_out(msg_out * msgout)
197 g_free(msgout); 197 {
198 } 198 if (msgout) {
199 } 199 if (msgout->return_path)
200 200 destroy_address(msgout->return_path);
201 void destroy_msg_out_list(GList *msgout_list) 201 if (msgout->hdr_list)
202 { 202 g_list_free(msgout->hdr_list);
203 GList *msgout_node; 203 if (msgout->xtra_hdr_list) {
204 204 GList *hdr_node;
205 foreach(msgout_list, msgout_node){ 205 foreach(msgout->xtra_hdr_list, hdr_node) {
206 msg_out *msgout = (msg_out *)(msgout_node->data); 206 header *hdr = (header *) (hdr_node->data);
207 destroy_msg_out(msgout); 207 destroy_header(hdr);
208 } 208 }
209 g_list_free(msgout_list); 209 g_list_free(msgout->xtra_hdr_list);
210 } 210 }
211 g_free(msgout);
212 }
213 }
214
215 void
216 destroy_msg_out_list(GList * msgout_list)
217 {
218 GList *msgout_node;
219
220 foreach(msgout_list, msgout_node) {
221 msg_out *msgout = (msg_out *) (msgout_node->data);
222 destroy_msg_out(msgout);
223 }
224 g_list_free(msgout_list);
225 }