static struct istream * maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail, bool *deleted_r) { struct istream *input; const char *path; struct maildir_open_context ctx; *deleted_r = FALSE; ctx.fd = -1; ctx.path = NULL; mail->transaction->stats.open_lookup_count++; if (!mail->saving) { if (maildir_file_do(mbox, mail->uid, do_open, &ctx) < 0) return NULL; } else { path = maildir_save_file_get_path(mail->transaction, mail->seq); if (do_open(mbox, path, &ctx) <= 0) return NULL; } if (ctx.fd == -1) { *deleted_r = TRUE; return NULL; } input = i_stream_create_fd_autoclose(&ctx.fd, 0); if (input->stream_errno == EISDIR) { i_stream_destroy(&input); if (maildir_lose_unexpected_dir(&mbox->storage->storage, ctx.path) >= 0) *deleted_r = TRUE; } else { i_stream_set_name(input, ctx.path); index_mail_set_read_buffer_size(mail, input); } i_free(ctx.path); return input; }
static int maildir_expunge(struct maildir_mailbox *mbox, const char *path, struct maildir_index_sync_context *ctx) { struct mailbox *box = &mbox->box; ctx->expunge_count++; if (unlink(path) == 0) { if (box->v.sync_notify != NULL) { box->v.sync_notify(box, ctx->uid, MAILBOX_SYNC_TYPE_EXPUNGE); } return 1; } if (errno == ENOENT) return 0; if (UNLINK_EISDIR(errno)) return maildir_lose_unexpected_dir(box->storage, path); mail_storage_set_critical(&mbox->storage->storage, "unlink(%s) failed: %m", path); return -1; }