bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen /* read-only mbox stream */
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainen mbox_is_backend_readonly(mbox) ? O_RDONLY : O_RDWR);
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainen if (fd == -1 && errno == EACCES && !mbox->backend_readonly) {
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen fd = open(mailbox_get_path(&mbox->box), O_RDONLY);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenvoid mbox_file_close(struct mbox_mailbox *mbox)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenint mbox_file_open_stream(struct mbox_mailbox *mbox)
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen /* read-only mbox stream */
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainen i_assert(mbox->mbox_fd == -1 && mbox_is_backend_readonly(mbox));
d42eb03b3a4e79a2da22a1be2de59b95660af2beTimo Sirainen i_stream_set_init_buffer_size(mbox->mbox_file_stream,
f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08Timo Sirainen mbox->mbox_stream = i_stream_create_raw_mbox(mbox->mbox_file_stream);
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen istream_raw_mbox_set_locked(mbox->mbox_stream);
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainenstatic void mbox_file_fix_atime(struct mbox_mailbox *mbox)
4145cbac82bfc0c8bfeceeca0ef841700117930cTimo Sirainen (mbox->box.flags & MAILBOX_FLAG_DROP_RECENT) == 0 &&
c000c8eca8f24b2a0c76393ec4bbf76a505a4983Timo Sirainen mbox->mbox_fd != -1 && !mbox_is_backend_readonly(mbox)) {
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen /* we've seen recent messages which we want to keep recent.
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen keep file's atime lower than mtime so \Marked status
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen gets shown while listing */
3d4c24127f4f83259c0f81851184abc34793dbe0Timo Sirainen /* EPERM can happen with shared mailboxes */
ca98892a6b8a30ffc1fe26fcf02c7d59e3204e7eTimo Sirainen if (utime(mailbox_get_path(&mbox->box), &buf) < 0 &&
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenvoid mbox_file_close_stream(struct mbox_mailbox *mbox)
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen /* if we read anything, fix the atime if needed */
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen /* read-only mbox stream */
1b5366b2234892f8930a29351da06b193e385150Timo Sirainenint mbox_file_lookup_offset(struct mbox_mailbox *mbox,
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen mail_index_lookup_ext(view, seq, mbox->mbox_ext_idx, &data, &deleted);
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi "Cached message offset lost for seq %u in mbox", seq);
1b5366b2234892f8930a29351da06b193e385150Timo Sirainenint mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view,
1b5366b2234892f8930a29351da06b193e385150Timo Sirainen ret = mbox_file_lookup_offset(mbox, view, seq, &offset);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen mail_storage_set_error(&mbox->storage->storage,
f1901fd21906911f7be075c965ac882f6a87b4c3Timo Sirainen "Mailbox isn't a valid mbox file");
d4002fe1f64d25a792f76fb102ef7dc519cd4e24Martti Rannanjärvi "Cached message offset %s is invalid for mbox",
3343a61404603b21c246783a7963b77833095f31Timo Sirainen /* we're dirty - make sure this is the correct mail */
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen if (!mbox_sync_parse_match_mail(mbox, view, seq))