array_create(&ibox->box.module_contexts,
ibox->box.pool, sizeof(void *), 5);
- ibox->readonly = (flags & MAILBOX_OPEN_READONLY) != 0;
ibox->keep_recent = (flags & MAILBOX_OPEN_KEEP_RECENT) != 0;
ibox->keep_locked = (flags & MAILBOX_OPEN_KEEP_LOCKED) != 0;
ibox->move_to_memory = move_to_memory;
{
struct index_mailbox *ibox = (struct index_mailbox *) box;
- return ibox->readonly;
+ return (ibox->box.open_flags & MAILBOX_OPEN_READONLY) != 0 ||
+ ibox->backend_readonly;
}
bool index_storage_allow_new_keywords(struct mailbox *box)
{
- struct index_mailbox *ibox = (struct index_mailbox *) box;
-
/* FIXME: return FALSE if we're full */
- return !ibox->readonly;
+ return index_storage_is_readonly(box);
}
bool index_storage_is_inconsistent(struct mailbox *box)
time_t sync_last_check;
- unsigned int readonly:1;
+ /* we've discovered there aren't enough permissions to modify mailbox */
+ unsigned int backend_readonly:1;
unsigned int keep_recent:1;
unsigned int keep_locked:1;
unsigned int sent_diskspace_warning:1;
if (access(t_strconcat(path, "/cur", NULL), W_OK) < 0 &&
errno == EACCES)
- mbox->ibox.readonly = TRUE;
+ mbox->ibox.backend_readonly = TRUE;
mbox->keywords = maildir_keywords_init(mbox);
return &mbox->ibox.box;
ctx->trans = trans;
ctx->keywords_sync_ctx =
maildir_keywords_sync_init(mbox->keywords, mbox->ibox.index);
-
- ctx->sync_changes = index_sync_changes_init(&mbox->ibox, ctx->sync_ctx,
- ctx->view, ctx->trans,
- mbox->ibox.readonly);
+ ctx->sync_changes =
+ index_sync_changes_init(&mbox->ibox, ctx->sync_ctx,
+ ctx->view, ctx->trans,
+ mbox->ibox.backend_readonly);
*ctx_r = ctx;
return 0;
if (mbox->mbox_file_stream != NULL) {
/* read-only mbox stream */
- i_assert(mbox->mbox_readonly);
+ i_assert(mbox->ibox.backend_readonly);
return 0;
}
- fd = open(mbox->path, mbox->mbox_readonly ? O_RDONLY : O_RDWR);
- if (fd == -1 && errno == EACCES && !mbox->mbox_readonly) {
- mbox->mbox_readonly = TRUE;
+ fd = open(mbox->path, mbox->ibox.backend_readonly ? O_RDONLY : O_RDWR);
+ if (fd == -1 && errno == EACCES && !mbox->ibox.backend_readonly) {
+ mbox->ibox.backend_readonly = TRUE;
fd = open(mbox->path, O_RDONLY);
}
if (mbox->mbox_file_stream != NULL) {
/* read-only mbox stream */
- i_assert(mbox->mbox_fd == -1 && mbox->mbox_readonly);
+ i_assert(mbox->mbox_fd == -1 && mbox->ibox.backend_readonly);
} else {
if (mbox->mbox_fd == -1) {
if (mbox_file_open(mbox) < 0)
struct stat st;
if (mbox->ibox.recent_flags_count > 0 && mbox->ibox.keep_recent &&
- mbox->mbox_fd != -1 && !mbox->mbox_readonly) {
+ mbox->mbox_fd != -1 && !mbox->ibox.backend_readonly) {
/* we've seen recent messages which we want to keep recent.
keep file's atime lower than mtime so \Marked status
gets shown while listing */
if (mbox->mbox_file_stream != NULL) {
if (mbox->mbox_fd == -1) {
/* read-only mbox stream */
- i_assert(mbox->mbox_readonly);
+ i_assert(mbox->ibox.backend_readonly);
i_stream_seek(mbox->mbox_file_stream, 0);
} else {
i_stream_destroy(&mbox->mbox_file_stream);
if (mbox->mbox_fd == -1 && mbox->mbox_file_stream != NULL) {
/* read-only mbox stream. no need to lock. */
- i_assert(mbox->mbox_readonly);
+ i_assert(mbox->ibox.backend_readonly);
mbox->mbox_lock_type = lock_type;
return 1;
}
bool empty = FALSE;
int ret;
- if (ctx->mbox->mbox_readonly) {
+ if (ctx->mbox->ibox.backend_readonly) {
mail_storage_set_error(storage, MAIL_ERROR_PERM,
"Read-only mbox");
return -1;
if (access(path, R_OK|W_OK) < 0) {
if (errno < EACCES)
mbox_set_syscall_error(mbox, "access()");
- else {
- mbox->ibox.readonly = TRUE;
- mbox->mbox_readonly = TRUE;
- }
+ else
+ mbox->ibox.backend_readonly = TRUE;
}
if (strcmp(name, "INBOX") == 0) {
i_stream_ref(input);
mbox->mbox_file_stream = input;
- mbox->mbox_readonly = TRUE;
+ mbox->ibox.backend_readonly = TRUE;
mbox->no_mbox_file = TRUE;
mbox->path = "(read-only mbox stream)";
if (mbox->ibox.view != NULL) {
hdr = mail_index_get_header(mbox->ibox.view);
if ((hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 &&
- !mbox->mbox_readonly) {
+ !mbox->ibox.backend_readonly) {
/* we've done changes to mbox which haven't been
written yet. do it now. */
sync_flags |= MBOX_SYNC_REWRITE;
struct dotlock *mbox_dotlock;
unsigned int mbox_lock_id, mbox_global_lock_id;
struct timeout *keep_lock_to;
- bool mbox_readonly, mbox_writeonly;
+ bool mbox_writeonly;
uint32_t mbox_ext_idx;
struct mbox_index_header mbox_hdr;
}
index_sync_changes_read(sync_ctx->sync_changes, uid, sync_expunge_r);
- if (sync_ctx->mbox->mbox_readonly) {
+ if (sync_ctx->mbox->ibox.backend_readonly) {
/* we can't expunge anything from read-only mboxes */
*sync_expunge_r = FALSE;
}
/* a) partial sync didn't work
b) we ran out of UIDs
c) syncing had errors */
- if (sync_ctx->delay_writes && !sync_ctx->mbox->mbox_readonly &&
+ if (sync_ctx->delay_writes &&
+ !sync_ctx->mbox->ibox.backend_readonly &&
(sync_ctx->errors || sync_ctx->renumber_uids)) {
/* fixing a broken mbox state, be sure to write
the changes. */
int ret, changed;
bool delay_writes;
- delay_writes = mbox->mbox_readonly ||
+ delay_writes = mbox->ibox.backend_readonly ||
((flags & MBOX_SYNC_REWRITE) == 0 &&
getenv("MBOX_LAZY_WRITES") != NULL);
lock it for writing immediately. the mbox must be locked
before index syncing is started to avoid deadlocks, so we
don't have much choice either (well, easy ones anyway). */
- int lock_type = mbox->mbox_readonly ? F_RDLCK : F_WRLCK;
+ int lock_type = mbox->ibox.backend_readonly ? F_RDLCK : F_WRLCK;
if ((ret = mbox_lock(mbox, lock_type, lock_id)) <= 0) {
if (ret == 0 || lock_type == F_RDLCK)
/* try as read-only */
if (mbox_lock(mbox, F_RDLCK, lock_id) <= 0)
return -1;
- mbox->mbox_readonly = TRUE;
+ mbox->ibox.backend_readonly = TRUE;
}
}
i_array_init(&sync_ctx.mails, 64);
sync_ctx.flags = flags;
- sync_ctx.delay_writes = delay_writes || sync_ctx.mbox->mbox_readonly;
+ sync_ctx.delay_writes = delay_writes ||
+ sync_ctx.mbox->ibox.backend_readonly;
sync_ctx.sync_changes =
index_sync_changes_init(&mbox->ibox, index_sync_ctx,
sync_ctx.index_sync_ctx = NULL;
if (ret == 0 && mbox->mbox_fd != -1 && mbox->ibox.keep_recent &&
- !sync_ctx.mbox->mbox_readonly) {
+ !sync_ctx.mbox->ibox.backend_readonly) {
/* try to set atime back to its original value */
struct utimbuf buf;
struct stat st;