dbox-mail.c revision baa93d5ed7c015309dc51aa238f8d0c79561121f
b9f30617c2c96d54acbc4f85ed17b939c4f28916Timo Sirainen/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainendbox_mail_alloc(struct mailbox_transaction_context *t,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen struct mailbox_header_lookup_ctx *wanted_headers)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen index_mail_init(&mail->imail, t, wanted_fields, wanted_headers);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* close the dbox file only after index is closed, since it may still
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen try to read from it. */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenint dbox_mail_metadata_read(struct dbox_mail *mail, struct dbox_file **file_r)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen (struct dbox_storage *)mail->imail.mail.mail.box->storage;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen if (storage->v.mail_open(mail, &offset, file_r) < 0)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen /* we just messed up mail's input stream by reading metadata */
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainendbox_mail_metadata_get(struct dbox_mail *mail, enum dbox_metadata_key key,
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen const char **value_r)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenint dbox_mail_get_physical_size(struct mail *_mail, uoff_t *size_r)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen struct index_mail_data *data = &mail->imail.data;
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen if (index_mail_get_physical_size(_mail, size_r) == 0)
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainen data->physical_size = dbox_file_get_plaintext_size(file);
9f0f2de10e4ea0c99052bf4b2bef8179f2536228Timo Sirainenint dbox_mail_get_virtual_size(struct mail *_mail, uoff_t *size_r)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct index_mail_data *data = &mail->imail.data;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (index_mail_get_cached_virtual_size(&mail->imail, size_r))
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (dbox_mail_metadata_get(mail, DBOX_METADATA_VIRTUAL_SIZE,
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainen return index_mail_get_virtual_size(_mail, size_r);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (str_to_uintmax_hex(value, &size) < 0 || size > (uoff_t)-1)
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainenint dbox_mail_get_received_date(struct mail *_mail, time_t *date_r)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct index_mail_data *data = &mail->imail.data;
7744586e3e0fd60158abfbb03a233d3bd8d6c48bTimo Sirainen if (index_mail_get_received_date(_mail, date_r) == 0)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (dbox_mail_metadata_get(mail, DBOX_METADATA_RECEIVED_TIME,
1cfdcb36985904eff281fc6d7ea2d13b3c375980Timo Sirainen if (value != NULL && str_to_uintmax_hex(value, &time) < 0)
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainenint dbox_mail_get_save_date(struct mail *_mail, time_t *date_r)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct index_mail_data *data = &mail->imail.data;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (index_mail_get_save_date(_mail, date_r) == 0)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (storage->v.mail_open(mail, &offset, &file) < 0)
50e20db49f29917fe9adcf1b56b11badf28bd0e4Timo Sirainen _mail->transaction->stats.fstat_lookup_count++;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainendbox_get_cached_metadata(struct dbox_mail *mail, enum dbox_metadata_key key,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const char **value_r)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (mail_cache_lookup_field(imail->mail.mail.transaction->cache_view,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* order=0 means it doesn't exist. we don't
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen want to return "0" though, because then the
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen mails get ordered to beginning, while
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen nonexistent are supposed to be ordered at
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if (dbox_mail_metadata_get(mail, key, &value) < 0)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen index_mail_cache_add_idx(imail, ibox->cache_fields[cache_field].idx,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* don't return pointer to dbox metadata directly, since it may
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen change unexpectedly */
383d0e8c24451468d6bea17e4b55d74de744abe6Timo Sirainenint dbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
2024157e8de36edd31f5fd72f5ea7364a0955fa7Timo Sirainen const char **value_r)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen struct dbox_mail *mail = (struct dbox_mail *)_mail;
9575316ab47b32f14c5f8527bbb9673b2827dee0Timo Sirainen /* keep the UIDL in cache file, otherwise POP3 would open all
2024157e8de36edd31f5fd72f5ea7364a0955fa7Timo Sirainen mail files and read the metadata. same for GUIDs if they're
15f526e5ac611b4532568d131fcd0abf664abe41Timo Sirainen return dbox_get_cached_metadata(mail, DBOX_METADATA_POP3_UIDL,
15f526e5ac611b4532568d131fcd0abf664abe41Timo Sirainen return dbox_get_cached_metadata(mail, DBOX_METADATA_POP3_ORDER,
d477acb83e14a776ece4ca94dcd1869e75d0c6eeTimo Sirainen return dbox_get_cached_metadata(mail, DBOX_METADATA_GUID,
2024157e8de36edd31f5fd72f5ea7364a0955fa7Timo Sirainen return index_mail_get_special(_mail, field, value_r);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenget_mail_stream(struct dbox_mail *mail, uoff_t offset,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen struct mail_private *pmail = &mail->imail.mail;
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen if ((ret = dbox_file_seek(file, offset)) <= 0) {
return ret;
int ret;
if (ret <= 0) {
if (ret < 0)
stream_r);