bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mdbox_mail_lookup(struct mdbox_mailbox *mbox, struct mail_index_view *view,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mdbox_mail_index_record *dbox_rec;
03010dbaa74ec70f062994dfe3cd39bedc99a28bTimo Sirainen mail_index_lookup_ext(view, seq, mbox->ext_id, &data, NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (dbox_rec == NULL || dbox_rec->map_uid == 0) {
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen if (mdbox_read_header(mbox, &hdr, &need_resize) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mbox->map_uid_validity = hdr.map_uid_validity;
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen if (mdbox_map_open_or_create(mbox->storage->map) < 0)
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen cur_map_uid_validity = mdbox_map_get_uid_validity(mbox->storage->map);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (cur_map_uid_validity != mbox->map_uid_validity) {
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi "mdbox: map uidvalidity mismatch (%u vs %u)",
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi mbox->map_uid_validity, cur_map_uid_validity);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void dbox_mail_set_expunged(struct dbox_mail *mail, uint32_t map_uid)
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(_mail->box);
767ff4367960efd5fa868f3b56f850fd4c205c8bTimo Sirainen if (mail_index_is_expunged(_mail->transaction->view, _mail->seq)) {
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen "Unexpectedly lost %s uid=%u map_uid=%u",
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic int dbox_mail_open_init(struct dbox_mail *mail, uint32_t map_uid)
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(mail->imail.mail.mail.box);
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen if ((ret = mdbox_map_lookup(mbox->storage->map, map_uid,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* map_uid doesn't exist anymore. either it
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen got just expunged or the map index is
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen corrupted. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mail->open_file = mdbox_file_init(mbox->storage, file_id);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(_mail->box);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* already open */
767ff4367960efd5fa868f3b56f850fd4c205c8bTimo Sirainen if (mdbox_mail_lookup(mbox, _mail->transaction->view,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* mail is being saved in this transaction */
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen _mail->transaction->stats.open_lookup_count++;
4ca83616715c3bd417e34ced2c1d61852513e427Timo Sirainen if (dbox_file_open(mail->open_file, &deleted) <= 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* either it's expunged now or moved to another file. */
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen if (mdbox_map_refresh(mbox->storage->map) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic int mdbox_mail_get_save_date(struct mail *mail, time_t *date_r)
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(mail->transaction->box);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mdbox_mail_index_record *dbox_rec;
767ff4367960efd5fa868f3b56f850fd4c205c8bTimo Sirainen mail_index_lookup_ext(mail->transaction->view, mail->seq,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (dbox_rec == NULL || dbox_rec->map_uid == 0) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* lost for some reason, use fallback */
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainenmdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen const char **value_r)
804fa3f03bd9170272168a5ad214053bbe3160c7Josef 'Jeff' Sipek struct dbox_mail *mail = DBOX_MAIL(_mail);
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(_mail->transaction->box);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen if (mdbox_mail_lookup(mbox, _mail->transaction->view,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen if (mdbox_map_lookup_full(mbox->storage->map, map_uid,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen *value_r = p_strdup_printf(mail->imail.mail.data_pool, "%u",
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen if (!dbox_header_have_flag(&mbox->box, mbox->hdr_ext_id,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen if (!dbox_header_have_flag(&mbox->box, mbox->hdr_ext_id,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen return dbox_mail_get_special(_mail, field, value_r);
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainenmdbox_mail_update_flags(struct mail *mail, enum modify_type modify_type,
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen mdbox_purge_alt_flag_change(mail, modify_type != MODIFY_REMOVE);
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen if (flags == 0 && modify_type != MODIFY_REPLACE)