mbox-file.c revision 23bdbb7b1831785c6ba6df190f6369da882d2b9d
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* Copyright (c) 2002-2016 Dovecot authors, see the included COPYING file */
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch /* read-only mbox stream */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch mbox_is_backend_readonly(mbox) ? O_RDONLY : O_RDWR);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if (fd == -1 && errno == EACCES && !mbox->backend_readonly) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch fd = open(mailbox_get_path(&mbox->box), O_RDONLY);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Boschvoid mbox_file_close(struct mbox_mailbox *mbox)
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschint mbox_file_open_stream(struct mbox_mailbox *mbox)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* read-only mbox stream */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch i_assert(mbox->mbox_fd == -1 && mbox_is_backend_readonly(mbox));
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen i_stream_set_init_buffer_size(mbox->mbox_file_stream,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen mbox->mbox_stream = i_stream_create_raw_mbox(mbox->mbox_file_stream);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch istream_raw_mbox_set_locked(mbox->mbox_stream);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic void mbox_file_fix_atime(struct mbox_mailbox *mbox)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch (mbox->box.flags & MAILBOX_FLAG_DROP_RECENT) == 0 &&
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch mbox->mbox_fd != -1 && !mbox_is_backend_readonly(mbox)) {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* we've seen recent messages which we want to keep recent.
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch keep file's atime lower than mtime so \Marked status
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch gets shown while listing */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen /* EPERM can happen with shared mailboxes */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen if (utime(mailbox_get_path(&mbox->box), &buf) < 0 &&
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschvoid mbox_file_close_stream(struct mbox_mailbox *mbox)
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* if we read anything, fix the atime if needed */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch /* read-only mbox stream */
38af46387e565053adf6c47f7f6871676d685de8Stephan Boschint mbox_file_lookup_offset(struct mbox_mailbox *mbox,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch mail_index_lookup_ext(view, seq, mbox->mbox_ext_idx, &data, &deleted);
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen "Cached message offset lost for seq %u in mbox file %s",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschint mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch ret = mbox_file_lookup_offset(mbox, view, seq, &offset);
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch mail_storage_set_error(&mbox->storage->storage,
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch "Mailbox isn't a valid mbox file");
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch mail_storage_set_critical(&mbox->storage->storage,
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch "Cached message offset %s is invalid for mbox file %s",
2f64a4c88de91c483fb378bc80d10e1caa6f2305Stephan Bosch dec2str(offset), mailbox_get_path(&mbox->box));
5560e4cd4f5eded857471042fb5485dfa16b7c46Stephan Bosch /* we're dirty - make sure this is the correct mail */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch if (!mbox_sync_parse_match_mail(mbox, view, seq))