maildir-mail.c revision 3ec2c1f31631bb5ff86f5fc93a563c33e5cae90d
76b43e4417bab52e913da39b5f5bc2a130d3f149Timo Sirainen/* Copyright (C) 2003 Timo Sirainen */
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainendo_open(struct maildir_mailbox *mbox, const char *path, int *fd)
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainendo_stat(struct maildir_mailbox *mbox, const char *path, struct stat *st)
af1f4b17a92ca7b2661737e65c7849df289d3070Timo Sirainen mail_storage_set_critical(&mbox->storage->storage,
01cbf4ac5d44137ab434791be7f838d98d0fcf3bTimo Sirainenstatic struct istream *
4b41116563110d00330896a568eff1078c382827Timo Sirainenmaildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail,
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen if (maildir_file_do(mbox, mail->uid, do_open, &fd) < 0)
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen path = maildir_save_file_get_path(mail->transaction, mail->seq);
597dce34068d603fb759b4dff404b34049213e51Timo Sirainenstatic int maildir_mail_stat(struct mail *mail, struct stat *st)
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->box;
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen struct index_mail_data *data = &((struct index_mail *)mail)->data;
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen if (data->access_part != 0 && data->stream == NULL) {
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen /* we're going to open the mail anyway */
7f773564b94e6054a40d3785cb63c29f1e4d4deeTimo Sirainen mail_storage_set_critical(&mbox->storage->storage,
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen "fstat(maildir) failed: %m");
fe6c1556d3529a6376d4cbb3766c34aebde0de99Timo Sirainen if (maildir_file_do(mbox, mail->uid, do_stat, st) <= 0)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen path = maildir_save_file_get_path(mail->transaction, mail->seq);
ae1b268ffff743ad9927c304a1344c5cbd7f909dTimo Sirainenstatic time_t maildir_mail_get_received_date(struct mail *_mail)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo 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;
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen index_mail_cache_add(mail, MAIL_CACHE_SAVE_DATE, &t, sizeof(t));
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainenmaildir_mail_get_fname(struct maildir_mailbox *mbox, struct mail *mail,
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen const char **fname_r)
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen *fname_r = maildir_uidlist_lookup(mbox->uidlist, mail->uid, &flags);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenstatic uoff_t maildir_mail_get_virtual_size(struct mail *_mail)
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
a0b0d629931773c17a236f6214adbe0e13b9b3fdTimo Sirainen if ((mail->wanted_fields & MAIL_FETCH_VIRTUAL_SIZE) == 0) {
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen data->virtual_size = index_mail_get_cached_virtual_size(mail);
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen if (!maildir_mail_get_fname(mbox, _mail, &fname))
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen path = maildir_save_file_get_path(_mail->transaction,
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen /* size can be included in filename */
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen if (maildir_filename_get_size(fname, MAILDIR_EXTRA_VIRTUAL_SIZE,
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen index_mail_cache_add(mail, MAIL_CACHE_VIRTUAL_FULL_SIZE,
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainenstatic const char *
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainenmaildir_mail_get_special(struct mail *_mail, enum mail_fetch_field field)
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen if (!maildir_mail_get_fname(mbox, _mail, &fname))
a5c8dc283ef673fcdae158513b8032e74b45f59aTimo Sirainen path = maildir_save_file_get_path(_mail->transaction,
a5c8dc283ef673fcdae158513b8032e74b45f59aTimo Sirainen return end == NULL ? fname : t_strdup_until(fname, end);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainenstatic uoff_t maildir_mail_get_physical_size(struct mail *_mail)
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
aa215ab623706463cea1d047f975ffe51d3f0c05Timo Sirainen if (!maildir_mail_get_fname(mbox, _mail, &fname))
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen path = maildir_save_file_get_path(_mail->transaction,
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen /* size can be included in filename */
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen if (!maildir_filename_get_size(fname, MAILDIR_EXTRA_FILE_SIZE, &size)) {
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen /* saved mail which hasn't been committed yet */
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen index_mail_cache_add(mail, MAIL_CACHE_PHYSICAL_FULL_SIZE,
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainenstatic struct istream *maildir_mail_get_stream(struct mail *_mail,
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen struct index_mail *mail = (struct index_mail *)_mail;
64a67c0296b120b6e15169ac9d84dec964e55969Timo Sirainen struct maildir_mailbox *mbox = (struct maildir_mailbox *)mail->ibox;
59151b71059df1190acd75d8717ed04a7920c862Timo Sirainen data->stream = maildir_open_mail(mbox, _mail, &deleted);