From: Timo Sirainen Date: Sat, 26 Jul 2003 16:55:11 +0000 (+0300) Subject: API changes: Don't keep variables in mailbox class. X-Git-Tag: 1.1.alpha1~4464 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff1c87522054d080d68b0123373d989a8991aa2a;p=thirdparty%2Fdovecot%2Fcore.git API changes: Don't keep variables in mailbox class. --HG-- branch : HEAD --- diff --git a/src/imap/cmd-close.c b/src/imap/cmd-close.c index 50a541b9f9..cbbdab859a 100644 --- a/src/imap/cmd-close.c +++ b/src/imap/cmd-close.c @@ -13,7 +13,7 @@ int cmd_close(struct client *client) client->mailbox = NULL; - if (!mailbox->readonly) { + if (!mailbox->is_readonly(mailbox)) { if (!imap_expunge(mailbox, FALSE)) client_send_untagged_storage_error(client); } diff --git a/src/imap/cmd-select.c b/src/imap/cmd-select.c index 634e3260da..0134578bb5 100644 --- a/src/imap/cmd-select.c +++ b/src/imap/cmd-select.c @@ -73,7 +73,7 @@ int _cmd_select_full(struct client *client, int readonly) "Disk space is full, delete some messages."); } - client_send_tagline(client, box->readonly ? + client_send_tagline(client, box->is_readonly(box) ? "OK [READ-ONLY] Select completed." : "OK [READ-WRITE] Select completed."); diff --git a/src/imap/commands-util.c b/src/imap/commands-util.c index 4da8155d44..d56ee4ecc2 100644 --- a/src/imap/commands-util.c +++ b/src/imap/commands-util.c @@ -288,14 +288,14 @@ void client_send_mailbox_flags(struct client *client, struct mailbox *box, client_send_line(client, t_strconcat("* FLAGS ("SYSTEM_FLAGS, str, ")", NULL)); - if (box->readonly) { + if (box->is_readonly(box)) { client_send_line(client, "* OK [PERMANENTFLAGS ()] " "Read-only mailbox."); } else { client_send_line(client, t_strconcat("* OK [PERMANENTFLAGS ("SYSTEM_FLAGS, str, - box->allow_custom_flags ? " \\*" : "", - ")] Flags permitted.", NULL)); + box->allow_new_custom_flags(box) ? + " \\*" : "", ")] Flags permitted.", NULL)); } } diff --git a/src/imap/imap-fetch.c b/src/imap/imap-fetch.c index 2b5dff5d7e..4832076270 100644 --- a/src/imap/imap-fetch.c +++ b/src/imap/imap-fetch.c @@ -275,7 +275,7 @@ int imap_fetch(struct client *client, ctx.select_counter = client->select_counter; ctx.seen_flag.flags = MAIL_SEEN; - if (!box->readonly) { + if (!box->is_readonly(box)) { /* If we have any BODY[..] sections, \Seen flag is added for all messages */ struct imap_fetch_body_data *body; diff --git a/src/lib-storage/index/index-expunge.c b/src/lib-storage/index/index-expunge.c index da9c0d2cc7..37e2273142 100644 --- a/src/lib-storage/index/index-expunge.c +++ b/src/lib-storage/index/index-expunge.c @@ -53,7 +53,7 @@ index_storage_expunge_init(struct mailbox *box, struct index_mailbox *ibox = (struct index_mailbox *) box; struct mail_expunge_context *ctx; - if (box->readonly) { + if (box->is_readonly(box)) { box->storage->callbacks-> notify_no(box, "Mailbox is read-only, ignoring expunge", box->storage->callback_context); diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index 0bd23fe9fa..f5d31b81d7 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -271,7 +271,7 @@ static void lock_notify(enum mail_lock_notify_type notify_type, void index_storage_init_lock_notify(struct index_mailbox *ibox) { if (ibox->index->mailbox_readonly) - ibox->box.readonly = TRUE; + ibox->readonly = TRUE; ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL; ibox->last_notify_type = (enum mail_lock_notify_type)-1; @@ -328,7 +328,7 @@ index_storage_mailbox_init(struct mail_storage *storage, struct mailbox *box, ibox->box.storage = storage; ibox->box.name = i_strdup(name); - ibox->box.readonly = (flags & MAILBOX_OPEN_READONLY) != 0; + ibox->readonly = (flags & MAILBOX_OPEN_READONLY) != 0; ibox->index = index; @@ -356,8 +356,6 @@ index_storage_mailbox_init(struct mail_storage *storage, struct mailbox *box, if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED)) break; - ibox->box.allow_custom_flags = - ibox->index->allow_new_custom_flags; ibox->synced_messages_count = mail_index_get_header(index)->messages_count; @@ -391,6 +389,27 @@ int index_storage_mailbox_free(struct mailbox *box) return TRUE; } +int index_storage_is_readonly(struct mailbox *box) +{ + struct index_mailbox *ibox = (struct index_mailbox *) box; + + return ibox->readonly; +} + +int index_storage_allow_new_custom_flags(struct mailbox *box) +{ + struct index_mailbox *ibox = (struct index_mailbox *) box; + + return ibox->index->allow_new_custom_flags; +} + +int index_storage_is_inconsistency_error(struct mailbox *box) +{ + struct index_mailbox *ibox = (struct index_mailbox *) box; + + return ibox->inconsistent; +} + void index_storage_set_callbacks(struct mail_storage *storage, struct mail_storage_callbacks *callbacks, void *context) @@ -408,7 +427,7 @@ int mail_storage_set_index_error(struct index_mailbox *ibox) mail_storage_set_internal_error(ibox->box.storage); break; case MAIL_INDEX_ERROR_INCONSISTENT: - ibox->box.inconsistent = TRUE; + ibox->inconsistent = TRUE; break; case MAIL_INDEX_ERROR_DISKSPACE: mail_storage_set_error(ibox->box.storage, "Out of disk space"); diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index be044734ee..8fa90e39e6 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -34,6 +34,8 @@ struct index_mailbox { time_t next_lock_notify; /* temporary */ enum mail_lock_notify_type last_notify_type; + unsigned int readonly:1; + unsigned int inconsistent:1; unsigned int sent_diskspace_warning:1; unsigned int sent_readonly_flags_warning:1; }; @@ -57,6 +59,10 @@ index_storage_mailbox_init(struct mail_storage *storage, struct mailbox *box, enum mailbox_open_flags flags); int index_storage_mailbox_free(struct mailbox *box); +int index_storage_is_readonly(struct mailbox *box); +int index_storage_allow_new_custom_flags(struct mailbox *box); +int index_storage_is_inconsistency_error(struct mailbox *box); + int index_storage_sync_and_lock(struct index_mailbox *ibox, int sync_size, int minimal_sync, enum mail_lock_type data_lock_type); diff --git a/src/lib-storage/index/index-update-flags.c b/src/lib-storage/index/index-update-flags.c index 87aacc1ab4..80a7d6e9be 100644 --- a/src/lib-storage/index/index-update-flags.c +++ b/src/lib-storage/index/index-update-flags.c @@ -14,7 +14,7 @@ int index_storage_update_flags(struct mail *mail, struct mail_storage *storage = mail->box->storage; enum mail_flags modify_flags, new_flags; - if (mail->box->readonly) { + if (mail->box->is_readonly(mail->box)) { if (ibox->sent_readonly_flags_warning) return TRUE; ibox->sent_readonly_flags_warning = TRUE; diff --git a/src/lib-storage/index/maildir/maildir-copy.c b/src/lib-storage/index/maildir/maildir-copy.c index bfb8b9f321..c9f5d9346b 100644 --- a/src/lib-storage/index/maildir/maildir-copy.c +++ b/src/lib-storage/index/maildir/maildir-copy.c @@ -133,7 +133,7 @@ struct mail_copy_context *maildir_storage_copy_init(struct mailbox *box) struct index_mailbox *ibox = (struct index_mailbox *) box; struct maildir_copy_context *ctx; - if (box->readonly) { + if (box->is_readonly(box)) { mail_storage_set_error(box->storage, "Destination mailbox is read-only"); return NULL; diff --git a/src/lib-storage/index/maildir/maildir-expunge.c b/src/lib-storage/index/maildir/maildir-expunge.c index f9a8699a28..eb329edadc 100644 --- a/src/lib-storage/index/maildir/maildir-expunge.c +++ b/src/lib-storage/index/maildir/maildir-expunge.c @@ -56,7 +56,7 @@ int maildir_storage_expunge(struct mail *mail, struct index_mail *imail = (struct index_mail *) mail; int ret; - if (mail->box->readonly) { + if (mail->box->is_readonly(mail->box)) { /* send warning */ return index_storage_expunge(mail, ctx->ctx, seq_r, notify); } diff --git a/src/lib-storage/index/maildir/maildir-save.c b/src/lib-storage/index/maildir/maildir-save.c index 584094db60..921b3548ed 100644 --- a/src/lib-storage/index/maildir/maildir-save.c +++ b/src/lib-storage/index/maildir/maildir-save.c @@ -172,7 +172,7 @@ maildir_storage_save_init(struct mailbox *box, int transaction) struct mail_save_context *ctx; pool_t pool; - if (box->readonly) { + if (box->is_readonly(box)) { mail_storage_set_error(box->storage, "Mailbox is read-only"); return NULL; } diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 054b654c88..7cf0796184 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -764,6 +764,8 @@ struct mailbox maildir_mailbox = { NULL, /* name */ NULL, /* storage */ + index_storage_is_readonly, + index_storage_allow_new_custom_flags, maildir_storage_close, maildir_storage_lock, index_storage_get_status, @@ -786,9 +788,5 @@ struct mailbox maildir_mailbox = { maildir_storage_expunge_init, maildir_storage_expunge_deinit, maildir_storage_expunge_fetch_next, - mail_storage_is_inconsistency_error, - - FALSE, - FALSE, - FALSE + index_storage_is_inconsistency_error }; diff --git a/src/lib-storage/index/mbox/mbox-save.c b/src/lib-storage/index/mbox/mbox-save.c index e8815469e3..6c0dadc3bc 100644 --- a/src/lib-storage/index/mbox/mbox-save.c +++ b/src/lib-storage/index/mbox/mbox-save.c @@ -320,7 +320,7 @@ mbox_storage_save_init(struct mailbox *box, int transaction) struct index_mailbox *ibox = (struct index_mailbox *) box; struct mail_save_context *ctx; - if (box->readonly) { + if (box->is_readonly(box)) { mail_storage_set_error(box->storage, "Mailbox is read-only"); return NULL; } diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index c540857ae6..db4e117b95 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -780,6 +780,8 @@ struct mailbox mbox_mailbox = { NULL, /* name */ NULL, /* storage */ + index_storage_is_readonly, + index_storage_allow_new_custom_flags, mbox_storage_close, mbox_storage_lock, index_storage_get_status, @@ -802,9 +804,5 @@ struct mailbox mbox_mailbox = { mbox_storage_expunge_init, mbox_storage_expunge_deinit, mbox_storage_expunge_fetch_next, - mail_storage_is_inconsistency_error, - - FALSE, - FALSE, - FALSE + index_storage_is_inconsistency_error }; diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 25da04fa10..c5b70b2f65 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -256,8 +256,3 @@ const char *mail_storage_get_last_error(struct mail_storage *storage, *syntax = storage->syntax_error; return storage->error; } - -int mail_storage_is_inconsistency_error(struct mailbox *box) -{ - return box->inconsistent; -} diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 9d442f87d8..d1ca820d19 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -229,6 +229,12 @@ struct mailbox { struct mail_storage *storage; + /* Returns TRUE if mailbox is read-only. */ + int (*is_readonly)(struct mailbox *box); + + /* Returns TRUE if mailbox supports adding custom flags. */ + int (*allow_new_custom_flags)(struct mailbox *box); + /* Close the box. Returns FALSE if some cleanup errors occured, but the mailbox was closed anyway. */ int (*close)(struct mailbox *box); @@ -342,12 +348,6 @@ struct mailbox { connection this would mean a forced disconnection since we can't do forced CLOSE. */ int (*is_inconsistency_error)(struct mailbox *box); - -/* public: */ - unsigned int readonly:1; - unsigned int allow_custom_flags:1; -/* private: */ - unsigned int inconsistent:1; }; struct mail { @@ -508,6 +508,5 @@ void mail_storage_set_internal_error(struct mail_storage *storage); const char *mail_storage_get_last_error(struct mail_storage *storage, int *syntax); -int mail_storage_is_inconsistency_error(struct mailbox *box); #endif