maildir-mail.c revision ccc895c0358108d2304239063e940b7d75f364ab
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (C) 2003 Timo Sirainen */
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainendo_open(struct maildir_mailbox *mbox, const char *path, int *fd)
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
2cfe9983ce7a6280636ee12beccc2e865111967bTimo Sirainendo_stat(struct maildir_mailbox *mbox, const char *path, struct stat *st)
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct istream *
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainenmaildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail,
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen if (maildir_file_do(mbox, mail->uid, do_open, &fd) < 0)
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen path = maildir_save_file_get_path(mail->transaction, mail->seq);
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainenstatic int maildir_mail_stat(struct mail *mail, struct stat *st)
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->box;
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen struct index_mail_data *data = &((struct index_mail *)mail)->data;
55773f17bccf6361d6599ffcbe072d7c9fe205bfTimo Sirainen if (data->access_part != 0 && data->stream == NULL) {
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen /* we're going to open the mail anyway */
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "fstat(maildir) failed: %m");
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen if (maildir_file_do(mbox, mail->uid, do_stat, st) <= 0)
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen path = maildir_save_file_get_path(mail->transaction, mail->seq);
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainenstatic time_t maildir_mail_get_received_date(struct mail *_mail)
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
8000c86be02008b74acc71fa422444dc432e2c01Timo Sirainen index_mail_cache_add(mail, MAIL_CACHE_RECEIVED_DATE, &t, sizeof(t));
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainenstatic time_t maildir_mail_get_save_date(struct mail *_mail)
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
a63bc30f167a221691ad0a3fe5cd45c57444411eTimo Sirainen index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainenstatic uoff_t maildir_mail_get_virtual_size(struct mail *_mail)
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen if ((mail->wanted_fields & MAIL_FETCH_VIRTUAL_SIZE) == 0) {
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen data->virtual_size = index_mail_get_cached_virtual_size(mail);
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen fname = maildir_uidlist_lookup(mbox->uidlist, _mail->uid,
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen path = maildir_save_file_get_path(_mail->transaction,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* size can be included in filename */
677e22747b82bf15b339e31d1d0106d62bf806daTimo Sirainen if (maildir_filename_get_size(fname, MAILDIR_EXTRA_VIRTUAL_SIZE,
677e22747b82bf15b339e31d1d0106d62bf806daTimo Sirainen index_mail_cache_add(mail, MAIL_CACHE_VIRTUAL_FULL_SIZE,
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainenstatic const char *
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainenmaildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field)
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen path = maildir_save_file_get_path(_mail->transaction,
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen return end == NULL ? fname : t_strdup_until(fname, end);
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainenstatic uoff_t maildir_mail_get_physical_size(struct mail *_mail)
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen fname = maildir_uidlist_lookup(mbox->uidlist, _mail->uid,
b142deb9a831c89b1bb9129ada655f3e56b9d4ccTimo Sirainen path = maildir_save_file_get_path(_mail->transaction,
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen /* size can be included in filename */
677e22747b82bf15b339e31d1d0106d62bf806daTimo Sirainen if (!maildir_filename_get_size(fname, MAILDIR_EXTRA_FILE_SIZE, &size)) {
677e22747b82bf15b339e31d1d0106d62bf806daTimo Sirainen /* saved mail which hasn't been committed yet */
97511ac4d7607e1ba64ce151eda3d9b5f9775519Timo Sirainen index_mail_cache_add(mail, MAIL_CACHE_PHYSICAL_FULL_SIZE,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct istream *maildir_mail_get_stream(struct mail *_mail,
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
b6a7e0a7899e7f5d60c23cdaa50e025e4c67d05fTimo Sirainen data->stream = maildir_open_mail(mbox, _mail, &deleted);