mbox-mail.c revision 8000c86be02008b74acc71fa422444dc432e2c01
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (C) 2003-2006 Timo Sirainen */
c0757c70cfd2c9b44de3504b753a4d2f38690ef0Timo Sirainenstatic void mbox_prepare_resync(struct index_mail *mail)
b624773984e35dd894db8dff976c1a2114c70782Timo Sirainen (struct mbox_transaction_context *)mail->trans;
5afc76d0215c5f7631dec06ef864d59f0686a0a8Timo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainenstatic int mbox_mail_seek(struct index_mail *mail)
be5c76fabc7439fd33bc799bc3ab3f570799977bTimo Sirainen (struct mbox_transaction_context *)mail->trans;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
788a0754cfd38dcfec1902844b085e4e84cfe7e6Timo Sirainen /* refresh index file after mbox has been locked to make
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen sure we get only up-to-date mbox offsets. */
43d3ea2780b5f8557ede7b4c039e8f56cb8d357dTimo Sirainen if (mail_index_refresh(mbox->ibox.index) < 0) {
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen } else if ((sync_flags & MBOX_SYNC_FORCE_SYNC) != 0) {
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen /* dirty offsets are broken and mbox is write-locked.
f93c833d644ecff0b0f80bee4f1cdde3e697b5c8Timo Sirainen sync it to update offsets. */
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen ret = mbox_file_seek(mbox, mail->trans->trans_view,
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen /* we'll need to re-sync it completely */
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC;
31597236d79ac38a5cea7ab65a9d0a3df64ed201Timo Sirainenstatic time_t mbox_mail_get_received_date(struct mail *_mail)
83d2e37f065eabe38dc92db485c5ca39ee43ce05Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
83d2e37f065eabe38dc92db485c5ca39ee43ce05Timo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
e0a84bcd487b05872da59781452168609b5c1f2cTimo Sirainen istream_raw_mbox_get_received_time(mbox->mbox_stream);
e0a84bcd487b05872da59781452168609b5c1f2cTimo Sirainen /* it's broken and conflicts with our "not found"
e0a84bcd487b05872da59781452168609b5c1f2cTimo Sirainen return value. change it. */
50168536f8d04626d71860c73b2efc18d407d083Aki Tuomi index_mail_cache_add(mail, MAIL_CACHE_RECEIVED_DATE, &t, sizeof(t));
798cfe56c9871262770384da1239162b3800cce1Timo Sirainenstatic time_t mbox_mail_get_save_date(struct mail *_mail)
798cfe56c9871262770384da1239162b3800cce1Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen /* no way to know this. save the current time into cache and use
d1ba8ecbb936ace90179d2292952546708d68f71Timo Sirainen that from now on. this works only as long as the index files
c0757c70cfd2c9b44de3504b753a4d2f38690ef0Timo Sirainen are permanent */
4b1781e4c64be52e25b5994e5242dbe696cc7d29Timo Sirainen index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE,
c0757c70cfd2c9b44de3504b753a4d2f38690ef0Timo Sirainenstatic const char *
798cfe56c9871262770384da1239162b3800cce1Timo Sirainenmbox_mail_get_special(struct mail *_mail, enum mail_fetch_field field)
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo Sirainen#define EMPTY_MD5_SUM "00000000000000000000000000000000"
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
e0a84bcd487b05872da59781452168609b5c1f2cTimo Sirainen return istream_raw_mbox_get_sender(mbox->mbox_stream);
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo Sirainen if (value != NULL && strcmp(value, EMPTY_MD5_SUM) != 0)
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo Sirainen /* i guess in theory the EMPTY_MD5_SUM is valid and can happen,
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo Sirainen but it's almost guaranteed that it means the MD5 sum is
a138ac12134564b151f00fdef86fba9cd9ba8af0Timo Sirainen missing. recalculate it. */
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen if (mbox_sync(mbox, MBOX_SYNC_FORCE_SYNC) < 0)
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainenstatic uoff_t mbox_mail_get_physical_size(struct mail *_mail)
6e5a4cdf7ef123589e2409e0012b1024c97957d5Aki Tuomi struct index_mail *mail = (struct index_mail *)_mail;
6e5a4cdf7ef123589e2409e0012b1024c97957d5Aki Tuomi struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
865a82c1e9bba11609835a36674964649025bf77Timo Sirainen /* our header size varies, so don't do any caching */
b0e9375a1ff97c9c7d40655922af5ccc73ecaa76Timo Sirainen hdr_offset = istream_raw_mbox_get_header_offset(stream);
b0e9375a1ff97c9c7d40655922af5ccc73ecaa76Timo Sirainen body_offset = istream_raw_mbox_get_body_offset(stream);
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen body_size = istream_raw_mbox_get_body_size(stream, (uoff_t)-1);
82f53ea81671bcc7b9bf24a34b04a4ba2752efd3Timo Sirainen data->physical_size = (body_offset - hdr_offset) + body_size;
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainenstatic struct istream *mbox_mail_get_stream(struct mail *_mail,
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
2e29e4797a48d78d669821722bdb54fd0a1d3b94Timo Sirainen struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox;
e9503210d3521a6833ed62dc332fc42ffb0e7a13Timo Sirainen offset = istream_raw_mbox_get_header_offset(raw_stream);
31597236d79ac38a5cea7ab65a9d0a3df64ed201Timo Sirainen raw_stream = i_stream_create_limit(default_pool, raw_stream,