index-update-flags.c revision b37634f5bf23ff8c72b88ef6966fd5c730017419
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (C) 2002 Timo Sirainen */
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen#include "lib.h"
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen#include "index-storage.h"
7ef3553585e556f35d5919589cfdc1de3329e4bbTimo Sirainen#include "index-messageset.h"
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen#include "mail-custom-flags.h"
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainenint index_storage_update_flags(struct mail *mail,
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen const struct mail_full_flags *flags,
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen enum modify_type modify_type)
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen{
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen struct index_mail *imail = (struct index_mail *) mail;
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen struct index_mailbox *ibox = imail->ibox;
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen struct mail_storage *storage = mail->box->storage;
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen enum mail_flags modify_flags;
7ef3553585e556f35d5919589cfdc1de3329e4bbTimo Sirainen
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen if (mail->box->is_readonly(mail->box)) {
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen if (ibox->sent_readonly_flags_warning)
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen return TRUE;
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen ibox->sent_readonly_flags_warning = TRUE;
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen storage->callbacks->
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen notify_no(&ibox->box,
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen "Mailbox is read-only, ignoring flag changes",
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen storage->callback_context);
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen return TRUE;
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen }
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen /* \Recent can't be changed */
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen modify_flags = flags->flags & ~MAIL_RECENT;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen if (!index_mailbox_fix_custom_flags(ibox, &modify_flags,
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen flags->custom_flags,
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen flags->custom_flags_count))
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen return FALSE;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen if (!ibox->index->update_flags(ibox->index, imail->data.rec,
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen imail->data.idx_seq,
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen modify_type, modify_flags, FALSE))
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen return FALSE;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen if (mail_custom_flags_has_changes(ibox->index->custom_flags)) {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen storage->callbacks->new_custom_flags(&ibox->box,
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen mail_custom_flags_list_get(ibox->index->custom_flags),
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen MAIL_CUSTOM_FLAGS_COUNT, storage->callback_context);
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen }
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen return TRUE;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen}
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen