Diffstat (limited to 'kmicromail/libetpan/mime/mailmime_types.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libetpan/mime/mailmime_types.c | 750 |
1 files changed, 750 insertions, 0 deletions
diff --git a/kmicromail/libetpan/mime/mailmime_types.c b/kmicromail/libetpan/mime/mailmime_types.c new file mode 100644 index 0000000..a81c87a --- a/dev/null +++ b/kmicromail/libetpan/mime/mailmime_types.c | |||
@@ -0,0 +1,750 @@ | |||
1 | /* | ||
2 | * libEtPan! -- a mail stuff library | ||
3 | * | ||
4 | * Copyright (C) 2001, 2002 - DINH Viet Hoa | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. Neither the name of the libEtPan! project nor the names of its | ||
16 | * contributors may be used to endorse or promote products derived | ||
17 | * from this software without specific prior written permission. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
29 | * SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * $Id$ | ||
34 | */ | ||
35 | |||
36 | #include "mailmime_types.h" | ||
37 | #include "mmapstring.h" | ||
38 | |||
39 | #include <string.h> | ||
40 | #include <stdlib.h> | ||
41 | |||
42 | void mailmime_attribute_free(char * attribute) | ||
43 | { | ||
44 | mailmime_token_free(attribute); | ||
45 | } | ||
46 | |||
47 | |||
48 | |||
49 | struct mailmime_composite_type * | ||
50 | mailmime_composite_type_new(int ct_type, char * ct_token) | ||
51 | { | ||
52 | struct mailmime_composite_type * ct; | ||
53 | |||
54 | ct = malloc(sizeof(* ct)); | ||
55 | if (ct == NULL) | ||
56 | return NULL; | ||
57 | |||
58 | ct->ct_type = ct_type; | ||
59 | ct->ct_token = ct_token; | ||
60 | |||
61 | return ct; | ||
62 | } | ||
63 | |||
64 | void mailmime_composite_type_free(struct mailmime_composite_type * ct) | ||
65 | { | ||
66 | if (ct->ct_token != NULL) | ||
67 | mailmime_extension_token_free(ct->ct_token); | ||
68 | free(ct); | ||
69 | } | ||
70 | |||
71 | |||
72 | struct mailmime_content * | ||
73 | mailmime_content_new(struct mailmime_type * ct_type, | ||
74 | char * ct_subtype, | ||
75 | clist * ct_parameters) | ||
76 | { | ||
77 | struct mailmime_content * content; | ||
78 | |||
79 | content = malloc(sizeof(* content)); | ||
80 | if (content == NULL) | ||
81 | return NULL; | ||
82 | |||
83 | content->ct_type = ct_type; | ||
84 | content->ct_subtype = ct_subtype; | ||
85 | content->ct_parameters = ct_parameters; | ||
86 | |||
87 | return content; | ||
88 | } | ||
89 | |||
90 | void mailmime_content_free(struct mailmime_content * content) | ||
91 | { | ||
92 | mailmime_type_free(content->ct_type); | ||
93 | mailmime_subtype_free(content->ct_subtype); | ||
94 | if (content->ct_parameters != NULL) { | ||
95 | clist_foreach(content->ct_parameters, | ||
96 | (clist_func) mailmime_parameter_free, NULL); | ||
97 | clist_free(content->ct_parameters); | ||
98 | } | ||
99 | |||
100 | free(content); | ||
101 | } | ||
102 | |||
103 | |||
104 | void mailmime_description_free(char * description) | ||
105 | { | ||
106 | free(description); | ||
107 | } | ||
108 | |||
109 | struct mailmime_discrete_type * | ||
110 | mailmime_discrete_type_new(int dt_type, char * dt_extension) | ||
111 | { | ||
112 | struct mailmime_discrete_type * discrete_type; | ||
113 | |||
114 | discrete_type = malloc(sizeof(* discrete_type)); | ||
115 | if (discrete_type == NULL) | ||
116 | return NULL; | ||
117 | |||
118 | discrete_type->dt_type = dt_type; | ||
119 | discrete_type->dt_extension = dt_extension; | ||
120 | |||
121 | return discrete_type; | ||
122 | } | ||
123 | |||
124 | void mailmime_discrete_type_free(struct mailmime_discrete_type * discrete_type) | ||
125 | { | ||
126 | if (discrete_type->dt_extension != NULL) | ||
127 | mailmime_extension_token_free(discrete_type->dt_extension); | ||
128 | free(discrete_type); | ||
129 | } | ||
130 | |||
131 | void mailmime_encoding_free(struct mailmime_mechanism * encoding) | ||
132 | { | ||
133 | mailmime_mechanism_free(encoding); | ||
134 | } | ||
135 | |||
136 | void mailmime_extension_token_free(char * extension) | ||
137 | { | ||
138 | mailmime_token_free(extension); | ||
139 | } | ||
140 | |||
141 | void mailmime_id_free(char * id) | ||
142 | { | ||
143 | mailimf_msg_id_free(id); | ||
144 | } | ||
145 | |||
146 | struct mailmime_mechanism * mailmime_mechanism_new(int enc_type, char * enc_token) | ||
147 | { | ||
148 | struct mailmime_mechanism * mechanism; | ||
149 | |||
150 | mechanism = malloc(sizeof(* mechanism)); | ||
151 | if (mechanism == NULL) | ||
152 | return NULL; | ||
153 | |||
154 | mechanism->enc_type = enc_type; | ||
155 | mechanism->enc_token = enc_token; | ||
156 | |||
157 | return mechanism; | ||
158 | } | ||
159 | |||
160 | void mailmime_mechanism_free(struct mailmime_mechanism * mechanism) | ||
161 | { | ||
162 | if (mechanism->enc_token != NULL) | ||
163 | mailmime_token_free(mechanism->enc_token); | ||
164 | free(mechanism); | ||
165 | } | ||
166 | |||
167 | struct mailmime_parameter * | ||
168 | mailmime_parameter_new(char * pa_name, char * pa_value) | ||
169 | { | ||
170 | struct mailmime_parameter * parameter; | ||
171 | |||
172 | parameter = malloc(sizeof(* parameter)); | ||
173 | if (parameter == NULL) | ||
174 | return NULL; | ||
175 | |||
176 | parameter->pa_name = pa_name; | ||
177 | parameter->pa_value = pa_value; | ||
178 | |||
179 | return parameter; | ||
180 | } | ||
181 | |||
182 | void mailmime_parameter_free(struct mailmime_parameter * parameter) | ||
183 | { | ||
184 | mailmime_attribute_free(parameter->pa_name); | ||
185 | mailmime_value_free(parameter->pa_value); | ||
186 | free(parameter); | ||
187 | } | ||
188 | |||
189 | |||
190 | void mailmime_subtype_free(char * subtype) | ||
191 | { | ||
192 | mailmime_extension_token_free(subtype); | ||
193 | } | ||
194 | |||
195 | |||
196 | void mailmime_token_free(char * token) | ||
197 | { | ||
198 | free(token); | ||
199 | } | ||
200 | |||
201 | |||
202 | struct mailmime_type * | ||
203 | mailmime_type_new(int tp_type, | ||
204 | struct mailmime_discrete_type * tp_discrete_type, | ||
205 | struct mailmime_composite_type * tp_composite_type) | ||
206 | { | ||
207 | struct mailmime_type * mime_type; | ||
208 | |||
209 | mime_type = malloc(sizeof(* mime_type)); | ||
210 | if (mime_type == NULL) | ||
211 | return NULL; | ||
212 | |||
213 | mime_type->tp_type = tp_type; | ||
214 | switch (tp_type) { | ||
215 | case MAILMIME_TYPE_DISCRETE_TYPE: | ||
216 | mime_type->tp_data.tp_discrete_type = tp_discrete_type; | ||
217 | break; | ||
218 | case MAILMIME_TYPE_COMPOSITE_TYPE: | ||
219 | mime_type->tp_data.tp_composite_type = tp_composite_type; | ||
220 | break; | ||
221 | } | ||
222 | |||
223 | return mime_type; | ||
224 | } | ||
225 | |||
226 | void mailmime_type_free(struct mailmime_type * type) | ||
227 | { | ||
228 | switch (type->tp_type) { | ||
229 | case MAILMIME_TYPE_DISCRETE_TYPE: | ||
230 | mailmime_discrete_type_free(type->tp_data.tp_discrete_type); | ||
231 | break; | ||
232 | case MAILMIME_TYPE_COMPOSITE_TYPE: | ||
233 | mailmime_composite_type_free(type->tp_data.tp_composite_type); | ||
234 | break; | ||
235 | } | ||
236 | free(type); | ||
237 | } | ||
238 | |||
239 | void mailmime_value_free(char * value) | ||
240 | { | ||
241 | free(value); | ||
242 | } | ||
243 | |||
244 | |||
245 | /* | ||
246 | void mailmime_x_token_free(gchar * x_token) | ||
247 | { | ||
248 | g_free(x_token); | ||
249 | } | ||
250 | */ | ||
251 | |||
252 | struct mailmime_field * | ||
253 | mailmime_field_new(int fld_type, | ||
254 | struct mailmime_content * fld_content, | ||
255 | struct mailmime_mechanism * fld_encoding, | ||
256 | char * fld_id, | ||
257 | char * fld_description, | ||
258 | uint32_t fld_version, | ||
259 | struct mailmime_disposition * fld_disposition, | ||
260 | struct mailmime_language * fld_language) | ||
261 | { | ||
262 | struct mailmime_field * field; | ||
263 | |||
264 | field = malloc(sizeof(* field)); | ||
265 | if (field == NULL) | ||
266 | return NULL; | ||
267 | field->fld_type = fld_type; | ||
268 | |||
269 | switch (fld_type) { | ||
270 | case MAILMIME_FIELD_TYPE: | ||
271 | field->fld_data.fld_content = fld_content; | ||
272 | break; | ||
273 | case MAILMIME_FIELD_TRANSFER_ENCODING: | ||
274 | field->fld_data.fld_encoding = fld_encoding; | ||
275 | break; | ||
276 | case MAILMIME_FIELD_ID: | ||
277 | field->fld_data.fld_id = fld_id; | ||
278 | break; | ||
279 | case MAILMIME_FIELD_DESCRIPTION: | ||
280 | field->fld_data.fld_description = fld_description; | ||
281 | break; | ||
282 | case MAILMIME_FIELD_VERSION: | ||
283 | field->fld_data.fld_version = fld_version; | ||
284 | break; | ||
285 | case MAILMIME_FIELD_DISPOSITION: | ||
286 | field->fld_data.fld_disposition = fld_disposition; | ||
287 | break; | ||
288 | case MAILMIME_FIELD_LANGUAGE: | ||
289 | field->fld_data.fld_language = fld_language; | ||
290 | break; | ||
291 | } | ||
292 | return field; | ||
293 | } | ||
294 | |||
295 | void mailmime_field_free(struct mailmime_field * field) | ||
296 | { | ||
297 | switch (field->fld_type) { | ||
298 | case MAILMIME_FIELD_TYPE: | ||
299 | if (field->fld_data.fld_content != NULL) | ||
300 | mailmime_content_free(field->fld_data.fld_content); | ||
301 | break; | ||
302 | case MAILMIME_FIELD_TRANSFER_ENCODING: | ||
303 | if (field->fld_data.fld_encoding != NULL) | ||
304 | mailmime_encoding_free(field->fld_data.fld_encoding); | ||
305 | break; | ||
306 | case MAILMIME_FIELD_ID: | ||
307 | if (field->fld_data.fld_id != NULL) | ||
308 | mailmime_id_free(field->fld_data.fld_id); | ||
309 | break; | ||
310 | case MAILMIME_FIELD_DESCRIPTION: | ||
311 | if (field->fld_data.fld_description != NULL) | ||
312 | mailmime_description_free(field->fld_data.fld_description); | ||
313 | break; | ||
314 | case MAILMIME_FIELD_DISPOSITION: | ||
315 | if (field->fld_data.fld_disposition != NULL) | ||
316 | mailmime_disposition_free(field->fld_data.fld_disposition); | ||
317 | break; | ||
318 | case MAILMIME_FIELD_LANGUAGE: | ||
319 | if (field->fld_data.fld_language != NULL) | ||
320 | mailmime_language_free(field->fld_data.fld_language); | ||
321 | break; | ||
322 | } | ||
323 | |||
324 | free(field); | ||
325 | } | ||
326 | |||
327 | struct mailmime_fields * mailmime_fields_new(clist * fld_list) | ||
328 | { | ||
329 | struct mailmime_fields * fields; | ||
330 | |||
331 | fields = malloc(sizeof(* fields)); | ||
332 | if (fields == NULL) | ||
333 | return NULL; | ||
334 | |||
335 | fields->fld_list = fld_list; | ||
336 | |||
337 | return fields; | ||
338 | } | ||
339 | |||
340 | void mailmime_fields_free(struct mailmime_fields * fields) | ||
341 | { | ||
342 | clist_foreach(fields->fld_list, (clist_func) mailmime_field_free, NULL); | ||
343 | clist_free(fields->fld_list); | ||
344 | free(fields); | ||
345 | } | ||
346 | |||
347 | |||
348 | /* | ||
349 | struct mailmime_body_part * | ||
350 | mailmime_body_part_new(gchar * text, guint32 size) | ||
351 | { | ||
352 | struct mailmime_body_part * body_part; | ||
353 | |||
354 | body_part = g_new(struct mailmime_body_part, 1); | ||
355 | if (body_part == NULL) | ||
356 | return NULL; | ||
357 | |||
358 | body_part->text = text; | ||
359 | body_part->size = size; | ||
360 | |||
361 | return body_part; | ||
362 | } | ||
363 | |||
364 | void mailmime_body_part_free(struct mailmime_body_part * body_part) | ||
365 | { | ||
366 | g_free(body_part); | ||
367 | } | ||
368 | */ | ||
369 | |||
370 | struct mailmime_multipart_body * | ||
371 | mailmime_multipart_body_new(clist * bd_list) | ||
372 | { | ||
373 | struct mailmime_multipart_body * mp_body; | ||
374 | |||
375 | mp_body = malloc(sizeof(* mp_body)); | ||
376 | if (mp_body == NULL) | ||
377 | return NULL; | ||
378 | |||
379 | mp_body->bd_list = bd_list; | ||
380 | |||
381 | return mp_body; | ||
382 | } | ||
383 | |||
384 | void mailmime_multipart_body_free(struct mailmime_multipart_body * mp_body) | ||
385 | { | ||
386 | clist_foreach(mp_body->bd_list, (clist_func) mailimf_body_free, NULL); | ||
387 | clist_free(mp_body->bd_list); | ||
388 | free(mp_body); | ||
389 | } | ||
390 | |||
391 | |||
392 | |||
393 | |||
394 | struct mailmime * mailmime_new(int mm_type, | ||
395 | const char * mm_mime_start, size_t mm_length, | ||
396 | struct mailmime_fields * mm_mime_fields, | ||
397 | struct mailmime_content * mm_content_type, | ||
398 | struct mailmime_data * mm_body, | ||
399 | struct mailmime_data * mm_preamble, | ||
400 | struct mailmime_data * mm_epilogue, | ||
401 | clist * mm_mp_list, | ||
402 | struct mailimf_fields * mm_fields, | ||
403 | struct mailmime * mm_msg_mime) | ||
404 | { | ||
405 | struct mailmime * mime; | ||
406 | clistiter * cur; | ||
407 | |||
408 | mime = malloc(sizeof(* mime)); | ||
409 | if (mime == NULL) | ||
410 | return NULL; | ||
411 | |||
412 | mime->mm_parent = NULL; | ||
413 | mime->mm_parent_type = MAILMIME_NONE; | ||
414 | mime->mm_multipart_pos = NULL; | ||
415 | |||
416 | mime->mm_type = mm_type; | ||
417 | mime->mm_mime_start = mm_mime_start; | ||
418 | mime->mm_length = mm_length; | ||
419 | mime->mm_mime_fields = mm_mime_fields; | ||
420 | mime->mm_content_type = mm_content_type; | ||
421 | |||
422 | mime->mm_body = mm_body; | ||
423 | |||
424 | switch (mm_type) { | ||
425 | case MAILMIME_SINGLE: | ||
426 | mime->mm_data.mm_single = mm_body; | ||
427 | break; | ||
428 | |||
429 | case MAILMIME_MULTIPLE: | ||
430 | mime->mm_data.mm_multipart.mm_preamble = mm_preamble; | ||
431 | mime->mm_data.mm_multipart.mm_epilogue = mm_epilogue; | ||
432 | mime->mm_data.mm_multipart.mm_mp_list = mm_mp_list; | ||
433 | |||
434 | for(cur = clist_begin(mm_mp_list) ; cur != NULL ; | ||
435 | cur = clist_next(cur)) { | ||
436 | struct mailmime * submime; | ||
437 | |||
438 | submime = clist_content(cur); | ||
439 | submime->mm_parent = mime; | ||
440 | submime->mm_parent_type = MAILMIME_MULTIPLE; | ||
441 | submime->mm_multipart_pos = cur; | ||
442 | } | ||
443 | break; | ||
444 | |||
445 | case MAILMIME_MESSAGE: | ||
446 | mime->mm_data.mm_message.mm_fields = mm_fields; | ||
447 | mime->mm_data.mm_message.mm_msg_mime = mm_msg_mime; | ||
448 | if (mm_msg_mime != NULL) { | ||
449 | mm_msg_mime->mm_parent = mime; | ||
450 | mm_msg_mime->mm_parent_type = MAILMIME_MESSAGE; | ||
451 | } | ||
452 | break; | ||
453 | |||
454 | } | ||
455 | |||
456 | return mime; | ||
457 | } | ||
458 | |||
459 | void mailmime_free(struct mailmime * mime) | ||
460 | { | ||
461 | if (mime->mm_body != NULL) | ||
462 | mailmime_data_free(mime->mm_body); | ||
463 | switch (mime->mm_type) { | ||
464 | case MAILMIME_SINGLE: | ||
465 | /* do nothing */ | ||
466 | break; | ||
467 | |||
468 | case MAILMIME_MULTIPLE: | ||
469 | if (mime->mm_data.mm_multipart.mm_preamble != NULL) | ||
470 | mailmime_data_free(mime->mm_data.mm_multipart.mm_preamble); | ||
471 | if (mime->mm_data.mm_multipart.mm_epilogue != NULL) | ||
472 | mailmime_data_free(mime->mm_data.mm_multipart.mm_epilogue); | ||
473 | clist_foreach(mime->mm_data.mm_multipart.mm_mp_list, | ||
474 | (clist_func) mailmime_free, NULL); | ||
475 | clist_free(mime->mm_data.mm_multipart.mm_mp_list); | ||
476 | break; | ||
477 | |||
478 | case MAILMIME_MESSAGE: | ||
479 | if (mime->mm_data.mm_message.mm_fields != NULL) | ||
480 | mailimf_fields_free(mime->mm_data.mm_message.mm_fields); | ||
481 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) | ||
482 | mailmime_free(mime->mm_data.mm_message.mm_msg_mime); | ||
483 | break; | ||
484 | |||
485 | } | ||
486 | if (mime->mm_mime_fields != NULL) | ||
487 | mailmime_fields_free(mime->mm_mime_fields); | ||
488 | if (mime->mm_content_type != NULL) | ||
489 | mailmime_content_free(mime->mm_content_type); | ||
490 | free(mime); | ||
491 | } | ||
492 | |||
493 | |||
494 | |||
495 | struct mailmime_encoded_word * | ||
496 | mailmime_encoded_word_new(char * wd_charset, char * wd_text) | ||
497 | { | ||
498 | struct mailmime_encoded_word * ew; | ||
499 | |||
500 | ew = malloc(sizeof(* ew)); | ||
501 | if (ew == NULL) | ||
502 | return NULL; | ||
503 | ew->wd_charset = wd_charset; | ||
504 | ew->wd_text = wd_text; | ||
505 | |||
506 | return ew; | ||
507 | } | ||
508 | |||
509 | void mailmime_charset_free(char * charset) | ||
510 | { | ||
511 | free(charset); | ||
512 | } | ||
513 | |||
514 | void mailmime_encoded_text_free(char * text) | ||
515 | { | ||
516 | free(text); | ||
517 | } | ||
518 | |||
519 | void mailmime_encoded_word_free(struct mailmime_encoded_word * ew) | ||
520 | { | ||
521 | mailmime_charset_free(ew->wd_charset); | ||
522 | mailmime_encoded_text_free(ew->wd_text); | ||
523 | free(ew); | ||
524 | } | ||
525 | |||
526 | |||
527 | |||
528 | /* mailmime_disposition */ | ||
529 | |||
530 | |||
531 | struct mailmime_disposition * | ||
532 | mailmime_disposition_new(struct mailmime_disposition_type * dsp_type, | ||
533 | clist * dsp_parms) | ||
534 | { | ||
535 | struct mailmime_disposition * dsp; | ||
536 | |||
537 | dsp = malloc(sizeof(* dsp)); | ||
538 | if (dsp == NULL) | ||
539 | return NULL; | ||
540 | dsp->dsp_type = dsp_type; | ||
541 | dsp->dsp_parms = dsp_parms; | ||
542 | |||
543 | return dsp; | ||
544 | } | ||
545 | |||
546 | void mailmime_disposition_free(struct mailmime_disposition * dsp) | ||
547 | { | ||
548 | mailmime_disposition_type_free(dsp->dsp_type); | ||
549 | clist_foreach(dsp->dsp_parms, | ||
550 | (clist_func) mailmime_disposition_parm_free, NULL); | ||
551 | clist_free(dsp->dsp_parms); | ||
552 | free(dsp); | ||
553 | } | ||
554 | |||
555 | |||
556 | |||
557 | struct mailmime_disposition_type * | ||
558 | mailmime_disposition_type_new(int dsp_type, char * dsp_extension) | ||
559 | { | ||
560 | struct mailmime_disposition_type * m_dsp_type; | ||
561 | |||
562 | m_dsp_type = malloc(sizeof(* m_dsp_type)); | ||
563 | if (m_dsp_type == NULL) | ||
564 | return NULL; | ||
565 | |||
566 | m_dsp_type->dsp_type = dsp_type; | ||
567 | m_dsp_type->dsp_extension = dsp_extension; | ||
568 | |||
569 | return m_dsp_type; | ||
570 | } | ||
571 | |||
572 | void mailmime_disposition_type_free(struct mailmime_disposition_type * dsp_type) | ||
573 | { | ||
574 | if (dsp_type->dsp_extension != NULL) | ||
575 | free(dsp_type->dsp_extension); | ||
576 | free(dsp_type); | ||
577 | } | ||
578 | |||
579 | |||
580 | struct mailmime_disposition_parm * | ||
581 | mailmime_disposition_parm_new(int pa_type, | ||
582 | char * pa_filename, | ||
583 | char * pa_creation_date, | ||
584 | char * pa_modification_date, | ||
585 | char * pa_read_date, | ||
586 | size_t pa_size, | ||
587 | struct mailmime_parameter * pa_parameter) | ||
588 | { | ||
589 | struct mailmime_disposition_parm * dsp_parm; | ||
590 | |||
591 | dsp_parm = malloc(sizeof(* dsp_parm)); | ||
592 | if (dsp_parm == NULL) | ||
593 | return NULL; | ||
594 | |||
595 | dsp_parm->pa_type = pa_type; | ||
596 | switch (pa_type) { | ||
597 | case MAILMIME_DISPOSITION_PARM_FILENAME: | ||
598 | dsp_parm->pa_data.pa_filename = pa_filename; | ||
599 | break; | ||
600 | case MAILMIME_DISPOSITION_PARM_CREATION_DATE: | ||
601 | dsp_parm->pa_data.pa_creation_date = pa_creation_date; | ||
602 | break; | ||
603 | case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: | ||
604 | dsp_parm->pa_data.pa_modification_date = pa_modification_date; | ||
605 | break; | ||
606 | case MAILMIME_DISPOSITION_PARM_READ_DATE: | ||
607 | dsp_parm->pa_data.pa_read_date = pa_read_date; | ||
608 | break; | ||
609 | case MAILMIME_DISPOSITION_PARM_SIZE: | ||
610 | dsp_parm->pa_data.pa_size = pa_size; | ||
611 | break; | ||
612 | case MAILMIME_DISPOSITION_PARM_PARAMETER: | ||
613 | dsp_parm->pa_data.pa_parameter = pa_parameter; | ||
614 | break; | ||
615 | } | ||
616 | |||
617 | return dsp_parm; | ||
618 | } | ||
619 | |||
620 | void mailmime_disposition_parm_free(struct mailmime_disposition_parm * | ||
621 | dsp_parm) | ||
622 | { | ||
623 | switch (dsp_parm->pa_type) { | ||
624 | case MAILMIME_DISPOSITION_PARM_FILENAME: | ||
625 | mailmime_filename_parm_free(dsp_parm->pa_data.pa_filename); | ||
626 | break; | ||
627 | case MAILMIME_DISPOSITION_PARM_CREATION_DATE: | ||
628 | mailmime_creation_date_parm_free(dsp_parm->pa_data.pa_creation_date); | ||
629 | break; | ||
630 | case MAILMIME_DISPOSITION_PARM_MODIFICATION_DATE: | ||
631 | mailmime_modification_date_parm_free(dsp_parm->pa_data.pa_modification_date); | ||
632 | break; | ||
633 | case MAILMIME_DISPOSITION_PARM_READ_DATE: | ||
634 | mailmime_read_date_parm_free(dsp_parm->pa_data.pa_read_date); | ||
635 | break; | ||
636 | case MAILMIME_DISPOSITION_PARM_PARAMETER: | ||
637 | mailmime_parameter_free(dsp_parm->pa_data.pa_parameter); | ||
638 | break; | ||
639 | } | ||
640 | |||
641 | free(dsp_parm); | ||
642 | } | ||
643 | |||
644 | |||
645 | void mailmime_filename_parm_free(char * filename) | ||
646 | { | ||
647 | mailmime_value_free(filename); | ||
648 | } | ||
649 | |||
650 | void mailmime_creation_date_parm_free(char * date) | ||
651 | { | ||
652 | mailmime_quoted_date_time_free(date); | ||
653 | } | ||
654 | |||
655 | void mailmime_modification_date_parm_free(char * date) | ||
656 | { | ||
657 | mailmime_quoted_date_time_free(date); | ||
658 | } | ||
659 | |||
660 | void mailmime_read_date_parm_free(char * date) | ||
661 | { | ||
662 | mailmime_quoted_date_time_free(date); | ||
663 | } | ||
664 | |||
665 | void mailmime_quoted_date_time_free(char * date) | ||
666 | { | ||
667 | mailimf_quoted_string_free(date); | ||
668 | } | ||
669 | |||
670 | struct mailmime_section * mailmime_section_new(clist * sec_list) | ||
671 | { | ||
672 | struct mailmime_section * section; | ||
673 | |||
674 | section = malloc(sizeof(* section)); | ||
675 | if (section == NULL) | ||
676 | return NULL; | ||
677 | |||
678 | section->sec_list = sec_list; | ||
679 | |||
680 | return section; | ||
681 | } | ||
682 | |||
683 | void mailmime_section_free(struct mailmime_section * section) | ||
684 | { | ||
685 | clist_foreach(section->sec_list, (clist_func) free, NULL); | ||
686 | clist_free(section->sec_list); | ||
687 | free(section); | ||
688 | } | ||
689 | |||
690 | |||
691 | |||
692 | struct mailmime_language * mailmime_language_new(clist * lg_list) | ||
693 | { | ||
694 | struct mailmime_language * lang; | ||
695 | |||
696 | lang = malloc(sizeof(* lang)); | ||
697 | if (lang == NULL) | ||
698 | return NULL; | ||
699 | |||
700 | lang->lg_list = lg_list; | ||
701 | |||
702 | return lang; | ||
703 | } | ||
704 | |||
705 | void mailmime_language_free(struct mailmime_language * lang) | ||
706 | { | ||
707 | clist_foreach(lang->lg_list, (clist_func) mailimf_atom_free, NULL); | ||
708 | clist_free(lang->lg_list); | ||
709 | free(lang); | ||
710 | } | ||
711 | |||
712 | void mailmime_decoded_part_free(char * part) | ||
713 | { | ||
714 | mmap_string_unref(part); | ||
715 | } | ||
716 | |||
717 | struct mailmime_data * mailmime_data_new(int dt_type, int dt_encoding, | ||
718 | int dt_encoded, const char * dt_data, size_t dt_length, char * dt_filename) | ||
719 | { | ||
720 | struct mailmime_data * mime_data; | ||
721 | |||
722 | mime_data = malloc(sizeof(* mime_data)); | ||
723 | if (mime_data == NULL) | ||
724 | return NULL; | ||
725 | |||
726 | mime_data->dt_type = dt_type; | ||
727 | mime_data->dt_encoding = dt_encoding; | ||
728 | mime_data->dt_encoded = dt_encoded; | ||
729 | switch (dt_type) { | ||
730 | case MAILMIME_DATA_TEXT: | ||
731 | mime_data->dt_data.dt_text.dt_data = dt_data; | ||
732 | mime_data->dt_data.dt_text.dt_length = dt_length; | ||
733 | break; | ||
734 | case MAILMIME_DATA_FILE: | ||
735 | mime_data->dt_data.dt_filename = dt_filename; | ||
736 | break; | ||
737 | } | ||
738 | |||
739 | return mime_data; | ||
740 | } | ||
741 | |||
742 | void mailmime_data_free(struct mailmime_data * mime_data) | ||
743 | { | ||
744 | switch (mime_data->dt_type) { | ||
745 | case MAILMIME_DATA_FILE: | ||
746 | free(mime_data->dt_data.dt_filename); | ||
747 | break; | ||
748 | } | ||
749 | free(mime_data); | ||
750 | } | ||