diff -r 73a3a6b1af36 src/lib-storage/index/index-mail.c --- a/src/lib-storage/index/index-mail.c Sun Nov 18 20:13:59 2007 +0200 +++ b/src/lib-storage/index/index-mail.c Tue Nov 20 05:48:19 2007 +0200 @@ -763,12 +763,26 @@ index_mail_alloc(struct mailbox_transact static void index_mail_close(struct index_mail *mail) { - if (mail->data.parser_ctx != NULL) - (void)message_parser_deinit(&mail->data.parser_ctx); - if (mail->data.stream != NULL) - i_stream_destroy(&mail->data.stream); - if (mail->data.filter_stream != NULL) - i_stream_destroy(&mail->data.filter_stream); + if (mail->data.stream != NULL && mail->data.stream->v_offset != 0 && + strcmp(mail->mail.mail.box->storage->name, "maildir") == 0) { + /* drop the data that has been read by the client. with partial + fetches we drop only what has been read so far. + + if we read the mail just to return e.g. virtual size or + bodystructure, v_offset=0 and we don't drop anything since + there's a good chance that the client will soon fetch the + mail body. */ + int fd = i_stream_get_fd(mail->data.stream); + if (posix_fadvise(fd, 0, mail->data.stream->v_offset, + POSIX_FADV_DONTNEED) < 0) + i_error("posix_fadvise() failed: %m"); + } + if (mail->data.parser_ctx != NULL) + (void)message_parser_deinit(&mail->data.parser_ctx); + if (mail->data.stream != NULL) + i_stream_destroy(&mail->data.stream); + if (mail->data.filter_stream != NULL) + i_stream_destroy(&mail->data.filter_stream); } int index_mail_set_seq(struct mail *_mail, uint32_t seq) diff -r 73a3a6b1af36 src/lib-storage/index/maildir/maildir-mail.c --- a/src/lib-storage/index/maildir/maildir-mail.c Sun Nov 18 20:13:59 2007 +0200 +++ b/src/lib-storage/index/maildir/maildir-mail.c Tue Nov 20 05:48:19 2007 +0200 @@ -45,6 +45,7 @@ maildir_open_mail(struct maildir_mailbox maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail, bool *deleted_r) { + struct index_mail *imail = (struct index_mail *)mail; const char *path; int fd = -1; @@ -62,6 +63,10 @@ maildir_open_mail(struct maildir_mailbox if (fd == -1) { *deleted_r = TRUE; return NULL; + } + if ((imail->data.access_part & (READ_BODY|PARSE_BODY)) != 0) { + if (posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL) < 0) + i_error("posix_fadvise() failed: %m"); } if (mbox->ibox.mail_read_mmaped) {