static int imapc_mail_get_stream(struct mail *_mail, bool get_body, struct message_size *hdr_size, struct message_size *body_size, struct istream **stream_r) { struct imapc_mail *mail = (struct imapc_mail *)_mail; struct index_mail_data *data = &mail->imail.data; enum mail_fetch_field fetch_field; if (get_body && !mail->body_fetched && mail->imail.data.stream != NULL) { /* we've fetched the header, but we need the body now too */ index_mail_close_streams(&mail->imail); } if (data->stream == NULL) { if (!data->initialized) { /* coming here from mail_set_seq() */ mail_set_aborted(_mail); return -1; } fetch_field = get_body || (data->access_part & READ_BODY) != 0 ? MAIL_FETCH_STREAM_BODY : MAIL_FETCH_STREAM_HEADER; if (imapc_mail_fetch(_mail, fetch_field) < 0) return -1; if (data->stream == NULL) { if (imapc_mail_failed(_mail, "BODY[]") < 0) return -1; i_assert(data->stream == NULL); /* this could be either a temporary server bug, or the server may permanently just not return anything for this mail. the latter happens at least with Exchange when trying to fetch calendar "mails", so we'll just return them as empty mails instead of disconnecting the client. */ mail->body_fetched = TRUE; data->stream = i_stream_create_from_data(&uchar_nul, 0); imapc_mail_init_stream(mail, TRUE); } } return index_mail_init_stream(&mail->imail, hdr_size, body_size, stream_r); }
static int imapc_mail_get_stream(struct mail *_mail, bool get_body, struct message_size *hdr_size, struct message_size *body_size, struct istream **stream_r) { struct imapc_mail *mail = (struct imapc_mail *)_mail; struct index_mail_data *data = &mail->imail.data; enum mail_fetch_field fetch_field; if (get_body && !mail->body_fetched && mail->imail.data.stream != NULL) { /* we've fetched the header, but we need the body now too */ index_mail_close_streams(&mail->imail); } if (data->stream == NULL) { if (!data->initialized) { /* coming here from mail_set_seq() */ mail_set_aborted(_mail); return -1; } fetch_field = get_body || (data->access_part & READ_BODY) != 0 ? MAIL_FETCH_STREAM_BODY : MAIL_FETCH_STREAM_HEADER; if (imapc_mail_fetch(_mail, fetch_field, NULL) < 0) return -1; if (data->stream == NULL) { if (imapc_mail_failed(_mail, "BODY[]")) return -1; i_assert(data->stream == NULL); /* return the broken email as empty */ mail->body_fetched = TRUE; data->stream = i_stream_create_from_data(NULL, 0); imapc_mail_init_stream(mail); } } return index_mail_init_stream(&mail->imail, hdr_size, body_size, stream_r); }