index-mail.h revision 33d63688ed8b26dc333e3c2edbfb2fe6e412604d
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
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 enum mail_cache_field cached_fields;
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen struct mail_sent_date sent_date;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen buffer_t *headers;
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen string_t *header_data;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen int header_data_cached, header_data_cached_contiguous;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen size_t header_data_uncached_offset;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen struct istream *header_stream;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen int header_save_idx;
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
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct istream *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;
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen unsigned int bodystructure_header_want:1;
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen unsigned int bodystructure_header_parse:1;
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen unsigned int bodystructure_header_parsed:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen unsigned int save_envelope:1;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen unsigned int save_sent_date:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen unsigned int hdr_size_set:1;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen unsigned int body_size_set:1;
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen unsigned int deleted:1;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen unsigned int header_data_cached_partial:1;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen unsigned int header_fully_parsed:1;
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen unsigned int header_save: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;
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainen unsigned int expunge_counter;
5bc4a5fd9a421f4c5763e03c0449479cedcf9f06Timo Sirainen buffer_t *header_buf;
33d63688ed8b26dc333e3c2edbfb2fe6e412604dTimo Sirainen uint32_t uid_validity;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen enum mail_fetch_field wanted_fields;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen const char *const *wanted_headers;
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen int wanted_headers_idx;
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,
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen const char *const wanted_headers[]);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenint index_mail_next(struct index_mail *mail,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const struct mail_index_record *rec,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen uint32_t seq, int delay_open);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenvoid index_mail_deinit(struct index_mail *mail);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainenvoid index_mail_parse_header_init(struct index_mail *mail,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen const char *const headers[]);
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainenint index_mail_parse_header(struct message_part *part,
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainen struct message_header_line *hdr,
644268f7848a7c4221146d0b11feb8ed5bbed233Timo Sirainen struct index_mail *mail);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenint index_mail_cache_transaction_begin(struct index_mail *mail);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenvoid index_mail_cache_add(struct index_mail *mail, enum mail_cache_field field,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen const void *data, size_t size);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
96541d31299bb40b5a6efdbf9b4cb3d4f4b4a069Timo Sirainenint index_mail_parse_headers(struct index_mail *mail);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenvoid index_mail_headers_init(struct index_mail *mail);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenvoid index_mail_headers_init_next(struct index_mail *mail);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenvoid index_mail_headers_close(struct index_mail *mail);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenconst char *index_mail_get_header(struct mail *_mail, const char *field);
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenstruct istream *index_mail_get_headers(struct mail *_mail,
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainen const char *const minimum_fields[]);
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
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenchar *index_mail_get_cached_string(struct index_mail *mail,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen enum mail_cache_field field);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenuoff_t index_mail_get_cached_uoff_t(struct index_mail *mail,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen enum mail_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