mbox-file.c revision e5afebd2df1d4990f7bec2a839260ff2e6d78168
89a126810703c666309310d0f3189e9834d70b5bTimo Sirainen/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* read-only mbox stream */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fd = open(mbox->path, mbox->mbox_readonly ? O_RDONLY : O_RDWR);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (fd == -1 && errno == EACCES && !mbox->mbox_readonly) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid mbox_file_close(struct mbox_mailbox *mbox)
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainenint mbox_file_open_stream(struct mbox_mailbox *mbox)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* read-only mbox stream */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen i_assert(mbox->mbox_fd == -1 && mbox->mbox_readonly);
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen i_stream_create_raw_mbox(mbox->mbox_file_stream,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mbox->mbox_file_stream = i_stream_create_from_data(NULL, 0);
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen mbox->mbox_stream = i_stream_create_raw_mbox(mbox->mbox_file_stream,
e9d29ae46d435aee85514decfe6ee27399ebf794Timo Sirainenstatic void mbox_file_fix_atime(struct mbox_mailbox *mbox)
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen if (mbox->ibox.recent_flags_count > 0 && mbox->ibox.keep_recent &&
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen mbox->mbox_fd != -1 && !mbox->mbox_readonly) {
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen /* we've seen recent messages which we want to keep recent.
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen keep file's atime lower than mtime so \Marked status
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen gets shown while listing */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainenvoid mbox_file_close_stream(struct mbox_mailbox *mbox)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* if we read anything, fix the atime if needed */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen /* read-only mbox stream */
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenint mbox_file_lookup_offset(struct mbox_mailbox *mbox,
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen mail_index_lookup_ext(view, seq, mbox->mbox_ext_idx, &data, &deleted);
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
3ec2c1f31631bb5ff86f5fc93a563c33e5cae90dTimo Sirainen "Cached message offset lost for seq %u in mbox file %s",
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainenint mbox_file_seek(struct mbox_mailbox *mbox, struct mail_index_view *view,
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen ret = mbox_file_lookup_offset(mbox, view, seq, &offset);
8b58939517a381db55670089c0984da39fc0f099Timo Sirainen if (istream_raw_mbox_seek(mbox->mbox_stream, offset) < 0) {
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen mail_storage_set_error(&mbox->storage->storage,
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen "Mailbox isn't a valid mbox file");
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen "Cached message offset %s is invalid for mbox file %s",
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen /* we're dirty - make sure this is the correct mail */
c36ec256c1bd1abe1c12e792cf64f0b7e3b3135aTimo Sirainen if (!mbox_sync_parse_match_mail(mbox, view, seq))