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.h,v 1.34 2011/01/06 00:09:52 hoa Exp $
34  */
35 
36 /*
37   IMAP4rev1 grammar
38 
39    address         = "(" addr-name SP addr-adl SP addr-mailbox SP
40                      addr-host ")"
41 
42    addr-adl        = nstring
43                        ; Holds route from [RFC-822] route-addr if
44                        ; non-NIL
45 
46    addr-host       = nstring
47                        ; NIL indicates [RFC-822] group syntax.
48                        ; Otherwise, holds [RFC-822] domain name
49 
50    addr-mailbox    = nstring
51                        ; NIL indicates end of [RFC-822] group; if
52                        ; non-NIL and addr-host is NIL, holds
53                        ; [RFC-822] group name.
54                        ; Otherwise, holds [RFC-822] local-part
55                        ; after removing [RFC-822] quoting
56 
57 
58 
59    addr-name       = nstring
60                        ; If non-NIL, holds phrase from [RFC-822]
61                        ; mailbox after removing [RFC-822] quoting
62 
63    append          = "APPEND" SP mailbox [SP flag-list] [SP date-time] SP
64                      literal
65 
66    astring         = 1*ASTRING-CHAR / string
67 
68    ASTRING-CHAR   = ATOM-CHAR / resp-specials
69 
70    atom            = 1*ATOM-CHAR
71 
72    ATOM-CHAR       = <any CHAR except atom-specials>
73 
74    atom-specials   = "(" / ")" / "{" / SP / CTL / list-wildcards /
75                      quoted-specials / resp-specials
76 
77    authenticate    = "AUTHENTICATE" SP auth-type *(CRLF base64)
78 
79    auth-type       = atom
80                        ; Defined by [SASL]
81 
82    base64          = *(4base64-char) [base64-terminal]
83 
84    base64-char     = ALPHA / DIGIT / "+" / "/"
85                        ; Case-sensitive
86 
87    base64-terminal = (2base64-char "==") / (3base64-char "=")
88 
89    body            = "(" (body-type-1part / body-type-mpart) ")"
90 
91    body-extension  = nstring / number /
92                       "(" body-extension *(SP body-extension) ")"
93                        ; Future expansion.  Client implementations
94                        ; MUST accept body-extension fields.  Server
95                        ; implementations MUST NOT generate
96                        ; body-extension fields except as defined by
97                        ; future standard or standards-track
98                        ; revisions of this specification.
99 
100    body-ext-1part  = body-fld-md5 [SP body-fld-dsp [SP body-fld-lang
101                      *(SP body-extension)]]
102                        ; MUST NOT be returned on non-extensible
103                        ; "BODY" fetch
104 
105 
106    body-ext-mpart  = body-fld-param [SP body-fld-dsp [SP body-fld-lang
107                      *(SP body-extension)]]
108                        ; MUST NOT be returned on non-extensible
109                        ; "BODY" fetch
110 
111    body-fields     = body-fld-param SP body-fld-id SP body-fld-desc SP
112                      body-fld-enc SP body-fld-octets
113 
114    body-fld-desc   = nstring
115 
116    body-fld-dsp    = "(" string SP body-fld-param ")" / nil
117 
118    body-fld-enc    = (DQUOTE ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
119                      "QUOTED-PRINTABLE") DQUOTE) / string
120 
121    body-fld-id     = nstring
122 
123    body-fld-lang   = nstring / "(" string *(SP string) ")"
124 
125    body-fld-lines  = number
126 
127    body-fld-md5    = nstring
128 
129    body-fld-octets = number
130 
131    body-fld-param  = "(" string SP string *(SP string SP string) ")" / nil
132 
133    body-type-1part = (body-type-basic / body-type-msg / body-type-text)
134                      [SP body-ext-1part]
135 
136    body-type-basic = media-basic SP body-fields
137                        ; MESSAGE subtype MUST NOT be "RFC822"
138 
139    body-type-mpart = 1*body SP media-subtype
140                      [SP body-ext-mpart]
141 
142    body-type-msg   = media-message SP body-fields SP envelope
143                      SP body SP body-fld-lines
144 
145    body-type-text  = media-text SP body-fields SP body-fld-lines
146 
147    capability      = ("AUTH=" auth-type) / atom
148                        ; New capabilities MUST begin with "X" or be
149                        ; registered with IANA as standard or
150                        ; standards-track
151 
152 
153    capability-data = "CAPABILITY" *(SP capability) SP "IMAP4rev1"
154                      *(SP capability)
155                        ; IMAP4rev1 servers which offer RFC 1730
156                        ; compatibility MUST list "IMAP4" as the first
157                        ; capability.
158 
159    CHAR8           = %x01-ff
160                        ; any OCTET except NUL, %x00
161 
162    command         = tag SP (command-any / command-auth / command-nonauth /
163                      command-select) CRLF
164                        ; Modal based on state
165 
166    command-any     = "CAPABILITY" / "LOGOUT" / "NOOP" / x-command
167                        ; Valid in all states
168 
169    command-auth    = append / create / delete / examine / list / lsub /
170                      rename / select / status / subscribe / unsubscribe
171                        ; Valid only in Authenticated or Selected state
172 
173    command-nonauth = login / authenticate
174                        ; Valid only when in Not Authenticated state
175 
176    command-select  = "CHECK" / "CLOSE" / "EXPUNGE" / copy / fetch / store /
177                      uid / search
178                        ; Valid only when in Selected state
179 
180    continue-req    = "+" SP (resp-text / base64) CRLF
181 
182    copy            = "COPY" SP set SP mailbox
183 
184    create          = "CREATE" SP mailbox
185                        ; Use of INBOX gives a NO error
186 
187    date            = date-text / DQUOTE date-text DQUOTE
188 
189    date-day        = 1*2DIGIT
190                        ; Day of month
191 
192    date-day-fixed  = (SP DIGIT) / 2DIGIT
193                        ; Fixed-format version of date-day
194 
195    date-month      = "Jan" / "Feb" / "Mar" / "Apr" / "May" / "Jun" /
196                      "Jul" / "Aug" / "Sep" / "Oct" / "Nov" / "Dec"
197 
198    date-text       = date-day "-" date-month "-" date-year
199 
200    date-year       = 4DIGIT
201 
202    date-time       = DQUOTE date-day-fixed "-" date-month "-" date-year
203                      SP time SP zone DQUOTE
204 
205    delete          = "DELETE" SP mailbox
206                        ; Use of INBOX gives a NO error
207 
208    digit-nz        = %x31-39
209                        ; 1-9
210 
211    envelope        = "(" env-date SP env-subject SP env-from SP env-sender SP
212                      env-reply-to SP env-to SP env-cc SP env-bcc SP
213                      env-in-reply-to SP env-message-id ")"
214 
215    env-bcc         = "(" 1*address ")" / nil
216 
217    env-cc          = "(" 1*address ")" / nil
218 
219    env-date        = nstring
220 
221    env-from        = "(" 1*address ")" / nil
222 
223    env-in-reply-to = nstring
224 
225    env-message-id  = nstring
226 
227    env-reply-to    = "(" 1*address ")" / nil
228 
229    env-sender      = "(" 1*address ")" / nil
230 
231    env-subject     = nstring
232 
233    env-to          = "(" 1*address ")" / nil
234 
235    examine         = "EXAMINE" SP mailbox
236 
237    fetch           = "FETCH" SP set SP ("ALL" / "FULL" / "FAST" / fetch-att /
238                      "(" fetch-att *(SP fetch-att) ")")
239 
240    fetch-att       = "ENVELOPE" / "FLAGS" / "INTERNALDATE" /
241                      "RFC822" [".HEADER" / ".SIZE" / ".TEXT"] /
242                      "BODY" ["STRUCTURE"] / "UID" /
243                      "BODY" [".PEEK"] section ["<" number "." nz-number ">"]
244 
245    flag            = "\Answered" / "\Flagged" / "\Deleted" /
246                      "\Seen" / "\Draft" / flag-keyword / flag-extension
247                        ; Does not include "\Recent"
248 
249    flag-extension  = "\" atom
250                        ; Future expansion.  Client implementations
251                        ; MUST accept flag-extension flags.  Server
252                        ; implementations MUST NOT generate
253                        ; flag-extension flags except as defined by
254                        ; future standard or standards-track
255                        ; revisions of this specification.
256 
257    flag-fetch      = flag / "\Recent"
258 
259    flag-keyword    = atom
260 
261    flag-list       = "(" [flag *(SP flag)] ")"
262 
263    flag-perm       = flag / "\*"
264 
265    greeting        = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
266 
267    header-fld-name = astring
268 
269    header-list     = "(" header-fld-name *(SP header-fld-name) ")"
270 
271    list            = "LIST" SP mailbox SP list-mailbox
272 
273    list-mailbox    = 1*list-char / string
274 
275    list-char       = ATOM-CHAR / list-wildcards / resp-specials
276 
277    list-wildcards  = "%" / "*"
278 
279    literal         = "{" number "}" CRLF *CHAR8
280                        ; Number represents the number of CHAR8s
281 
282    login           = "LOGIN" SP userid SP password
283 
284    lsub            = "LSUB" SP mailbox SP list-mailbox
285 
286    mailbox         = "INBOX" / astring
287                        ; INBOX is case-insensitive.  All case variants of
288                        ; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX
289                        ; not as an astring.  An astring which consists of
290                        ; the case-insensitive sequence "I" "N" "B" "O" "X"
291                        ; is considered to be INBOX and not an astring.
292                        ;  Refer to section 5.1 for further
293                        ; semantic details of mailbox names.
294 
295    mailbox-data    =  "FLAGS" SP flag-list / "LIST" SP mailbox-list /
296                       "LSUB" SP mailbox-list / "SEARCH" *(SP nz-number) /
297                       "STATUS" SP mailbox SP "("
298                       [status-att SP number *(SP status-att SP number)] ")" /
299                       number SP "EXISTS" / number SP "RECENT"
300 
301    mailbox-list    = "(" [mbx-list-flags] ")" SP
302                       (DQUOTE QUOTED-CHAR DQUOTE / nil) SP mailbox
303 
304    mbx-list-flags  = *(mbx-list-oflag SP) mbx-list-sflag
305                      *(SP mbx-list-oflag) /
306                      mbx-list-oflag *(SP mbx-list-oflag)
307 
308    mbx-list-oflag  = "\Noinferiors" / flag-extension
309                        ; Other flags; multiple possible per LIST response
310 
311    mbx-list-sflag  = "\Noselect" / "\Marked" / "\Unmarked"
312                        ; Selectability flags; only one per LIST response
313 
314    media-basic     = ((DQUOTE ("APPLICATION" / "AUDIO" / "IMAGE" / "MESSAGE" /
315                      "VIDEO") DQUOTE) / string) SP media-subtype
316                        ; Defined in [MIME-IMT]
317 
318    media-message   = DQUOTE "MESSAGE" DQUOTE SP DQUOTE "RFC822" DQUOTE
319                        ; Defined in [MIME-IMT]
320 
321    media-subtype   = string
322                        ; Defined in [MIME-IMT]
323 
324    media-text      = DQUOTE "TEXT" DQUOTE SP media-subtype
325                        ; Defined in [MIME-IMT]
326 
327    message-data    = nz-number SP ("EXPUNGE" / ("FETCH" SP msg-att))
328 
329    msg-att         = "(" (msg-att-dynamic / msg-att-static)
330                       *(SP (msg-att-dynamic / msg-att-static)) ")"
331 
332    msg-att-dynamic = "FLAGS" SP "(" [flag-fetch *(SP flag-fetch)] ")"
333                        ; MAY change for a message
334 
335    msg-att-static  = "ENVELOPE" SP envelope / "INTERNALDATE" SP date-time /
336                      "RFC822" [".HEADER" / ".TEXT"] SP nstring /
337                      "RFC822.SIZE" SP number / "BODY" ["STRUCTURE"] SP body /
338                      "BODY" section ["<" number ">"] SP nstring /
339                      "UID" SP uniqueid
340                        ; MUST NOT change for a message
341 
342    nil             = "NIL"
343 
344    nstring         = string / nil
345 
346    number          = 1*DIGIT
347                        ; Unsigned 32-bit integer
348                        ; (0 <= n < 4,294,967,296)
349 
350    nz-number       = digit-nz *DIGIT
351                        ; Non-zero unsigned 32-bit integer
352                        ; (0 < n < 4,294,967,296)
353 
354    password        = astring
355 
356    quoted          = DQUOTE *QUOTED-CHAR DQUOTE
357 
358    QUOTED-CHAR     = <any TEXT-CHAR except quoted-specials> /
359                      "\" quoted-specials
360 
361    quoted-specials = DQUOTE / "\"
362 
363    rename          = "RENAME" SP mailbox SP mailbox
364                        ; Use of INBOX as a destination gives a NO error
365 
366    response        = *(continue-req / response-data) response-done
367 
368    response-data   = "*" SP (resp-cond-state / resp-cond-bye /
369                      mailbox-data / message-data / capability-data) CRLF
370 
371    response-done   = response-tagged / response-fatal
372 
373    response-fatal  = "*" SP resp-cond-bye CRLF
374                        ; Server closes connection immediately
375 
376    response-tagged = tag SP resp-cond-state CRLF
377 
378    resp-cond-auth  = ("OK" / "PREAUTH") SP resp-text
379                        ; Authentication condition
380 
381    resp-cond-bye   = "BYE" SP resp-text
382 
383    resp-cond-state = ("OK" / "NO" / "BAD") SP resp-text
384                        ; Status condition
385 
386    resp-specials   = "]"
387 
388    resp-text       = ["[" resp-text-code "]" SP] text
389 
390    resp-text-code  = "ALERT" /
391                      "BADCHARSET" [SP "(" astring *(SP astring) ")" ] /
392                      capability-data / "PARSE" /
393                      "PERMANENTFLAGS" SP "(" [flag-perm *(SP flag-perm)] ")" /
394                      "READ-ONLY" / "READ-WRITE" / "TRYCREATE" /
395                      "UIDNEXT" SP nz-number / "UIDVALIDITY" SP nz-number /
396                      "UNSEEN" SP nz-number /
397                      atom [SP 1*<any TEXT-CHAR except "]">]
398 
399    search          = "SEARCH" [SP "CHARSET" SP astring] 1*(SP search-key)
400                        ; CHARSET argument to MUST be registered with IANA
401 
402    search-key      = "ALL" / "ANSWERED" / "BCC" SP astring /
403                      "BEFORE" SP date / "BODY" SP astring /
404                      "CC" SP astring / "DELETED" / "FLAGGED" /
405                      "FROM" SP astring / "KEYWORD" SP flag-keyword / "NEW" /
406                      "OLD" / "ON" SP date / "RECENT" / "SEEN" /
407                      "SINCE" SP date / "SUBJECT" SP astring /
408                      "TEXT" SP astring / "TO" SP astring /
409                      "UNANSWERED" / "UNDELETED" / "UNFLAGGED" /
410                      "UNKEYWORD" SP flag-keyword / "UNSEEN" /
411                        ; Above this line were in [IMAP2]
412                      "DRAFT" / "HEADER" SP header-fld-name SP astring /
413                      "LARGER" SP number / "NOT" SP search-key /
414                      "OR" SP search-key SP search-key /
415                      "SENTBEFORE" SP date / "SENTON" SP date /
416                      "SENTSINCE" SP date / "SMALLER" SP number /
417                      "UID" SP set / "UNDRAFT" / set /
418                      "(" search-key *(SP search-key) ")"
419 
420    section         = "[" [section-spec] "]"
421 
422    section-msgtext = "HEADER" / "HEADER.FIELDS" [".NOT"] SP header-list /
423                      "TEXT"
424                        ; top-level or MESSAGE/RFC822 part
425 
426    section-part    = nz-number *("." nz-number)
427                        ; body part nesting
428 
429    section-spec    = section-msgtext / (section-part ["." section-text])
430 
431    section-text    = section-msgtext / "MIME"
432                        ; text other than actual body part (headers, etc.)
433 
434    select          = "SELECT" SP mailbox
435 
436    sequence-num    = nz-number / "*"
437                        ; * is the largest number in use.  For message
438                        ; sequence numbers, it is the number of messages
439                        ; in the mailbox.  For unique identifiers, it is
440                        ; the unique identifier of the last message in
441                        ; the mailbox.
442 
443    set             = sequence-num / (sequence-num ":" sequence-num) /
444                      (set "," set)
445                        ; Identifies a set of messages.  For message
446                        ; sequence numbers, these are consecutive
447                        ; numbers from 1 to the number of messages in
448                        ; the mailbox
449                        ; Comma delimits individual numbers, colon
450                        ; delimits between two numbers inclusive.
451                        ; Example: 2,4:7,9,12:* is 2,4,5,6,7,9,12,13,
452                        ; 14,15 for a mailbox with 15 messages.
453 
454 
455    status          = "STATUS" SP mailbox SP "(" status-att *(SP status-att) ")"
456 
457    status-att      = "MESSAGES" / "RECENT" / "UIDNEXT" / "UIDVALIDITY" /
458                      "UNSEEN"
459 
460    store           = "STORE" SP set SP store-att-flags
461 
462    store-att-flags = (["+" / "-"] "FLAGS" [".SILENT"]) SP
463                      (flag-list / (flag *(SP flag)))
464 
465    string          = quoted / literal
466 
467    subscribe       = "SUBSCRIBE" SP mailbox
468 
469    tag             = 1*<any ASTRING-CHAR except "+">
470 
471    text            = 1*TEXT-CHAR
472 
473    TEXT-CHAR       = <any CHAR except CR and LF>
474 
475    time            = 2DIGIT ":" 2DIGIT ":" 2DIGIT
476                        ; Hours minutes seconds
477 
478    uid             = "UID" SP (copy / fetch / search / store)
479                        ; Unique identifiers used instead of message
480                        ; sequence numbers
481 
482    uniqueid        = nz-number
483                        ; Strictly ascending
484 
485    unsubscribe     = "UNSUBSCRIBE" SP mailbox
486 
487    userid          = astring
488 
489    x-command       = "X" atom <experimental command arguments>
490 
491    zone            = ("+" / "-") 4DIGIT
492                        ; Signed four-digit value of hhmm representing
493                        ; hours and minutes east of Greenwich (that is,
494                        ; the amount that the given time differs from
495                        ; Universal Time).  Subtracting the timezone
496                        ; from the given time will give the UT form.
497                        ; The Universal Time zone is "+0000".
498 */
499 
500 
501 #ifndef MAILIMAP_TYPES_H
502 
503 #define MAILIMAP_TYPES_H
504 
505 #ifdef __cplusplus
506 extern "C" {
507 #endif
508 
509 #include <libetpan/libetpan-config.h>
510 #include <libetpan/mailstream.h>
511 #include <libetpan/clist.h>
512 #include <stdbool.h>
513 
514 
515 /*
516   IMPORTANT NOTE:
517 
518   All allocation functions will take as argument allocated data
519   and will store these data in the structure they will allocate.
520   Data should be persistant during all the use of the structure
521   and will be freed by the free function of the structure
522 
523   allocation functions will return NULL on failure
524 */
525 
526 
527 /*
528   mailimap_address represents a mail address
529 
530   - personal_name is the name to display in an address
531     '"name"' in '"name" <address@domain>', should be allocated
532     with a malloc()
533 
534   - source_route is the source-route information in the
535     mail address (RFC 822), should be allocated with a malloc()
536 
537   - mailbox_name is the name of the mailbox 'address' in
538     '"name" <address@domain>', should be allocated with a malloc()
539 
540   - host_name is the name of the host 'domain' in
541     '"name" <address@domain>', should be allocated with a malloc()
542 
543   if mailbox_name is not NULL and host_name is NULL, this is the name
544   of a group, the next addresses in the list are elements of the group
545   until we reach an address with a NULL mailbox_name.
546 */
547 
548 struct mailimap_address {
549   char * ad_personal_name; /* can be NULL */
550   char * ad_source_route;  /* can be NULL */
551   char * ad_mailbox_name;  /* can be NULL */
552   char * ad_host_name;     /* can be NULL */
553 };
554 
555 
556 LIBETPAN_EXPORT
557 struct mailimap_address *
558 mailimap_address_new(char * ad_personal_name, char * ad_source_route,
559 		     char * ad_mailbox_name, char * ad_host_name);
560 
561 LIBETPAN_EXPORT
562 void mailimap_address_free(struct mailimap_address * addr);
563 
564 
565 /* this is the type of MIME body parsed by IMAP server */
566 
567 enum {
568   MAILIMAP_BODY_ERROR,
569   MAILIMAP_BODY_1PART, /* single part */
570   MAILIMAP_BODY_MPART  /* multi-part */
571 };
572 
573 /*
574   mailimap_body represent a MIME body parsed by IMAP server
575 
576   - type is the type of the MIME part (single part or multipart)
577 
578   - body_1part is defined if this is a single part
579 
580   - body_mpart is defined if this is a multipart
581 */
582 
583 struct mailimap_body {
584   int bd_type;
585   /* can be MAILIMAP_BODY_1PART or MAILIMAP_BODY_MPART */
586   union {
587     struct mailimap_body_type_1part * bd_body_1part; /* can be NULL */
588     struct mailimap_body_type_mpart * bd_body_mpart; /* can be NULL */
589   } bd_data;
590 };
591 
592 
593 LIBETPAN_EXPORT
594 struct mailimap_body *
595 mailimap_body_new(int bd_type,
596 		  struct mailimap_body_type_1part * bd_body_1part,
597 		  struct mailimap_body_type_mpart * bd_body_mpart);
598 
599 LIBETPAN_EXPORT
600 void mailimap_body_free(struct mailimap_body * body);
601 
602 
603 
604 /*
605   this is the type of MIME body extension
606 */
607 
608 enum {
609   MAILIMAP_BODY_EXTENSION_ERROR,
610   MAILIMAP_BODY_EXTENSION_NSTRING, /* string */
611   MAILIMAP_BODY_EXTENSION_NUMBER,  /* number */
612   MAILIMAP_BODY_EXTENSION_LIST     /* list of
613                                       (struct mailimap_body_extension *) */
614 };
615 
616 /*
617   mailimap_body_extension is a future extension header field value
618 
619   - type is the type of the body extension (string, number or
620     list of extension)
621 
622   - nstring is a string value if the type is string
623 
624   - number is a integer value if the type is number
625 
626   - list is a list of body extension if the type is a list
627 */
628 
629 struct mailimap_body_extension {
630   int ext_type;
631   /*
632     can be MAILIMAP_BODY_EXTENSION_NSTRING, MAILIMAP_BODY_EXTENSION_NUMBER
633     or MAILIMAP_BODY_EXTENSION_LIST
634   */
635   union {
636     char * ext_nstring;    /* can be NULL */
637     uint32_t ext_number;
638     clist * ext_body_extension_list;
639     /* list of (struct mailimap_body_extension *) */
640     /* can be NULL */
641   } ext_data;
642 };
643 
644 LIBETPAN_EXPORT
645 struct mailimap_body_extension *
646 mailimap_body_extension_new(int ext_type, char * ext_nstring,
647     uint32_t ext_number,
648     clist * ext_body_extension_list);
649 
650 LIBETPAN_EXPORT
651 void mailimap_body_extension_free(struct mailimap_body_extension * be);
652 
653 
654 /*
655   mailimap_body_ext_1part is the extended result part of a single part
656   bodystructure.
657 
658   - body_md5 is the value of the Content-MD5 header field, should be
659     allocated with malloc()
660 
661   - body_disposition is the value of the Content-Disposition header field
662 
663   - body_language is the value of the Content-Language header field
664 
665   - body_extension_list is the list of extension fields value.
666 */
667 
668 struct mailimap_body_ext_1part {
669   char * bd_md5;   /* can be NULL */
670   struct mailimap_body_fld_dsp * bd_disposition; /* can be NULL */
671   struct mailimap_body_fld_lang * bd_language;   /* can be NULL */
672   char * bd_loc; /* can be NULL */
673 
674   clist * bd_extension_list; /* list of (struct mailimap_body_extension *) */
675                                /* can be NULL */
676 };
677 
678 LIBETPAN_EXPORT
679 struct mailimap_body_ext_1part *
680 mailimap_body_ext_1part_new(char * bd_md5,
681 			    struct mailimap_body_fld_dsp * bd_disposition,
682 			    struct mailimap_body_fld_lang * bd_language,
683           char * bd_loc,
684 			    clist * bd_extension_list);
685 
686 
687 LIBETPAN_EXPORT
688 void
689 mailimap_body_ext_1part_free(struct mailimap_body_ext_1part * body_ext_1part);
690 
691 
692 /*
693   mailimap_body_ext_mpart is the extended result part of a multipart
694   bodystructure.
695 
696   - body_parameter is the list of parameters of Content-Type header field
697 
698   - body_disposition is the value of Content-Disposition header field
699 
700   - body_language is the value of Content-Language header field
701 
702   - body_extension_list is the list of extension fields value.
703 */
704 
705 struct mailimap_body_ext_mpart {
706   struct mailimap_body_fld_param * bd_parameter; /* can be NULL */
707   struct mailimap_body_fld_dsp * bd_disposition; /* can be NULL */
708   struct mailimap_body_fld_lang * bd_language;   /* can be NULL */
709   char * bd_loc; /* can be NULL */
710   clist * bd_extension_list; /* list of (struct mailimap_body_extension *) */
711                                /* can be NULL */
712 };
713 
714 LIBETPAN_EXPORT
715 struct mailimap_body_ext_mpart *
716 mailimap_body_ext_mpart_new(struct mailimap_body_fld_param * bd_parameter,
717 			    struct mailimap_body_fld_dsp * bd_disposition,
718 			    struct mailimap_body_fld_lang * bd_language,
719           char * bd_loc,
720 			    clist * bd_extension_list);
721 
722 LIBETPAN_EXPORT
723 void
724 mailimap_body_ext_mpart_free(struct mailimap_body_ext_mpart * body_ext_mpart);
725 
726 
727 /*
728   mailimap_body_fields is the MIME fields of a MIME part.
729 
730   - body_parameter is the list of parameters of Content-Type header field
731 
732   - body_id is the value of Content-ID header field, should be allocated
733     with malloc()
734 
735   - body_description is the value of Content-Description header field,
736     should be allocated with malloc()
737 
738   - body_encoding is the value of Content-Transfer-Encoding header field
739 
740   - body_disposition is the value of Content-Disposition header field
741 
742   - body_size is the size of the MIME part
743 */
744 
745 struct mailimap_body_fields {
746   struct mailimap_body_fld_param * bd_parameter; /* can be NULL */
747   char * bd_id;                                  /* can be NULL */
748   char * bd_description;                         /* can be NULL */
749   struct mailimap_body_fld_enc * bd_encoding;    /* != NULL */
750   uint32_t bd_size;
751 };
752 
753 LIBETPAN_EXPORT
754 struct mailimap_body_fields *
755 mailimap_body_fields_new(struct mailimap_body_fld_param * bd_parameter,
756 			 char * bd_id,
757 			 char * bd_description,
758 			 struct mailimap_body_fld_enc * bd_encoding,
759 			 uint32_t bd_size);
760 
761 LIBETPAN_EXPORT
762 void
763 mailimap_body_fields_free(struct mailimap_body_fields * body_fields);
764 
765 
766 
767 /*
768   mailimap_body_fld_dsp is the parsed value of the Content-Disposition field
769 
770   - disposition_type is the type of Content-Disposition
771     (usually attachment or inline), should be allocated with malloc()
772 
773   - attributes is the list of Content-Disposition attributes
774 */
775 
776 struct mailimap_body_fld_dsp {
777   char * dsp_type;                     /* != NULL */
778   struct mailimap_body_fld_param * dsp_attributes; /* can be NULL */
779 };
780 
781 LIBETPAN_EXPORT
782 struct mailimap_body_fld_dsp *
783 mailimap_body_fld_dsp_new(char * dsp_type,
784     struct mailimap_body_fld_param * dsp_attributes);
785 
786 LIBETPAN_EXPORT
787 void mailimap_body_fld_dsp_free(struct mailimap_body_fld_dsp * bfd);
788 
789 
790 
791 /* these are the different parsed values for Content-Transfer-Encoding */
792 
793 enum {
794   MAILIMAP_BODY_FLD_ENC_7BIT,             /* 7bit */
795   MAILIMAP_BODY_FLD_ENC_8BIT,             /* 8bit */
796   MAILIMAP_BODY_FLD_ENC_BINARY,           /* binary */
797   MAILIMAP_BODY_FLD_ENC_BASE64,           /* base64 */
798   MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE, /* quoted-printable */
799   MAILIMAP_BODY_FLD_ENC_OTHER             /* other */
800 };
801 
802 /*
803   mailimap_body_fld_enc is a parsed value for Content-Transfer-Encoding
804 
805   - type is the kind of Content-Transfer-Encoding, this can be
806     MAILIMAP_BODY_FLD_ENC_7BIT, MAILIMAP_BODY_FLD_ENC_8BIT,
807     MAILIMAP_BODY_FLD_ENC_BINARY, MAILIMAP_BODY_FLD_ENC_BASE64,
808     MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE or MAILIMAP_BODY_FLD_ENC_OTHER
809 
810   - in case of MAILIMAP_BODY_FLD_ENC_OTHER, this value is defined,
811     should be allocated with malloc()
812 */
813 
814 struct mailimap_body_fld_enc {
815   int enc_type;
816   char * enc_value; /* can be NULL */
817 };
818 
819 LIBETPAN_EXPORT
820 struct mailimap_body_fld_enc *
821 mailimap_body_fld_enc_new(int enc_type, char * enc_value);
822 
823 LIBETPAN_EXPORT
824 void mailimap_body_fld_enc_free(struct mailimap_body_fld_enc * bfe);
825 
826 
827 /* this is the type of Content-Language header field value */
828 
829 enum {
830   MAILIMAP_BODY_FLD_LANG_ERROR,  /* error parse */
831   MAILIMAP_BODY_FLD_LANG_SINGLE, /* single value */
832   MAILIMAP_BODY_FLD_LANG_LIST    /* list of values */
833 };
834 
835 /*
836   mailimap_body_fld_lang is the parsed value of the Content-Language field
837 
838   - type is the type of content, this can be MAILIMAP_BODY_FLD_LANG_SINGLE
839     if this is a single value or MAILIMAP_BODY_FLD_LANG_LIST if there are
840     several values
841 
842   - single is the single value if the type is MAILIMAP_BODY_FLD_LANG_SINGLE,
843     should be allocated with malloc()
844 
845   - list is the list of value if the type is MAILIMAP_BODY_FLD_LANG_LIST,
846     all elements of the list should be allocated with malloc()
847 */
848 
849 struct mailimap_body_fld_lang {
850   int lg_type;
851   union {
852     char * lg_single; /* can be NULL */
853     clist * lg_list; /* list of string (char *), can be NULL */
854   } lg_data;
855 };
856 
857 LIBETPAN_EXPORT
858 struct mailimap_body_fld_lang *
859 mailimap_body_fld_lang_new(int lg_type, char * lg_single, clist * lg_list);
860 
861 LIBETPAN_EXPORT
862 void
863 mailimap_body_fld_lang_free(struct mailimap_body_fld_lang * fld_lang);
864 
865 
866 
867 /*
868   mailimap_single_body_fld_param is a body field parameter
869 
870   - name is the name of the parameter, should be allocated with malloc()
871 
872   - value is the value of the parameter, should be allocated with malloc()
873 */
874 
875 struct mailimap_single_body_fld_param {
876   char * pa_name;  /* != NULL */
877   char * pa_value; /* != NULL */
878 };
879 
880 LIBETPAN_EXPORT
881 struct mailimap_single_body_fld_param *
882 mailimap_single_body_fld_param_new(char * pa_name, char * pa_value);
883 
884 LIBETPAN_EXPORT
885 void
886 mailimap_single_body_fld_param_free(struct mailimap_single_body_fld_param * p);
887 
888 
889 /*
890   mailmap_body_fld_param is a list of parameters
891 
892   - list is the list of parameters.
893 */
894 
895 struct mailimap_body_fld_param {
896   clist * pa_list; /* list of (struct mailimap_single_body_fld_param *) */
897                 /* != NULL */
898 };
899 
900 LIBETPAN_EXPORT
901 struct mailimap_body_fld_param *
902 mailimap_body_fld_param_new(clist * pa_list);
903 
904 LIBETPAN_EXPORT
905 void
906 mailimap_body_fld_param_free(struct mailimap_body_fld_param * fld_param);
907 
908 
909 /*
910   this is the kind of single part: a text part
911   (when Content-Type is text/xxx), a message part (when Content-Type is
912   message/rfc2822) or a basic part (others than multpart/xxx)
913 */
914 
915 enum {
916   MAILIMAP_BODY_TYPE_1PART_ERROR, /* parse error */
917   MAILIMAP_BODY_TYPE_1PART_BASIC, /* others then multipart/xxx */
918   MAILIMAP_BODY_TYPE_1PART_MSG,   /* message/rfc2822 */
919   MAILIMAP_BODY_TYPE_1PART_TEXT   /* text/xxx */
920 };
921 
922 
923 /*
924   mailimap_body_type_1part is
925 
926   - type is the kind of single part, this can be
927   MAILIMAP_BODY_TYPE_1PART_BASIC, MAILIMAP_BODY_TYPE_1PART_MSG or
928   MAILIMAP_BODY_TYPE_1PART_TEXT.
929 
930   - body_type_basic is the basic part when type is
931     MAILIMAP_BODY_TYPE_1PART_BASIC
932 
933   - body_type_msg is the message part when type is
934     MAILIMAP_BODY_TYPE_1PART_MSG
935 
936   - body_type_text is the text part when type is
937     MAILIMAP_BODY_TYPE_1PART_TEXT
938 */
939 
940 struct mailimap_body_type_1part {
941   int bd_type;
942   union {
943     struct mailimap_body_type_basic * bd_type_basic; /* can be NULL */
944     struct mailimap_body_type_msg * bd_type_msg;     /* can be NULL */
945     struct mailimap_body_type_text * bd_type_text;   /* can be NULL */
946   } bd_data;
947   struct mailimap_body_ext_1part * bd_ext_1part;   /* can be NULL */
948 };
949 
950 LIBETPAN_EXPORT
951 struct mailimap_body_type_1part *
952 mailimap_body_type_1part_new(int bd_type,
953     struct mailimap_body_type_basic * bd_type_basic,
954     struct mailimap_body_type_msg * bd_type_msg,
955     struct mailimap_body_type_text * bd_type_text,
956     struct mailimap_body_ext_1part * bd_ext_1part);
957 
958 LIBETPAN_EXPORT
959 void
960 mailimap_body_type_1part_free(struct mailimap_body_type_1part * bt1p);
961 
962 
963 
964 /*
965   mailimap_body_type_basic is a basic field (with Content-Type other
966   than multipart/xxx, message/rfc2822 and text/xxx
967 
968   - media_basic will be the MIME type of the part
969 
970   - body_fields will be the parsed fields of the MIME part
971 */
972 
973 struct mailimap_body_type_basic {
974   struct mailimap_media_basic * bd_media_basic; /* != NULL */
975   struct mailimap_body_fields * bd_fields; /* != NULL */
976 };
977 
978 LIBETPAN_EXPORT
979 struct mailimap_body_type_basic *
980 mailimap_body_type_basic_new(struct mailimap_media_basic * bd_media_basic,
981 			     struct mailimap_body_fields * bd_fields);
982 
983 LIBETPAN_EXPORT
984 void mailimap_body_type_basic_free(struct mailimap_body_type_basic *
985 				   body_type_basic);
986 
987 /*
988   mailimap_body_type_mpart is a MIME multipart.
989 
990   - body_list is the list of sub-parts.
991 
992   - media_subtype is the subtype of the multipart (for example
993     in multipart/alternative, this is "alternative")
994 
995   - body_ext_mpart is the extended fields of the MIME multipart
996 */
997 
998 struct mailimap_body_type_mpart {
999   clist * bd_list; /* list of (struct mailimap_body *) */
1000                      /* != NULL */
1001   char * bd_media_subtype; /* != NULL */
1002   struct mailimap_body_ext_mpart * bd_ext_mpart; /* can be NULL */
1003 };
1004 
1005 LIBETPAN_EXPORT
1006 struct mailimap_body_type_mpart *
1007 mailimap_body_type_mpart_new(clist * bd_list, char * bd_media_subtype,
1008     struct mailimap_body_ext_mpart * bd_ext_mpart);
1009 
1010 LIBETPAN_EXPORT
1011 void mailimap_body_type_mpart_free(struct mailimap_body_type_mpart *
1012     body_type_mpart);
1013 
1014 /*
1015   mailimap_body_type_msg is a MIME message part
1016 
1017   - body_fields is the MIME fields of the MIME message part
1018 
1019   - envelope is the list of parsed RFC 822 fields of the MIME message
1020 
1021   - body is the sub-part of the message
1022 
1023   - body_lines is the number of lines of the message part
1024 */
1025 
1026 struct mailimap_body_type_msg {
1027   struct mailimap_body_fields * bd_fields; /* != NULL */
1028   struct mailimap_envelope * bd_envelope;       /* != NULL */
1029   struct mailimap_body * bd_body;               /* != NULL */
1030   uint32_t bd_lines;
1031 };
1032 
1033 LIBETPAN_EXPORT
1034 struct mailimap_body_type_msg *
1035 mailimap_body_type_msg_new(struct mailimap_body_fields * bd_fields,
1036 			   struct mailimap_envelope * bd_envelope,
1037 			   struct mailimap_body * bd_body,
1038 			   uint32_t bd_lines);
1039 
1040 LIBETPAN_EXPORT
1041 void
1042 mailimap_body_type_msg_free(struct mailimap_body_type_msg * body_type_msg);
1043 
1044 
1045 
1046 /*
1047   mailimap_body_type_text is a single MIME part where Content-Type is text/xxx
1048 
1049   - media-text is the subtype of the text part (for example, in "text/plain",
1050     this is "plain", should be allocated with malloc()
1051 
1052   - body_fields is the MIME fields of the MIME message part
1053 
1054   - body_lines is the number of lines of the message part
1055 */
1056 
1057 struct mailimap_body_type_text {
1058   char * bd_media_text;                         /* != NULL */
1059   struct mailimap_body_fields * bd_fields; /* != NULL */
1060   uint32_t bd_lines;
1061 };
1062 
1063 LIBETPAN_EXPORT
1064 struct mailimap_body_type_text *
1065 mailimap_body_type_text_new(char * bd_media_text,
1066     struct mailimap_body_fields * bd_fields,
1067     uint32_t bd_lines);
1068 
1069 LIBETPAN_EXPORT
1070 void
1071 mailimap_body_type_text_free(struct mailimap_body_type_text * body_type_text);
1072 
1073 
1074 
1075 /* this is the type of capability field */
1076 
1077 enum {
1078   MAILIMAP_CAPABILITY_AUTH_TYPE, /* when the capability is an
1079                                       authentication type */
1080   MAILIMAP_CAPABILITY_NAME       /* other type of capability */
1081 };
1082 
1083 /*
1084   mailimap_capability is a capability of the IMAP server
1085 
1086   - type is the type of capability, this is either a authentication type
1087     (MAILIMAP_CAPABILITY_AUTH_TYPE) or an other type of capability
1088     (MAILIMAP_CAPABILITY_NAME)
1089 
1090   - auth_type is a type of authentication "name" in "AUTH=name",
1091     auth_type can be for example "PLAIN", when this is an authentication type,
1092     should be allocated with malloc()
1093 
1094   - name is a type of capability when this is not an authentication type,
1095     should be allocated with malloc()
1096 */
1097 
1098 struct mailimap_capability {
1099   int cap_type;
1100   union {
1101     char * cap_auth_type; /* can be NULL */
1102     char * cap_name;      /* can be NULL */
1103   } cap_data;
1104 };
1105 
1106 LIBETPAN_EXPORT
1107 struct mailimap_capability *
1108 mailimap_capability_new(int cap_type, char * cap_auth_type, char * cap_name);
1109 
1110 LIBETPAN_EXPORT
1111 void mailimap_capability_free(struct mailimap_capability * c);
1112 
1113 
1114 
1115 
1116 /*
1117   mailimap_capability_data is a list of capability
1118 
1119   - list is the list of capability
1120 */
1121 
1122 struct mailimap_capability_data {
1123   clist * cap_list; /* list of (struct mailimap_capability *), != NULL */
1124 };
1125 
1126 LIBETPAN_EXPORT
1127 struct mailimap_capability_data *
1128 mailimap_capability_data_new(clist * cap_list);
1129 
1130 LIBETPAN_EXPORT
1131 void
1132 mailimap_capability_data_free(struct mailimap_capability_data * cap_data);
1133 
1134 
1135 
1136 /* this is the type of continue request data */
1137 
1138 enum {
1139   MAILIMAP_CONTINUE_REQ_ERROR,  /* on parse error */
1140   MAILIMAP_CONTINUE_REQ_TEXT,   /* when data is a text response */
1141   MAILIMAP_CONTINUE_REQ_BASE64  /* when data is a base64 response */
1142 };
1143 
1144 /*
1145   mailimap_continue_req is a continue request (a response prefixed by "+")
1146 
1147   - type is the type of continue request response
1148     MAILIMAP_CONTINUE_REQ_TEXT (when information data is text),
1149     MAILIMAP_CONTINUE_REQ_BASE64 (when information data is base64)
1150 
1151   - text is the information of type text in case of text data
1152 
1153   - base64 is base64 encoded data in the other case, should be allocated
1154     with malloc()
1155 */
1156 
1157 struct mailimap_continue_req {
1158   int cr_type;
1159   union {
1160     struct mailimap_resp_text * cr_text; /* can be NULL */
1161     char * cr_base64;                    /* can be NULL */
1162   } cr_data;
1163 };
1164 
1165 LIBETPAN_EXPORT
1166 struct mailimap_continue_req *
1167 mailimap_continue_req_new(int cr_type, struct mailimap_resp_text * cr_text,
1168 			  char * cr_base64);
1169 
1170 LIBETPAN_EXPORT
1171 void mailimap_continue_req_free(struct mailimap_continue_req * cont_req);
1172 
1173 
1174 /*
1175   mailimap_date_time is a date
1176 
1177   - day is the day of month (1 to 31)
1178 
1179   - month (1 to 12)
1180 
1181   - year (4 digits)
1182 
1183   - hour (0 to 23)
1184 
1185   - min (0 to 59)
1186 
1187   - sec (0 to 59)
1188 
1189   - zone (this is the decimal value that we can read, for example:
1190     for "-0200", the value is -200)
1191 */
1192 
1193 struct mailimap_date_time {
1194   int dt_day;
1195   int dt_month;
1196   int dt_year;
1197   int dt_hour;
1198   int dt_min;
1199   int dt_sec;
1200   int dt_zone;
1201 };
1202 
1203 LIBETPAN_EXPORT
1204 struct mailimap_date_time *
1205 mailimap_date_time_new(int dt_day, int dt_month, int dt_year, int dt_hour,
1206 		       int dt_min, int dt_sec, int dt_zone);
1207 
1208 LIBETPAN_EXPORT
1209 void mailimap_date_time_free(struct mailimap_date_time * date_time);
1210 
1211 
1212 
1213 /*
1214   mailimap_envelope is the list of fields that can be parsed by
1215   the IMAP server.
1216 
1217   - date is the (non-parsed) content of the "Date" header field,
1218     should be allocated with malloc()
1219 
1220   - subject is the subject of the message, should be allocated with
1221     malloc()
1222 
1223   - sender is the the parsed content of the "Sender" field
1224 
1225   - reply-to is the parsed content of the "Reply-To" field
1226 
1227   - to is the parsed content of the "To" field
1228 
1229   - cc is the parsed content of the "Cc" field
1230 
1231   - bcc is the parsed content of the "Bcc" field
1232 
1233   - in_reply_to is the content of the "In-Reply-To" field,
1234     should be allocated with malloc()
1235 
1236   - message_id is the content of the "Message-ID" field,
1237     should be allocated with malloc()
1238 */
1239 
1240 struct mailimap_envelope {
1241   char * env_date;                             /* can be NULL */
1242   char * env_subject;                          /* can be NULL */
1243   struct mailimap_env_from * env_from;         /* can be NULL */
1244   struct mailimap_env_sender * env_sender;     /* can be NULL */
1245   struct mailimap_env_reply_to * env_reply_to; /* can be NULL */
1246   struct mailimap_env_to * env_to;             /* can be NULL */
1247   struct mailimap_env_cc * env_cc;             /* can be NULL */
1248   struct mailimap_env_bcc * env_bcc;           /* can be NULL */
1249   char * env_in_reply_to;                      /* can be NULL */
1250   char * env_message_id;                       /* can be NULL */
1251 };
1252 
1253 LIBETPAN_EXPORT
1254 struct mailimap_envelope *
1255 mailimap_envelope_new(char * env_date, char * env_subject,
1256 		      struct mailimap_env_from * env_from,
1257 		      struct mailimap_env_sender * env_sender,
1258 		      struct mailimap_env_reply_to * env_reply_to,
1259 		      struct mailimap_env_to * env_to,
1260 		      struct mailimap_env_cc* env_cc,
1261 		      struct mailimap_env_bcc * env_bcc,
1262 		      char * env_in_reply_to, char * env_message_id);
1263 
1264 LIBETPAN_EXPORT
1265 void mailimap_envelope_free(struct mailimap_envelope * env);
1266 
1267 
1268 
1269 /*
1270   mailimap_env_bcc is the parsed "Bcc" field
1271 
1272   - list is the list of addresses
1273 */
1274 
1275 struct mailimap_env_bcc {
1276   clist * bcc_list; /* list of (struct mailimap_address *), can be NULL */
1277 };
1278 
1279 LIBETPAN_EXPORT
1280 struct mailimap_env_bcc * mailimap_env_bcc_new(clist * bcc_list);
1281 
1282 LIBETPAN_EXPORT
1283 void mailimap_env_bcc_free(struct mailimap_env_bcc * env_bcc);
1284 
1285 
1286 /*
1287   mailimap_env_cc is the parsed "Cc" field
1288 
1289   - list is the list of addresses
1290 */
1291 
1292 struct mailimap_env_cc {
1293   clist * cc_list; /* list of (struct mailimap_address *), can be NULL */
1294 };
1295 
1296 LIBETPAN_EXPORT
1297 struct mailimap_env_cc * mailimap_env_cc_new(clist * cc_list);
1298 
1299 LIBETPAN_EXPORT
1300 void mailimap_env_cc_free(struct mailimap_env_cc * env_cc);
1301 
1302 
1303 
1304 /*
1305   mailimap_env_from is the parsed "From" field
1306 
1307   - list is the list of addresses
1308 */
1309 
1310 struct mailimap_env_from {
1311   clist * frm_list; /* list of (struct mailimap_address *) */
1312                 /* can be NULL */
1313 };
1314 
1315 LIBETPAN_EXPORT
1316 struct mailimap_env_from * mailimap_env_from_new(clist * frm_list);
1317 
1318 LIBETPAN_EXPORT
1319 void mailimap_env_from_free(struct mailimap_env_from * env_from);
1320 
1321 
1322 
1323 /*
1324   mailimap_env_reply_to is the parsed "Reply-To" field
1325 
1326   - list is the list of addresses
1327 */
1328 
1329 struct mailimap_env_reply_to {
1330   clist * rt_list; /* list of (struct mailimap_address *), can be NULL */
1331 };
1332 
1333 LIBETPAN_EXPORT
1334 struct mailimap_env_reply_to * mailimap_env_reply_to_new(clist * rt_list);
1335 
1336 LIBETPAN_EXPORT
1337 void
1338 mailimap_env_reply_to_free(struct mailimap_env_reply_to * env_reply_to);
1339 
1340 
1341 
1342 /*
1343   mailimap_env_sender is the parsed "Sender" field
1344 
1345   - list is the list of addresses
1346 */
1347 
1348 struct mailimap_env_sender {
1349   clist * snd_list; /* list of (struct mailimap_address *), can be NULL */
1350 };
1351 
1352 LIBETPAN_EXPORT
1353 struct mailimap_env_sender * mailimap_env_sender_new(clist * snd_list);
1354 
1355 LIBETPAN_EXPORT
1356 void mailimap_env_sender_free(struct mailimap_env_sender * env_sender);
1357 
1358 
1359 
1360 /*
1361   mailimap_env_to is the parsed "To" field
1362 
1363   - list is the list of addresses
1364 */
1365 
1366 struct mailimap_env_to {
1367   clist * to_list; /* list of (struct mailimap_address *), can be NULL */
1368 };
1369 
1370 LIBETPAN_EXPORT
1371 struct mailimap_env_to * mailimap_env_to_new(clist * to_list);
1372 
1373 LIBETPAN_EXPORT
1374 void mailimap_env_to_free(struct mailimap_env_to * env_to);
1375 
1376 
1377 /* this is the type of flag */
1378 
1379 enum {
1380   MAILIMAP_FLAG_ANSWERED,  /* \Answered flag */
1381   MAILIMAP_FLAG_FLAGGED,   /* \Flagged flag */
1382   MAILIMAP_FLAG_DELETED,   /* \Deleted flag */
1383   MAILIMAP_FLAG_SEEN,      /* \Seen flag */
1384   MAILIMAP_FLAG_DRAFT,     /* \Draft flag */
1385   MAILIMAP_FLAG_KEYWORD,   /* keyword flag */
1386   MAILIMAP_FLAG_EXTENSION  /* \extension flag */
1387 };
1388 
1389 
1390 /*
1391   mailimap_flag is a message flag (that we can associate with a message)
1392 
1393   - type is the type of the flag, MAILIMAP_FLAG_XXX
1394 
1395   - keyword is the flag when the flag is of keyword type,
1396     should be allocated with malloc()
1397 
1398   - extension is the flag when the flag is of extension type, should be
1399     allocated with malloc()
1400 */
1401 
1402 struct mailimap_flag {
1403   int fl_type;
1404   union {
1405     char * fl_keyword;   /* can be NULL */
1406     char * fl_extension; /* can be NULL */
1407   } fl_data;
1408 };
1409 
1410 LIBETPAN_EXPORT
1411 struct mailimap_flag * mailimap_flag_new(int fl_type,
1412     char * fl_keyword, char * fl_extension);
1413 
1414 LIBETPAN_EXPORT
1415 void mailimap_flag_free(struct mailimap_flag * f);
1416 
1417 
1418 
1419 
1420 /* this is the type of flag */
1421 
1422 enum {
1423   MAILIMAP_FLAG_FETCH_ERROR,  /* on parse error */
1424   MAILIMAP_FLAG_FETCH_RECENT, /* \Recent flag */
1425   MAILIMAP_FLAG_FETCH_OTHER   /* other type of flag */
1426 };
1427 
1428 /*
1429   mailimap_flag_fetch is a message flag (when we fetch it)
1430 
1431   - type is the type of flag fetch
1432 
1433   - flag is the flag when this is not a \Recent flag
1434 */
1435 
1436 struct mailimap_flag_fetch {
1437   int fl_type;
1438   struct mailimap_flag * fl_flag; /* can be NULL */
1439 };
1440 
1441 LIBETPAN_EXPORT
1442 struct mailimap_flag_fetch *
1443 mailimap_flag_fetch_new(int fl_type, struct mailimap_flag * fl_flag);
1444 
1445 LIBETPAN_EXPORT
1446 void mailimap_flag_fetch_free(struct mailimap_flag_fetch * flag_fetch);
1447 
1448 
1449 
1450 
1451 /* this is the type of flag */
1452 
1453 enum {
1454   MAILIMAP_FLAG_PERM_ERROR, /* on parse error */
1455   MAILIMAP_FLAG_PERM_FLAG,  /* to specify that usual flags can be changed */
1456   MAILIMAP_FLAG_PERM_ALL    /* to specify that new flags can be created */
1457 };
1458 
1459 
1460 /*
1461   mailimap_flag_perm is a flag returned in case of PERMANENTFLAGS response
1462 
1463   - type is the type of returned PERMANENTFLAGS, it can be
1464     MAILIMAP_FLAG_PERM_FLAG (the given flag can be changed permanently) or
1465     MAILIMAP_FLAG_PERM_ALL (new flags can be created)
1466 
1467   - flag is the given flag when type is MAILIMAP_FLAG_PERM_FLAG
1468 */
1469 
1470 struct mailimap_flag_perm {
1471   int fl_type;
1472   struct mailimap_flag * fl_flag; /* can be NULL */
1473 };
1474 
1475 LIBETPAN_EXPORT
1476 struct mailimap_flag_perm *
1477 mailimap_flag_perm_new(int fl_type, struct mailimap_flag * fl_flag);
1478 
1479 LIBETPAN_EXPORT
1480 void mailimap_flag_perm_free(struct mailimap_flag_perm * flag_perm);
1481 
1482 
1483 /*
1484   mailimap_flag_list is a list of flags
1485 
1486   - list is a list of flags
1487 */
1488 
1489 struct mailimap_flag_list {
1490   clist * fl_list; /* list of (struct mailimap_flag *), != NULL */
1491 };
1492 
1493 LIBETPAN_EXPORT
1494 struct mailimap_flag_list *
1495 mailimap_flag_list_new(clist * fl_list);
1496 
1497 LIBETPAN_EXPORT
1498 void mailimap_flag_list_free(struct mailimap_flag_list * flag_list);
1499 
1500 
1501 
1502 
1503 /* this is the type of greeting response */
1504 
1505 enum {
1506   MAILIMAP_GREETING_RESP_COND_ERROR, /* on parse error */
1507   MAILIMAP_GREETING_RESP_COND_AUTH,  /* when connection is accepted */
1508   MAILIMAP_GREETING_RESP_COND_BYE    /* when connection is refused */
1509 };
1510 
1511 /*
1512   mailimap_greeting is the response returned on connection
1513 
1514   - type is the type of response on connection, either
1515   MAILIMAP_GREETING_RESP_COND_AUTH if connection is accepted or
1516   MAIMIMAP_GREETING_RESP_COND_BYE if connection is refused
1517 */
1518 
1519 struct mailimap_greeting {
1520   int gr_type;
1521   union {
1522     struct mailimap_resp_cond_auth * gr_auth; /* can be NULL */
1523     struct mailimap_resp_cond_bye * gr_bye;   /* can be NULL */
1524   } gr_data;
1525 };
1526 
1527 LIBETPAN_EXPORT
1528 struct mailimap_greeting *
1529 mailimap_greeting_new(int gr_type,
1530     struct mailimap_resp_cond_auth * gr_auth,
1531     struct mailimap_resp_cond_bye * gr_bye);
1532 
1533 LIBETPAN_EXPORT
1534 void mailimap_greeting_free(struct mailimap_greeting * greeting);
1535 
1536 
1537 /*
1538   mailimap_header_list is a list of headers that can be specified when
1539   we want to fetch fields
1540 
1541   - list is a list of header names, each header name should be allocated
1542     with malloc()
1543 */
1544 
1545 struct mailimap_header_list {
1546   clist * hdr_list; /* list of astring (char *), != NULL */
1547 };
1548 
1549 LIBETPAN_EXPORT
1550 struct mailimap_header_list *
1551 mailimap_header_list_new(clist * hdr_list);
1552 
1553 LIBETPAN_EXPORT
1554 void
1555 mailimap_header_list_free(struct mailimap_header_list * header_list);
1556 
1557 
1558 
1559 /* this is the type of mailbox STATUS that can be returned */
1560 
1561 enum {
1562   MAILIMAP_STATUS_ATT_MESSAGES,      /* when requesting the number of
1563                                         messages */
1564   MAILIMAP_STATUS_ATT_RECENT,        /* when requesting the number of
1565                                         recent messages */
1566   MAILIMAP_STATUS_ATT_UIDNEXT,       /* when requesting the next unique
1567                                         identifier */
1568   MAILIMAP_STATUS_ATT_UIDVALIDITY,   /* when requesting the validity of
1569                                         message unique identifiers*/
1570   MAILIMAP_STATUS_ATT_UNSEEN,        /* when requesting the number of
1571                                         unseen messages */
1572   MAILIMAP_STATUS_ATT_HIGHESTMODSEQ, /* when requesting the highest
1573                                         mod-sequence value of all messages in
1574                                         the mailbox */
1575   MAILIMAP_STATUS_ATT_EXTENSION
1576 };
1577 
1578 /*
1579   mailimap_status_info is a returned information when a STATUS of
1580   a mailbox is requested
1581 
1582   - att is the type of mailbox STATUS, the value can be
1583     MAILIMAP_STATUS_ATT_MESSAGES, MAILIMAP_STATUS_ATT_RECENT,
1584     MAILIMAP_STATUS_ATT_UIDNEXT, MAILIMAP_STATUS_ATT_UIDVALIDITY,
1585     MAILIMAP_STATUS_ATT_UNSEEN or MAILIMAP_STATUS_ATT_EXTENSION
1586 
1587   - value is the value of the given information
1588 
1589   - st_ext_data is the data of the extension.
1590 */
1591 
1592 struct mailimap_status_info {
1593   int st_att;
1594   uint32_t st_value;
1595   struct mailimap_extension_data * st_ext_data; /* can be NULL */
1596 };
1597 
1598 LIBETPAN_EXPORT
1599 struct mailimap_status_info *
1600   mailimap_status_info_new(int st_att, uint32_t st_value,
1601   struct mailimap_extension_data * st_ext_data);
1602 
1603 LIBETPAN_EXPORT
1604 void mailimap_status_info_free(struct mailimap_status_info * info);
1605 
1606 
1607 
1608 /*
1609   mailimap_mailbox_data_status is the list of information returned
1610   when a STATUS of a mailbox is requested
1611 
1612   - mailbox is the name of the mailbox, should be allocated with malloc()
1613 
1614   - status_info_list is the list of information returned
1615 */
1616 
1617 struct mailimap_mailbox_data_status {
1618   char * st_mailbox;
1619   clist * st_info_list; /* list of (struct mailimap_status_info *) */
1620                             /* can be NULL */
1621 };
1622 
1623 LIBETPAN_EXPORT
1624 struct mailimap_mailbox_data_status *
1625 mailimap_mailbox_data_status_new(char * st_mailbox,
1626     clist * st_info_list);
1627 
1628 LIBETPAN_EXPORT
1629 void
1630 mailimap_mailbox_data_status_free(struct mailimap_mailbox_data_status * info);
1631 
1632 
1633 
1634 /* this is the type of mailbox information that is returned */
1635 
1636 enum {
1637   MAILIMAP_MAILBOX_DATA_ERROR,  /* on parse error */
1638   MAILIMAP_MAILBOX_DATA_FLAGS,  /* flag that are applicable to the mailbox */
1639   MAILIMAP_MAILBOX_DATA_LIST,   /* this is a mailbox in the list of mailboxes
1640                                    returned on LIST command*/
1641   MAILIMAP_MAILBOX_DATA_LSUB,   /* this is a mailbox in the list of
1642                                    subscribed mailboxes returned on LSUB
1643                                    command */
1644   MAILIMAP_MAILBOX_DATA_SEARCH, /* this is a list of messages numbers or
1645                                    unique identifiers returned
1646                                    on a SEARCH command*/
1647   MAILIMAP_MAILBOX_DATA_STATUS, /* this is the list of information returned
1648                                    on a STATUS command */
1649   MAILIMAP_MAILBOX_DATA_EXISTS, /* this is the number of messages in the
1650                                    mailbox */
1651   MAILIMAP_MAILBOX_DATA_RECENT, /* this is the number of recent messages
1652                                    in the mailbox */
1653   MAILIMAP_MAILBOX_DATA_EXTENSION_DATA  /* this mailbox-data stores data
1654                                            returned by an extension */
1655 };
1656 
1657 /*
1658   mailimap_mailbox_data is an information related to a mailbox
1659 
1660   - type is the type of mailbox_data that is filled, the value of this field
1661     can be MAILIMAP_MAILBOX_DATA_FLAGS, MAILIMAP_MAILBOX_DATA_LIST,
1662     MAILIMAP_MAILBOX_DATA_LSUB, MAILIMAP_MAILBOX_DATA_SEARCH,
1663     MAILIMAP_MAILBOX_DATA_STATUS, MAILIMAP_MAILBOX_DATA_EXISTS
1664     or MAILIMAP_MAILBOX_DATA_RECENT.
1665 
1666   - flags is the flags that are applicable to the mailbox when
1667     type is MAILIMAP_MAILBOX_DATA_FLAGS
1668 
1669   - list is a mailbox in the list of mailboxes returned on LIST command
1670     when type is MAILIMAP_MAILBOX_DATA_LIST
1671 
1672   - lsub is a mailbox in the list of subscribed mailboxes returned on
1673     LSUB command when type is MAILIMAP_MAILBOX_DATA_LSUB
1674 
1675   - search is a list of messages numbers or unique identifiers returned
1676     on SEARCH command when type MAILIMAP_MAILBOX_DATA_SEARCH, each element
1677     should be allocated with malloc()
1678 
1679   - status is a list of information returned on STATUS command when
1680     type is MAILIMAP_MAILBOX_DATA_STATUS
1681 
1682   - exists is the number of messages in the mailbox when type
1683     is MAILIMAP_MAILBOX_DATA_EXISTS
1684 
1685   - recent is the number of recent messages in the mailbox when type
1686     is MAILIMAP_MAILBOX_DATA_RECENT
1687 */
1688 
1689 struct mailimap_mailbox_data {
1690   int mbd_type;
1691   union {
1692     struct mailimap_flag_list * mbd_flags;   /* can be NULL */
1693     struct mailimap_mailbox_list * mbd_list; /* can be NULL */
1694     struct mailimap_mailbox_list * mbd_lsub; /* can be NULL */
1695     clist * mbd_search;  /* list of nz-number (uint32_t *), can be NULL */
1696     struct mailimap_mailbox_data_status *  mbd_status; /* can be NULL */
1697     uint32_t mbd_exists;
1698     uint32_t mbd_recent;
1699     struct mailimap_extension_data * mbd_extension; /* can be NULL */
1700   } mbd_data;
1701 };
1702 
1703 LIBETPAN_EXPORT
1704 struct mailimap_mailbox_data *
1705 mailimap_mailbox_data_new(int mbd_type, struct mailimap_flag_list * mbd_flags,
1706     struct mailimap_mailbox_list * mbd_list,
1707     struct mailimap_mailbox_list * mbd_lsub,
1708     clist * mbd_search,
1709     struct mailimap_mailbox_data_status * mbd_status,
1710     uint32_t mbd_exists,
1711     uint32_t mbd_recent,
1712     struct mailimap_extension_data * mbd_extension);
1713 
1714 LIBETPAN_EXPORT
1715 void
1716 mailimap_mailbox_data_free(struct mailimap_mailbox_data * mb_data);
1717 
1718 
1719 
1720 /* this is the type of mailbox flags */
1721 
1722 enum {
1723   MAILIMAP_MBX_LIST_FLAGS_SFLAG,    /* mailbox single flag - a flag in
1724                                        {\NoSelect, \Marked, \Unmarked} */
1725   MAILIMAP_MBX_LIST_FLAGS_NO_SFLAG  /* mailbox other flag -  mailbox flag
1726                                        other than \NoSelect \Marked and
1727                                        \Unmarked) */
1728 };
1729 
1730 /* this is a single flag type */
1731 
1732 enum {
1733   MAILIMAP_MBX_LIST_SFLAG_ERROR,
1734   MAILIMAP_MBX_LIST_SFLAG_MARKED,
1735   MAILIMAP_MBX_LIST_SFLAG_NOSELECT,
1736   MAILIMAP_MBX_LIST_SFLAG_UNMARKED
1737 };
1738 
1739 /*
1740   mailimap_mbx_list_flags is a mailbox flag
1741 
1742   - type is the type of mailbox flag, it can be MAILIMAP_MBX_LIST_FLAGS_SFLAG,
1743     or MAILIMAP_MBX_LIST_FLAGS_NO_SFLAG.
1744 
1745   - oflags is a list of "mailbox other flag"
1746 
1747   - sflag is a mailbox single flag
1748 */
1749 
1750 struct mailimap_mbx_list_flags {
1751   int mbf_type;
1752   clist * mbf_oflags; /* list of
1753                          (struct mailimap_mbx_list_oflag *), != NULL */
1754   int mbf_sflag;
1755 };
1756 
1757 LIBETPAN_EXPORT
1758 struct mailimap_mbx_list_flags *
1759 mailimap_mbx_list_flags_new(int mbf_type,
1760     clist * mbf_oflags, int mbf_sflag);
1761 
1762 LIBETPAN_EXPORT
1763 void
1764 mailimap_mbx_list_flags_free(struct mailimap_mbx_list_flags * mbx_list_flags);
1765 
1766 
1767 
1768 /* this is the type of the mailbox other flag */
1769 
1770 enum {
1771   MAILIMAP_MBX_LIST_OFLAG_ERROR,       /* on parse error */
1772   MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS, /* \NoInferior flag */
1773   MAILIMAP_MBX_LIST_OFLAG_FLAG_EXT     /* other flag */
1774 };
1775 
1776 /*
1777   mailimap_mbx_list_oflag is a mailbox other flag
1778 
1779   - type can be MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS when this is
1780     a \NoInferior flag or MAILIMAP_MBX_LIST_OFLAG_FLAG_EXT
1781 
1782   - flag_ext is set when MAILIMAP_MBX_LIST_OFLAG_FLAG_EXT and is
1783     an extension flag, should be allocated with malloc()
1784 */
1785 
1786 struct mailimap_mbx_list_oflag {
1787   int of_type;
1788   char * of_flag_ext; /* can be NULL */
1789 };
1790 
1791 LIBETPAN_EXPORT
1792 struct mailimap_mbx_list_oflag *
1793 mailimap_mbx_list_oflag_new(int of_type, char * of_flag_ext);
1794 
1795 LIBETPAN_EXPORT
1796 void
1797 mailimap_mbx_list_oflag_free(struct mailimap_mbx_list_oflag * oflag);
1798 
1799 
1800 
1801 /*
1802   mailimap_mailbox_list is a list of mailbox flags
1803 
1804   - mb_flag is a list of mailbox flags
1805 
1806   - delimiter is the delimiter of the mailbox path
1807 
1808   - mb is the name of the mailbox, should be allocated with malloc()
1809 */
1810 
1811 struct mailimap_mailbox_list {
1812   struct mailimap_mbx_list_flags * mb_flag; /* can be NULL */
1813   char mb_delimiter;
1814   char * mb_name; /* != NULL */
1815 };
1816 
1817 LIBETPAN_EXPORT
1818 struct mailimap_mailbox_list *
1819 mailimap_mailbox_list_new(struct mailimap_mbx_list_flags * mbx_flags,
1820     char mb_delimiter, char * mb_name);
1821 
1822 LIBETPAN_EXPORT
1823 void
1824 mailimap_mailbox_list_free(struct mailimap_mailbox_list * mb_list);
1825 
1826 
1827 
1828 /* this is the MIME type */
1829 
1830 enum {
1831   MAILIMAP_MEDIA_BASIC_APPLICATION, /* application/xxx */
1832   MAILIMAP_MEDIA_BASIC_AUDIO,       /* audio/xxx */
1833   MAILIMAP_MEDIA_BASIC_IMAGE,       /* image/xxx */
1834   MAILIMAP_MEDIA_BASIC_MESSAGE,     /* message/xxx */
1835   MAILIMAP_MEDIA_BASIC_VIDEO,       /* video/xxx */
1836   MAILIMAP_MEDIA_BASIC_OTHER        /* for all other cases */
1837 };
1838 
1839 
1840 /*
1841   mailimap_media_basic is the MIME type
1842 
1843   - type can be MAILIMAP_MEDIA_BASIC_APPLICATION, MAILIMAP_MEDIA_BASIC_AUDIO,
1844     MAILIMAP_MEDIA_BASIC_IMAGE, MAILIMAP_MEDIA_BASIC_MESSAGE,
1845     MAILIMAP_MEDIA_BASIC_VIDEO or MAILIMAP_MEDIA_BASIC_OTHER
1846 
1847   - basic_type is defined when type is MAILIMAP_MEDIA_BASIC_OTHER, should
1848     be allocated with malloc()
1849 
1850   - subtype is the subtype of the MIME type, for example, this is
1851     "data" in "application/data", should be allocated with malloc()
1852 */
1853 
1854 struct mailimap_media_basic {
1855   int med_type;
1856   char * med_basic_type; /* can be NULL */
1857   char * med_subtype;    /* != NULL */
1858 };
1859 
1860 LIBETPAN_EXPORT
1861 struct mailimap_media_basic *
1862 mailimap_media_basic_new(int med_type,
1863     char * med_basic_type, char * med_subtype);
1864 
1865 LIBETPAN_EXPORT
1866 void
1867 mailimap_media_basic_free(struct mailimap_media_basic * media_basic);
1868 
1869 
1870 
1871 /* this is the type of message data */
1872 
1873 enum {
1874   MAILIMAP_MESSAGE_DATA_ERROR,
1875   MAILIMAP_MESSAGE_DATA_EXPUNGE,
1876   MAILIMAP_MESSAGE_DATA_FETCH
1877 };
1878 
1879 /*
1880   mailimap_message_data is an information related to a message
1881 
1882   - number is the number or the unique identifier of the message
1883 
1884   - type is the type of information, this value can be
1885     MAILIMAP_MESSAGE_DATA_EXPUNGE or MAILIMAP_MESSAGE_DATA_FETCH
1886 
1887   - msg_att is the message data
1888 */
1889 
1890 struct mailimap_message_data {
1891   uint32_t mdt_number;
1892   int mdt_type;
1893   struct mailimap_msg_att * mdt_msg_att; /* can be NULL */
1894                                      /* if type = EXPUNGE, can be NULL */
1895 };
1896 
1897 LIBETPAN_EXPORT
1898 struct mailimap_message_data *
1899 mailimap_message_data_new(uint32_t mdt_number, int mdt_type,
1900     struct mailimap_msg_att * mdt_msg_att);
1901 
1902 LIBETPAN_EXPORT
1903 void
1904 mailimap_message_data_free(struct mailimap_message_data * msg_data);
1905 
1906 
1907 
1908 /* this the type of the message attributes */
1909 
1910 enum {
1911   MAILIMAP_MSG_ATT_ITEM_ERROR,   /* on parse error */
1912   MAILIMAP_MSG_ATT_ITEM_DYNAMIC, /* dynamic message attributes (flags) */
1913   MAILIMAP_MSG_ATT_ITEM_STATIC,  /* static messages attributes
1914                                     (message content) */
1915   MAILIMAP_MSG_ATT_ITEM_EXTENSION /* extension data */
1916 };
1917 
1918 /*
1919   mailimap_msg_att_item is a message attribute
1920 
1921   - type is the type of message attribute, the value can be
1922     MAILIMAP_MSG_ATT_ITEM_DYNAMIC, MAILIMAP_MSG_ATT_ITEM_STATIC or MAILIMAP_MSG_ATT_ITEM_EXTENSION
1923 
1924   - att_dyn is a dynamic message attribute when type is
1925     MAILIMAP_MSG_ATT_ITEM_DYNAMIC
1926 
1927   - att_static is a static message attribute when type is
1928     MAILIMAP_MSG_ATT_ITEM_STATIC
1929 
1930   - att_extension_data is an extension data.
1931 */
1932 
1933 struct mailimap_msg_att_item {
1934   int att_type;
1935   union {
1936     struct mailimap_msg_att_dynamic * att_dyn;   /* can be NULL */
1937     struct mailimap_msg_att_static * att_static; /* can be NULL */
1938     struct mailimap_extension_data * att_extension_data; /* can be NULL */
1939   } att_data;
1940 };
1941 
1942 LIBETPAN_EXPORT
1943 struct mailimap_msg_att_item *
1944 mailimap_msg_att_item_new(int att_type,
1945     struct mailimap_msg_att_dynamic * att_dyn,
1946     struct mailimap_msg_att_static * att_static,
1947     struct mailimap_extension_data * att_extension_data);
1948 
1949 LIBETPAN_EXPORT
1950 void
1951 mailimap_msg_att_item_free(struct mailimap_msg_att_item * item);
1952 
1953 
1954 /*
1955   mailimap_msg_att is a list of attributes
1956 
1957   - list is a list of message attributes
1958 
1959   - number is the message number or unique identifier, this field
1960     has been added for implementation purpose
1961 */
1962 
1963 struct mailimap_msg_att {
1964   clist * att_list; /* list of (struct mailimap_msg_att_item *) */
1965                 /* != NULL */
1966   uint32_t att_number; /* extra field to store the message number,
1967 		     used for mailimap */
1968 };
1969 
1970 LIBETPAN_EXPORT
1971 struct mailimap_msg_att * mailimap_msg_att_new(clist * att_list);
1972 
1973 LIBETPAN_EXPORT
1974 void mailimap_msg_att_free(struct mailimap_msg_att * msg_att);
1975 
1976 
1977 /*
1978   mailimap_msg_att_dynamic is a dynamic message attribute
1979 
1980   - list is a list of flags (that have been fetched)
1981 */
1982 
1983 struct mailimap_msg_att_dynamic {
1984   clist * att_list; /* list of (struct mailimap_flag_fetch *) */
1985   /* can be NULL */
1986 };
1987 
1988 LIBETPAN_EXPORT
1989 struct mailimap_msg_att_dynamic *
1990 mailimap_msg_att_dynamic_new(clist * att_list);
1991 
1992 LIBETPAN_EXPORT
1993 void
1994 mailimap_msg_att_dynamic_free(struct mailimap_msg_att_dynamic * msg_att_dyn);
1995 
1996 
1997 
1998 /*
1999   mailimap_msg_att_body_section is a MIME part content
2000 
2001   - section is the location of the MIME part in the message
2002 
2003   - origin_octet is the offset of the requested part of the MIME part
2004 
2005   - body_part is the content or partial content of the MIME part,
2006     should be allocated through a MMAPString
2007 
2008   - length is the size of the content
2009 */
2010 
2011 struct mailimap_msg_att_body_section {
2012   struct mailimap_section * sec_section; /* != NULL */
2013   uint32_t sec_origin_octet;
2014   char * sec_body_part; /* can be NULL */
2015   size_t sec_length;
2016 };
2017 
2018 LIBETPAN_EXPORT
2019 struct mailimap_msg_att_body_section *
2020 mailimap_msg_att_body_section_new(struct mailimap_section * section,
2021     uint32_t sec_origin_octet,
2022     char * sec_body_part,
2023     size_t sec_length);
2024 
2025 LIBETPAN_EXPORT
2026 void
2027 mailimap_msg_att_body_section_free(struct mailimap_msg_att_body_section *
2028     msg_att_body_section);
2029 
2030 
2031 
2032 /*
2033   this is the type of static message attribute
2034 */
2035 
2036 enum {
2037   MAILIMAP_MSG_ATT_ERROR,         /* on parse error */
2038   MAILIMAP_MSG_ATT_ENVELOPE,      /* this is the fields that can be
2039                                     parsed by the server */
2040   MAILIMAP_MSG_ATT_INTERNALDATE,  /* this is the message date kept
2041                                      by the server */
2042   MAILIMAP_MSG_ATT_RFC822,        /* this is the message content
2043                                      (header and body) */
2044   MAILIMAP_MSG_ATT_RFC822_HEADER, /* this is the message header */
2045   MAILIMAP_MSG_ATT_RFC822_TEXT,   /* this is the message text part */
2046   MAILIMAP_MSG_ATT_RFC822_SIZE,   /* this is the size of the message content */
2047   MAILIMAP_MSG_ATT_BODY,          /* this is the MIME description of
2048                                      the message */
2049   MAILIMAP_MSG_ATT_BODYSTRUCTURE, /* this is the MIME description of the
2050                                      message with additional information */
2051   MAILIMAP_MSG_ATT_BODY_SECTION,  /* this is a MIME part content */
2052   MAILIMAP_MSG_ATT_UID            /* this is the message unique identifier */
2053 };
2054 
2055 /*
2056   mailimap_msg_att_static is a given part of the message
2057 
2058   - type is the type of the static message attribute, the value can be
2059     MAILIMAP_MSG_ATT_ENVELOPE, MAILIMAP_MSG_ATT_INTERNALDATE,
2060     MAILIMAP_MSG_ATT_RFC822, MAILIMAP_MSG_ATT_RFC822_HEADER,
2061     MAILIMAP_MSG_ATT_RFC822_TEXT, MAILIMAP_MSG_ATT_RFC822_SIZE,
2062     MAILIMAP_MSG_ATT_BODY, MAILIMAP_MSG_ATT_BODYSTRUCTURE,
2063     MAILIMAP_MSG_ATT_BODY_SECTION, MAILIMAP_MSG_ATT_UID
2064 
2065   - env is the headers parsed by the server if type is
2066     MAILIMAP_MSG_ATT_ENVELOPE
2067 
2068   - internal_date is the date of message kept by the server if type is
2069     MAILIMAP_MSG_ATT_INTERNALDATE
2070 
2071   - rfc822 is the message content if type is MAILIMAP_MSG_ATT_RFC822,
2072     should be allocated through a MMAPString
2073 
2074   - rfc822_header is the message header if type is
2075     MAILIMAP_MSG_ATT_RFC822_HEADER, should be allocated through a MMAPString
2076 
2077   - rfc822_text is the message text part if type is
2078     MAILIMAP_MSG_ATT_RFC822_TEXT, should be allocated through a MMAPString
2079 
2080   - rfc822_size is the message size if type is MAILIMAP_MSG_ATT_SIZE
2081 
2082   - body is the MIME description of the message
2083 
2084   - bodystructure is the MIME description of the message with additional
2085     information
2086 
2087   - body_section is a MIME part content
2088 
2089   - uid is a unique message identifier
2090 */
2091 
2092 struct mailimap_msg_att_static {
2093   int att_type;
2094   union {
2095     struct mailimap_envelope * att_env;            /* can be NULL */
2096     struct mailimap_date_time * att_internal_date; /* can be NULL */
2097     struct {
2098       char * att_content; /* can be NULL */
2099       size_t att_length;
2100     } att_rfc822;
2101     struct {
2102       char * att_content; /* can be NULL */
2103       size_t att_length;
2104     } att_rfc822_header;
2105     struct {
2106       char * att_content; /* can be NULL */
2107       size_t att_length;
2108     } att_rfc822_text;
2109     uint32_t att_rfc822_size;
2110     struct mailimap_body * att_bodystructure; /* can be NULL */
2111     struct mailimap_body * att_body;          /* can be NULL */
2112     struct mailimap_msg_att_body_section * att_body_section; /* can be NULL */
2113     uint32_t att_uid;
2114   } att_data;
2115 };
2116 
2117 LIBETPAN_EXPORT
2118 struct mailimap_msg_att_static *
2119 mailimap_msg_att_static_new(int att_type, struct mailimap_envelope * att_env,
2120     struct mailimap_date_time * att_internal_date,
2121     char * att_rfc822,
2122     char * att_rfc822_header,
2123     char * att_rfc822_text,
2124     size_t att_length,
2125     uint32_t att_rfc822_size,
2126     struct mailimap_body * att_bodystructure,
2127     struct mailimap_body * att_body,
2128     struct mailimap_msg_att_body_section * att_body_section,
2129     uint32_t att_uid);
2130 
2131 LIBETPAN_EXPORT
2132 void
2133 mailimap_msg_att_static_free(struct mailimap_msg_att_static * item);
2134 
2135 
2136 
2137 /* this is the type of a response element */
2138 
2139 enum {
2140   MAILIMAP_RESP_ERROR,     /* on parse error */
2141   MAILIMAP_RESP_CONT_REQ,  /* continuation request */
2142   MAILIMAP_RESP_RESP_DATA  /* response data */
2143 };
2144 
2145 /*
2146   mailimap_cont_req_or_resp_data is a response element
2147 
2148   - type is the type of response, the value can be MAILIMAP_RESP_CONT_REQ
2149     or MAILIMAP_RESP_RESP_DATA
2150 
2151   - cont_req is a continuation request
2152 
2153   - resp_data is a reponse data
2154 */
2155 
2156 struct mailimap_cont_req_or_resp_data {
2157   int rsp_type;
2158   union {
2159     struct mailimap_continue_req * rsp_cont_req;   /* can be NULL */
2160     struct mailimap_response_data * rsp_resp_data; /* can be NULL */
2161   } rsp_data;
2162 };
2163 
2164 LIBETPAN_EXPORT
2165 struct mailimap_cont_req_or_resp_data *
2166 mailimap_cont_req_or_resp_data_new(int rsp_type,
2167     struct mailimap_continue_req * rsp_cont_req,
2168     struct mailimap_response_data * rsp_resp_data);
2169 
2170 LIBETPAN_EXPORT
2171 void
2172 mailimap_cont_req_or_resp_data_free(struct mailimap_cont_req_or_resp_data *
2173 				    cont_req_or_resp_data);
2174 
2175 
2176 /*
2177   mailimap_response is a list of response elements
2178 
2179   - cont_req_or_resp_data_list is a list of response elements
2180 
2181   - resp_done is an ending response element
2182 */
2183 
2184 struct mailimap_response {
2185   clist * rsp_cont_req_or_resp_data_list;
2186   /* list of (struct mailiap_cont_req_or_resp_data *) */
2187                                    /* can be NULL */
2188   struct mailimap_response_done * rsp_resp_done; /* != NULL */
2189 };
2190 
2191 LIBETPAN_EXPORT
2192 struct mailimap_response *
2193 mailimap_response_new(clist * rsp_cont_req_or_resp_data_list,
2194     struct mailimap_response_done * rsp_resp_done);
2195 
2196 LIBETPAN_EXPORT
2197 void
2198 mailimap_response_free(struct mailimap_response * resp);
2199 
2200 
2201 
2202 /* this is the type of an untagged response */
2203 
2204 enum {
2205   MAILIMAP_RESP_DATA_TYPE_ERROR,           /* on parse error */
2206   MAILIMAP_RESP_DATA_TYPE_COND_STATE,      /* condition state response */
2207   MAILIMAP_RESP_DATA_TYPE_COND_BYE,        /* BYE response (server is about
2208                                               to close the connection) */
2209   MAILIMAP_RESP_DATA_TYPE_MAILBOX_DATA,    /* response related to a mailbox */
2210   MAILIMAP_RESP_DATA_TYPE_MESSAGE_DATA,    /* response related to a message */
2211   MAILIMAP_RESP_DATA_TYPE_CAPABILITY_DATA, /* capability information */
2212   MAILIMAP_RESP_DATA_TYPE_EXTENSION_DATA   /* data parsed by extension */
2213 };
2214 
2215 /*
2216   mailimap_reponse_data is an untagged response
2217 
2218   - type is the type of the untagged response, it can be
2219     MAILIMAP_RESP_DATA_COND_STATE, MAILIMAP_RESP_DATA_COND_BYE,
2220     MAILIMAP_RESP_DATA_MAILBOX_DATA, MAILIMAP_RESP_DATA_MESSAGE_DATA
2221     or MAILIMAP_RESP_DATA_CAPABILITY_DATA
2222 
2223   - cond_state is a condition state response
2224 
2225   - bye is a BYE response (server is about to close the connection)
2226 
2227   - mailbox_data is a response related to a mailbox
2228 
2229   - message_data is a response related to a message
2230 
2231   - capability is information about capabilities
2232 */
2233 
2234 struct mailimap_response_data {
2235   int rsp_type;
2236   union {
2237     struct mailimap_resp_cond_state * rsp_cond_state;      /* can be NULL */
2238     struct mailimap_resp_cond_bye * rsp_bye;               /* can be NULL */
2239     struct mailimap_mailbox_data * rsp_mailbox_data;       /* can be NULL */
2240     struct mailimap_message_data * rsp_message_data;       /* can be NULL */
2241     struct mailimap_capability_data * rsp_capability_data; /* can be NULL */
2242     struct mailimap_extension_data * rsp_extension_data;   /* can be NULL */
2243   } rsp_data;
2244 };
2245 
2246 LIBETPAN_EXPORT
2247 struct mailimap_response_data *
2248 mailimap_response_data_new(int rsp_type,
2249     struct mailimap_resp_cond_state * rsp_cond_state,
2250     struct mailimap_resp_cond_bye * rsp_bye,
2251     struct mailimap_mailbox_data * rsp_mailbox_data,
2252     struct mailimap_message_data * rsp_message_data,
2253     struct mailimap_capability_data * rsp_capability_data,
2254     struct mailimap_extension_data * rsp_extension_data);
2255 
2256 LIBETPAN_EXPORT
2257 void
2258 mailimap_response_data_free(struct mailimap_response_data * resp_data);
2259 
2260 
2261 
2262 /* this is the type of an ending response */
2263 
2264 enum {
2265   MAILIMAP_RESP_DONE_TYPE_ERROR,  /* on parse error */
2266   MAILIMAP_RESP_DONE_TYPE_TAGGED, /* tagged response */
2267   MAILIMAP_RESP_DONE_TYPE_FATAL   /* fatal error response */
2268 };
2269 
2270 /*
2271   mailimap_response_done is an ending response
2272 
2273   - type is the type of the ending response
2274 
2275   - tagged is a tagged response
2276 
2277   - fatal is a fatal error response
2278 */
2279 
2280 struct mailimap_response_done {
2281   int rsp_type;
2282   union {
2283     struct mailimap_response_tagged * rsp_tagged; /* can be NULL */
2284     struct mailimap_response_fatal * rsp_fatal;   /* can be NULL */
2285   } rsp_data;
2286 };
2287 
2288 LIBETPAN_EXPORT
2289 struct mailimap_response_done *
2290 mailimap_response_done_new(int rsp_type,
2291     struct mailimap_response_tagged * rsp_tagged,
2292     struct mailimap_response_fatal * rsp_fatal);
2293 
2294 LIBETPAN_EXPORT
2295 void mailimap_response_done_free(struct mailimap_response_done *
2296 				 resp_done);
2297 
2298 
2299 /*
2300   mailimap_response_fatal is a fatal error response
2301 
2302   - bye is a BYE response text
2303 */
2304 
2305 struct mailimap_response_fatal {
2306   struct mailimap_resp_cond_bye * rsp_bye; /* != NULL */
2307 };
2308 
2309 LIBETPAN_EXPORT
2310 struct mailimap_response_fatal *
2311 mailimap_response_fatal_new(struct mailimap_resp_cond_bye * rsp_bye);
2312 
2313 LIBETPAN_EXPORT
2314 void mailimap_response_fatal_free(struct mailimap_response_fatal * resp_fatal);
2315 
2316 
2317 
2318 /*
2319   mailimap_response_tagged is a tagged response
2320 
2321   - tag is the sent tag, should be allocated with malloc()
2322 
2323   - cond_state is a condition state response
2324 */
2325 
2326 struct mailimap_response_tagged {
2327   char * rsp_tag; /* != NULL */
2328   struct mailimap_resp_cond_state * rsp_cond_state; /* != NULL */
2329 };
2330 
2331 LIBETPAN_EXPORT
2332 struct mailimap_response_tagged *
2333 mailimap_response_tagged_new(char * rsp_tag,
2334     struct mailimap_resp_cond_state * rsp_cond_state);
2335 
2336 LIBETPAN_EXPORT
2337 void
2338 mailimap_response_tagged_free(struct mailimap_response_tagged * tagged);
2339 
2340 
2341 /* this is the type of an authentication condition response */
2342 
2343 enum {
2344   MAILIMAP_RESP_COND_AUTH_ERROR,   /* on parse error */
2345   MAILIMAP_RESP_COND_AUTH_OK,      /* authentication is needed */
2346   MAILIMAP_RESP_COND_AUTH_PREAUTH  /* authentication is not needed */
2347 };
2348 
2349 /*
2350   mailimap_resp_cond_auth is an authentication condition response
2351 
2352   - type is the type of the authentication condition response,
2353     the value can be MAILIMAP_RESP_COND_AUTH_OK or
2354     MAILIMAP_RESP_COND_AUTH_PREAUTH
2355 
2356   - text is a text response
2357 */
2358 
2359 struct mailimap_resp_cond_auth {
2360   int rsp_type;
2361   struct mailimap_resp_text * rsp_text; /* != NULL */
2362 };
2363 
2364 LIBETPAN_EXPORT
2365 struct mailimap_resp_cond_auth *
2366 mailimap_resp_cond_auth_new(int rsp_type,
2367     struct mailimap_resp_text * rsp_text);
2368 
2369 LIBETPAN_EXPORT
2370 void
2371 mailimap_resp_cond_auth_free(struct mailimap_resp_cond_auth * cond_auth);
2372 
2373 
2374 
2375 /*
2376   mailimap_resp_cond_bye is a BYE response
2377 
2378   - text is a text response
2379 */
2380 
2381 struct mailimap_resp_cond_bye {
2382   struct mailimap_resp_text * rsp_text; /* != NULL */
2383 };
2384 
2385 LIBETPAN_EXPORT
2386 struct mailimap_resp_cond_bye *
2387 mailimap_resp_cond_bye_new(struct mailimap_resp_text * rsp_text);
2388 
2389 LIBETPAN_EXPORT
2390 void
2391 mailimap_resp_cond_bye_free(struct mailimap_resp_cond_bye * cond_bye);
2392 
2393 
2394 
2395 /* this is the type of a condition state response */
2396 
2397 enum {
2398   MAILIMAP_RESP_COND_STATE_OK,
2399   MAILIMAP_RESP_COND_STATE_NO,
2400   MAILIMAP_RESP_COND_STATE_BAD
2401 };
2402 
2403 /*
2404   mailimap_resp_cond_state is a condition state reponse
2405 
2406   - type is the type of the condition state response
2407 
2408   - text is a text response
2409 */
2410 
2411 struct mailimap_resp_cond_state {
2412   int rsp_type;
2413   struct mailimap_resp_text * rsp_text; /* can be NULL */
2414 };
2415 
2416 LIBETPAN_EXPORT
2417 struct mailimap_resp_cond_state *
2418 mailimap_resp_cond_state_new(int rsp_type,
2419     struct mailimap_resp_text * rsp_text);
2420 
2421 LIBETPAN_EXPORT
2422 void
2423 mailimap_resp_cond_state_free(struct mailimap_resp_cond_state * cond_state);
2424 
2425 
2426 
2427 /*
2428   mailimap_resp_text is a text response
2429 
2430   - resp_code is a response code
2431 
2432   - text is a human readable text, should be allocated with malloc()
2433 */
2434 
2435 struct mailimap_resp_text {
2436   struct mailimap_resp_text_code * rsp_code; /* can be NULL */
2437   char * rsp_text; /* can be NULL */
2438 };
2439 
2440 LIBETPAN_EXPORT
2441 struct mailimap_resp_text *
2442 mailimap_resp_text_new(struct mailimap_resp_text_code * resp_code,
2443 		       char * rsp_text);
2444 
2445 LIBETPAN_EXPORT
2446 void mailimap_resp_text_free(struct mailimap_resp_text * resp_text);
2447 
2448 
2449 
2450 /* this is the type of the response code */
2451 
2452 enum {
2453   MAILIMAP_RESP_TEXT_CODE_ALERT,           /* ALERT response */
2454   MAILIMAP_RESP_TEXT_CODE_BADCHARSET,      /* BADCHARSET response */
2455   MAILIMAP_RESP_TEXT_CODE_CAPABILITY_DATA, /* CAPABILITY response */
2456   MAILIMAP_RESP_TEXT_CODE_PARSE,           /* PARSE response */
2457   MAILIMAP_RESP_TEXT_CODE_PERMANENTFLAGS,  /* PERMANENTFLAGS response */
2458   MAILIMAP_RESP_TEXT_CODE_READ_ONLY,       /* READONLY response */
2459   MAILIMAP_RESP_TEXT_CODE_READ_WRITE,      /* READWRITE response */
2460   MAILIMAP_RESP_TEXT_CODE_TRY_CREATE,      /* TRYCREATE response */
2461   MAILIMAP_RESP_TEXT_CODE_UIDNEXT,         /* UIDNEXT response */
2462   MAILIMAP_RESP_TEXT_CODE_UIDVALIDITY,     /* UIDVALIDITY response */
2463   MAILIMAP_RESP_TEXT_CODE_UNSEEN,          /* UNSEEN response */
2464   MAILIMAP_RESP_TEXT_CODE_OTHER,           /* other type of response */
2465   MAILIMAP_RESP_TEXT_CODE_EXTENSION        /* extension response */
2466 };
2467 
2468 /*
2469   mailimap_resp_text_code is a response code
2470 
2471   - type is the type of the response code, the value can be
2472     MAILIMAP_RESP_TEXT_CODE_ALERT, MAILIMAP_RESP_TEXT_CODE_BADCHARSET,
2473     MAILIMAP_RESP_TEXT_CODE_CAPABILITY_DATA, MAILIMAP_RESP_TEXT_CODE_PARSE,
2474     MAILIMAP_RESP_TEXT_CODE_PERMANENTFLAGS, MAILIMAP_RESP_TEXT_CODE_READ_ONLY,
2475     MAILIMAP_RESP_TEXT_CODE_READ_WRITE, MAILIMAP_RESP_TEXT_CODE_TRY_CREATE,
2476     MAILIMAP_RESP_TEXT_CODE_UIDNEXT, MAILIMAP_RESP_TEXT_CODE_UIDVALIDITY,
2477     MAILIMAP_RESP_TEXT_CODE_UNSEEN or MAILIMAP_RESP_TEXT_CODE_OTHER
2478 
2479   - badcharset is a list of charsets if type
2480     is MAILIMAP_RESP_TEXT_CODE_BADCHARSET, each element should be
2481     allocated with malloc()
2482 
2483   - cap_data is a list of capabilities
2484 
2485   - perm_flags is a list of flags, this is the flags that can be changed
2486     permanently on the messages of the mailbox.
2487 
2488   - uidnext is the next unique identifier of a message
2489 
2490   - uidvalidity is the unique identifier validity value
2491 
2492   - first_unseen is the number of the first message without the \Seen flag
2493 
2494   - atom is a keyword for an extension response code, should be allocated
2495     with malloc()
2496 
2497   - atom_value is the data related with the extension response code,
2498     should be allocated with malloc()
2499 */
2500 
2501 struct mailimap_resp_text_code {
2502   int rc_type;
2503   union {
2504     clist * rc_badcharset; /* list of astring (char *) */
2505     /* can be NULL */
2506     struct mailimap_capability_data * rc_cap_data; /* != NULL */
2507     clist * rc_perm_flags; /* list of (struct mailimap_flag_perm *) */
2508     /* can be NULL */
2509     uint32_t rc_uidnext;
2510     uint32_t rc_uidvalidity;
2511     uint32_t rc_first_unseen;
2512     struct {
2513       char * atom_name;  /* can be NULL */
2514       char * atom_value; /* can be NULL */
2515     } rc_atom;
2516     struct mailimap_extension_data * rc_ext_data; /* can be NULL */
2517   } rc_data;
2518 };
2519 
2520 LIBETPAN_EXPORT
2521 struct mailimap_resp_text_code *
2522 mailimap_resp_text_code_new(int rc_type, clist * rc_badcharset,
2523     struct mailimap_capability_data * rc_cap_data,
2524     clist * rc_perm_flags,
2525     uint32_t rc_uidnext, uint32_t rc_uidvalidity,
2526     uint32_t rc_first_unseen, char * rc_atom, char * rc_atom_value,
2527     struct mailimap_extension_data * rc_ext_data);
2528 
2529 LIBETPAN_EXPORT
2530 void
2531 mailimap_resp_text_code_free(struct mailimap_resp_text_code * resp_text_code);
2532 
2533 
2534 /*
2535   mailimap_section is a MIME part section identifier
2536 
2537   section_spec is the MIME section identifier
2538 */
2539 
2540 struct mailimap_section {
2541   struct mailimap_section_spec * sec_spec; /* can be NULL */
2542 };
2543 
2544 LIBETPAN_EXPORT
2545 struct mailimap_section *
2546 mailimap_section_new(struct mailimap_section_spec * sec_spec);
2547 
2548 LIBETPAN_EXPORT
2549 void mailimap_section_free(struct mailimap_section * section);
2550 
2551 
2552 /* this is the type of the message/rfc822 part description */
2553 
2554 enum {
2555   MAILIMAP_SECTION_MSGTEXT_HEADER,            /* header fields part of the
2556                                                  message */
2557   MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS,     /* given header fields of the
2558                                                  message */
2559   MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS_NOT, /* header fields of the
2560                                                  message except the given */
2561   MAILIMAP_SECTION_MSGTEXT_TEXT               /* text part  */
2562 };
2563 
2564 /*
2565   mailimap_section_msgtext is a message/rfc822 part description
2566 
2567   - type is the type of the content part and the value can be
2568     MAILIMAP_SECTION_MSGTEXT_HEADER, MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS,
2569     MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS_NOT
2570     or MAILIMAP_SECTION_MSGTEXT_TEXT
2571 
2572   - header_list is the list of headers when type is
2573     MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS or
2574     MAILIMAP_SECTION_MSGTEXT_HEADER_FIELDS_NOT
2575 */
2576 
2577 struct mailimap_section_msgtext {
2578   int sec_type;
2579   struct mailimap_header_list * sec_header_list; /* can be NULL */
2580 };
2581 
2582 LIBETPAN_EXPORT
2583 struct mailimap_section_msgtext *
2584 mailimap_section_msgtext_new(int sec_type,
2585     struct mailimap_header_list * sec_header_list);
2586 
2587 LIBETPAN_EXPORT
2588 void
2589 mailimap_section_msgtext_free(struct mailimap_section_msgtext * msgtext);
2590 
2591 
2592 
2593 /*
2594   mailimap_section_part is the MIME part location in a message
2595 
2596   - section_id is a list of number index of the sub-part in the mail structure,
2597     each element should be allocated with malloc()
2598 
2599 */
2600 
2601 struct mailimap_section_part {
2602   clist * sec_id; /* list of nz-number (uint32_t *) */
2603                       /* != NULL */
2604 };
2605 
2606 LIBETPAN_EXPORT
2607 struct mailimap_section_part *
2608 mailimap_section_part_new(clist * sec_id);
2609 
2610 LIBETPAN_EXPORT
2611 void
2612 mailimap_section_part_free(struct mailimap_section_part * section_part);
2613 
2614 
2615 
2616 /* this is the type of section specification */
2617 
2618 enum {
2619   MAILIMAP_SECTION_SPEC_SECTION_MSGTEXT, /* if requesting data of the root
2620                                             MIME message/rfc822 part */
2621   MAILIMAP_SECTION_SPEC_SECTION_PART     /* location of the MIME part
2622                                             in the message */
2623 };
2624 
2625 /*
2626   mailimap_section_spec is a section specification
2627 
2628   - type is the type of the section specification, the value can be
2629     MAILIMAP_SECTION_SPEC_SECTION_MSGTEXT or
2630     MAILIMAP_SECTION_SPEC_SECTION_PART
2631 
2632   - section_msgtext is a message/rfc822 part description if type is
2633     MAILIMAP_SECTION_SPEC_SECTION_MSGTEXT
2634 
2635   - section_part is a body part location in the message if type is
2636     MAILIMAP_SECTION_SPEC_SECTION_PART
2637 
2638   - section_text is a body part location for a given MIME part,
2639     this can be NULL if the body of the part is requested (and not
2640     the MIME header).
2641 */
2642 
2643 struct mailimap_section_spec {
2644   int sec_type;
2645   union {
2646     struct mailimap_section_msgtext * sec_msgtext; /* can be NULL */
2647     struct mailimap_section_part * sec_part;       /* can be NULL */
2648   } sec_data;
2649   struct mailimap_section_text * sec_text;       /* can be NULL */
2650 };
2651 
2652 LIBETPAN_EXPORT
2653 struct mailimap_section_spec *
2654 mailimap_section_spec_new(int sec_type,
2655     struct mailimap_section_msgtext * sec_msgtext,
2656     struct mailimap_section_part * sec_part,
2657     struct mailimap_section_text * sec_text);
2658 
2659 LIBETPAN_EXPORT
2660 void
2661 mailimap_section_spec_free(struct mailimap_section_spec * section_spec);
2662 
2663 
2664 
2665 /* this is the type of body part location for a given MIME part */
2666 
2667 enum {
2668   MAILIMAP_SECTION_TEXT_ERROR,           /* on parse error **/
2669   MAILIMAP_SECTION_TEXT_SECTION_MSGTEXT, /* if the MIME type is
2670                                             message/rfc822, headers or text
2671                                             can be requested */
2672   MAILIMAP_SECTION_TEXT_MIME             /* for all MIME types,
2673                                             MIME headers can be requested */
2674 };
2675 
2676 /*
2677   mailimap_section_text is the body part location for a given MIME part
2678 
2679   - type can be MAILIMAP_SECTION_TEXT_SECTION_MSGTEXT or
2680     MAILIMAP_SECTION_TEXT_MIME
2681 
2682   - section_msgtext is the part of the MIME part when MIME type is
2683     message/rfc822 than can be requested, when type is
2684     MAILIMAP_TEXT_SECTION_MSGTEXT
2685 */
2686 
2687 struct mailimap_section_text {
2688   int sec_type;
2689   struct mailimap_section_msgtext * sec_msgtext; /* can be NULL */
2690 };
2691 
2692 LIBETPAN_EXPORT
2693 struct mailimap_section_text *
2694 mailimap_section_text_new(int sec_type,
2695     struct mailimap_section_msgtext * sec_msgtext);
2696 
2697 LIBETPAN_EXPORT
2698 void
2699 mailimap_section_text_free(struct mailimap_section_text * section_text);
2700 
2701 
2702 
2703 
2704 
2705 
2706 
2707 
2708 
2709 
2710 /* ************************************************************************* */
2711 /* the following part concerns only the IMAP command that are sent */
2712 
2713 
2714 /*
2715   mailimap_set_item is a message set
2716 
2717   - first is the first message of the set
2718   - last is the last message of the set
2719 
2720   this can be message numbers of message unique identifiers
2721 */
2722 
2723 struct mailimap_set_item {
2724   uint32_t set_first;
2725   uint32_t set_last;
2726 };
2727 
2728 LIBETPAN_EXPORT
2729 struct mailimap_set_item *
2730 mailimap_set_item_new(uint32_t set_first, uint32_t set_last);
2731 
2732 LIBETPAN_EXPORT
2733 void mailimap_set_item_free(struct mailimap_set_item * set_item);
2734 
2735 
2736 
2737 /*
2738   set is a list of message sets
2739 
2740   - list is a list of message sets
2741 */
2742 
2743 struct mailimap_set {
2744   clist * set_list; /* list of (struct mailimap_set_item *) */
2745 };
2746 
2747 LIBETPAN_EXPORT
2748 struct mailimap_set * mailimap_set_new(clist * list);
2749 
2750 LIBETPAN_EXPORT
2751 void mailimap_set_free(struct mailimap_set * set);
2752 
2753 
2754 /*
2755   mailimap_date is a date
2756 
2757   - day is the day in the month (1 to 31)
2758 
2759   - month (1 to 12)
2760 
2761   - year (4 digits)
2762 */
2763 
2764 struct mailimap_date {
2765   int dt_day;
2766   int dt_month;
2767   int dt_year;
2768 };
2769 
2770 LIBETPAN_EXPORT
2771 struct mailimap_date *
2772 mailimap_date_new(int dt_day, int dt_month, int dt_year);
2773 
2774 LIBETPAN_EXPORT
2775 void mailimap_date_free(struct mailimap_date * date);
2776 
2777 
2778 
2779 
2780 /* this is the type of fetch attribute for a given message */
2781 
2782 enum {
2783   MAILIMAP_FETCH_ATT_ENVELOPE,          /* to fetch the headers parsed by
2784                                            the IMAP server */
2785   MAILIMAP_FETCH_ATT_FLAGS,             /* to fetch the flags */
2786   MAILIMAP_FETCH_ATT_INTERNALDATE,      /* to fetch the date of the message
2787                                            kept by the server */
2788   MAILIMAP_FETCH_ATT_RFC822,            /* to fetch the entire message */
2789   MAILIMAP_FETCH_ATT_RFC822_HEADER,     /* to fetch the headers */
2790   MAILIMAP_FETCH_ATT_RFC822_SIZE,       /* to fetch the size */
2791   MAILIMAP_FETCH_ATT_RFC822_TEXT,       /* to fetch the text part */
2792   MAILIMAP_FETCH_ATT_BODY,              /* to fetch the MIME structure */
2793   MAILIMAP_FETCH_ATT_BODYSTRUCTURE,     /* to fetch the MIME structure with
2794                                            additional information */
2795   MAILIMAP_FETCH_ATT_UID,               /* to fetch the unique identifier */
2796   MAILIMAP_FETCH_ATT_BODY_SECTION,      /* to fetch a given part */
2797   MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION, /* to fetch a given part without
2798                                            marking the message as read */
2799   MAILIMAP_FETCH_ATT_EXTENSION
2800 };
2801 
2802 
2803 /*
2804   mailimap_fetch_att is the description of the fetch attribute
2805 
2806   - type is the type of fetch attribute, the value can be
2807     MAILIMAP_FETCH_ATT_ENVELOPE, MAILIMAP_FETCH_ATT_FLAGS,
2808     MAILIMAP_FETCH_ATT_INTERNALDATE, MAILIMAP_FETCH_ATT_RFC822,
2809     MAILIMAP_FETCH_ATT_RFC822_HEADER, MAILIMAP_FETCH_ATT_RFC822_SIZE,
2810     MAILIMAP_FETCH_ATT_RFC822_TEXT, MAILIMAP_FETCH_ATT_BODY,
2811     MAILIMAP_FETCH_ATT_BODYSTRUCTURE, MAILIMAP_FETCH_ATT_UID,
2812     MAILIMAP_FETCH_ATT_BODY_SECTION, MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION,
2813     MAILIMAP_FETCH_ATT_EXTENSION
2814 
2815   - section is the location of the part to fetch if type is
2816     MAILIMAP_FETCH_ATT_BODY_SECTION or MAILIMAP_FETCH_ATT_BODY_PEEK_SECTION
2817 
2818   - offset is the first byte to fetch in the given part
2819 
2820   - size is the maximum size of the part to fetch
2821 
2822   - att_extension: keyword to send when MAILIMAP_FETCH_ATT_EXTENSION is used
2823 */
2824 
2825 struct mailimap_fetch_att {
2826   int att_type;
2827   struct mailimap_section * att_section;
2828   uint32_t att_offset;
2829   uint32_t att_size;
2830   char * att_extension; /* can be NULL */
2831 };
2832 
2833 LIBETPAN_EXPORT
2834 struct mailimap_fetch_att *
2835 mailimap_fetch_att_new(int att_type, struct mailimap_section * att_section,
2836 		       uint32_t att_offset, uint32_t att_size, char * att_extension);
2837 
2838 
2839 LIBETPAN_EXPORT
2840 void mailimap_fetch_att_free(struct mailimap_fetch_att * fetch_att);
2841 
2842 
2843 /* this is the type of a FETCH operation */
2844 
2845 enum {
2846   MAILIMAP_FETCH_TYPE_ALL,            /* equivalent to (FLAGS INTERNALDATE
2847                                          RFC822.SIZE ENVELOPE) */
2848   MAILIMAP_FETCH_TYPE_FULL,           /* equivalent to (FLAGS INTERNALDATE
2849                                          RFC822.SIZE ENVELOPE BODY) */
2850   MAILIMAP_FETCH_TYPE_FAST,           /* equivalent to (FLAGS INTERNALDATE
2851                                          RFC822.SIZE) */
2852   MAILIMAP_FETCH_TYPE_FETCH_ATT,      /* when there is only of fetch
2853                                          attribute */
2854   MAILIMAP_FETCH_TYPE_FETCH_ATT_LIST  /* when there is a list of fetch
2855                                          attributes */
2856 };
2857 
2858 /*
2859   mailimap_fetch_type is the description of the FETCH operation
2860 
2861   - type can be MAILIMAP_FETCH_TYPE_ALL, MAILIMAP_FETCH_TYPE_FULL,
2862     MAILIMAP_FETCH_TYPE_FAST, MAILIMAP_FETCH_TYPE_FETCH_ATT or
2863     MAILIMAP_FETCH_TYPE_FETCH_ATT_LIST
2864 
2865   - fetch_att is a fetch attribute if type is MAILIMAP_FETCH_TYPE_FETCH_ATT
2866 
2867   - fetch_att_list is a list of fetch attributes if type is
2868     MAILIMAP_FETCH_TYPE_FETCH_ATT_LIST
2869 */
2870 
2871 struct mailimap_fetch_type {
2872   int ft_type;
2873   union {
2874     struct mailimap_fetch_att * ft_fetch_att;
2875     clist * ft_fetch_att_list; /* list of (struct mailimap_fetch_att *) */
2876   } ft_data;
2877 };
2878 
2879 LIBETPAN_EXPORT
2880 struct mailimap_fetch_type *
2881 mailimap_fetch_type_new(int ft_type,
2882     struct mailimap_fetch_att * ft_fetch_att,
2883     clist * ft_fetch_att_list);
2884 
2885 
2886 LIBETPAN_EXPORT
2887 void mailimap_fetch_type_free(struct mailimap_fetch_type * fetch_type);
2888 
2889 
2890 
2891 /*
2892   mailimap_store_att_flags is the description of the STORE operation
2893   (change flags of a message)
2894 
2895   - sign can be 0 (set flag), +1 (add flag) or -1 (remove flag)
2896 
2897   - silent has a value of 1 if the flags are changed with no server
2898     response
2899 
2900   - flag_list is the list of flags to change
2901 */
2902 
2903 struct mailimap_store_att_flags {
2904   int fl_sign;
2905   int fl_silent;
2906   struct mailimap_flag_list * fl_flag_list;
2907 };
2908 
2909 LIBETPAN_EXPORT
2910 struct mailimap_store_att_flags *
2911 mailimap_store_att_flags_new(int fl_sign, int fl_silent,
2912 			     struct mailimap_flag_list * fl_flag_list);
2913 
2914 LIBETPAN_EXPORT
2915 void mailimap_store_att_flags_free(struct mailimap_store_att_flags *
2916     store_att_flags);
2917 
2918 
2919 
2920 /* this is the condition of the SEARCH operation */
2921 
2922 enum {
2923   MAILIMAP_SEARCH_KEY_ALL,        /* all messages */
2924   MAILIMAP_SEARCH_KEY_ANSWERED,   /* messages with the flag \Answered */
2925   MAILIMAP_SEARCH_KEY_BCC,        /* messages whose Bcc field contains the
2926                                      given string */
2927   MAILIMAP_SEARCH_KEY_BEFORE,     /* messages whose internal date is earlier
2928                                      than the specified date */
2929   MAILIMAP_SEARCH_KEY_BODY,       /* message that contains the given string
2930                                      (in header and text parts) */
2931   MAILIMAP_SEARCH_KEY_CC,         /* messages whose Cc field contains the
2932                                      given string */
2933   MAILIMAP_SEARCH_KEY_DELETED,    /* messages with the flag \Deleted */
2934   MAILIMAP_SEARCH_KEY_FLAGGED,    /* messages with the flag \Flagged */
2935   MAILIMAP_SEARCH_KEY_FROM,       /* messages whose From field contains the
2936                                      given string */
2937   MAILIMAP_SEARCH_KEY_KEYWORD,    /* messages with the flag keyword set */
2938   MAILIMAP_SEARCH_KEY_NEW,        /* messages with the flag \Recent and not
2939                                      the \Seen flag */
2940   MAILIMAP_SEARCH_KEY_OLD,        /* messages that do not have the
2941                                      \Recent flag set */
2942   MAILIMAP_SEARCH_KEY_ON,         /* messages whose internal date is the
2943                                      specified date */
2944   MAILIMAP_SEARCH_KEY_RECENT,     /* messages with the flag \Recent */
2945   MAILIMAP_SEARCH_KEY_SEEN,       /* messages with the flag \Seen */
2946   MAILIMAP_SEARCH_KEY_SINCE,      /* messages whose internal date is later
2947                                      than specified date */
2948   MAILIMAP_SEARCH_KEY_SUBJECT,    /* messages whose Subject field contains the
2949                                      given string */
2950   MAILIMAP_SEARCH_KEY_TEXT,       /* messages whose text part contains the
2951                                      given string */
2952   MAILIMAP_SEARCH_KEY_TO,         /* messages whose To field contains the
2953                                      given string */
2954   MAILIMAP_SEARCH_KEY_UNANSWERED, /* messages with no flag \Answered */
2955   MAILIMAP_SEARCH_KEY_UNDELETED,  /* messages with no flag \Deleted */
2956   MAILIMAP_SEARCH_KEY_UNFLAGGED,  /* messages with no flag \Flagged */
2957   MAILIMAP_SEARCH_KEY_UNKEYWORD,  /* messages with no flag keyword */
2958   MAILIMAP_SEARCH_KEY_UNSEEN,     /* messages with no flag \Seen */
2959   MAILIMAP_SEARCH_KEY_DRAFT,      /* messages with no flag \Draft */
2960   MAILIMAP_SEARCH_KEY_HEADER,     /* messages whose given field
2961                                      contains the given string */
2962   MAILIMAP_SEARCH_KEY_LARGER,     /* messages whose size is larger then
2963                                      the given size */
2964   MAILIMAP_SEARCH_KEY_NOT,        /* not operation of the condition */
2965   MAILIMAP_SEARCH_KEY_OR,         /* or operation between two conditions */
2966   MAILIMAP_SEARCH_KEY_SENTBEFORE, /* messages whose date given in Date header
2967                                      is earlier than the specified date */
2968   MAILIMAP_SEARCH_KEY_SENTON,     /* messages whose date given in Date header
2969                                      is the specified date */
2970   MAILIMAP_SEARCH_KEY_SENTSINCE,  /* messages whose date given in Date header
2971                                      is later than specified date */
2972   MAILIMAP_SEARCH_KEY_SMALLER,    /* messages whose size is smaller than
2973                                      the given size */
2974   MAILIMAP_SEARCH_KEY_UID,        /* messages whose unique identifiers are
2975                                      in the given range */
2976   MAILIMAP_SEARCH_KEY_UNDRAFT,    /* messages with no flag \Draft */
2977   MAILIMAP_SEARCH_KEY_SET,        /* messages whose number (or unique
2978                                      identifiers in case of UID SEARCH) are
2979                                      in the given range */
2980   MAILIMAP_SEARCH_KEY_MULTIPLE,   /* the boolean operator between the
2981                                      conditions is AND */
2982   MAILIMAP_SEARCH_KEY_MODSEQ,     /* mod sequence */
2983   MAILIMAP_SEARCH_KEY_XGMTHRID,   /* Gmail thread id */
2984   MAILIMAP_SEARCH_KEY_XGMMSGID,   /* Gmail Message id */
2985   MAILIMAP_SEARCH_KEY_XGMRAW      /* Gmail RAW expression */
2986 };
2987 
2988 /*
2989   mailimap_search_key is the condition on the messages to return
2990 
2991   - type is the type of the condition
2992 
2993   - bcc is the text to search in the Bcc field when type is
2994     MAILIMAP_SEARCH_KEY_BCC, should be allocated with malloc()
2995 
2996   - before is a date when type is MAILIMAP_SEARCH_KEY_BEFORE
2997 
2998   - body is the text to search in the message when type is
2999     MAILIMAP_SEARCH_KEY_BODY, should be allocated with malloc()
3000 
3001   - cc is the text to search in the Cc field when type is
3002     MAILIMAP_SEARCH_KEY_CC, should be allocated with malloc()
3003 
3004   - from is the text to search in the From field when type is
3005     MAILIMAP_SEARCH_KEY_FROM, should be allocated with malloc()
3006 
3007   - keyword is the keyword flag name when type is MAILIMAP_SEARCH_KEY_KEYWORD,
3008     should be allocated with malloc()
3009 
3010   - on is a date when type is MAILIMAP_SEARCH_KEY_ON
3011 
3012   - since is a date when type is MAILIMAP_SEARCH_KEY_SINCE
3013 
3014   - subject is the text to search in the Subject field when type is
3015     MAILIMAP_SEARCH_KEY_SUBJECT, should be allocated with malloc()
3016 
3017   - text is the text to search in the text part of the message when
3018     type is MAILIMAP_SEARCH_KEY_TEXT, should be allocated with malloc()
3019 
3020   - to is the text to search in the To field when type is
3021     MAILIMAP_SEARCH_KEY_TO, should be allocated with malloc()
3022 
3023   - unkeyword is the keyword flag name when type is
3024     MAILIMAP_SEARCH_KEY_UNKEYWORD, should be allocated with malloc()
3025 
3026   - header_name is the header name when type is MAILIMAP_SEARCH_KEY_HEADER,
3027     should be allocated with malloc()
3028 
3029   - header_value is the text to search in the given header when type is
3030     MAILIMAP_SEARCH_KEY_HEADER, should be allocated with malloc()
3031 
3032   - larger is a size when type is MAILIMAP_SEARCH_KEY_LARGER
3033 
3034   - not is a condition when type is MAILIMAP_SEARCH_KEY_NOT
3035 
3036   - or1 is a condition when type is MAILIMAP_SEARCH_KEY_OR
3037 
3038   - or2 is a condition when type is MAILIMAP_SEARCH_KEY_OR
3039 
3040   - sentbefore is a date when type is MAILIMAP_SEARCH_KEY_SENTBEFORE
3041 
3042   - senton is a date when type is MAILIMAP_SEARCH_KEY_SENTON
3043 
3044   - sentsince is a date when type is MAILIMAP_SEARCH_KEY_SENTSINCE
3045 
3046   - smaller is a size when type is MAILIMAP_SEARCH_KEY_SMALLER
3047 
3048   - uid is a set of messages when type is MAILIMAP_SEARCH_KEY_UID
3049 
3050   - set is a set of messages when type is MAILIMAP_SEARCH_KEY_SET
3051 
3052   - xgmthrid is a number of the gmail thread id when type is MAILIMAP_SEARCH_KEY_XGMTHRID
3053     use mailimap_search_key_new_xgmthrid() for this key
3054 
3055   - xgmmsgid is a gmail message id expression when type is MAILIMAP_SEARCH_KEY_XGMMSGID
3056    use mailimap_search_key_new_xgmmsgid() for this key
3057 
3058   - xgmraw is a raw gmail search expression when type is MAILIMAP_SEARCH_KEY_XGMRAW
3059     use mailimap_search_key_new_xgmraw() for this key
3060 
3061   - multiple is a set of message when type is MAILIMAP_SEARCH_KEY_MULTIPLE
3062 */
3063 
3064 enum {
3065 	MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_PRIV,
3066 	MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_SHARED,
3067 	MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_ALL,
3068 };
3069 
3070 struct mailimap_search_key {
3071   int sk_type;
3072   union {
3073     char * sk_bcc;
3074     struct mailimap_date * sk_before;
3075     char * sk_body;
3076     char * sk_cc;
3077     char * sk_from;
3078     char * sk_keyword;
3079     struct mailimap_date * sk_on;
3080     struct mailimap_date * sk_since;
3081     char * sk_subject;
3082     char * sk_text;
3083     char * sk_to;
3084     char * sk_unkeyword;
3085     struct {
3086       char * sk_header_name;
3087       char * sk_header_value;
3088     } sk_header;
3089     uint32_t sk_larger;
3090     struct mailimap_search_key * sk_not;
3091     struct {
3092       struct mailimap_search_key * sk_or1;
3093       struct mailimap_search_key * sk_or2;
3094     } sk_or;
3095     struct mailimap_date * sk_sentbefore;
3096     struct mailimap_date * sk_senton;
3097     struct mailimap_date * sk_sentsince;
3098     uint32_t sk_smaller;
3099     struct mailimap_set * sk_uid;
3100     struct mailimap_set * sk_set;
3101     uint64_t sk_xgmthrid;
3102     uint64_t sk_xgmmsgid;
3103     char * sk_xgmraw;
3104     clist * sk_multiple; /* list of (struct mailimap_search_key *) */
3105     struct {
3106       struct mailimap_flag * sk_entry_name;
3107       int sk_entry_type_req;
3108       uint64_t sk_modseq_valzer;
3109     } sk_modseq;
3110   } sk_data;
3111 };
3112 
3113 LIBETPAN_EXPORT
3114 struct mailimap_search_key *
3115 mailimap_search_key_new(int sk_type,
3116     char * sk_bcc, struct mailimap_date * sk_before, char * sk_body,
3117     char * sk_cc, char * sk_from, char * sk_keyword,
3118     struct mailimap_date * sk_on, struct mailimap_date * sk_since,
3119     char * sk_subject, char * sk_text, char * sk_to,
3120     char * sk_unkeyword, char * sk_header_name,
3121     char * sk_header_value, uint32_t sk_larger,
3122     struct mailimap_search_key * sk_not,
3123     struct mailimap_search_key * sk_or1,
3124     struct mailimap_search_key * sk_or2,
3125     struct mailimap_date * sk_sentbefore,
3126     struct mailimap_date * sk_senton,
3127     struct mailimap_date * sk_sentsince,
3128     uint32_t sk_smaller, struct mailimap_set * sk_uid,
3129     struct mailimap_set * sk_set, clist * sk_multiple);
3130 
3131 /*
3132   this function creates a condition structure to match messages with
3133   the given gmail thread id
3134 */
3135 
3136 LIBETPAN_EXPORT
3137 struct mailimap_search_key *
3138 mailimap_search_key_new_xgmthrid(uint64_t sk_xgmthrid);
3139 
3140 LIBETPAN_EXPORT
3141 struct mailimap_search_key *
3142 mailimap_search_key_new_xgmmsgid(uint64_t sk_xgmmsgid);
3143 
3144 LIBETPAN_EXPORT
3145 struct mailimap_search_key *
3146 mailimap_search_key_new_xgmraw(char * sk_xgmraw);
3147 
3148 LIBETPAN_EXPORT
3149 void mailimap_search_key_free(struct mailimap_search_key * key);
3150 
3151 /*
3152   mailimap_status_att_list is a list of mailbox STATUS request type
3153 
3154   - list is a list of mailbox STATUS request type
3155     (value of elements in the list can be MAILIMAP_STATUS_ATT_MESSAGES,
3156     MAILIMAP_STATUS_ATT_RECENT, MAILIMAP_STATUS_ATT_UIDNEXT,
3157     MAILIMAP_STATUS_ATT_UIDVALIDITY or MAILIMAP_STATUS_ATT_UNSEEN),
3158     each element should be allocated with malloc()
3159 */
3160 
3161 struct mailimap_status_att_list {
3162   clist * att_list; /* list of (uint32_t *) */
3163 };
3164 
3165 LIBETPAN_EXPORT
3166 struct mailimap_status_att_list *
3167 mailimap_status_att_list_new(clist * att_list);
3168 
3169 LIBETPAN_EXPORT
3170 void mailimap_status_att_list_free(struct mailimap_status_att_list *
3171     status_att_list);
3172 
3173 
3174 
3175 
3176 /* internal use functions */
3177 
3178 
3179 LIBETPAN_EXPORT
3180 uint32_t * mailimap_number_alloc_new(uint32_t number);
3181 
3182 LIBETPAN_EXPORT
3183 void mailimap_number_alloc_free(uint32_t * pnumber);
3184 
3185 
3186 LIBETPAN_EXPORT
3187 void mailimap_addr_host_free(char * addr_host);
3188 
3189 LIBETPAN_EXPORT
3190 void mailimap_addr_mailbox_free(char * addr_mailbox);
3191 
3192 LIBETPAN_EXPORT
3193 void mailimap_addr_adl_free(char * addr_adl);
3194 
3195 LIBETPAN_EXPORT
3196 void mailimap_addr_name_free(char * addr_name);
3197 
3198 LIBETPAN_EXPORT
3199 void mailimap_astring_free(char * astring);
3200 
3201 LIBETPAN_EXPORT
3202 void mailimap_atom_free(char * atom);
3203 
3204 LIBETPAN_EXPORT
3205 void mailimap_auth_type_free(char * auth_type);
3206 
3207 LIBETPAN_EXPORT
3208 void mailimap_base64_free(char * base64);
3209 
3210 LIBETPAN_EXPORT
3211 void mailimap_body_fld_desc_free(char * body_fld_desc);
3212 
3213 LIBETPAN_EXPORT
3214 void mailimap_body_fld_id_free(char * body_fld_id);
3215 
3216 LIBETPAN_EXPORT
3217 void mailimap_body_fld_md5_free(char * body_fld_md5);
3218 
3219 LIBETPAN_EXPORT
3220 void mailimap_body_fld_loc_free(char * body_fld_loc);
3221 
3222 LIBETPAN_EXPORT
3223 void mailimap_env_date_free(char * date);
3224 
3225 LIBETPAN_EXPORT
3226 void mailimap_env_in_reply_to_free(char * in_reply_to);
3227 
3228 LIBETPAN_EXPORT
3229 void mailimap_env_message_id_free(char * message_id);
3230 
3231 LIBETPAN_EXPORT
3232 void mailimap_env_subject_free(char * subject);
3233 
3234 LIBETPAN_EXPORT
3235 void mailimap_flag_extension_free(char * flag_extension);
3236 
3237 LIBETPAN_EXPORT
3238 void mailimap_flag_keyword_free(char * flag_keyword);
3239 
3240 LIBETPAN_EXPORT
3241 void
3242 mailimap_header_fld_name_free(char * header_fld_name);
3243 
3244 LIBETPAN_EXPORT
3245 void mailimap_literal_free(char * literal);
3246 
3247 LIBETPAN_EXPORT
3248 void mailimap_mailbox_free(char * mailbox);
3249 
3250 LIBETPAN_EXPORT
3251 void
3252 mailimap_mailbox_data_search_free(clist * data_search);
3253 
3254 LIBETPAN_EXPORT
3255 void mailimap_media_subtype_free(char * media_subtype);
3256 
3257 LIBETPAN_EXPORT
3258 void mailimap_media_text_free(char * media_text);
3259 
3260 LIBETPAN_EXPORT
3261 void mailimap_msg_att_envelope_free(struct mailimap_envelope * env);
3262 
3263 LIBETPAN_EXPORT
3264 void
3265 mailimap_msg_att_internaldate_free(struct mailimap_date_time * date_time);
3266 
3267 LIBETPAN_EXPORT
3268 void
3269 mailimap_msg_att_rfc822_free(char * str);
3270 
3271 LIBETPAN_EXPORT
3272 void
3273 mailimap_msg_att_rfc822_header_free(char * str);
3274 
3275 LIBETPAN_EXPORT
3276 void
3277 mailimap_msg_att_rfc822_text_free(char * str);
3278 
3279 LIBETPAN_EXPORT
3280 void
3281 mailimap_msg_att_body_free(struct mailimap_body * body);
3282 
3283 LIBETPAN_EXPORT
3284 void
3285 mailimap_msg_att_bodystructure_free(struct mailimap_body * body);
3286 
3287 LIBETPAN_EXPORT
3288 void mailimap_nstring_free(char * str);
3289 
3290 LIBETPAN_EXPORT
3291 void
3292 mailimap_string_free(char * str);
3293 
3294 LIBETPAN_EXPORT
3295 void mailimap_tag_free(char * tag);
3296 
3297 LIBETPAN_EXPORT
3298 void mailimap_text_free(char * text);
3299 
3300 
3301 
3302 
3303 
3304 /* IMAP connection */
3305 
3306 /* this is the state of the IMAP connection */
3307 
3308 enum {
3309   MAILIMAP_STATE_DISCONNECTED,
3310   MAILIMAP_STATE_NON_AUTHENTICATED,
3311   MAILIMAP_STATE_AUTHENTICATED,
3312   MAILIMAP_STATE_SELECTED,
3313   MAILIMAP_STATE_LOGOUT
3314 };
3315 
3316 /*
3317   mailimap is an IMAP connection
3318 
3319   - response is a human readable message returned with a reponse,
3320     must be accessed read-only
3321 
3322   - stream is the connection with the IMAP server
3323 
3324   - stream_buffer is the buffer where the data to parse are stored
3325 
3326   - state is the state of IMAP connection
3327 
3328   - tag is the current tag being used in IMAP connection
3329 
3330   - response_buffer is the buffer for response messages
3331 
3332   - connection_info is the information returned in response
3333     for the last command about the connection
3334 
3335   - selection_info is the information returned in response
3336     for the last command about the current selected mailbox
3337 
3338   - response_info is the other information returned in response
3339     for the last command
3340 */
3341 
3342 typedef void mailimap_msg_att_handler(struct mailimap_msg_att * msg_att, void * context);
3343 
3344 typedef bool mailimap_msg_body_handler(int msg_att_type, struct mailimap_msg_att_body_section * section,
3345                                        const char * bytes, size_t length, void * context);
3346 
3347 typedef struct mailimap mailimap;
3348 
3349 struct mailimap {
3350   char * imap_response;
3351 
3352   /* internals */
3353   mailstream * imap_stream;
3354 
3355   size_t imap_progr_rate;
3356   progress_function * imap_progr_fun;
3357 
3358   MMAPString * imap_stream_buffer;
3359   MMAPString * imap_response_buffer;
3360 
3361   int imap_state;
3362   int imap_tag;
3363 
3364   struct mailimap_connection_info * imap_connection_info;
3365   struct mailimap_selection_info * imap_selection_info;
3366   struct mailimap_response_info * imap_response_info;
3367 
3368   struct {
3369     void * sasl_conn;
3370     const char * sasl_server_fqdn;
3371     const char * sasl_login;
3372     const char * sasl_auth_name;
3373     const char * sasl_password;
3374     const char * sasl_realm;
3375     void * sasl_secret;
3376   } imap_sasl;
3377 
3378   time_t imap_idle_timestamp;
3379   time_t imap_idle_maxdelay;
3380 
3381   mailprogress_function * imap_body_progress_fun;
3382   mailprogress_function * imap_items_progress_fun;
3383   void * imap_progress_context;
3384   mailimap_msg_att_handler * imap_msg_att_handler;
3385   void * imap_msg_att_handler_context;
3386   mailimap_msg_body_handler * imap_msg_body_handler;
3387   void * imap_msg_body_handler_context;
3388 
3389   time_t imap_timeout;
3390 
3391   void (* imap_logger)(mailimap * session, int log_type, const char * str, size_t size, void * context);
3392   void * imap_logger_context;
3393 
3394   int is_163_workaround_enabled;
3395   int is_rambler_workaround_enabled;
3396   int is_qip_workaround_enabled;
3397 };
3398 
3399 
3400 
3401 /*
3402   mailimap_connection_info is the information about the connection
3403 
3404   - capability is the list of capability of the IMAP server
3405 */
3406 
3407 struct mailimap_connection_info {
3408   struct mailimap_capability_data * imap_capability;
3409 };
3410 
3411 LIBETPAN_EXPORT
3412 struct mailimap_connection_info *
3413 mailimap_connection_info_new(void);
3414 
3415 LIBETPAN_EXPORT
3416 void
3417 mailimap_connection_info_free(struct mailimap_connection_info * conn_info);
3418 
3419 
3420 /* this is the type of mailbox access */
3421 
3422 enum {
3423   MAILIMAP_MAILBOX_READONLY,
3424   MAILIMAP_MAILBOX_READWRITE
3425 };
3426 
3427 /*
3428   mailimap_selection_info is information about the current selected mailbox
3429 
3430   - perm_flags is a list of flags that can be changed permanently on the
3431     messages of the mailbox
3432 
3433   - perm is the access on the mailbox, value can be
3434     MAILIMAP_MAILBOX_READONLY or MAILIMAP_MAILBOX_READWRITE
3435 
3436   - uidnext is the next unique identifier
3437 
3438   - uidvalidity is the unique identifiers validity
3439 
3440   - first_unseen is the number of the first unseen message
3441 
3442   - flags is a list of flags that can be used on the messages of
3443     the mailbox
3444 
3445   - exists is the number of messages in the mailbox
3446 
3447   - recent is the number of recent messages in the mailbox
3448 
3449   - unseen is the number of unseen messages in the mailbox
3450 */
3451 
3452 struct mailimap_selection_info {
3453   clist * sel_perm_flags; /* list of (struct flag_perm *) */
3454   int sel_perm;
3455   uint32_t sel_uidnext;
3456   uint32_t sel_uidvalidity;
3457   uint32_t sel_first_unseen;
3458   struct mailimap_flag_list * sel_flags;
3459   uint32_t sel_exists;
3460   uint32_t sel_recent;
3461   uint32_t sel_unseen;
3462   uint8_t  sel_has_exists:1;
3463   uint8_t  sel_has_recent:1;
3464 };
3465 
3466 LIBETPAN_EXPORT
3467 struct mailimap_selection_info *
3468 mailimap_selection_info_new(void);
3469 
3470 LIBETPAN_EXPORT
3471 void
3472 mailimap_selection_info_free(struct mailimap_selection_info * sel_info);
3473 
3474 
3475 /*
3476   mailimap_response_info is the other information returned in the
3477   response for a command
3478 
3479   - alert is the human readable text returned with ALERT response
3480 
3481   - parse is the human readable text returned with PARSE response
3482 
3483   - badcharset is a list of charset returned with a BADCHARSET response
3484 
3485   - trycreate is set to 1 if a trycreate response was returned
3486 
3487   - mailbox_list is a list of mailboxes
3488 
3489   - mailbox_lsub is a list of subscribed mailboxes
3490 
3491   - search_result is a list of message numbers or unique identifiers
3492 
3493   - status is a STATUS response
3494 
3495   - expunged is a list of message numbers
3496 
3497   - fetch_list is a list of fetch response
3498 */
3499 
3500 struct mailimap_response_info {
3501   char * rsp_alert;
3502   char * rsp_parse;
3503   clist * rsp_badcharset; /* list of (char *) */
3504   int rsp_trycreate;
3505   clist * rsp_mailbox_list; /* list of (struct mailimap_mailbox_list *) */
3506   clist * rsp_mailbox_lsub; /* list of (struct mailimap_mailbox_list *) */
3507   clist * rsp_search_result; /* list of (uint32_t *) */
3508   struct mailimap_mailbox_data_status * rsp_status;
3509   clist * rsp_expunged; /* list of (uint32_t 32 *) */
3510   clist * rsp_fetch_list; /* list of (struct mailimap_msg_att *) */
3511   clist * rsp_extension_list; /* list of (struct mailimap_extension_data *) */
3512   char * rsp_atom;
3513   char * rsp_value;
3514 };
3515 
3516 LIBETPAN_EXPORT
3517 struct mailimap_response_info *
3518 mailimap_response_info_new(void);
3519 
3520 LIBETPAN_EXPORT
3521 void
3522 mailimap_response_info_free(struct mailimap_response_info * resp_info);
3523 
3524 
3525 /* these are the possible returned error codes */
3526 
3527 enum {
3528   MAILIMAP_NO_ERROR = 0,
3529   MAILIMAP_NO_ERROR_AUTHENTICATED = 1,
3530   MAILIMAP_NO_ERROR_NON_AUTHENTICATED = 2,
3531   MAILIMAP_ERROR_BAD_STATE,
3532   MAILIMAP_ERROR_STREAM,
3533   MAILIMAP_ERROR_PARSE,
3534   MAILIMAP_ERROR_CONNECTION_REFUSED,
3535   MAILIMAP_ERROR_MEMORY,
3536   MAILIMAP_ERROR_FATAL,
3537   MAILIMAP_ERROR_PROTOCOL,
3538   MAILIMAP_ERROR_DONT_ACCEPT_CONNECTION,
3539   MAILIMAP_ERROR_APPEND,
3540   MAILIMAP_ERROR_NOOP,
3541   MAILIMAP_ERROR_LOGOUT,
3542   MAILIMAP_ERROR_CAPABILITY,
3543   MAILIMAP_ERROR_CHECK,
3544   MAILIMAP_ERROR_CLOSE,
3545   MAILIMAP_ERROR_EXPUNGE,
3546   MAILIMAP_ERROR_COPY,
3547   MAILIMAP_ERROR_UID_COPY,
3548   MAILIMAP_ERROR_MOVE,
3549   MAILIMAP_ERROR_UID_MOVE,
3550   MAILIMAP_ERROR_CREATE,
3551   MAILIMAP_ERROR_DELETE,
3552   MAILIMAP_ERROR_EXAMINE,
3553   MAILIMAP_ERROR_FETCH,
3554   MAILIMAP_ERROR_UID_FETCH,
3555   MAILIMAP_ERROR_LIST,
3556   MAILIMAP_ERROR_LOGIN,
3557   MAILIMAP_ERROR_LSUB,
3558   MAILIMAP_ERROR_RENAME,
3559   MAILIMAP_ERROR_SEARCH,
3560   MAILIMAP_ERROR_UID_SEARCH,
3561   MAILIMAP_ERROR_SELECT,
3562   MAILIMAP_ERROR_STATUS,
3563   MAILIMAP_ERROR_STORE,
3564   MAILIMAP_ERROR_UID_STORE,
3565   MAILIMAP_ERROR_SUBSCRIBE,
3566   MAILIMAP_ERROR_UNSUBSCRIBE,
3567   MAILIMAP_ERROR_STARTTLS,
3568   MAILIMAP_ERROR_INVAL,
3569   MAILIMAP_ERROR_EXTENSION,
3570   MAILIMAP_ERROR_SASL,
3571   MAILIMAP_ERROR_SSL,
3572   MAILIMAP_ERROR_NEEDS_MORE_DATA,
3573   MAILIMAP_ERROR_CUSTOM_COMMAND,
3574   MAILIMAP_ERROR_CLIENTID,
3575 };
3576 
3577 /* information about parser context */
3578 
3579 struct mailimap_parser_context {
3580   int is_rambler_workaround_enabled;
3581   int is_qip_workaround_enabled;
3582 
3583   mailimap_msg_body_handler * msg_body_handler;
3584   void * msg_body_handler_context;
3585   struct mailimap_msg_att_body_section * msg_body_section;
3586   int msg_body_att_type;
3587   bool msg_body_parse_in_progress;
3588 };
3589 
3590 LIBETPAN_EXPORT
3591 struct mailimap_parser_context *
3592 mailimap_parser_context_new(mailimap * session);
3593 
3594 LIBETPAN_EXPORT
3595 void
3596 mailimap_parser_context_free(struct mailimap_parser_context * ctx);
3597 
3598 LIBETPAN_EXPORT
3599 int
3600 mailimap_parser_context_is_rambler_workaround_enabled(struct mailimap_parser_context * parser_ctx);
3601 
3602 LIBETPAN_EXPORT
3603 int
3604 mailimap_parser_context_is_qip_workaround_enabled(struct mailimap_parser_context * parser_ctx);
3605 
3606 #ifdef __cplusplus
3607 }
3608 #endif
3609 
3610 #endif
3611 
3612