index-mail.h revision 645f258ea29afaf09b673fc65d1bd788dfec8db8
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"
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;
b7f14c9568e7edc75d1d7fd86751c02bc97cde3eTimo Sirainen const char *envelope, *body, *bodystructure;
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainen struct message_part_envelope_data *envelope_data;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct mail_index_record *rec;
6389aeec8c26b585e583c364b48ad12adf741898Timo Sirainen unsigned int idx_seq;
6389aeec8c26b585e583c364b48ad12adf741898Timo Sirainen
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct istream *stream;
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen struct message_size hdr_size, body_size;
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;
dbb1fb1c51727e2050792f8c333b212e22a36d69Timo Sirainen unsigned int expunge_counter;
5bc4a5fd9a421f4c5763e03c0449479cedcf9f06Timo Sirainen buffer_t *header_buf;
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
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenvoid index_mail_init(struct index_mailbox *ibox, struct index_mail *mail,
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen enum mail_fetch_field wanted_fields,
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen const char *const wanted_headers[]);
6389aeec8c26b585e583c364b48ad12adf741898Timo Sirainenint index_mail_next(struct index_mail *mail, struct mail_index_record *rec,
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen unsigned int idx_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[]);
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainenvoid index_mail_parse_header(struct message_part *part,
5bc4a5fd9a421f4c5763e03c0449479cedcf9f06Timo Sirainen struct message_header_line *hdr, void *context);
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
1bdda5c0c30463160c47151537e6bb2c6c994841Timo Sirainenint index_mail_open_stream(struct index_mail *mail, uoff_t position);
645f258ea29afaf09b673fc65d1bd788dfec8db8Timo Sirainenint index_mail_parse_headers(struct index_mail *mail, int get_parts);
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
e8a59a1671127f87e2d22f42e84c572f28299d81Timo Sirainen#endif