c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef INDEX_MAIL_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define INDEX_MAIL_H
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainen#include "message-size.h"
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen#include "mail-cache.h"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#include "mail-storage-private.h"
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenenum index_cache_field {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* fixed size fields */
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainen MAIL_CACHE_FLAGS = 0,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_SENT_DATE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_RECEIVED_DATE,
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen MAIL_CACHE_SAVE_DATE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_VIRTUAL_FULL_SIZE,
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen MAIL_CACHE_PHYSICAL_FULL_SIZE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* variable sized field */
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen MAIL_CACHE_IMAP_BODY,
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen MAIL_CACHE_IMAP_BODYSTRUCTURE,
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen MAIL_CACHE_IMAP_ENVELOPE,
4b95b3147352f12e5f5df7267c3021ac6cfa8debTimo Sirainen MAIL_CACHE_POP3_UIDL,
147a788fea2a88f7125b27226451271d55cf5b01Timo Sirainen MAIL_CACHE_POP3_ORDER,
b19a1420da0618a10edf67c2cfd13c8c8633057aTimo Sirainen MAIL_CACHE_GUID,
bb6a0eeab27569790d58a036f67dcd2a965fc539Timo Sirainen MAIL_CACHE_MESSAGE_PARTS,
6e8f0036cad59d1d6bcd9ef69bfe712d01656ca3Timo Sirainen MAIL_CACHE_BINARY_PARTS,
52fbebc87d7ae4fc4585863d38cb87f166a6521aTimo Sirainen MAIL_CACHE_BODY_SNIPPET,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
31be5ed1551c98cddeb2295a594f010aaf4b76bcTimo Sirainen MAIL_INDEX_CACHE_FIELD_COUNT
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
31be5ed1551c98cddeb2295a594f010aaf4b76bcTimo Sirainenextern struct mail_cache_field
31be5ed1551c98cddeb2295a594f010aaf4b76bcTimo Sirainen global_cache_fields[MAIL_INDEX_CACHE_FIELD_COUNT];
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
1b4441e3e6f9e78ebeae8218de971959cd55bf60Timo Sirainen#define IMAP_BODY_PLAIN_7BIT_ASCII \
1b4441e3e6f9e78ebeae8218de971959cd55bf60Timo Sirainen "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\""
1b4441e3e6f9e78ebeae8218de971959cd55bf60Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenenum mail_cache_record_flag {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* If binary flags are set, it's not checked whether mail is
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen missing CRs. So this flag may be set as an optimization for
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen regular non-binary mails as well if it's known that it contains
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen valid CR+LF line breaks. */
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainen MAIL_CACHE_FLAG_BINARY_HEADER = 0x0001,
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainen MAIL_CACHE_FLAG_BINARY_BODY = 0x0002,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* Mail header or body is known to contain NUL characters. */
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainen MAIL_CACHE_FLAG_HAS_NULS = 0x0004,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* Mail header or body is known to not contain NUL characters. */
884228e5496378bada39a932db67aa3d9478198fTimo Sirainen MAIL_CACHE_FLAG_HAS_NO_NULS = 0x0020,
884228e5496378bada39a932db67aa3d9478198fTimo Sirainen /* obsolete _HAS_NO_NULS flag, which was being set incorrectly */
884228e5496378bada39a932db67aa3d9478198fTimo Sirainen MAIL_CACHE_FLAG_HAS_NO_NULS_BROKEN = 0x0008,
1b4441e3e6f9e78ebeae8218de971959cd55bf60Timo Sirainen
1b4441e3e6f9e78ebeae8218de971959cd55bf60Timo Sirainen /* BODY is IMAP_BODY_PLAIN_7BIT_ASCII and rest of BODYSTRUCTURE
1b4441e3e6f9e78ebeae8218de971959cd55bf60Timo Sirainen fields are NIL */
1b4441e3e6f9e78ebeae8218de971959cd55bf60Timo Sirainen MAIL_CACHE_FLAG_TEXT_PLAIN_7BIT_ASCII = 0x0010
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainenenum index_mail_access_part {
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen READ_HDR = 0x01,
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen READ_BODY = 0x02,
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen PARSE_HDR = 0x04,
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen PARSE_BODY = 0x08
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen};
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstruct mail_sent_date {
e192a3b1ca8ae857e7d87298ea507d32977ba570Timo Sirainen uint32_t time;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen int32_t timezone;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstruct index_mail_line {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen unsigned int field_idx;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen uint32_t start_pos, end_pos;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen uint32_t line_num;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainenstruct message_header_line;
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenstruct index_mail_data {
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen time_t date, received_date, save_date;
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen uoff_t virtual_size, physical_size;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen struct mail_sent_date sent_date;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct index_mail_line parse_line;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen uint32_t parse_line_num;
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct message_part *parts;
6e8f0036cad59d1d6bcd9ef69bfe712d01656ca3Timo Sirainen struct message_binary_part *bin_parts;
46c903eac3abcc7d32780da76ee6a79c26d185b6Timo Sirainen const char *envelope, *body, *bodystructure, *guid, *filename;
52fbebc87d7ae4fc4585863d38cb87f166a6521aTimo Sirainen const char *from_envelope, *body_snippet;
b674bd911aaab7e8b1a77c106a0b5bccb603439fStephan Bosch struct message_part_envelope *envelope_data;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen uint32_t seq;
e667602217af55105d44d8d9b75f09a8a9ac2f14Timo Sirainen uint32_t cache_flags;
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen uint64_t modseq, pvt_modseq;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen enum index_mail_access_part access_part;
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen /* dont_cache_fields overrides cache_fields */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainen enum mail_fetch_field cache_fetch_fields, dont_cache_fetch_fields;
942312f81841c0e3a8b5609c7530826afa5a7f3bTimo Sirainen unsigned int dont_cache_field_idx;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen enum mail_fetch_field wanted_fields;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers;
6389aeec8c26b585e583c364b48ad12adf741898Timo Sirainen
1af0a59380337d4d9adc634da47888c150869f65Timo Sirainen buffer_t *search_results;
1af0a59380337d4d9adc634da47888c150869f65Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct istream *stream, *filter_stream;
6f6f3dc5b33b09097192124bce17b7017d6bbfcfTimo Sirainen struct tee_istream *tee_stream;
96541d31299bb40b5a6efdbf9b4cb3d4f4b4a069Timo Sirainen struct message_size hdr_size, body_size;
49be238e250e99af8c69321264a461d8f6ceef62Timo Sirainen struct istream *parser_input;
96541d31299bb40b5a6efdbf9b4cb3d4f4b4a069Timo Sirainen struct message_parser_ctx *parser_ctx;
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainen int parsing_count;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen ARRAY_TYPE(keywords) keywords;
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainen ARRAY_TYPE(keyword_indexes) keyword_indexes;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool initialized:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool save_sent_date:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool sent_date_parsed:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool save_envelope:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool save_bodystructure_header:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool save_bodystructure_body:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool save_message_parts:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool save_body_snippet:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool stream_has_only_header:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool parsed_bodystructure:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool hdr_size_set:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool body_size_set:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool messageparts_saved_to_cache:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool header_parsed:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool no_caching:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool forced_no_caching:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool destroying_stream:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool initialized_wrapper_stream:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool destroy_callback_set:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool prefetch_sent:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool header_parser_initialized:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen};
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenstruct index_mail {
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mail_private mail;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct index_mail_data data;
d22301419109ed4a38351715e6760011421dadecTimo Sirainen struct index_mailbox_context *ibox;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen int pop3_state;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* per-mail variables, here for performance reasons: */
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainen uint32_t header_seq;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen string_t *header_data;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct index_mail_line) header_lines;
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen#define HEADER_MATCH_FLAG_FOUND 1
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen#define HEADER_MATCH_SKIP_COUNT 2
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen#define HEADER_MATCH_USABLE(mail, num) \
86ad841251a38aa9ffcf4db4ee2c9fd449121bcbTimo Sirainen ((num & ~1) == (mail)->header_match_value)
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(uint8_t) header_match;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(unsigned int) header_match_lines;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen uint8_t header_match_value;
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool pop3_state_set:1;
eef4ba0cc3e78f8c26804c1c9251a76580a41f0cTimo Sirainen /* mail created by mailbox_search_*() */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool search_mail:1;
4906414a3e02e7750b0e702ec992afba20a0338aTimo Sirainen /* close() is being called from mail_free() */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool freeing:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen};
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
87490012895b4f371635ded00add04c9107dcfefJosef 'Jeff' Sipek#define INDEX_MAIL(s) container_of(s, struct index_mail, mail.mail)
87490012895b4f371635ded00add04c9107dcfefJosef 'Jeff' Sipek
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstruct mail *
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenindex_mail_alloc(struct mailbox_transaction_context *t,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen enum mail_fetch_field wanted_fields,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
4bab017ff69d6877253dde54b5a5f1f3f5e92fdfTimo Sirainenvoid index_mail_init(struct index_mail *mail,
4bab017ff69d6877253dde54b5a5f1f3f5e92fdfTimo Sirainen struct mailbox_transaction_context *_t,
4bab017ff69d6877253dde54b5a5f1f3f5e92fdfTimo Sirainen enum mail_fetch_field wanted_fields,
4bab017ff69d6877253dde54b5a5f1f3f5e92fdfTimo Sirainen struct mailbox_header_lookup_ctx *_wanted_headers);
4bab017ff69d6877253dde54b5a5f1f3f5e92fdfTimo Sirainen
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainenvoid index_mail_set_seq(struct mail *mail, uint32_t seq, bool saving);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenbool index_mail_set_uid(struct mail *mail, uint32_t uid);
aa247243412a49f9bdebf7255e131dc6ece4ed46Timo Sirainenvoid index_mail_set_uid_cache_updates(struct mail *mail, bool set);
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainenbool index_mail_prefetch(struct mail *mail);
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainenvoid index_mail_add_temp_wanted_fields(struct mail *mail,
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen enum mail_fetch_field fields,
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen struct mailbox_header_lookup_ctx *headers);
823af4a2cc4e2ce90d12f9ec362160546aa4c4b8Timo Sirainenvoid index_mail_update_access_parts_pre(struct mail *mail);
823af4a2cc4e2ce90d12f9ec362160546aa4c4b8Timo Sirainenvoid index_mail_update_access_parts_post(struct mail *_mail);
0d86aa0d47f7393c669c084b34c0537b193688adTimo Sirainenvoid index_mail_close(struct mail *mail);
15979d11259a2391c943bb47af4d174df52d9eb9Timo Sirainenvoid index_mail_close_streams(struct index_mail *mail);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenvoid index_mail_free(struct mail *mail);
489301ee88b2174e3171875e979e667de2c4a174Timo Sirainenvoid index_mail_set_message_parts_corrupted(struct mail *mail, const char *error);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
77af0bd168cf3e3ddc3ae68abc82bfad7e9b5ff4Timo Sirainenbool index_mail_want_parse_headers(struct index_mail *mail);
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainenvoid index_mail_parse_header_init(struct index_mail *mail,
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen struct mailbox_header_lookup_ctx *headers)
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen ATTR_NULL(2);
d2b94d25f842cd1b7acaf4dd7de858f7c6a821c9Timo Sirainenvoid index_mail_parse_header(struct message_part *part,
d2b94d25f842cd1b7acaf4dd7de858f7c6a821c9Timo Sirainen struct message_header_line *hdr,
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen struct index_mail *mail) ATTR_NULL(1);
2aecf7be5834e7f6520f8deaad683a6fa1de4d61Timo Sirainenint index_mail_parse_headers(struct index_mail *mail,
02b78558dc03daa2e7da2010b63f247b49936a38Timo Sirainen struct mailbox_header_lookup_ctx *headers,
02b78558dc03daa2e7da2010b63f247b49936a38Timo Sirainen const char *reason)
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen ATTR_NULL(2);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_headers_get_envelope(struct index_mail *mail);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_first_header(struct mail *_mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen bool decode_to_utf8, const char **value_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_headers(struct mail *_mail, const char *field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen bool decode_to_utf8, const char *const **value_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_header_stream(struct mail *_mail,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct mailbox_header_lookup_ctx *headers,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct istream **stream_r);
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainenvoid index_mail_set_read_buffer_size(struct mail *mail, struct istream *input);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenenum mail_flags index_mail_get_flags(struct mail *_mail);
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainenuint64_t index_mail_get_modseq(struct mail *_mail);
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainenuint64_t index_mail_get_pvt_modseq(struct mail *_mail);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenconst char *const *index_mail_get_keywords(struct mail *_mail);
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainenconst ARRAY_TYPE(keyword_indexes) *
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainenindex_mail_get_keyword_indexes(struct mail *_mail);
c0225f7f6b43d34dc58c17d3304f0fd60ab89894Timo Sirainenint index_mail_get_parts(struct mail *_mail, struct message_part **parts_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_received_date(struct mail *_mail, time_t *date_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_save_date(struct mail *_mail, time_t *date_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_date(struct mail *_mail, time_t *date_r, int *timezone_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_virtual_size(struct mail *mail, uoff_t *size_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_physical_size(struct mail *mail, uoff_t *size_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_init_stream(struct index_mail *mail,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct message_size *hdr_size,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct message_size *body_size,
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen struct istream **stream_r) ATTR_NULL(2, 3);
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainenint index_mail_get_binary_stream(struct mail *_mail,
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen const struct message_part *part,
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen bool include_hdr, uoff_t *size_r,
e53ab6c7081246c865917f9aa0eff031a08ad1e7Timo Sirainen unsigned int *body_lines_r, bool *binary_r,
e53ab6c7081246c865917f9aa0eff031a08ad1e7Timo Sirainen struct istream **stream_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenint index_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen const char **value_r);
21aaa6affb9f134112b75b5db737309fc35ef1cfMartti Rannanjärviint index_mail_get_backend_mail(struct mail *mail, struct mail **real_mail_r);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenvoid index_mail_update_flags(struct mail *mail, enum modify_type modify_type,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen enum mail_flags flags);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenvoid index_mail_update_keywords(struct mail *mail, enum modify_type modify_type,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen struct mail_keywords *keywords);
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainenvoid index_mail_update_modseq(struct mail *mail, uint64_t min_modseq);
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainenvoid index_mail_update_pvt_modseq(struct mail *mail, uint64_t min_pvt_modseq);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenvoid index_mail_expunge(struct mail *mail);
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainenvoid index_mail_precache(struct mail *mail);
838e367716bbd5e44b4a1691db9cbf72af53e9f0Timo Sirainenvoid index_mail_set_cache_corrupted(struct mail *mail,
0206dc57f2c04da69599dea5816235cfeb2b897aMartti Rannanjärvi enum mail_fetch_field field,
0206dc57f2c04da69599dea5816235cfeb2b897aMartti Rannanjärvi const char *reason);
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainenint index_mail_opened(struct mail *mail, struct istream **stream);
50de46721446795c42943c572625f2f1a9abfe01Timo Sirainenint index_mail_stream_check_failure(struct index_mail *mail);
d052dcfff0c96a0af17a3158e51f709edf4b93a1Timo Sirainenvoid index_mail_stream_log_failure_for(struct index_mail *mail,
d052dcfff0c96a0af17a3158e51f709edf4b93a1Timo Sirainen struct istream *input);
bc15c6934f69be09cca1e9f87f9dc344f77e8b7cTimo Sirainenvoid index_mail_refresh_expunged(struct mail *mail);
01404d41657a104c5ea1c12bb87f9c321e9c1ac4Timo Sirainenstruct index_mail *index_mail_get_index_mail(struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenbool index_mail_get_cached_uoff_t(struct index_mail *mail,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen enum index_cache_field field, uoff_t *size_r);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenbool index_mail_get_cached_virtual_size(struct index_mail *mail,
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen uoff_t *size_r);
b2723d68898e4a6a6e6ba2a06926dcaa1911daf5Timo Sirainenbool index_mail_get_cached_body(struct index_mail *mail, const char **value_r);
b2723d68898e4a6a6e6ba2a06926dcaa1911daf5Timo Sirainenbool index_mail_get_cached_bodystructure(struct index_mail *mail,
b2723d68898e4a6a6e6ba2a06926dcaa1911daf5Timo Sirainen const char **value_r);
424633d1a1e22139a5ab9345f807a89d0792ead3Timo Sirainenconst uint32_t *index_mail_get_vsize_extension(struct mail *_mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
2c4349f25ae850ffff0543bdbbbd7806b9af3c80Timo Sirainenbool index_mail_want_cache(struct index_mail *mail, enum index_cache_field field);
5cda0bfea032000c4a51134c748d9efe6614870bTimo Sirainenvoid index_mail_cache_add(struct index_mail *mail, enum index_cache_field field,
97511ac4d7607e1ba64ce151eda3d9b5f9775519Timo Sirainen const void *data, size_t data_size);
5cda0bfea032000c4a51134c748d9efe6614870bTimo Sirainenvoid index_mail_cache_add_idx(struct index_mail *mail, unsigned int field_idx,
5cda0bfea032000c4a51134c748d9efe6614870bTimo Sirainen const void *data, size_t data_size);
97511ac4d7607e1ba64ce151eda3d9b5f9775519Timo Sirainen
e54512a5189192fe72d1e2c53927c98c5ac920b4Timo Sirainenstruct istream *index_mail_cache_parse_init(struct mail *mail,
e54512a5189192fe72d1e2c53927c98c5ac920b4Timo Sirainen struct istream *input);
2ebeb22b9a8a8bb7fbe2f2e2908478a220792b87Timo Sirainenvoid index_mail_cache_parse_continue(struct mail *mail);
2d1663351e67fd778ed34df09b8ad5fe29da23d9Timo Sirainenvoid index_mail_cache_parse_deinit(struct mail *mail, time_t received_date,
2d1663351e67fd778ed34df09b8ad5fe29da23d9Timo Sirainen bool success);
2ebeb22b9a8a8bb7fbe2f2e2908478a220792b87Timo Sirainen
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainenint index_mail_cache_lookup_field(struct index_mail *mail, buffer_t *buf,
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen unsigned int field_idx);
e8dc3747de75e2bf208f0f2dbdbae4a279b5ee6fTimo Sirainenvoid index_mail_save_finish(struct mail_save_context *ctx);
b0a901f1dbe9e05ac1c92a0974af6bce0274f31aTimo Sirainen
02b78558dc03daa2e7da2010b63f247b49936a38Timo Sirainenconst char *index_mail_cache_reason(struct mail *mail, const char *reason);
02b78558dc03daa2e7da2010b63f247b49936a38Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen#endif