mdbox-mail.c revision 767ff4367960efd5fa868f3b56f850fd4c205c8b
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2010 Dovecot authors, see the included COPYING file */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschint mdbox_mail_lookup(struct mdbox_mailbox *mbox, struct mail_index_view *view,
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const struct mdbox_mail_index_record *dbox_rec;
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch mail_index_lookup_ext(view, seq, mbox->ext_id, &data, &expunged);
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch if (dbox_rec == NULL || dbox_rec->map_uid == 0) {
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mail_storage_set_critical(&mbox->storage->storage.storage,
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch "dbox %s: map uid lost for uid %u",
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mbox->storage->storage.files_corrupted = TRUE;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mbox->storage->storage.files_corrupted = TRUE;
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch mbox->map_uid_validity = hdr.map_uid_validity;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch if (dbox_map_open(mbox->storage->map, TRUE) < 0)
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch cur_map_uid_validity = dbox_map_get_uid_validity(mbox->storage->map);
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch if (cur_map_uid_validity != mbox->map_uid_validity) {
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mail_storage_set_critical(&mbox->storage->storage.storage,
f883bf3eff62f5d27df5ee9ee664edc38a77937fStephan Bosch "dbox %s: map uidvalidity mismatch (%u vs %u)",
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mbox->storage->storage.files_corrupted = TRUE;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschstatic void dbox_mail_set_expunged(struct dbox_mail *mail, uint32_t map_uid)
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)_mail->box;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch if (mail_index_is_expunged(_mail->transaction->view, _mail->seq)) {
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch "Unexpectedly lost %s uid=%u map_uid=%u",
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mbox->storage->storage.files_corrupted = TRUE;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschstatic int dbox_mail_open_init(struct dbox_mail *mail, uint32_t map_uid)
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch (struct mdbox_mailbox *)mail->imail.mail.mail.box;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch if ((ret = dbox_map_lookup(mbox->storage->map, map_uid,
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* map_uid doesn't exist anymore. either it
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch got just expunged or the map index is
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch corrupted. */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mail->open_file = mdbox_file_init(mbox->storage, file_id);
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschint mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
62aa68310d6f42467ca26880f678173bf1d26a83Stephan Bosch struct mdbox_mailbox *mbox = (struct mdbox_mailbox *)_mail->box;
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* already open */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch if (mdbox_mail_lookup(mbox, _mail->transaction->view,
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* mail is being saved in this transaction */
66134fbce11778241ca9f8458ee2a0488a05bde0Stephan Bosch if (dbox_file_open(mail->open_file, &deleted) <= 0)
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* either it's expunged now or moved to another file. */
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Boschstatic int mdbox_mail_get_save_date(struct mail *mail, time_t *date_r)
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch (struct mdbox_mailbox *)mail->transaction->box;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch const struct mdbox_mail_index_record *dbox_rec;
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch mail_index_lookup_ext(mail->transaction->view, mail->seq,
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch if (dbox_rec == NULL || dbox_rec->map_uid == 0) {
6ae6496c225238a2c55a8cd96744ad976c44a726Stephan Bosch /* lost for some reason, use fallback */