maildir-mail.c revision 052e0c9dc04dcdc74e136d12c6d7dea2c635bf51
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (C) 2003 Timo Sirainen */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainendo_open(struct maildir_mailbox *mbox, const char *path, void *context)
8153fdec343e40e2a78f5c12353e89b994b28f74Timo Sirainen mail_storage_set_critical(STORAGE(mbox->storage),
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainendo_stat(struct maildir_mailbox *mbox, const char *path, void *context)
8153fdec343e40e2a78f5c12353e89b994b28f74Timo Sirainen mail_storage_set_critical(STORAGE(mbox->storage),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct istream *
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenmaildir_open_mail(struct maildir_mailbox *mbox, uint32_t uid, int *deleted)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen if (maildir_file_do(mbox, uid, do_open, &fd) < 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic time_t maildir_mail_get_received_date(struct mail *_mail)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen if (data->open_mail && data->stream == NULL) {
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen /* we're going to open the mail anyway */
8153fdec343e40e2a78f5c12353e89b994b28f74Timo Sirainen mail_storage_set_critical(STORAGE(mbox->storage),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "fstat(maildir) failed: %m");
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen if (maildir_file_do(mbox, mail->mail.mail.uid,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen mail_cache_add(mail->trans->cache_trans, mail->data.seq,
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen &data->received_date, sizeof(data->received_date));
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;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen const char *fname, *p;
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen if ((mail->wanted_fields & MAIL_FETCH_VIRTUAL_SIZE) == 0) {
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen data->virtual_size = index_mail_get_cached_virtual_size(mail);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* size can be included in filename */
052e0c9dc04dcdc74e136d12c6d7dea2c635bf51Timo Sirainen p = strstr(fname, MAILDIR_EXTRA_SEP_S MAILDIR_EXTRA_VIRTUAL_SIZE "=");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen virtual_size = virtual_size * 10 + (*p - '0');
8754bb7a1f24705ffa5434f9e10d57e0b3b88d6eTimo Sirainen if (*p == MAILDIR_INFO_SEP || *p == MAILDIR_EXTRA_SEP ||
8754bb7a1f24705ffa5434f9e10d57e0b3b88d6eTimo Sirainen *p == '\0') {
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen mail_cache_add(mail->trans->cache_trans, mail->data.seq,
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;
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;
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen const char *fname, *p;
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen /* size can be included in filename */
052e0c9dc04dcdc74e136d12c6d7dea2c635bf51Timo Sirainen p = strstr(fname, MAILDIR_EXTRA_SEP_S MAILDIR_EXTRA_FILE_SIZE "=");
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen if (maildir_file_do(mbox, mail->mail.mail.uid,
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen mail_cache_add(mail->trans->cache_trans, mail->data.seq,
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen MAIL_CACHE_PHYSICAL_FULL_SIZE, &size, sizeof(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;