imap-msgpart.h revision 306b3f41b05da642d87e7ca7a1496efce9f5902f
5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294Timo Sirainen#ifndef IMAP_MSGPART_H
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen#define IMAP_MSGPART_H
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenstruct imap_msgpart;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
31d32d39dd09be0625a6d92ee715155f5d679515Timo Sirainenstruct imap_msgpart_open_result {
9bbfe7f5ff821cac11d1d2550a91b148f389d82cTimo Sirainen /* message contents with CRLF linefeeds */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct istream *input;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* size of input */
31d32d39dd09be0625a6d92ee715155f5d679515Timo Sirainen uoff_t size;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* if size was looked up using cache and it ends up being wrong,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen this field can be used to log about cache corruption */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen enum mail_fetch_field size_field;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen /* TRUE if BINARY decoded content contains NUL characters */
55d33f807765482eb47374aaaced1fe714e0b256Timo Sirainen bool binary_decoded_input_has_nuls;
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen};
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
ec0cc8fa647794e44a1afaa448f495a713048dc4Timo Sirainenstruct imap_msgpart *imap_msgpart_full(void);
ec0cc8fa647794e44a1afaa448f495a713048dc4Timo Sirainenstruct imap_msgpart *imap_msgpart_header(void);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenstruct imap_msgpart *imap_msgpart_body(void);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen/* Parse section into imap_msgpart. Returns 0 and msgpart_r on success,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen -1 if the section isn't valid. The same imap_msgpart can be used to open
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen multiple messages. */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenint imap_msgpart_parse(struct mailbox *box, const char *section,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen struct imap_msgpart **msgpart_r);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenvoid imap_msgpart_free(struct imap_msgpart **msgpart);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen/* Decode MIME parts with Content-Transfer-Encoding: base64/quoted-printable
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen to binary data (IMAP BINARY extension). If something can't be decoded, fails
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen with storage error set to MAIL_ERROR_CONVERSION. */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenvoid imap_msgpart_set_decode_to_binary(struct imap_msgpart *msgpart);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen/* Set the fetch to be partial. For unlimited size use (uoff_t)-1. */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenvoid imap_msgpart_set_partial(struct imap_msgpart *msgpart,
d9b9687bf8cae9cfb070b1b7aadefa683220269fTimo Sirainen uoff_t offset, uoff_t size);
d9b9687bf8cae9cfb070b1b7aadefa683220269fTimo Sirainenuoff_t imap_msgpart_get_partial_offset(struct imap_msgpart *msgpart);
d9b9687bf8cae9cfb070b1b7aadefa683220269fTimo Sirainen/* Return wanted_fields mask. */
d9b9687bf8cae9cfb070b1b7aadefa683220269fTimo Sirainenenum mail_fetch_field imap_msgpart_get_fetch_data(struct imap_msgpart *msgpart);
d9b9687bf8cae9cfb070b1b7aadefa683220269fTimo Sirainen
d9b9687bf8cae9cfb070b1b7aadefa683220269fTimo Sirainen/* Open message part refenced by IMAP section as istream. Returns 0 if
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen successful, -1 if storage error. Returned istream is initially referenced,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen so i_stream_unref() must be called for it. */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenint imap_msgpart_open(struct mail *mail, struct imap_msgpart *msgpart,
0c47c2096714b50880d48d00ce0bf28349eb4aceTimo Sirainen struct imap_msgpart_open_result *result_r);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen/* Return msgpart's size without actually opening the stream (if possible). */
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainenint imap_msgpart_size(struct mail *mail, struct imap_msgpart *msgpart,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen size_t *size_r);
9eef11df882f9c14d164f42cb438f32fe724041cTimo Sirainen
9eef11df882f9c14d164f42cb438f32fe724041cTimo Sirainen#endif
9eef11df882f9c14d164f42cb438f32fe724041cTimo Sirainen