mbox-mail.c revision 3063bd8ff05d3d8cd33156f4366b36890e501436
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen/* Copyright (c) 2003-2014 Dovecot authors, see the included COPYING file */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainenstatic void mbox_prepare_resync(struct mail *mail)
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen (struct mbox_transaction_context *)mail->transaction;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->box;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainenstatic int mbox_mail_seek(struct index_mail *mail)
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen (struct mbox_transaction_context *)mail->mail.mail.transaction;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen istream_raw_mbox_is_corrupted(mbox->mbox_stream)) {
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* clear the corruption by forcing a full resync */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen if ((sync_flags & MBOX_SYNC_FORCE_SYNC) != 0) {
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* dirty offsets are broken. make sure we can sync. */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* refresh index file after mbox has been locked to
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen make sure we get only up-to-date mbox offsets. */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen if (mail_index_refresh(mbox->box.index) < 0) {
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen } else if (t->read_lock_id == 0) {
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* file is already locked by another transaction, but
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen we must keep it locked for the entire transaction,
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen so increase the lock counter. */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen ret = mbox_file_seek(mbox, _mail->transaction->view,
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* success */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* we'll need to re-sync it completely */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen "Losing sync for mail uid=%u in mbox file %s",
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainenstatic int mbox_mail_get_received_date(struct mail *_mail, time_t *date_r)
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen if (index_mail_get_received_date(_mail, date_r) == 0)
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen istream_raw_mbox_get_received_time(mbox->mbox_stream);
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* it's broken and conflicts with our "not found"
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen return value. change it. */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainenstatic int mbox_mail_get_save_date(struct mail *_mail, time_t *date_r)
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen if (index_mail_get_save_date(_mail, date_r) == 0)
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen /* no way to know this. save the current time into cache and use
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen that from now on. this works only as long as the index files
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen are permanent */
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainenmbox_mail_get_md5_header(struct index_mail *mail, const char **value_r)
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
9afebd21ced1d43f638e08a1411c9a89e526231fTimo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)_mail->box;
const void *ext_data;
const char **value_r)
bool move_offset;
int ret;
switch (field) {
case MAIL_FETCH_FROM_ENVELOPE:
case MAIL_FETCH_GUID:
case MAIL_FETCH_HEADER_MD5:
offset = 0;
MBOX_SYNC_READONLY) < 0)
if (move_offset) {
offset) < 0) {
int trailer_size;
next_offset_r) <= 0)
ret = 0;
return ret;
int ret;
if (ret < 0) {
if (ret < 0) {
bool ret;
return ret;
NULL,