index-mail.h revision a58e4aec412a30352d9d45e63726cac044aa6aa5
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen#ifndef __INDEX_MAIL_H
e8a59a1671127f87e2d22f42e84c572f28299d81Timo 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 */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_INDEX_FLAGS = 0,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_SENT_DATE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_RECEIVED_DATE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_VIRTUAL_FULL_SIZE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* variable sized field */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_BODY,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_BODYSTRUCTURE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_ENVELOPE,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_MESSAGEPART,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_UID_STRING,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_CACHE_FIELD_COUNT
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenextern struct mail_cache_field cache_fields[MAIL_CACHE_FIELD_COUNT];
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo 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. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_INDEX_FLAG_BINARY_HEADER = 0x0001,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_INDEX_FLAG_BINARY_BODY = 0x0002,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* Mail header or body is known to contain NUL characters. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_INDEX_FLAG_HAS_NULS = 0x0004,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* Mail header or body is known to not contain NUL characters. */
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen MAIL_INDEX_FLAG_HAS_NO_NULS = 0x0008
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstruct mail_sent_date {
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen time_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 unsigned int cache:1;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen};
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainenstruct message_header_line;
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenstruct index_mail_data {
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct mail_full_flags flags;
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen time_t date, received_date;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen uoff_t 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;
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainen const char *envelope, *body, *bodystructure, *uid_string;
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen struct message_part_envelope_data *envelope_data;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen uint32_t seq;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_index_record *rec;
6389aeec8c26b585e583c364b48ad12adf741898Timo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct istream *stream, *filter_stream;
96541d31299bb40b5a6efdbf9b4cb3d4f4b4a069Timo Sirainen struct message_size hdr_size, body_size;
96541d31299bb40b5a6efdbf9b4cb3d4f4b4a069Timo Sirainen struct message_parser_ctx *parser_ctx;
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainen int parsing_count;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen unsigned int parse_header:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen unsigned int save_envelope:1;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen unsigned int save_sent_date:1;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen unsigned int save_bodystructure_header:1;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen unsigned int save_bodystructure_body:1;
a58e4aec412a30352d9d45e63726cac044aa6aa5Timo Sirainen unsigned int parsed_bodystructure:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen unsigned int hdr_size_set:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen unsigned int body_size_set:1;
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen unsigned int open_mail:1;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen unsigned int deleted:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen};
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenstruct index_mail {
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct mail mail;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct index_mail_data data;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen pool_t pool;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct index_mailbox *ibox;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct index_transaction_context *trans;
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainen uint32_t uid_validity;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen enum mail_fetch_field wanted_fields;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct index_header_lookup_ctx *wanted_headers;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen /* per-mail variables, here for performance reasons: */
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainen uint32_t header_seq;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen string_t *header_data;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen buffer_t *header_lines;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen buffer_t *header_match;
98dd8e6e81f11f1e6040ca72f4916242d246c863Timo Sirainen buffer_t *header_offsets;
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen uint8_t header_match_value;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen};
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid index_mail_init(struct index_transaction_context *t,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct index_mail *mail,
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen enum mail_fetch_field wanted_fields,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct mailbox_header_lookup_ctx *wanted_headers);
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenint index_mail_next(struct index_mail *mail, uint32_t seq);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenvoid index_mail_deinit(struct index_mail *mail);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainenvoid index_mail_parse_header_init(struct index_mail *mail,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct mailbox_header_lookup_ctx *headers);
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainenint index_mail_parse_header(struct message_part *part,
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainen struct message_header_line *hdr,
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainen struct index_mail *mail);
2aecf7be5834e7f6520f8deaad683a6fa1de4d61Timo Sirainenint index_mail_parse_headers(struct index_mail *mail,
2aecf7be5834e7f6520f8deaad683a6fa1de4d61Timo Sirainen struct mailbox_header_lookup_ctx *headers);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenvoid index_mail_headers_get_envelope(struct index_mail *mail);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenconst char *index_mail_get_header(struct mail *_mail, const char *field);
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenstruct istream *
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainenindex_mail_get_headers(struct mail *_mail,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen struct mailbox_header_lookup_ctx *headers);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst struct mail_full_flags *index_mail_get_flags(struct mail *_mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst struct message_part *index_mail_get_parts(struct mail *_mail);
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainentime_t index_mail_get_received_date(struct mail *_mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentime_t index_mail_get_date(struct mail *_mail, int *timezone);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenuoff_t index_mail_get_size(struct mail *_mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstruct istream *index_mail_init_stream(struct index_mail *mail,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct message_size *hdr_size,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct message_size *body_size);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenconst char *index_mail_get_special(struct mail *_mail,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen enum mail_fetch_field field);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint index_mail_update_flags(struct mail *mail,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_full_flags *flags,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen enum modify_type modify_type);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint index_mail_expunge(struct mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
1171f0abf442638bac1827bb24a0b6b8eb682a82Timo Sirainenconst char *index_mail_get_cached_string(struct index_mail *mail,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen enum index_cache_field field);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenuoff_t index_mail_get_cached_uoff_t(struct index_mail *mail,
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen enum index_cache_field field);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenuoff_t index_mail_get_cached_virtual_size(struct index_mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainentime_t index_mail_get_cached_received_date(struct index_mail *mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen#endif