static int mail_storage_try_copy(struct mail_save_context **_ctx, struct mail *mail) { struct mail_save_context *ctx = *_ctx; struct mail_private *pmail = (struct mail_private *)mail; struct istream *input; ctx->copying_via_save = TRUE; /* we need to open the file in any case. caching metadata is unlikely to help anything. */ pmail->v.set_uid_cache_updates(mail, TRUE); if (mail_get_stream_because(mail, NULL, NULL, "copying", &input) < 0) { mail_copy_set_failed(ctx, mail, "stream"); return -1; } if (mail_save_copy_default_metadata(ctx, mail) < 0) return -1; if (mailbox_save_begin(_ctx, input) < 0) return -1; ssize_t ret; do { if (mailbox_save_continue(ctx) < 0) break; ret = i_stream_read(input); i_assert(ret != 0); } while (ret != -1); if (input->stream_errno != 0) { mail_storage_set_critical(ctx->transaction->box->storage, "copy: i_stream_read(%s) failed: %s", i_stream_get_name(input), i_stream_get_error(input)); return -1; } return 0; }
int mail_get_stream(struct mail *mail, struct message_size *hdr_size, struct message_size *body_size, struct istream **stream_r) { return mail_get_stream_because(mail, hdr_size, body_size, "mail stream", stream_r); }