summaryrefslogtreecommitdiffabout
path: root/libetpan/src/low-level/imap/mailimap_types_helper.c
Unidiff
Diffstat (limited to 'libetpan/src/low-level/imap/mailimap_types_helper.c') (more/less context) (ignore whitespace changes)
-rw-r--r--libetpan/src/low-level/imap/mailimap_types_helper.c1269
1 files changed, 1269 insertions, 0 deletions
diff --git a/libetpan/src/low-level/imap/mailimap_types_helper.c b/libetpan/src/low-level/imap/mailimap_types_helper.c
new file mode 100644
index 0000000..574897b
--- a/dev/null
+++ b/libetpan/src/low-level/imap/mailimap_types_helper.c
@@ -0,0 +1,1269 @@
1/*
2 * libEtPan! -- a mail stuff library
3 *
4 * Copyright (C) 2001, 2005 - 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 AUTHORS 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 AUTHORS 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 "mailimap_types.h"
37#include "mail.h"
38
39#include <stdlib.h>
40
41/* ************************************************************************* */
42/* ************************************************************************* */
43/* ************************************************************************* */
44/* ************************************************************************* */
45/* ************************************************************************* */
46/* ************************************************************************* */
47
48/* in helper */
49
50
51
52
53struct mailimap_set_item * mailimap_set_item_new_single(uint32_t index)
54{
55 return mailimap_set_item_new(index, index);
56}
57
58struct mailimap_set *
59mailimap_set_new_single_item(struct mailimap_set_item * item)
60{
61 struct mailimap_set * set;
62 clist * list;
63 int r;
64
65 list = clist_new();
66 if (list == NULL)
67 return NULL;
68
69 r = clist_append(list, item);
70 if (r < 0) {
71 clist_free(list);
72 return NULL;
73 }
74
75 set = mailimap_set_new(list);
76 if (set == NULL) {
77 clist_free(list);
78 return NULL;
79 }
80
81 return set;
82}
83
84struct mailimap_set * mailimap_set_new_interval(uint32_t first, uint32_t last)
85{
86 struct mailimap_set_item * item;
87 struct mailimap_set * set;
88
89 item = mailimap_set_item_new(first, last);
90 if (item == NULL)
91 return NULL;
92
93 set = mailimap_set_new_single_item(item);
94 if (set == NULL) {
95 mailimap_set_item_free(item);
96 return NULL;
97 }
98
99 return set;
100}
101
102struct mailimap_set * mailimap_set_new_single(uint32_t index)
103{
104 return mailimap_set_new_interval(index, index);
105}
106
107
108struct mailimap_set * mailimap_set_new_empty(void)
109{
110 clist * list;
111
112 list = clist_new();
113 if (list == NULL)
114 return NULL;
115
116 return mailimap_set_new(list);
117}
118
119int mailimap_set_add(struct mailimap_set * set,
120 struct mailimap_set_item * set_item)
121{
122 int r;
123
124 r = clist_append(set->set_list, set_item);
125 if (r < 0)
126 return MAILIMAP_ERROR_MEMORY;
127
128 return MAILIMAP_NO_ERROR;
129}
130
131int mailimap_set_add_interval(struct mailimap_set * set,
132 uint32_t first, uint32_t last)
133{
134 struct mailimap_set_item * item;
135 int r;
136
137 item = mailimap_set_item_new(first, last);
138 if (item == NULL)
139 return MAILIMAP_ERROR_MEMORY;
140
141 r = mailimap_set_add(set, item);
142 if (r != MAILIMAP_NO_ERROR) {
143 mailimap_set_item_free(item);
144 return r;
145 }
146 else
147 return MAILIMAP_NO_ERROR;
148}
149
150int mailimap_set_add_single(struct mailimap_set * set,
151 uint32_t index)
152{
153 return mailimap_set_add_interval(set, index, index);
154}
155
156/* CHECK */
157/* no args */
158
159/* CLOSE */
160/* no args */
161
162/* EXPUNGE */
163/* no args */
164
165/* COPY */
166/* set and gchar */
167
168/* FETCH */
169/* set and gchar fetch_type */
170
171
172
173/* section */
174
175#if 0
176/* not correct XXX */
177
178struct mailimap_section * mailimap_section_new_empty(void)
179{
180 clist * list;
181
182 list = clist_new();
183 if (list == NULL)
184 return NULL;
185
186 return mailimap_section_new(list);
187}
188#endif
189
190static struct mailimap_section *
191mailimap_section_new_msgtext(struct mailimap_section_msgtext * msgtext)
192{
193 struct mailimap_section_spec * spec;
194 struct mailimap_section * section;
195
196 spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_MSGTEXT,
197 msgtext, NULL, NULL);
198 if (spec == NULL)
199 return NULL;
200
201 section = mailimap_section_new(spec);
202 if (section == NULL) {
203 /* detach section_msgtext so that it will not be freed */
204 spec->sec_data.sec_msgtext = NULL;
205 mailimap_section_spec_free(spec);
206 return NULL;
207 }
208
209 return section;
210}
211
212static struct mailimap_section *
213mailimap_section_new_part_msgtext(struct mailimap_section_part * part,
214 struct mailimap_section_msgtext * msgtext)
215{
216 struct mailimap_section_spec * spec;
217 struct mailimap_section * section;
218 struct mailimap_section_text * text;
219
220 text = mailimap_section_text_new(MAILIMAP_SECTION_TEXT_SECTION_MSGTEXT,
221 msgtext);
222 if (text == NULL)
223 return NULL;
224
225 spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART,
226 NULL, part, text);
227 if (spec == NULL) {
228 /* detach section_msgtext so that it will not be freed */
229 text->sec_msgtext = NULL;
230 mailimap_section_text_free(text);
231 return NULL;
232 }
233
234 section = mailimap_section_new(spec);
235 if (section == NULL) {
236 /* detach section_msgtext so that it will not be freed */
237 text->sec_msgtext = NULL;
238 mailimap_section_spec_free(spec);
239 return NULL;
240 }
241
242 return section;
243}
244
245/*
246HEADER
247HEADER.FIELDS fields
248HEADER.FIELDS.NOT fields
249TEXT
250*/
251
252struct mailimap_section * mailimap_section_new_header(void)
253{
254 struct mailimap_section_msgtext * msgtext;
255 struct mailimap_section * section;
256
257 msgtext = mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_HEADER,
258 NULL);
259 if (msgtext == NULL)
260 return NULL;
261
262 section = mailimap_section_new_msgtext(msgtext);
263 if (section == NULL) {
264 mailimap_section_msgtext_free(msgtext);
265 return NULL;
266 }
267
268 return section;
269}
270
271struct mailimap_section *
272mailimap_section_new_header_fields(struct mailimap_header_list * header_list)
273{
274 struct mailimap_section * section;
275 struct mailimap_section_msgtext * msgtext;
276
277 msgtext =
278 mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS,
279 header_list);
280 if (msgtext == NULL)
281 return NULL;
282
283 section = mailimap_section_new_msgtext(msgtext);
284 if (section == NULL) {
285 /* detach header_list so that it will not be freed */
286 msgtext->sec_header_list = NULL;
287 mailimap_section_msgtext_free(msgtext);
288 return NULL;
289 }
290
291 return section;
292}
293
294struct mailimap_section *
295mailimap_section_new_header_fields_not(struct mailimap_header_list * header_list)
296{
297 struct mailimap_section * section;
298 struct mailimap_section_msgtext * msgtext;
299
300 msgtext =
301 mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS_NOT,
302 header_list);
303 if (msgtext == NULL)
304 return NULL;
305
306 section = mailimap_section_new_msgtext(msgtext);
307 if (section == NULL) {
308 /* detach header_list so that it will not be freed */
309 msgtext->sec_header_list = NULL;
310 mailimap_section_msgtext_free(msgtext);
311 return NULL;
312 }
313
314 return section;
315}
316
317struct mailimap_section * mailimap_section_new_text(void)
318{
319 struct mailimap_section * section;
320 struct mailimap_section_msgtext * msgtext;
321
322 msgtext = mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_TEXT, NULL);
323 if (msgtext == NULL)
324 return NULL;
325
326 section = mailimap_section_new_msgtext(msgtext);
327 if (section == NULL) {
328 mailimap_section_msgtext_free(msgtext);
329 return NULL;
330 }
331
332 return section;
333}
334
335/*
336section-part
337section-part . MIME
338section-part . HEADER
339section-part . HEADER.FIELDS fields
340section-part . HEADER.FIELDS.NOT fields
341section-part . TEXT
342*/
343
344struct mailimap_section *
345mailimap_section_new_part(struct mailimap_section_part * part)
346{
347 struct mailimap_section_spec * spec;
348 struct mailimap_section * section;
349
350 spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART,
351 NULL, part, NULL);
352 if (spec == NULL)
353 return NULL;
354
355 section = mailimap_section_new(spec);
356 if (section == NULL) {
357 /* detach section_part so that it will not be freed */
358 spec->sec_data.sec_part = NULL;
359 mailimap_section_spec_free(spec);
360 return NULL;
361 }
362
363 return section;
364}
365
366struct mailimap_section *
367mailimap_section_new_part_mime(struct mailimap_section_part * part)
368{
369 struct mailimap_section_spec * spec;
370 struct mailimap_section * section;
371 struct mailimap_section_text * text;
372
373 text = mailimap_section_text_new(MAILIMAP_SECTION_TEXT_MIME, NULL);
374 if (text == NULL)
375 return NULL;
376
377 spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART,
378 NULL, part, text);
379 if (spec == NULL) {
380 mailimap_section_text_free(text);
381 return NULL;
382 }
383
384 section = mailimap_section_new(spec);
385 if (section == NULL) {
386 /* detach section_part so that it will not be freed */
387 spec->sec_data.sec_part = NULL;
388 mailimap_section_spec_free(spec);
389 return NULL;
390 }
391
392 return section;
393}
394
395struct mailimap_section *
396mailimap_section_new_part_header(struct mailimap_section_part * part)
397{
398 struct mailimap_section_msgtext * msgtext;
399 struct mailimap_section * section;
400
401 msgtext = mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_HEADER,
402 NULL);
403 if (msgtext == NULL)
404 return NULL;
405
406 section = mailimap_section_new_part_msgtext(part, msgtext);
407 if (section == NULL) {
408 mailimap_section_msgtext_free(msgtext);
409 return NULL;
410 }
411
412 return section;
413}
414
415struct mailimap_section *
416mailimap_section_new_part_header_fields(struct mailimap_section_part *
417 part,
418 struct mailimap_header_list *
419 header_list)
420{
421 struct mailimap_section * section;
422 struct mailimap_section_msgtext * msgtext;
423
424 msgtext =
425 mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS,
426 header_list);
427 if (msgtext == NULL)
428 return NULL;
429
430 section = mailimap_section_new_part_msgtext(part, msgtext);
431 if (section == NULL) {
432 /* detach header_list so that it will not be freed */
433 msgtext->sec_header_list = NULL;
434 mailimap_section_msgtext_free(msgtext);
435 return NULL;
436 }
437
438 return section;
439}
440
441struct mailimap_section *
442mailimap_section_new_part_header_fields_not(struct mailimap_section_part
443 * part,
444 struct mailimap_header_list
445 * header_list)
446{
447 struct mailimap_section * section;
448 struct mailimap_section_msgtext * msgtext;
449
450 msgtext =
451 mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS_NOT,
452 header_list);
453 if (msgtext == NULL)
454 return NULL;
455
456 section = mailimap_section_new_part_msgtext(part, msgtext);
457 if (section == NULL) {
458 /* detach header_list so that it will not be freed */
459 msgtext->sec_header_list = NULL;
460 mailimap_section_msgtext_free(msgtext);
461 return NULL;
462 }
463
464 return section;
465}
466
467struct mailimap_section *
468mailimap_section_new_part_text(struct mailimap_section_part * part)
469{
470 struct mailimap_section * section;
471 struct mailimap_section_msgtext * msgtext;
472
473 msgtext = mailimap_section_msgtext_new(MAILIMAP_SECTION_MSGTEXT_TEXT, NULL);
474 if (msgtext == NULL)
475 return NULL;
476
477 section = mailimap_section_new_part_msgtext(part, msgtext);
478 if (section == NULL) {
479 mailimap_section_msgtext_free(msgtext);
480 return NULL;
481 }
482
483 return section;
484}
485
486/* end of section */
487
488
489
490
491
492
493struct mailimap_fetch_att *
494mailimap_fetch_att_new_envelope(void)
495{
496 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_ENVELOPE, NULL, 0, 0);
497}
498
499struct mailimap_fetch_att *
500mailimap_fetch_att_new_flags(void)
501{
502 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_FLAGS, NULL, 0, 0);
503}
504
505struct mailimap_fetch_att *
506mailimap_fetch_att_new_internaldate(void)
507{
508 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_INTERNALDATE, NULL, 0, 0);
509}
510
511struct mailimap_fetch_att *
512mailimap_fetch_att_new_rfc822(void)
513{
514 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822, NULL, 0, 0);
515}
516
517struct mailimap_fetch_att *
518mailimap_fetch_att_new_rfc822_header(void)
519{
520 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_HEADER, NULL, 0, 0);
521}
522
523struct mailimap_fetch_att *
524mailimap_fetch_att_new_rfc822_size(void)
525{
526 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_SIZE, NULL, 0, 0);
527}
528
529struct mailimap_fetch_att *
530mailimap_fetch_att_new_rfc822_text(void)
531{
532 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_RFC822_TEXT, NULL, 0, 0);
533}
534
535struct mailimap_fetch_att *
536mailimap_fetch_att_new_body(void)
537{
538 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY, NULL, 0, 0);
539}
540
541struct mailimap_fetch_att *
542mailimap_fetch_att_new_bodystructure(void)
543{
544 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODYSTRUCTURE, NULL, 0, 0);
545}
546
547struct mailimap_fetch_att *
548mailimap_fetch_att_new_uid(void)
549{
550 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_UID, NULL, 0, 0);
551}
552
553struct mailimap_fetch_att *
554mailimap_fetch_att_new_body_section(struct mailimap_section * section)
555{
556 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_SECTION, section, 0, 0);
557}
558
559struct mailimap_fetch_att *
560mailimap_fetch_att_new_body_peek_section(struct mailimap_section * section)
561{
562 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION, section, 0, 0);
563}
564
565struct mailimap_fetch_att *
566mailimap_fetch_att_new_body_section_partial(struct mailimap_section * section,
567 uint32_t offset, uint32_t size)
568{
569 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_SECTION, section,
570 offset, size);
571}
572
573struct mailimap_fetch_att *
574mailimap_fetch_att_new_body_peek_section_partial(struct mailimap_section * section,
575 uint32_t offset, uint32_t size)
576{
577 return mailimap_fetch_att_new(MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION, section,
578 offset, size);
579}
580
581
582
583struct mailimap_fetch_type *
584mailimap_fetch_type_new_all(void)
585{
586 return mailimap_fetch_type_new(MAILIMAP_FETCH_TYPE_ALL, NULL, NULL);
587}
588
589struct mailimap_fetch_type *
590mailimap_fetch_type_new_full(void)
591{
592 return mailimap_fetch_type_new(MAILIMAP_FETCH_TYPE_FULL, NULL, NULL);
593}
594
595struct mailimap_fetch_type *
596mailimap_fetch_type_new_fast(void)
597{
598 return mailimap_fetch_type_new(MAILIMAP_FETCH_TYPE_FAST, NULL, NULL);
599}
600
601struct mailimap_fetch_type *
602mailimap_fetch_type_new_fetch_att(struct mailimap_fetch_att * fetch_att)
603{
604 return mailimap_fetch_type_new(MAILIMAP_FETCH_TYPE_FETCH_ATT, fetch_att, NULL);
605}
606
607struct mailimap_fetch_type *
608mailimap_fetch_type_new_fetch_att_list(clist * fetch_att_list)
609{
610 return mailimap_fetch_type_new(MAILIMAP_FETCH_TYPE_FETCH_ATT_LIST,
611 NULL, fetch_att_list);
612}
613
614struct mailimap_fetch_type *
615mailimap_fetch_type_new_fetch_att_list_empty(void)
616{
617 clist * list;
618
619 list = clist_new();
620 if (list == NULL)
621 return NULL;
622
623 return mailimap_fetch_type_new(MAILIMAP_FETCH_TYPE_FETCH_ATT_LIST,
624 NULL, list);
625}
626
627int
628mailimap_fetch_type_new_fetch_att_list_add(struct mailimap_fetch_type *
629 fetch_type,
630 struct mailimap_fetch_att * fetch_att)
631{
632 int r;
633
634 r = clist_append(fetch_type->ft_data.ft_fetch_att_list, fetch_att);
635 if (r < 0)
636 return MAILIMAP_ERROR_MEMORY;
637
638 return MAILIMAP_NO_ERROR;
639}
640
641
642
643/* STORE */
644/* set and store_att_flags */
645
646struct mailimap_store_att_flags *
647mailimap_store_att_flags_new_set_flags(struct mailimap_flag_list * flags)
648{
649 return mailimap_store_att_flags_new(0, FALSE, flags);
650}
651
652struct mailimap_store_att_flags *
653mailimap_store_att_flags_new_set_flags_silent(struct mailimap_flag_list *
654 flags)
655{
656 return mailimap_store_att_flags_new(0, TRUE, flags);
657}
658
659struct mailimap_store_att_flags *
660mailimap_store_att_flags_new_add_flags(struct mailimap_flag_list * flags)
661{
662 return mailimap_store_att_flags_new(1, FALSE, flags);
663}
664
665struct mailimap_store_att_flags *
666mailimap_store_att_flags_new_add_flags_silent(struct mailimap_flag_list *
667 flags)
668{
669 return mailimap_store_att_flags_new(1, TRUE, flags);
670}
671
672struct mailimap_store_att_flags *
673mailimap_store_att_flags_new_remove_flags(struct mailimap_flag_list * flags)
674{
675 return mailimap_store_att_flags_new(-1, FALSE, flags);
676}
677
678struct mailimap_store_att_flags *
679mailimap_store_att_flags_new_remove_flags_silent(struct mailimap_flag_list *
680 flags)
681{
682 return mailimap_store_att_flags_new(-1, TRUE, flags);
683}
684
685/* SEARCH */
686/* date search-key set */
687
688/*
689 return mailimap_search_key_new(type, bcc, before,
690 body, cc, from, keyword, on, since,
691 subject, text, to, unkeyword, header_name,
692 header_value, larger, not,
693 or1, or2, sentbefore, senton, sentsince,
694 smaller, uid, set, multiple);
695*/
696
697struct mailimap_search_key *
698mailimap_search_key_new_all(void)
699{
700 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_ALL, NULL, NULL,
701 NULL, NULL, NULL, NULL, NULL, NULL,
702 NULL, NULL, NULL, NULL, NULL,
703 NULL, 0, NULL,
704 NULL, NULL, NULL, NULL, NULL,
705 0, NULL, NULL, NULL);
706}
707
708struct mailimap_search_key *
709mailimap_search_key_new_bcc(char * sk_bcc)
710{
711 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_BCC, sk_bcc, NULL,
712 NULL, NULL, NULL, NULL, NULL, NULL,
713 NULL, NULL, NULL, NULL, NULL,
714 NULL, 0, NULL,
715 NULL, NULL, NULL, NULL, NULL,
716 0, NULL, NULL, NULL);
717}
718
719struct mailimap_search_key *
720mailimap_search_key_new_before(struct mailimap_date * sk_before)
721{
722 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_BEFORE, NULL, sk_before,
723 NULL, NULL, NULL, NULL, NULL, NULL,
724 NULL, NULL, NULL, NULL, NULL,
725 NULL, 0, NULL,
726 NULL, NULL, NULL, NULL, NULL,
727 0, NULL, NULL, NULL);
728}
729
730struct mailimap_search_key *
731mailimap_search_key_new_body(char * sk_body)
732{
733 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_BODY, NULL, NULL,
734 sk_body, NULL, NULL, NULL, NULL, NULL,
735 NULL, NULL, NULL, NULL, NULL,
736 NULL, 0, NULL,
737 NULL, NULL, NULL, NULL, NULL,
738 0, NULL, NULL, NULL);
739}
740
741struct mailimap_search_key *
742mailimap_search_key_new_cc(char * sk_cc)
743{
744 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_CC, NULL, NULL,
745 NULL, sk_cc, NULL, NULL, NULL, NULL,
746 NULL, NULL, NULL, NULL, NULL,
747 NULL, 0, NULL,
748 NULL, NULL, NULL, NULL, NULL,
749 0, NULL, NULL, NULL);
750}
751
752struct mailimap_search_key *
753mailimap_search_key_new_from(char * sk_from)
754{
755 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_FROM, NULL, NULL,
756 NULL, NULL, sk_from, NULL, NULL, NULL,
757 NULL, NULL, NULL, NULL, NULL,
758 NULL, 0, NULL,
759 NULL, NULL, NULL, NULL, NULL,
760 0, NULL, NULL, NULL);
761}
762
763struct mailimap_search_key *
764mailimap_search_key_new_keyword(char * sk_keyword)
765{
766 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_FROM, NULL, NULL,
767 NULL, NULL, NULL, sk_keyword, NULL, NULL,
768 NULL, NULL, NULL, NULL, NULL,
769 NULL, 0, NULL,
770 NULL, NULL, NULL, NULL, NULL,
771 0, NULL, NULL, NULL);
772}
773
774struct mailimap_search_key *
775mailimap_search_key_new_on(struct mailimap_date * sk_on)
776{
777 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_ON, NULL, NULL,
778 NULL, NULL, NULL, NULL, sk_on, NULL,
779 NULL, NULL, NULL, NULL, NULL,
780 NULL, 0, NULL,
781 NULL, NULL, NULL, NULL, NULL,
782 0, NULL, NULL, NULL);
783}
784
785struct mailimap_search_key *
786mailimap_search_key_new_since(struct mailimap_date * sk_since)
787{
788 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SINCE, NULL, NULL,
789 NULL, NULL, NULL, NULL, NULL, sk_since,
790 NULL, NULL, NULL, NULL, NULL,
791 NULL, 0, NULL,
792 NULL, NULL, NULL, NULL, NULL,
793 0, NULL, NULL, NULL);
794}
795
796struct mailimap_search_key *
797mailimap_search_key_new_subject(char * sk_subject)
798{
799 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SINCE, NULL, NULL,
800 NULL, NULL, NULL, NULL, NULL, NULL,
801 sk_subject, NULL, NULL, NULL, NULL,
802 NULL, 0, NULL,
803 NULL, NULL, NULL, NULL, NULL,
804 0, NULL, NULL, NULL);
805}
806
807struct mailimap_search_key *
808mailimap_search_key_new_text(char * sk_text)
809{
810 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_TEXT, NULL, NULL,
811 NULL, NULL, NULL, NULL, NULL, NULL,
812 NULL, sk_text, NULL, NULL, NULL,
813 NULL, 0, NULL,
814 NULL, NULL, NULL, NULL, NULL,
815 0, NULL, NULL, NULL);
816}
817
818struct mailimap_search_key *
819mailimap_search_key_new_to(char * sk_to)
820{
821 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_TO, NULL, NULL,
822 NULL, NULL, NULL, NULL, NULL, NULL,
823 NULL, NULL, sk_to, NULL, NULL,
824 NULL, 0, NULL,
825 NULL, NULL, NULL, NULL, NULL,
826 0, NULL, NULL, NULL);
827}
828
829struct mailimap_search_key *
830mailimap_search_key_new_unkeyword(char * sk_unkeyword)
831{
832 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_UNKEYWORD, NULL, NULL,
833 NULL, NULL, NULL, NULL, NULL, NULL,
834 NULL, NULL, NULL, sk_unkeyword, NULL,
835 NULL, 0, NULL,
836 NULL, NULL, NULL, NULL, NULL,
837 0, NULL, NULL, NULL);
838}
839
840struct mailimap_search_key *
841mailimap_search_key_new_header(char * sk_header_name, char * sk_header_value)
842{
843 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_HEADER, NULL, NULL,
844 NULL, NULL, NULL, NULL, NULL, NULL,
845 NULL, NULL, NULL, NULL, sk_header_name,
846 sk_header_value, 0, NULL,
847 NULL, NULL, NULL, NULL, NULL,
848 0, NULL, NULL, NULL);
849}
850
851struct mailimap_search_key *
852mailimap_search_key_new_larger(uint32_t sk_larger)
853{
854 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_LARGER, NULL, NULL,
855 NULL, NULL, NULL, NULL, NULL, NULL,
856 NULL, NULL, NULL, NULL, NULL,
857 NULL, sk_larger, NULL,
858 NULL, NULL, NULL, NULL, NULL,
859 0, NULL, NULL, NULL);
860}
861
862struct mailimap_search_key *
863mailimap_search_key_new_not(struct mailimap_search_key * sk_not)
864{
865 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_NOT, NULL, NULL,
866 NULL, NULL, NULL, NULL, NULL, NULL,
867 NULL, NULL, NULL, NULL, NULL,
868 NULL, 0, sk_not,
869 NULL, NULL, NULL, NULL, NULL,
870 0, NULL, NULL, NULL);
871}
872
873struct mailimap_search_key *
874mailimap_search_key_new_or(struct mailimap_search_key * sk_or1,
875 struct mailimap_search_key * sk_or2)
876{
877 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_OR, NULL, NULL,
878 NULL, NULL, NULL, NULL, NULL, NULL,
879 NULL, NULL, NULL, NULL, NULL,
880 NULL, 0, NULL,
881 sk_or1, sk_or2, NULL, NULL, NULL,
882 0, NULL, NULL, NULL);
883}
884
885struct mailimap_search_key *
886mailimap_search_key_new_sentbefore(struct mailimap_date * sk_sentbefore)
887{
888 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_NOT, NULL, NULL,
889 NULL, NULL, NULL, NULL, NULL, NULL,
890 NULL, NULL, NULL, NULL, NULL,
891 NULL, 0, NULL,
892 NULL, NULL, sk_sentbefore, NULL, NULL,
893 0, NULL, NULL, NULL);
894}
895
896struct mailimap_search_key *
897mailimap_search_key_new_senton(struct mailimap_date * sk_senton)
898{
899 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SENTON, NULL, NULL,
900 NULL, NULL, NULL, NULL, NULL, NULL,
901 NULL, NULL, NULL, NULL, NULL,
902 NULL, 0, NULL,
903 NULL, NULL, NULL, sk_senton, NULL,
904 0, NULL, NULL, NULL);
905}
906
907struct mailimap_search_key *
908mailimap_search_key_new_sentsince(struct mailimap_date * sk_sentsince)
909{
910 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SENTSINCE, NULL, NULL,
911 NULL, NULL, NULL, NULL, NULL, NULL,
912 NULL, NULL, NULL, NULL, NULL,
913 NULL, 0, NULL,
914 NULL, NULL, NULL, NULL, sk_sentsince,
915 0, NULL, NULL, NULL);
916}
917
918struct mailimap_search_key *
919mailimap_search_key_new_smaller(uint32_t sk_smaller)
920{
921 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SMALLER, NULL, NULL,
922 NULL, NULL, NULL, NULL, NULL, NULL,
923 NULL, NULL, NULL, NULL, NULL,
924 NULL, 0, NULL,
925 NULL, NULL, NULL, NULL, NULL,
926 sk_smaller, NULL, NULL, NULL);
927}
928
929struct mailimap_search_key *
930mailimap_search_key_new_uid(struct mailimap_set * sk_uid)
931{
932 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_UID, NULL, NULL,
933 NULL, NULL, NULL, NULL, NULL, NULL,
934 NULL, NULL, NULL, NULL, NULL,
935 NULL, 0, NULL,
936 NULL, NULL, NULL, NULL, NULL,
937 0, sk_uid, NULL, NULL);
938}
939
940struct mailimap_search_key *
941mailimap_search_key_new_set(struct mailimap_set * sk_set)
942{
943 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_SET, NULL, NULL,
944 NULL, NULL, NULL, NULL, NULL, NULL,
945 NULL, NULL, NULL, NULL, NULL,
946 NULL, 0, NULL,
947 NULL, NULL, NULL, NULL, NULL,
948 0, NULL, sk_set, NULL);
949}
950
951struct mailimap_search_key *
952mailimap_search_key_new_multiple(clist * sk_multiple)
953{
954 return mailimap_search_key_new(MAILIMAP_SEARCH_KEY_MULTIPLE, NULL, NULL,
955 NULL, NULL, NULL, NULL, NULL, NULL,
956 NULL, NULL, NULL, NULL, NULL,
957 NULL, 0, NULL,
958 NULL, NULL, NULL, NULL, NULL,
959 0, NULL, NULL, sk_multiple);
960}
961
962struct mailimap_search_key *
963mailimap_search_key_new_multiple_empty(void)
964{
965 clist * list;
966
967 list = clist_new();
968 if (list == NULL)
969 return NULL;
970
971 return mailimap_search_key_new_multiple(list);
972}
973
974int
975mailimap_search_key_multiple_add(struct mailimap_search_key * keys,
976 struct mailimap_search_key * key_item)
977{
978 int r;
979
980 r = clist_append(keys->sk_data.sk_multiple, key_item);
981 if (r < 0)
982 return MAILIMAP_ERROR_MEMORY;
983
984 return MAILIMAP_NO_ERROR;
985}
986
987
988
989/* CAPABILITY */
990/* no args */
991
992/* LOGOUT */
993/* no args */
994
995/* NOOP */
996/* no args */
997
998/* APPEND */
999/* gchar flag_list date_time gchar */
1000
1001struct mailimap_flag_list *
1002mailimap_flag_list_new_empty(void)
1003{
1004 clist * list;
1005
1006 list = clist_new();
1007 if (list == NULL)
1008 return NULL;
1009
1010 return mailimap_flag_list_new(list);
1011}
1012
1013int mailimap_flag_list_add(struct mailimap_flag_list * flag_list,
1014 struct mailimap_flag * f)
1015{
1016 int r;
1017
1018 r = clist_append(flag_list->fl_list, f);
1019 if (r < 0)
1020 return MAILIMAP_ERROR_MEMORY;
1021
1022 return MAILIMAP_NO_ERROR;
1023}
1024
1025struct mailimap_flag * mailimap_flag_new_answered(void)
1026{
1027 return mailimap_flag_new(MAILIMAP_FLAG_ANSWERED, NULL, NULL);
1028}
1029
1030struct mailimap_flag * mailimap_flag_new_flagged(void)
1031{
1032 return mailimap_flag_new(MAILIMAP_FLAG_FLAGGED, NULL, NULL);
1033}
1034
1035struct mailimap_flag * mailimap_flag_new_deleted(void)
1036{
1037 return mailimap_flag_new(MAILIMAP_FLAG_DELETED, NULL, NULL);
1038}
1039
1040struct mailimap_flag * mailimap_flag_new_seen(void)
1041{
1042 return mailimap_flag_new(MAILIMAP_FLAG_SEEN, NULL, NULL);
1043}
1044
1045struct mailimap_flag * mailimap_flag_new_draft(void)
1046{
1047 return mailimap_flag_new(MAILIMAP_FLAG_DRAFT, NULL, NULL);
1048}
1049
1050struct mailimap_flag * mailimap_flag_new_flag_keyword(char * flag_keyword)
1051{
1052 return mailimap_flag_new(MAILIMAP_FLAG_KEYWORD, flag_keyword, NULL);
1053}
1054
1055struct mailimap_flag * mailimap_flag_new_flag_extension(char * flag_extension)
1056{
1057 return mailimap_flag_new(MAILIMAP_FLAG_EXTENSION, NULL, flag_extension);
1058}
1059
1060
1061
1062
1063/* CREATE */
1064/* gchar */
1065
1066/* DELETE */
1067/* gchar */
1068
1069/* EXAMINE */
1070/* gchar */
1071
1072/* LIST */
1073/* gchar gchar */
1074
1075/* LSUB */
1076/* gchar gchar */
1077
1078/* RENAME */
1079/* gchar gchar */
1080
1081/* SELECT */
1082/* gchar */
1083
1084/* STATUS */
1085/* gchar GList of status_att */
1086
1087struct mailimap_status_att_list * mailimap_status_att_list_new_empty(void)
1088{
1089 clist * list;
1090
1091 list = clist_new();
1092 if (list == NULL)
1093 return NULL;
1094
1095 return mailimap_status_att_list_new(list);
1096}
1097
1098int
1099mailimap_status_att_list_add(struct mailimap_status_att_list * sa_list,
1100 int status_att)
1101{
1102 int * pstatus_att;
1103 int r;
1104
1105 pstatus_att = malloc(sizeof(* pstatus_att));
1106 * pstatus_att = status_att;
1107
1108 r = clist_append(sa_list->att_list, pstatus_att);
1109 if (r < 0) {
1110 free(pstatus_att);
1111 return MAILIMAP_ERROR_MEMORY;
1112 }
1113
1114 return MAILIMAP_NO_ERROR;
1115}
1116
1117/* SUBSCRIBE */
1118/* gchar */
1119
1120/* UNSUBSCRIBE */
1121/* gchar */
1122
1123/* LOGIN */
1124/* gchar gchar */
1125
1126/* AUTHENTICATE */
1127/* gchar */
1128
1129
1130static int recursive_build_path(struct mailimap_body * root_part,
1131 struct mailimap_body * part,
1132 clist ** result);
1133
1134static int try_build_part(struct mailimap_body * root_part,
1135 struct mailimap_body * part, uint32_t count,
1136 clist ** result)
1137{
1138 int r;
1139 clist * imap_id_list;
1140 uint32_t * id;
1141
1142 r = recursive_build_path(root_part, part, &imap_id_list);
1143 if (r != MAILIMAP_NO_ERROR)
1144 return r;
1145
1146 id = malloc(sizeof(* id));
1147 if (id == NULL) {
1148 clist_free(imap_id_list);
1149 return MAILIMAP_ERROR_MEMORY;
1150 }
1151
1152 * id = count;
1153
1154 r = clist_prepend(imap_id_list, id);
1155 if (r < 0) {
1156 free(id);
1157 clist_free(imap_id_list);
1158 return MAILIMAP_ERROR_MEMORY;
1159 }
1160
1161 * result = imap_id_list;
1162
1163 return MAILIMAP_NO_ERROR;
1164}
1165
1166
1167static int recursive_build_path(struct mailimap_body * root_part,
1168 struct mailimap_body * part,
1169 clist ** result)
1170{
1171 clistiter * cur;
1172 uint32_t count;
1173 int r;
1174 clist * imap_id_list;
1175
1176 if (part == root_part) {
1177 imap_id_list = clist_new();
1178 if (imap_id_list == NULL) {
1179 return MAILIMAP_ERROR_MEMORY;
1180 }
1181
1182 * result = imap_id_list;
1183
1184 return MAILIMAP_NO_ERROR;
1185 }
1186
1187 switch (root_part->bd_type) {
1188 case MAILIMAP_BODY_MPART:
1189 count = 0;
1190 for(cur = clist_begin(root_part->bd_data.bd_body_mpart->bd_list) ;
1191 cur != NULL ; cur = clist_next(cur)) {
1192 struct mailimap_body * current_part;
1193
1194 current_part = clist_content(cur);
1195 count ++;
1196
1197 r = try_build_part(current_part, part, count, &imap_id_list);
1198 if (r == MAILIMAP_ERROR_INVAL) {
1199 continue;
1200 } if (r != MAILIMAP_NO_ERROR) {
1201 return r;
1202 }
1203 else {
1204 * result = imap_id_list;
1205 return MAILIMAP_NO_ERROR;
1206 }
1207 }
1208 return MAILIMAP_ERROR_INVAL;
1209
1210 case MAILIMAP_BODY_1PART:
1211 if (root_part->bd_data.bd_body_1part->bd_type ==
1212 MAILIMAP_BODY_TYPE_1PART_MSG) {
1213 struct mailimap_body * current_part;
1214
1215 current_part =
1216 root_part->bd_data.bd_body_1part->bd_data.bd_type_msg->bd_body;
1217
1218 r = try_build_part(current_part, part, 1, &imap_id_list);
1219 if (r != MAILIMAP_NO_ERROR) {
1220 return r;
1221 }
1222 else {
1223 * result = imap_id_list;
1224 return MAILIMAP_NO_ERROR;
1225 }
1226 }
1227 else {
1228 return MAILIMAP_ERROR_INVAL;
1229 }
1230 break;
1231
1232 default:
1233 return MAILIMAP_ERROR_INVAL;
1234 }
1235}
1236
1237/* return mailimap_section_part from a given mailimap_body */
1238
1239int mailimap_get_section_part_from_body(struct mailimap_body * root_part,
1240 struct mailimap_body * part,
1241 struct mailimap_section_part ** result)
1242{
1243 struct mailimap_section_part * section_part;
1244 clist * id_list;
1245 int r;
1246 int res;
1247
1248 r = recursive_build_path(root_part, part, &id_list);
1249 if (r != MAILIMAP_NO_ERROR) {
1250 res = r;
1251 goto err;
1252 }
1253
1254 section_part = mailimap_section_part_new(id_list);
1255 if (section_part == NULL) {
1256 res = MAILIMAP_ERROR_MEMORY;
1257 goto free_list;
1258 }
1259
1260 * result = section_part;
1261
1262 return MAILIMAP_NO_ERROR;
1263
1264 free_list:
1265 clist_foreach(id_list, (clist_func) free, NULL);
1266 clist_free(id_list);
1267 err:
1268 return res;
1269}