package imap

  1. Overview
  2. Docs

IMAP queries and response data

Message flags

type flag =
  1. | FLAG_ANSWERED
    (*

    \Answered flag

    *)
  2. | FLAG_FLAGGED
    (*

    \Flagged flag

    *)
  3. | FLAG_DELETED
    (*

    \Deleted flag

    *)
  4. | FLAG_SEEN
    (*

    \Seen flag

    *)
  5. | FLAG_DRAFT
    (*

    \Draft flag

    *)
  6. | FLAG_KEYWORD of string
    (*

    keyword flag

    *)
  7. | FLAG_EXTENSION of string
    (*

    \extension flag

    *)
type flag_fetch =
  1. | FLAG_FETCH_RECENT
  2. | FLAG_FETCH_OTHER of flag
type flag_perm =
  1. | FLAG_PERM_FLAG of flag
  2. | FLAG_PERM_ALL

Flags returned with a PERMANENTFLAG response code

SEARCH command

type day_month_year = int * int * int
type search_key_modseq_entry_type =
  1. | SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_PRIV
  2. | SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_SHARED
  3. | SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_ALL
type search_key =
  1. | SEARCH_KEY_ALL
    (*

    All messages in the mailbox.

    *)
  2. | SEARCH_KEY_ANSWERED
    (*

    Messages with the \Answered flag set.

    *)
  3. | SEARCH_KEY_BCC of string
    (*

    Messages that contain the specified string in the envelope's BCC field.

    *)
  4. | SEARCH_KEY_BEFORE of day_month_year
    (*

    Messages whose internal date (disregarding time and timezone) is earlier than the specified date.

    *)
  5. | SEARCH_KEY_BODY of string
    (*

    Messages that contain the specified string in the body of the message.

    *)
  6. | SEARCH_KEY_CC of string
    (*

    Messages that contain the specified string in the envelope's CC field.

    *)
  7. | SEARCH_KEY_DELETED
    (*

    Messages with the \Deleted flag set.

    *)
  8. | SEARCH_KEY_FLAGGED
    (*

    Messages with the \Flagged flag set.

    *)
  9. | SEARCH_KEY_FROM of string
    (*

    Messages that contain the specified string in the envelope's FROM field.

    *)
  10. | SEARCH_KEY_KEYWORD of string
    (*

    Messages with the specified keyword flag set.

    *)
  11. | SEARCH_KEY_NEW
    (*

    Messages that have the \Recent flag set but not the \Seen flag. This is functionally equivalent to `AND (`RECENT, `UNSEEN).

    *)
  12. | SEARCH_KEY_OLD
    (*

    Messages that do not have the \Recent flag set. This is functionally equivalent to `NOT `RECENT (as opposed to `NOT `NEW).

    *)
  13. | SEARCH_KEY_ON of day_month_year
    (*

    Messages whose internal date (disregarding time and timezone) is within the specified date.

    *)
  14. | SEARCH_KEY_RECENT
    (*

    Messages that have the \Recent flag set.

    *)
  15. | SEARCH_KEY_SEEN
    (*

    Messages that have the \Seen flag set.

    *)
  16. | SEARCH_KEY_SINCE of day_month_year
    (*

    Messages whose internal date (disregarding time and timezone) is within or later than the specified date.

    *)
  17. | SEARCH_KEY_SUBJECT of string
    (*

    Messages that contain the specified string in the envelope's SUBJECT field.

    *)
  18. | SEARCH_KEY_TEXT of string
    (*

    Messages that contain the specified string in the header or body of the message.

    *)
  19. | SEARCH_KEY_TO of string
    (*

    Messages that contain the specified string in the envelope's TO field.

    *)
  20. | SEARCH_KEY_UNANSWERED
    (*

    Messages that do not have the \Answered flag set.

    *)
  21. | SEARCH_KEY_UNDELETED
    (*

    Messages that do not have the \Deleted flag set.

    *)
  22. | SEARCH_KEY_UNFLAGGED
    (*

    Messages that do not have the \Flagged flag set.

    *)
  23. | SEARCH_KEY_UNKEYWORD of string
    (*

    Messages that do not have the specified keyword flag set.

    *)
  24. | SEARCH_KEY_UNSEEN
    (*

    Messages that do not have the \Seen flag set.

    *)
  25. | SEARCH_KEY_DRAFT
    (*

    Messages with the \Draft flag set.

    *)
  26. | SEARCH_KEY_HEADER of string * string
    (*

    Messages that have a header with the specified field-name (as defined in RFC-2822) and that contains the specified string in the text of the header (what comes after the colon).

    *)
  27. | SEARCH_KEY_LARGER of int
    (*

    Messages with an RFC-2822 size larger than the specified number of bytes.

    *)
  28. | SEARCH_KEY_NOT of search_key
    (*

    Messages that do not match the specified search key.

    *)
  29. | SEARCH_KEY_OR of search_key * search_key
    (*

    Messages that match either search key.

    *)
  30. | SEARCH_KEY_SENTBEFORE of day_month_year
    (*

    Messages whose Date: header (disregarding time and timezone) is earlier than the specified date.

    *)
  31. | SEARCH_KEY_SENTON of day_month_year
    (*

    Messages whose Date: header (disregarding time and timezone) is within the specified date.

    *)
  32. | SEARCH_KEY_SENTSINCE of day_month_year
    (*

    Messages whose Date: header (disregarding time and timezone) is within or later than the specified date.

    *)
  33. | SEARCH_KEY_SMALLER of int
    (*

    Messages with an RFC-2822 size smaller than the specified number of bytes.

    *)
  34. | SEARCH_KEY_UID of ImapSet.t
    (*

    Messages with unique identifiers corresponding to the specified unique identifier set.

    *)
  35. | SEARCH_KEY_UNDRAFT
    (*

    Messages that do not have the \Draft flag set.

    *)
  36. | SEARCH_KEY_INSET of ImapSet.t
    (*

    Messages with message sequence numbers corresponding to the specified message sequence number set.

    *)
  37. | SEARCH_KEY_AND of search_key * search_key
    (*

    Messages that match both search keys.

    *)
  38. | SEARCH_KEY_MODSEQ of (flag * search_key_modseq_entry_type) option * Uint64.t
  39. | SEARCH_KEY_XGMRAW of string
    (*

    Messages that satisfy Gmail search expression.

    *)
  40. | SEARCH_KEY_XGMMSGID of Uint64.t
    (*

    Message with given Gmail Message ID.

    *)
  41. | SEARCH_KEY_XGMTHRID of Uint64.t
    (*

    Messages with given Gmail Thread ID.

    *)
  42. | SEARCH_KEY_XGMLABELS of string

Search keys

FETCH command

Queries

type section_msgtext =
  1. | SECTION_MSGTEXT_HEADER
  2. | SECTION_MSGTEXT_HEADER_FIELDS of string list
  3. | SECTION_MSGTEXT_HEADER_FIELDS_NOT of string list
  4. | SECTION_MSGTEXT_TEXT
type section_part = int list
type section_text =
  1. | SECTION_TEXT_MSGTEXT of section_msgtext
  2. | SECTION_TEXT_MIME
type section_spec =
  1. | SECTION_SPEC_SECTION_MSGTEXT of section_msgtext
  2. | SECTION_SPEC_SECTION_PART of section_part * section_text option
type section = section_spec option
type fetch_att =
  1. | FETCH_ATT_ENVELOPE
    (*

    MIME envelope information

    *)
  2. | FETCH_ATT_INTERNALDATE
    (*

    The message date kept by the server

    *)
  3. | FETCH_ATT_RFC822_HEADER
    (*

    The message header

    *)
  4. | FETCH_ATT_RFC822_TEXT
    (*

    The message text part

    *)
  5. | FETCH_ATT_RFC822_SIZE
    (*

    The size of the message content

    *)
  6. | FETCH_ATT_RFC822
    (*

    The message content (header and body)

    *)
  7. | FETCH_ATT_BODY
    (*

    The MIME description of the message

    *)
  8. | FETCH_ATT_BODY_SECTION of section * (int * int) option
    (*

    A MIME part content

    *)
  9. | FETCH_ATT_BODY_PEEK_SECTION of section * (int * int) option
    (*

    Like `BODYSECTION, but does not set the `Seen flag.

    *)
  10. | FETCH_ATT_BODYSTRUCTURE
    (*

    The MIME description of the message with additional information

    *)
  11. | FETCH_ATT_UID
    (*

    Unique identification number.

    *)
  12. | FETCH_ATT_FLAGS
    (*

    Message flags

    *)
  13. | FETCH_ATT_EXTENSION of string

FETCH queries

type fetch_type =
  1. | FETCH_TYPE_ALL
  2. | FETCH_TYPE_FULL
  3. | FETCH_TYPE_FAST
  4. | FETCH_TYPE_FETCH_ATT of fetch_att
  5. | FETCH_TYPE_FETCH_ATT_LIST of fetch_att list

MIME

type address = {
  1. ad_personal_name : string;
  2. ad_source_route : string;
  3. ad_mailbox_name : string;
  4. ad_host_name : string;
}
type envelope = {
  1. env_date : string;
  2. env_subject : string;
  3. env_from : address list;
  4. env_sender : address list;
  5. env_reply_to : address list;
  6. env_to : address list;
  7. env_cc : address list;
  8. env_bcc : address list;
  9. env_in_reply_to : string;
  10. env_message_id : string;
}
type body_fld_param = (string * string) list
type body_fld_dsp = {
  1. dsp_type : string;
  2. dsp_attributes : body_fld_param;
}
type body_fld_lang =
  1. | BODY_FLD_LANG_SINGLE of string option
  2. | BODY_FLD_LANG_LIST of string list
type media_basic_type =
  1. | MEDIA_BASIC_APPLICATION
  2. | MEDIA_BASIC_AUDIO
  3. | MEDIA_BASIC_IMAGE
  4. | MEDIA_BASIC_MESSAGE
  5. | MEDIA_BASIC_VIDEO
  6. | MEDIA_BASIC_OTHER of string
type media_basic = {
  1. med_basic_type : media_basic_type;
  2. med_basic_subtype : string;
}
type body_fld_enc =
  1. | BODY_FLD_ENC_7BIT
  2. | BODY_FLD_ENC_8BIT
  3. | BODY_FLD_ENC_BINARY
  4. | BODY_FLD_ENC_BASE64
  5. | BODY_FLD_ENC_QUOTED_PRINTABLE
  6. | BODY_FLD_ENC_OTHER of string
type body_extension =
  1. | BODY_EXTENSION_LIST of body_extension list
  2. | BODY_EXTENSION_NUMBER of Uint32.t
  3. | BODY_EXTENSION_NSTRING of string option
type body_ext_mpart = {
  1. bd_parameter : body_fld_param;
  2. bd_disposition : body_fld_dsp option;
  3. bd_language : body_fld_lang option;
  4. bd_loc : string option;
  5. bd_extension_list : body_extension list;
}
type body_ext_1part = {
  1. bd_md5 : string option;
  2. bd_disposition : body_fld_dsp option;
  3. bd_language : body_fld_lang option;
  4. bd_loc : string option;
  5. bd_extension_list : body_extension list;
}
type body_fields = {
  1. bd_parameter : body_fld_param;
  2. bd_id : string option;
  3. bd_description : string option;
  4. bd_encoding : body_fld_enc;
  5. bd_size : int;
}
type body_type_text = {
  1. bd_media_text : string;
  2. bd_fields : body_fields;
  3. bd_lines : int;
}
type body_type_basic = {
  1. bd_media_basic : media_basic;
  2. bd_fields : body_fields;
}
type body_type_msg = {
  1. bd_fields : body_fields;
  2. bd_envelope : envelope;
  3. bd_body : body;
}
and body_type_1part_data =
  1. | BODY_TYPE_1PART_BASIC of body_type_basic
  2. | BODY_TYPE_1PART_MSG of body_type_msg
  3. | BODY_TYPE_1PART_TEXT of body_type_text
and body_type_1part = {
  1. bd_data : body_type_1part_data;
  2. bd_ext_1part : body_ext_1part;
}
and body_type_mpart = {
  1. bd_list : body list;
  2. bd_media_subtype : string;
  3. bd_ext_mpart : body_ext_mpart;
}
and body =
  1. | BODY_1PART of body_type_1part
  2. | BODY_MPART of body_type_mpart

Responses

type date_time = {
  1. dt_day : int;
  2. dt_month : int;
  3. dt_year : int;
  4. dt_hour : int;
  5. dt_min : int;
  6. dt_sec : int;
  7. dt_zone : int;
}
type msg_att_body_section = {
  1. sec_section : section;
  2. sec_origin_octet : int option;
  3. sec_body_part : string;
}
type msg_att_static =
  1. | MSG_ATT_ENVELOPE of envelope
  2. | MSG_ATT_INTERNALDATE of date_time
  3. | MSG_ATT_RFC822 of string
  4. | MSG_ATT_RFC822_HEADER of string
  5. | MSG_ATT_RFC822_TEXT of string
  6. | MSG_ATT_RFC822_SIZE of int
  7. | MSG_ATT_BODY of body
  8. | MSG_ATT_BODYSTRUCTURE of body
  9. | MSG_ATT_BODY_SECTION of msg_att_body_section
  10. | MSG_ATT_UID of Uint32.t
type msg_att_dynamic = flag_fetch list
type msg_att_extension = ..
type msg_att_item =
  1. | MSG_ATT_ITEM_DYNAMIC of msg_att_dynamic
  2. | MSG_ATT_ITEM_STATIC of msg_att_static
  3. | MSG_ATT_ITEM_EXTENSION of msg_att_extension
type msg_att = msg_att_item list * Uint32.t

STORE command

type store_att_flags_sign =
  1. | STORE_ATT_FLAGS_SET
  2. | STORE_ATT_FLAGS_ADD
  3. | STORE_ATT_FLAGS_REMOVE
type store_att_flags = {
  1. fl_sign : store_att_flags_sign;
  2. fl_silent : bool;
  3. fl_flag_list : flag list;
}

STATUS command

type status_att =
  1. | STATUS_ATT_MESSAGES
    (*

    Number of messages in the mailbox.

    *)
  2. | STATUS_ATT_RECENT
    (*

    Number of new messages in the mailbox.

    *)
  3. | STATUS_ATT_UIDNEXT
    (*

    The probable unique identification number of the next message to arrive.

    *)
  4. | STATUS_ATT_UIDVALIDITY
    (*

    The UID validity value of the mailbox.

    *)
  5. | STATUS_ATT_UNSEEN
    (*

    The number of unseen messages in the mailbox.

    *)
  6. | STATUS_ATT_HIGHESTMODSEQ
    (*

    The highest modification sequence of the mailbox. This requires support for the CONDSTORE extension.

    *)

STATUS queries: the different mailbox status attributes that can be fetched via Imap.status.

type status_info_extension = ..
type status_info =
  1. | STATUS_ATT_MESSAGES of int
  2. | STATUS_ATT_RECENT of int
  3. | STATUS_ATT_UIDNEXT of Uint32.t
  4. | STATUS_ATT_UIDVALIDITY of Uint32.t
  5. | STATUS_ATT_UNSEEN of int
  6. | STATUS_ATT_HIGHESTMODSEQ of Uint64.t
  7. | STATUS_ATT_EXTENSION of status_info_extension

STATUS replies. See status_att.

LIST/LSUB commands

type mailbox_data_status = {
  1. st_mailbox : string;
  2. st_info_list : status_info list;
}
type mbx_list_sflag =
  1. | MBX_LIST_SFLAG_NOSELECT
  2. | MBX_LIST_SFLAG_MARKED
  3. | MBX_LIST_SFLAG_UNMARKED

The type of mailbox single flags

type mbx_list_oflag =
  1. | MBX_LIST_OFLAG_NOINFERIORS
  2. | MBX_LIST_OFLAG_EXT of string

The type of mailbox other flags

type mbx_list_flags = {
  1. mbf_sflag : mbx_list_sflag option;
    (*

    Mailbox single flag

    *)
  2. mbf_oflags : mbx_list_oflag list;
}

Mailbox flag

List of "mailbox other flag"

type mailbox_list = {
  1. mb_flag : mbx_list_flags;
    (*

    List of mailbox flags

    *)
  2. mb_delimiter : char option;
    (*

    Delimiter of the mailbox path, '\000' if not present

    *)
  3. mb_name : string;
}

List of mailbox flags

Name of the mailbox

CAPABILITY command

type capability =
  1. | CAPABILITY_AUTH_TYPE of string
  2. | CAPABILITY_NAME of string
type mailbox_perm =
  1. | MAILBOX_READONLY
  2. | MAILBOX_READWRITE
type capability_data = capability list

List of capabilities

Response codes

type resp_text_code_extension = ..
type resp_text_code =
  1. | RESP_TEXT_CODE_ALERT
  2. | RESP_TEXT_CODE_BADCHARSET of string list
  3. | RESP_TEXT_CODE_CAPABILITY_DATA of capability_data
  4. | RESP_TEXT_CODE_PARSE
  5. | RESP_TEXT_CODE_PERMANENTFLAGS of flag_perm list
  6. | RESP_TEXT_CODE_READ_ONLY
  7. | RESP_TEXT_CODE_READ_WRITE
  8. | RESP_TEXT_CODE_TRYCREATE
  9. | RESP_TEXT_CODE_UIDNEXT of Uint32.t
  10. | RESP_TEXT_CODE_UIDVALIDITY of Uint32.t
  11. | RESP_TEXT_CODE_UNSEEN of Uint32.t
  12. | RESP_TEXT_CODE_EXTENSION of resp_text_code_extension
  13. | RESP_TEXT_CODE_OTHER of string * string option
  14. | RESP_TEXT_CODE_NONE
type resp_text = {
  1. rsp_code : resp_text_code;
  2. rsp_text : string;
}

response code, human readable text

Untagged responses

type 'resp_type resp_cond = {
  1. rsp_type : 'resp_type;
  2. rsp_text : resp_text;
}
type resp_cond_auth_type =
  1. | RESP_COND_AUTH_OK
  2. | RESP_COND_AUTH_PREAUTH

Authentication condition responses

type resp_cond_auth = resp_cond_auth_type resp_cond
type resp_cond_bye = resp_text

BYE response

type response_fatal = resp_cond_bye
type resp_cond_state_type =
  1. | RESP_COND_STATE_OK
  2. | RESP_COND_STATE_NO
  3. | RESP_COND_STATE_BAD

Condition state responses

type resp_cond_state = resp_cond_state_type resp_cond
type message_data =
  1. | MESSAGE_DATA_EXPUNGE of Uint32.t
  2. | MESSAGE_DATA_FETCH of msg_att

Message information

type mailbox_data_extension = ..
type mailbox_data =
  1. | MAILBOX_DATA_FLAGS of flag list
  2. | MAILBOX_DATA_LIST of mailbox_list
  3. | MAILBOX_DATA_LSUB of mailbox_list
  4. | MAILBOX_DATA_STATUS of mailbox_data_status
  5. | MAILBOX_DATA_EXISTS of int
  6. | MAILBOX_DATA_RECENT of int
  7. | MAILBOX_DATA_EXTENSION_DATA of mailbox_data_extension

Mailbox information

type response_data_extension = ..
type response_data =
  1. | RESP_DATA_COND_STATE of resp_cond_state
  2. | RESP_DATA_COND_BYE of resp_cond_bye
  3. | RESP_DATA_MAILBOX_DATA of mailbox_data
  4. | RESP_DATA_MESSAGE_DATA of message_data
  5. | RESP_DATA_CAPABILITY_DATA of capability_data
  6. | RESP_DATA_EXTENSION_DATA of response_data_extension

Untagged response

Tagged responses

type response_tagged = {
  1. rsp_tag : string;
  2. rsp_cond_state : resp_cond_state;
}
type response_done =
  1. | RESP_DONE_TAGGED of response_tagged
  2. | RESP_DONE_FATAL of response_fatal

Ending response

type continue_req =
  1. | CONTINUE_REQ_TEXT of resp_text
  2. | CONTINUE_REQ_BASE64 of string
type cont_req_or_resp_data =
  1. | RESP_CONT_REQ of continue_req
  2. | RESP_CONT_DATA of response_data
type response = {
  1. rsp_cont_req_or_resp_data_list : cont_req_or_resp_data list;
  2. rsp_resp_done : response_done;
}

Greeting response

type greeting =
  1. | GREETING_RESP_COND_AUTH of resp_cond_auth
  2. | GREETING_RESP_COND_BYE of resp_cond_bye
type selection_info = {
  1. sel_perm_flags : flag_perm list;
  2. sel_perm : mailbox_perm;
  3. sel_uidnext : Uint32.t;
  4. sel_uidvalidity : Uint32.t;
  5. sel_first_unseen : Uint32.t;
  6. sel_flags : flag list;
  7. sel_exists : int option;
  8. sel_recent : int option;
  9. sel_unseen : int;
}
type rsp_extension_data =
  1. | EXTENSION_DATA : 'a extension_kind * 'a -> rsp_extension_data
type response_info = {
  1. rsp_alert : string;
  2. rsp_parse : string;
  3. rsp_badcharset : string list;
  4. rsp_trycreate : bool;
  5. rsp_mailbox_list : mailbox_list list;
  6. rsp_mailbox_lsub : mailbox_list list;
  7. rsp_search_results : Uint32.t list;
  8. rsp_status : mailbox_data_status;
  9. rsp_expunged : Uint32.t list;
  10. rsp_fetch_list : msg_att list;
  11. rsp_extension_list : rsp_extension_data list;
  12. rsp_other : string * string option;
}
type state = {
  1. rsp_info : response_info;
  2. sel_info : selection_info;
  3. cap_info : capability list;
  4. imap_response : string;
  5. current_tag : string option;
  6. next_tag : int;
  7. out_buf : string list;
  8. in_buf : Buffer.t;
  9. in_pos : int;
}
type error =
  1. | Bad
  2. | BadTag
  3. | No
  4. | Bye
  5. | ParseError of string * int
  6. | Auth_error
  7. | ExtensionError
type input =
  1. | End
  2. | More
type 'a parse_result =
  1. | Ok of 'a * int
  2. | Fail of int
  3. | Need of input -> 'a parse_result
OCaml

Innovation. Community. Security.