maildir-mail.c revision b093b87c303d420bd14aeb53498f881ef2944aa0
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen/* Copyright (C) 2003 Timo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic int do_open(struct index_mailbox *ibox, const char *path, void *context)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic int do_stat(struct index_mailbox *ibox, const char *path, void *context)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct istream *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenmaildir_open_mail(struct index_mailbox *ibox, uint32_t uid, int *deleted)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (maildir_file_do(ibox, uid, do_open, &fd) < 0)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic time_t maildir_mail_get_received_date(struct mail *_mail)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct index_mail *mail = (struct index_mail *) _mail;
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen if (data->open_mail && data->stream == NULL) {
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainen /* we're going to open the mail anyway */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_storage_set_critical(mail->ibox->box.storage,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "fstat(maildir) failed: %m");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (maildir_file_do(mail->ibox, 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;
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 fname = maildir_uidlist_lookup(mail->ibox->uidlist,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* size can be included in filename */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen virtual_size = virtual_size * 10 + (*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;
366d6311c9d5bac6613e3cd64619eb878adce9ecTimo Sirainen fname = maildir_uidlist_lookup(mail->ibox->uidlist,
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;
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen const char *fname, *p;
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen fname = maildir_uidlist_lookup(mail->ibox->uidlist,
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen /* size can be included in filename */
d67fde1a8ebc1d85704c5986d8f93aae97eccef3Timo Sirainen if (maildir_file_do(mail->ibox, 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,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen struct index_mail *mail = (struct index_mail *) _mail;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen data->stream = maildir_open_mail(mail->ibox, mail->mail.uid,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen return index_mail_init_stream(mail, hdr_size, body_size);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen 0, 0, 0, 0, 0, 0,