bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "lib.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "ioloop.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "istream.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "str.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "index-mail.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "dbox-mail.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mdbox-storage.h"
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen#include "mdbox-sync.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mdbox-map.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include "mdbox-file.h"
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen#include <sys/stat.h>
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mdbox_mail_lookup(struct mdbox_mailbox *mbox, struct mail_index_view *view,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t seq, uint32_t *map_uid_r)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen{
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mdbox_mail_index_record *dbox_rec;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mdbox_index_header hdr;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const void *data;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t uid, cur_map_uid_validity;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen bool need_resize;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
03010dbaa74ec70f062994dfe3cd39bedc99a28bTimo Sirainen mail_index_lookup_ext(view, seq, mbox->ext_id, &data, NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_rec = data;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (dbox_rec == NULL || dbox_rec->map_uid == 0) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mail_index_lookup_uid(view, seq, &uid);
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi mailbox_set_critical(&mbox->box,
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi "mdbox: map uid lost for uid %u", uid);
5b62dea2f88165f3f4d87bba9011343f3ff415ffTimo Sirainen mdbox_storage_set_corrupted(mbox->storage);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (mbox->map_uid_validity == 0) {
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen if (mdbox_read_header(mbox, &hdr, &need_resize) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mbox->map_uid_validity = hdr.map_uid_validity;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen if (mdbox_map_open_or_create(mbox->storage->map) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
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 mailbox_set_critical(&mbox->box,
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi "mdbox: map uidvalidity mismatch (%u vs %u)",
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi mbox->map_uid_validity, cur_map_uid_validity);
5b62dea2f88165f3f4d87bba9011343f3ff415ffTimo Sirainen mdbox_storage_set_corrupted(mbox->storage);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen *map_uid_r = dbox_rec->map_uid;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return 0;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen}
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic void dbox_mail_set_expunged(struct dbox_mail *mail, uint32_t map_uid)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen{
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mail *_mail = &mail->imail.mail.mail;
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(_mail->box);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
b66d803de86bfb411165b3465b0d9ef64ecfe2a1Timo Sirainen mail_index_refresh(_mail->box->index);
767ff4367960efd5fa868f3b56f850fd4c205c8bTimo Sirainen if (mail_index_is_expunged(_mail->transaction->view, _mail->seq)) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mail_set_expunged(_mail);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen mdbox_map_set_corrupted(mbox->storage->map,
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen "Unexpectedly lost %s uid=%u map_uid=%u",
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen mailbox_get_vname(_mail->box),
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen _mail->uid, map_uid);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen}
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic int dbox_mail_open_init(struct dbox_mail *mail, uint32_t map_uid)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen{
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(mail->imail.mail.mail.box);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t file_id;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen int ret;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen if ((ret = mdbox_map_lookup(mbox->storage->map, map_uid,
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen &file_id, &mail->offset)) <= 0) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (ret < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
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 dbox_mail_set_expunged(mail, map_uid);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen } else {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mail->open_file = mdbox_file_init(mbox->storage, file_id);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return 0;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen}
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenint mdbox_mail_open(struct dbox_mail *mail, uoff_t *offset_r,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct dbox_file **file_r)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen{
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mail *_mail = &mail->imail.mail.mail;
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(_mail->box);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen uint32_t prev_file_id = 0, map_uid = 0;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen bool deleted;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (_mail->lookup_abort != MAIL_LOOKUP_ABORT_NEVER) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mail_set_aborted(_mail);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
7204b8112e005ff81dcf628f7880ef1feed1effeTimo Sirainen _mail->mail_stream_opened = TRUE;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen do {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (mail->open_file != NULL) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* already open */
fc40a9a002458e372ff4b9f6f4e15239520c0bcdTimo Sirainen } else if (!_mail->saving) {
767ff4367960efd5fa868f3b56f850fd4c205c8bTimo Sirainen if (mdbox_mail_lookup(mbox, _mail->transaction->view,
ca98d6a1bbe73499da758a36bfab2963375c8d06Timo Sirainen _mail->seq, &map_uid) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (dbox_mail_open_init(mail, map_uid) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen } else {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* mail is being saved in this transaction */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mail->open_file =
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mdbox_save_file_get_file(_mail->transaction,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen _mail->seq,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen &mail->offset);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (!dbox_file_is_open(mail->open_file))
2d01cc1880cf2afd4fb1c8ad7fa6ce78e562e71eTimo Sirainen _mail->transaction->stats.open_lookup_count++;
4ca83616715c3bd417e34ced2c1d61852513e427Timo Sirainen if (dbox_file_open(mail->open_file, &deleted) <= 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (deleted) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* either it's expunged now or moved to another file. */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen struct mdbox_file *mfile =
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen (struct mdbox_file *)mail->open_file;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (mfile->file_id == prev_file_id) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_mail_set_expunged(mail, map_uid);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen prev_file_id = mfile->file_id;
c18ff860dc22960fd37c272d929f889c7939a2c8Timo Sirainen if (mdbox_map_refresh(mbox->storage->map) < 0)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return -1;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_file_unref(&mail->open_file);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen } while (mail->open_file == NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen *file_r = mail->open_file;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen *offset_r = mail->offset;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return 0;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen}
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstatic int mdbox_mail_get_save_date(struct mail *mail, time_t *date_r)
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen{
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(mail->transaction->box);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const struct mdbox_mail_index_record *dbox_rec;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen const void *data;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
767ff4367960efd5fa868f3b56f850fd4c205c8bTimo Sirainen mail_index_lookup_ext(mail->transaction->view, mail->seq,
03010dbaa74ec70f062994dfe3cd39bedc99a28bTimo Sirainen mbox->ext_id, &data, NULL);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_rec = data;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen if (dbox_rec == NULL || dbox_rec->map_uid == 0) {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen /* lost for some reason, use fallback */
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen return dbox_mail_get_save_date(mail, date_r);
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen }
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen *date_r = dbox_rec->save_date;
5096d157aa1acd28a93f45b058ca5bf26a4fddbeTimo Sirainen return 0;
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen}
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainenstatic int
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainenmdbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen const char **value_r)
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen{
804fa3f03bd9170272168a5ad214053bbe3160c7Josef 'Jeff' Sipek struct dbox_mail *mail = DBOX_MAIL(_mail);
b67974c4b89ab6950c2694cce8dfb1b6561cc084Josef 'Jeff' Sipek struct mdbox_mailbox *mbox = MDBOX_MAILBOX(_mail->transaction->box);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen struct mdbox_map_mail_index_record rec;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen uint32_t map_uid;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen uint16_t refcount;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen switch (field) {
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen case MAIL_FETCH_REFCOUNT:
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen if (mdbox_mail_lookup(mbox, _mail->transaction->view,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen _mail->seq, &map_uid) < 0)
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen return -1;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen if (mdbox_map_lookup_full(mbox->storage->map, map_uid,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen &rec, &refcount) < 0)
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen return -1;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen *value_r = p_strdup_printf(mail->imail.mail.data_pool, "%u",
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen refcount);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen return 0;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen case MAIL_FETCH_UIDL_BACKEND:
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen if (!dbox_header_have_flag(&mbox->box, mbox->hdr_ext_id,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen offsetof(struct mdbox_index_header, flags),
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen DBOX_INDEX_HEADER_FLAG_HAVE_POP3_UIDLS)) {
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen *value_r = "";
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen return 0;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen }
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen break;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen case MAIL_FETCH_POP3_ORDER:
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen if (!dbox_header_have_flag(&mbox->box, mbox->hdr_ext_id,
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen offsetof(struct mdbox_index_header, flags),
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen DBOX_INDEX_HEADER_FLAG_HAVE_POP3_ORDERS)) {
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen *value_r = "";
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen return 0;
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen }
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen break;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen default:
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen break;
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen }
9865d9e7c5713e41db939222ed9c0225a11fb99eTimo Sirainen return dbox_mail_get_special(_mail, field, value_r);
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen}
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainenstatic void
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainenmdbox_mail_update_flags(struct mail *mail, enum modify_type modify_type,
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen enum mail_flags flags)
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen{
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen if ((flags & DBOX_INDEX_FLAG_ALT) != 0) {
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen mdbox_purge_alt_flag_change(mail, modify_type != MODIFY_REMOVE);
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen flags &= ~DBOX_INDEX_FLAG_ALT;
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen if (flags == 0 && modify_type != MODIFY_REPLACE)
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen return;
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen }
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen index_mail_update_flags(mail, modify_type, flags);
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen}
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainenstruct mail_vfuncs mdbox_mail_vfuncs = {
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_mail_close,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_free,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_set_seq,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_set_uid,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_set_uid_cache_updates,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen index_mail_prefetch,
421d30619384e72a27e2a5d13ff6525aff4d17feTimo Sirainen index_mail_precache,
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen index_mail_add_temp_wanted_fields,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_flags,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_keywords,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_keyword_indexes,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_modseq,
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen index_mail_get_pvt_modseq,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_parts,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_date,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_mail_get_received_date,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen mdbox_mail_get_save_date,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_mail_get_virtual_size,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_mail_get_physical_size,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_first_header,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_headers,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_get_header_stream,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen dbox_mail_get_stream,
306b3f41b05da642d87e7ca7a1496efce9f5902fTimo Sirainen index_mail_get_binary_stream,
03de962febfc2ac572f9e4029463c16d29c1ed55Timo Sirainen mdbox_mail_get_special,
21aaa6affb9f134112b75b5db737309fc35ef1cfMartti Rannanjärvi index_mail_get_backend_mail,
5fb3f13537dffd15a31e997da133a721c0728af8Timo Sirainen mdbox_mail_update_flags,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_update_keywords,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_update_modseq,
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen index_mail_update_pvt_modseq,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen NULL,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen index_mail_expunge,
6564208826b0f46a00f010d1b5711d85944c3c88Timo Sirainen index_mail_set_cache_corrupted,
6de6ec228a41275ddda972d4a554699ea75cd06dTimo Sirainen index_mail_opened,
1ac7c8e9040e0d0b7e9f849e45b94bfe919595a9Timo Sirainen};