mbox-file.c revision 573f0491a5733fe21fa062a455acb4790b4e0499
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen /* read-only mbox stream */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen mbox->ibox.backend_readonly ? O_RDONLY : O_RDWR);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (fd == -1 && errno == EACCES && !mbox->ibox.backend_readonly) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid mbox_file_close(struct mbox_mailbox *mbox)
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenint mbox_file_open_stream(struct mbox_mailbox *mbox)
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen /* read-only mbox stream */
b437874782ad048daa155e0ac863c2326c3f5e43Timo Sirainen i_assert(mbox->mbox_fd == -1 && mbox->ibox.backend_readonly);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen i_stream_set_init_buffer_size(mbox->mbox_file_stream,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen mbox->mbox_stream = i_stream_create_raw_mbox(mbox->mbox_file_stream,
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen istream_raw_mbox_set_locked(mbox->mbox_stream);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic void mbox_file_fix_atime(struct mbox_mailbox *mbox)
7fe37c2b0e4cd2a39896ab16e47eb418a59e3934Timo Sirainen (mbox->ibox.box.flags & MAILBOX_FLAG_KEEP_RECENT) != 0 &&
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen mbox->mbox_fd != -1 && !mbox->ibox.backend_readonly) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* we've seen recent messages which we want to keep recent.
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen keep file's atime lower than mtime so \Marked status
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen gets shown while listing */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainenvoid mbox_file_close_stream(struct mbox_mailbox *mbox)
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen /* if we read anything, fix the atime if needed */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen /* read-only mbox stream */
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainenint mbox_file_lookup_offset(struct mbox_mailbox *mbox,
71056e0f5e1f68cb9ac002a7827eb98435c40d62Timo Sirainen mail_index_lookup_ext(view, seq, mbox->mbox_ext_idx, &data, &deleted);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen mail_storage_set_critical(&mbox->storage->storage,
28bf8f762fcd21c57bf71822cf818447babce9a0Timo Sirainen "Cached message offset lost for seq %u in mbox file %s",
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Boschint mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view,
8451c4b5afc1ff5366438b2766f75b592c33e1ecTimo Sirainen ret = mbox_file_lookup_offset(mbox, view, seq, &offset);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen mail_storage_set_error(&mbox->storage->storage,
ca4526e3b5fbf5ea3dd477a2098522a44c9ac52cTimo Sirainen "Mailbox isn't a valid mbox file");
0679f8a70a8dda43b204ae35fc6a903818cc6584Timo Sirainen mail_storage_set_critical(&mbox->storage->storage,
40a8e6948d662339c0c5e2c7abfb84ae7c1803fdTimo Sirainen "Cached message offset %s is invalid for mbox file %s",
1904e2fc786dbc037039d284b371730777277fc5Aki Tuomi /* we're dirty - make sure this is the correct mail */
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen if (!mbox_sync_parse_match_mail(mbox, view, seq))