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: mailimap_types_helper.h,v 1.12 2008/02/20 22:15:52 hoa Exp $ 34 */ 35 36 #ifndef MAILIMAP_TYPES_HELPER_H 37 38 #define MAILIMAP_TYPES_HELPER_H 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 #include <libetpan/mailimap_types.h> 45 46 /* 47 IMPORTANT NOTE: 48 49 All allocation functions will take as argument allocated data 50 and will store these data in the structure they will allocate. 51 Data should be persistant during all the use of the structure 52 and will be freed by the free function of the structure 53 54 allocation functions will return NULL on failure 55 */ 56 57 /* 58 this function creates a new set item with a single message 59 given by indx 60 */ 61 62 LIBETPAN_EXPORT 63 struct mailimap_set_item * mailimap_set_item_new_single(uint32_t indx); 64 65 /* 66 this function creates a new set with one set item 67 */ 68 69 LIBETPAN_EXPORT 70 struct mailimap_set * 71 mailimap_set_new_single_item(struct mailimap_set_item * item); 72 73 /* 74 this function creates a set with a single interval 75 */ 76 77 LIBETPAN_EXPORT 78 struct mailimap_set * mailimap_set_new_interval(uint32_t first, uint32_t last); 79 80 /* 81 this function creates a set with a single message 82 */ 83 84 LIBETPAN_EXPORT 85 struct mailimap_set * mailimap_set_new_single(uint32_t indx); 86 87 /* 88 this function creates an empty set of messages 89 */ 90 91 LIBETPAN_EXPORT 92 struct mailimap_set * mailimap_set_new_empty(void); 93 94 /* 95 this function adds a set item to the set of messages 96 97 @return MAILIMAP_NO_ERROR will be returned on success, 98 other code will be returned otherwise 99 */ 100 101 LIBETPAN_EXPORT 102 int mailimap_set_add(struct mailimap_set * set, 103 struct mailimap_set_item * set_item); 104 105 /* 106 this function adds an interval to the set 107 108 @return MAILIMAP_NO_ERROR will be returned on success, 109 other code will be returned otherwise 110 */ 111 112 LIBETPAN_EXPORT 113 int mailimap_set_add_interval(struct mailimap_set * set, 114 uint32_t first, uint32_t last); 115 116 /* 117 this function adds a single message to the set 118 119 @return MAILIMAP_NO_ERROR will be returned on success, 120 other code will be returned otherwise 121 */ 122 123 LIBETPAN_EXPORT 124 int mailimap_set_add_single(struct mailimap_set * set, 125 uint32_t indx); 126 127 /* 128 this function creates a mailimap_section structure to request 129 the header of a message 130 */ 131 132 LIBETPAN_EXPORT 133 struct mailimap_section * mailimap_section_new_header(void); 134 135 /* 136 this functions creates a mailimap_section structure to describe 137 a list of headers 138 */ 139 140 LIBETPAN_EXPORT 141 struct mailimap_section * 142 mailimap_section_new_header_fields(struct mailimap_header_list * header_list); 143 144 /* 145 this functions creates a mailimap_section structure to describe headers 146 other than those given 147 */ 148 149 LIBETPAN_EXPORT 150 struct mailimap_section * 151 mailimap_section_new_header_fields_not(struct mailimap_header_list * header_list); 152 153 /* 154 this function creates a mailimap_section structure to describe the 155 text of a message 156 */ 157 158 LIBETPAN_EXPORT 159 struct mailimap_section * mailimap_section_new_text(void); 160 161 /* 162 this function creates a mailimap_section structure to describe the 163 content of a MIME part 164 */ 165 166 LIBETPAN_EXPORT 167 struct mailimap_section * 168 mailimap_section_new_part(struct mailimap_section_part * part); 169 170 /* 171 this function creates a mailimap_section structure to describe the 172 MIME fields of a MIME part 173 */ 174 175 LIBETPAN_EXPORT 176 struct mailimap_section * 177 mailimap_section_new_part_mime(struct mailimap_section_part * part); 178 179 /* 180 this function creates a mailimap_section structure to describe the 181 headers of a MIME part if the MIME type is a message/rfc822 182 */ 183 184 LIBETPAN_EXPORT 185 struct mailimap_section * 186 mailimap_section_new_part_header(struct mailimap_section_part * part); 187 188 /* 189 this function creates a mailimap_section structure to describe 190 a list of headers of a MIME part if the MIME type is a message/rfc822 191 */ 192 193 LIBETPAN_EXPORT 194 struct mailimap_section * 195 mailimap_section_new_part_header_fields(struct mailimap_section_part * 196 part, 197 struct mailimap_header_list * 198 header_list); 199 200 /* 201 this function creates a mailimap_section structure to describe 202 headers of a MIME part other than those given if the MIME type 203 is a message/rfc822 204 */ 205 206 LIBETPAN_EXPORT 207 struct mailimap_section * 208 mailimap_section_new_part_header_fields_not(struct mailimap_section_part 209 * part, 210 struct mailimap_header_list 211 * header_list); 212 213 /* 214 this function creates a mailimap_section structure to describe 215 text part of message if the MIME type is a message/rfc822 216 */ 217 218 LIBETPAN_EXPORT 219 struct mailimap_section * 220 mailimap_section_new_part_text(struct mailimap_section_part * part); 221 222 223 /* 224 this function creates a mailimap_fetch_att structure to request 225 envelope of a message 226 */ 227 228 LIBETPAN_EXPORT 229 struct mailimap_fetch_att * 230 mailimap_fetch_att_new_envelope(void); 231 232 233 /* 234 this function creates a mailimap_fetch_att structure to request 235 flags of a message 236 */ 237 238 LIBETPAN_EXPORT 239 struct mailimap_fetch_att * 240 mailimap_fetch_att_new_flags(void); 241 242 /* 243 this function creates a mailimap_fetch_att structure to request 244 internal date of a message 245 */ 246 247 LIBETPAN_EXPORT 248 struct mailimap_fetch_att * 249 mailimap_fetch_att_new_internaldate(void); 250 251 252 /* 253 this function creates a mailimap_fetch_att structure to request 254 text part of a message 255 */ 256 257 LIBETPAN_EXPORT 258 struct mailimap_fetch_att * 259 mailimap_fetch_att_new_rfc822(void); 260 261 262 /* 263 this function creates a mailimap_fetch_att structure to request 264 header of a message 265 */ 266 267 LIBETPAN_EXPORT 268 struct mailimap_fetch_att * 269 mailimap_fetch_att_new_rfc822_header(void); 270 271 /* 272 this function creates a mailimap_fetch_att structure to request 273 size of a message 274 */ 275 276 LIBETPAN_EXPORT 277 struct mailimap_fetch_att * 278 mailimap_fetch_att_new_rfc822_size(void); 279 280 /* 281 this function creates a mailimap_fetch_att structure to request 282 envelope of a message 283 */ 284 285 LIBETPAN_EXPORT 286 struct mailimap_fetch_att * 287 mailimap_fetch_att_new_rfc822_text(void); 288 289 /* 290 this function creates a mailimap_fetch_att structure to request 291 the MIME structure of a message 292 */ 293 294 LIBETPAN_EXPORT 295 struct mailimap_fetch_att * 296 mailimap_fetch_att_new_body(void); 297 298 /* 299 this function creates a mailimap_fetch_att structure to request 300 the MIME structure of a message and additional MIME information 301 */ 302 303 LIBETPAN_EXPORT 304 struct mailimap_fetch_att * 305 mailimap_fetch_att_new_bodystructure(void); 306 307 /* 308 this function creates a mailimap_fetch_att structure to request 309 unique identifier of a message 310 */ 311 312 LIBETPAN_EXPORT 313 struct mailimap_fetch_att * 314 mailimap_fetch_att_new_uid(void); 315 316 /* 317 this function creates a mailimap_fetch_att structure to request 318 a given section of a message 319 */ 320 321 LIBETPAN_EXPORT 322 struct mailimap_fetch_att * 323 mailimap_fetch_att_new_body_section(struct mailimap_section * section); 324 325 /* 326 this function creates a mailimap_fetch_att structure to request 327 a given section of a message without marking it as read 328 */ 329 330 LIBETPAN_EXPORT 331 struct mailimap_fetch_att * 332 mailimap_fetch_att_new_body_peek_section(struct mailimap_section * section); 333 334 /* 335 this function creates a mailimap_fetch_att structure to request 336 a part of a section of a message 337 */ 338 339 LIBETPAN_EXPORT 340 struct mailimap_fetch_att * 341 mailimap_fetch_att_new_body_section_partial(struct mailimap_section * section, 342 uint32_t offset, uint32_t size); 343 344 /* 345 this function creates a mailimap_fetch_att structure to request 346 a part of a section of a message without marking it as read 347 */ 348 349 LIBETPAN_EXPORT 350 struct mailimap_fetch_att * 351 mailimap_fetch_att_new_body_peek_section_partial(struct mailimap_section * section, 352 uint32_t offset, uint32_t size); 353 354 /* 355 creates a mailimap_fetch_att extension 356 */ 357 358 LIBETPAN_EXPORT 359 struct mailimap_fetch_att * 360 mailimap_fetch_att_new_extension(char * ext_keyword); 361 362 /* 363 this function creates a mailimap_fetch_type structure to request 364 (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE) of a message 365 */ 366 367 LIBETPAN_EXPORT 368 struct mailimap_fetch_type * 369 mailimap_fetch_type_new_all(void); 370 371 /* 372 this function creates a mailimap_fetch_type structure to request 373 (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY) 374 */ 375 376 LIBETPAN_EXPORT 377 struct mailimap_fetch_type * 378 mailimap_fetch_type_new_full(void); 379 380 /* 381 this function creates a mailimap_fetch_type structure to request 382 (FLAGS INTERNALDATE RFC822.SIZE) 383 */ 384 385 LIBETPAN_EXPORT 386 struct mailimap_fetch_type * 387 mailimap_fetch_type_new_fast(void); 388 389 /* 390 this function creates a mailimap_fetch_type structure to request 391 the given fetch attribute 392 */ 393 394 LIBETPAN_EXPORT 395 struct mailimap_fetch_type * 396 mailimap_fetch_type_new_fetch_att(struct mailimap_fetch_att * fetch_att); 397 398 /* 399 this function creates a mailimap_fetch_type structure to request 400 the list of fetch attributes 401 */ 402 403 LIBETPAN_EXPORT 404 struct mailimap_fetch_type * 405 mailimap_fetch_type_new_fetch_att_list(clist * fetch_att_list); 406 407 /* 408 this function creates a mailimap_fetch_type structure 409 */ 410 411 LIBETPAN_EXPORT 412 struct mailimap_fetch_type * 413 mailimap_fetch_type_new_fetch_att_list_empty(void); 414 415 /* 416 this function adds a given fetch attribute to the mailimap_fetch 417 structure 418 419 @return MAILIMAP_NO_ERROR will be returned on success, 420 other code will be returned otherwise 421 */ 422 423 LIBETPAN_EXPORT 424 int 425 mailimap_fetch_type_new_fetch_att_list_add(struct mailimap_fetch_type * 426 fetch_type, 427 struct mailimap_fetch_att * 428 fetch_att); 429 430 /* 431 this function creates a store attribute to set the given flags 432 */ 433 434 LIBETPAN_EXPORT 435 struct mailimap_store_att_flags * 436 mailimap_store_att_flags_new_set_flags(struct mailimap_flag_list * flags); 437 438 /* 439 this function creates a store attribute to silently set the given flags 440 */ 441 442 LIBETPAN_EXPORT 443 struct mailimap_store_att_flags * 444 mailimap_store_att_flags_new_set_flags_silent(struct mailimap_flag_list * 445 flags); 446 447 /* 448 this function creates a store attribute to add the given flags 449 */ 450 451 LIBETPAN_EXPORT 452 struct mailimap_store_att_flags * 453 mailimap_store_att_flags_new_add_flags(struct mailimap_flag_list * flags); 454 455 /* 456 this function creates a store attribute to add silently the given flags 457 */ 458 459 LIBETPAN_EXPORT 460 struct mailimap_store_att_flags * 461 mailimap_store_att_flags_new_add_flags_silent(struct mailimap_flag_list * 462 flags); 463 464 /* 465 this function creates a store attribute to remove the given flags 466 */ 467 468 LIBETPAN_EXPORT 469 struct mailimap_store_att_flags * 470 mailimap_store_att_flags_new_remove_flags(struct mailimap_flag_list * flags); 471 472 /* 473 this function creates a store attribute to remove silently the given flags 474 */ 475 476 LIBETPAN_EXPORT 477 struct mailimap_store_att_flags * 478 mailimap_store_att_flags_new_remove_flags_silent(struct mailimap_flag_list * 479 flags); 480 481 482 /* 483 this function creates a condition structure to match all messages 484 */ 485 486 LIBETPAN_EXPORT 487 struct mailimap_search_key * 488 mailimap_search_key_new_all(void); 489 490 /* 491 this function creates a condition structure to match messages with Bcc field 492 493 @param bcc this is the content of Bcc to match, it should be allocated 494 with malloc() 495 */ 496 497 LIBETPAN_EXPORT 498 struct mailimap_search_key * 499 mailimap_search_key_new_bcc(char * sk_bcc); 500 501 /* 502 this function creates a condition structure to match messages with 503 internal date 504 */ 505 506 LIBETPAN_EXPORT 507 struct mailimap_search_key * 508 mailimap_search_key_new_before(struct mailimap_date * sk_before); 509 510 /* 511 this function creates a condition structure to match messages with 512 message content 513 514 @param body this is the content of the message to match, it should 515 be allocated with malloc() 516 */ 517 518 LIBETPAN_EXPORT 519 struct mailimap_search_key * 520 mailimap_search_key_new_body(char * sk_body); 521 522 /* 523 this function creates a condition structure to match messages with 524 Cc field 525 526 527 @param cc this is the content of Cc to match, it should be allocated 528 with malloc() 529 */ 530 531 LIBETPAN_EXPORT 532 struct mailimap_search_key * 533 mailimap_search_key_new_cc(char * sk_cc); 534 535 /* 536 this function creates a condition structure to match messages with 537 From field 538 539 @param from this is the content of From to match, it should be allocated 540 with malloc() 541 */ 542 543 LIBETPAN_EXPORT 544 struct mailimap_search_key * 545 mailimap_search_key_new_from(char * sk_from); 546 547 /* 548 this function creates a condition structure to match messages with 549 a flag given by keyword 550 */ 551 552 LIBETPAN_EXPORT 553 struct mailimap_search_key * 554 mailimap_search_key_new_keyword(char * sk_keyword); 555 556 /* 557 this function creates a condition structure to match messages with 558 internal date 559 */ 560 561 LIBETPAN_EXPORT 562 struct mailimap_search_key * 563 mailimap_search_key_new_on(struct mailimap_date * sk_on); 564 565 /* 566 this function creates a condition structure to match messages with 567 internal date 568 */ 569 570 LIBETPAN_EXPORT 571 struct mailimap_search_key * 572 mailimap_search_key_new_since(struct mailimap_date * sk_since); 573 574 /* 575 this function creates a condition structure to match messages with 576 Subject field 577 578 @param subject this is the content of Subject to match, it should 579 be allocated with malloc() 580 */ 581 582 LIBETPAN_EXPORT 583 struct mailimap_search_key * 584 mailimap_search_key_new_subject(char * sk_subject); 585 586 /* 587 this function creates a condition structure to match messages with 588 message text part 589 590 @param text this is the message text to match, it should 591 be allocated with malloc() 592 */ 593 594 LIBETPAN_EXPORT 595 struct mailimap_search_key * 596 mailimap_search_key_new_text(char * sk_text); 597 598 /* 599 this function creates a condition structure to match messages with 600 To field 601 602 @param to this is the content of To to match, it should be allocated 603 with malloc() 604 */ 605 606 LIBETPAN_EXPORT 607 struct mailimap_search_key * 608 mailimap_search_key_new_to(char * sk_to); 609 610 /* 611 this function creates a condition structure to match messages with 612 no a flag given by unkeyword 613 */ 614 615 LIBETPAN_EXPORT 616 struct mailimap_search_key * 617 mailimap_search_key_new_unkeyword(char * sk_unkeyword); 618 619 /* 620 this function creates a condition structure to match messages with 621 the given field 622 623 @param header_name this is the name of the field to match, it 624 should be allocated with malloc() 625 626 @param header_value this is the content, it should be allocated 627 with malloc() 628 */ 629 630 LIBETPAN_EXPORT 631 struct mailimap_search_key * 632 mailimap_search_key_new_header(char * sk_header_name, char * sk_header_value); 633 634 /* 635 this function creates a condition structure to match messages with size 636 */ 637 638 LIBETPAN_EXPORT 639 struct mailimap_search_key * 640 mailimap_search_key_new_larger(uint32_t sk_larger); 641 642 /* 643 this function creates a condition structure to match messages that 644 do not match the given condition 645 */ 646 647 LIBETPAN_EXPORT 648 struct mailimap_search_key * 649 mailimap_search_key_new_not(struct mailimap_search_key * sk_not); 650 651 /* 652 this function creates a condition structure to match messages that 653 match one of the given conditions 654 */ 655 656 LIBETPAN_EXPORT 657 struct mailimap_search_key * 658 mailimap_search_key_new_or(struct mailimap_search_key * sk_or1, 659 struct mailimap_search_key * sk_or2); 660 661 /* 662 this function creates a condition structure to match messages 663 with Date field 664 */ 665 666 LIBETPAN_EXPORT 667 struct mailimap_search_key * 668 mailimap_search_key_new_sentbefore(struct mailimap_date * sk_sentbefore); 669 670 /* 671 this function creates a condition structure to match messages 672 with Date field 673 */ 674 675 LIBETPAN_EXPORT 676 struct mailimap_search_key * 677 mailimap_search_key_new_senton(struct mailimap_date * sk_senton); 678 679 /* 680 this function creates a condition structure to match messages 681 with Date field 682 */ 683 684 LIBETPAN_EXPORT 685 struct mailimap_search_key * 686 mailimap_search_key_new_sentsince(struct mailimap_date * sk_sentsince); 687 688 /* 689 this function creates a condition structure to match messages with size 690 */ 691 692 LIBETPAN_EXPORT 693 struct mailimap_search_key * 694 mailimap_search_key_new_smaller(uint32_t sk_smaller); 695 696 /* 697 this function creates a condition structure to match messages with unique 698 identifier 699 */ 700 701 LIBETPAN_EXPORT 702 struct mailimap_search_key * 703 mailimap_search_key_new_uid(struct mailimap_set * sk_uid); 704 705 /* 706 this function creates a condition structure to match messages with number 707 or unique identifier (depending whether SEARCH or UID SEARCH is used) 708 */ 709 710 LIBETPAN_EXPORT 711 struct mailimap_search_key * 712 mailimap_search_key_new_set(struct mailimap_set * sk_set); 713 714 /* 715 this function creates a condition structure to match messages that match 716 all the conditions given in the list 717 */ 718 719 LIBETPAN_EXPORT 720 struct mailimap_search_key * 721 mailimap_search_key_new_multiple(clist * sk_multiple); 722 723 724 /* 725 same as previous but the list is empty 726 */ 727 728 LIBETPAN_EXPORT 729 struct mailimap_search_key * 730 mailimap_search_key_new_multiple_empty(void); 731 732 /* 733 this function adds a condition to the condition list 734 735 @return MAILIMAP_NO_ERROR will be returned on success, 736 other code will be returned otherwise 737 */ 738 739 LIBETPAN_EXPORT 740 int 741 mailimap_search_key_multiple_add(struct mailimap_search_key * keys, 742 struct mailimap_search_key * key_item); 743 744 745 746 /* 747 this function creates an empty list of flags 748 */ 749 750 LIBETPAN_EXPORT 751 struct mailimap_flag_list * 752 mailimap_flag_list_new_empty(void); 753 754 /* 755 this function adds a flag to the list of flags 756 757 @return MAILIMAP_NO_ERROR will be returned on success, 758 other code will be returned otherwise 759 */ 760 761 LIBETPAN_EXPORT 762 int mailimap_flag_list_add(struct mailimap_flag_list * flag_list, 763 struct mailimap_flag * f); 764 765 /* 766 this function creates a \Answered flag 767 */ 768 769 LIBETPAN_EXPORT 770 struct mailimap_flag * mailimap_flag_new_answered(void); 771 772 /* 773 this function creates a \Flagged flag 774 */ 775 776 LIBETPAN_EXPORT 777 struct mailimap_flag * mailimap_flag_new_flagged(void); 778 779 /* 780 this function creates a \Deleted flag 781 */ 782 783 LIBETPAN_EXPORT 784 struct mailimap_flag * mailimap_flag_new_deleted(void); 785 786 /* 787 this function creates a \Seen flag 788 */ 789 790 LIBETPAN_EXPORT 791 struct mailimap_flag * mailimap_flag_new_seen(void); 792 793 /* 794 this function creates a \Draft flag 795 */ 796 797 LIBETPAN_EXPORT 798 struct mailimap_flag * mailimap_flag_new_draft(void); 799 800 /* 801 this function creates a keyword flag 802 803 @param flag_keyword this should be allocated with malloc() 804 */ 805 806 LIBETPAN_EXPORT 807 struct mailimap_flag * mailimap_flag_new_flag_keyword(char * flag_keyword); 808 809 810 /* 811 this function creates an extension flag 812 813 @param flag_extension this should be allocated with malloc() 814 */ 815 816 LIBETPAN_EXPORT 817 struct mailimap_flag * mailimap_flag_new_flag_extension(char * flag_extension); 818 819 /* 820 this function creates an empty list of status attributes 821 */ 822 823 LIBETPAN_EXPORT 824 struct mailimap_status_att_list * mailimap_status_att_list_new_empty(void); 825 826 /* 827 this function adds status attributes to the list 828 829 @return MAILIMAP_NO_ERROR will be returned on success, 830 other code will be returned otherwise 831 */ 832 833 LIBETPAN_EXPORT 834 int 835 mailimap_status_att_list_add(struct mailimap_status_att_list * sa_list, 836 int status_att); 837 838 /* return mailimap_section_part from a given mailimap_body */ 839 840 LIBETPAN_EXPORT 841 int mailimap_get_section_part_from_body(struct mailimap_body * root_part, 842 struct mailimap_body * part, 843 struct mailimap_section_part ** result); 844 845 #ifdef __cplusplus 846 } 847 #endif 848 849 #endif 850