Skip to content

Commit

Permalink
lib-storage: move snippet generation to mail-save-finish
Browse files Browse the repository at this point in the history
This is necessary because some storage backends (most notably sdbox) do
not allow getting the mail stream before the mail is fully written out.
(See written_to_disk in sdbox-file.h.)

If we could avoid getting the stream to generate a snippet we could
leave this where it is.
  • Loading branch information
Josef 'Jeff' Sipek authored and sirainen committed Feb 19, 2018
1 parent 9733a20 commit eb34def
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/lib-storage/index/index-mail.c
Expand Up @@ -72,6 +72,7 @@ struct mail_cache_field global_cache_fields[MAIL_INDEX_CACHE_FIELD_COUNT] = {
static void index_mail_init_data(struct index_mail *mail);
static int index_mail_parse_body(struct index_mail *mail,
enum index_cache_field field);
static int index_mail_write_body_snippet(struct index_mail *mail);

int index_mail_cache_lookup_field(struct index_mail *mail, buffer_t *buf,
unsigned int field_idx)
Expand Down Expand Up @@ -861,8 +862,14 @@ index_mail_want_cache(struct index_mail *mail, enum index_cache_field field)
}
}

static void index_mail_body_parsed_cache_body_snippet(struct index_mail *mail)
static void index_mail_save_finish_make_snippet(struct index_mail *mail)
{
if (mail->data.save_body_snippet) {
if (index_mail_write_body_snippet(mail) < 0)
return;
mail->data.save_body_snippet = FALSE;
}

if (mail->data.body_snippet != NULL &&
index_mail_want_cache(mail, MAIL_CACHE_BODY_SNIPPET)) {
index_mail_cache_add(mail, MAIL_CACHE_BODY_SNIPPET,
Expand Down Expand Up @@ -1093,11 +1100,6 @@ index_mail_parse_body_finish(struct index_mail *mail,
mail->data.save_bodystructure_body = FALSE;
i_assert(mail->data.parts != NULL);
}
if (mail->data.save_body_snippet) {
if (index_mail_write_body_snippet(mail) < 0)
return -1;
mail->data.save_body_snippet = FALSE;
}

if (mail->data.no_caching) {
/* if we're here because we aborted parsing, don't get any
Expand All @@ -1111,7 +1113,6 @@ index_mail_parse_body_finish(struct index_mail *mail,
index_mail_body_parsed_cache_flags(mail);
index_mail_body_parsed_cache_message_parts(mail);
index_mail_body_parsed_cache_bodystructure(mail, field);
index_mail_body_parsed_cache_body_snippet(mail);
index_mail_cache_sizes(mail);
index_mail_cache_dates(mail);
return 0;
Expand Down Expand Up @@ -1358,6 +1359,15 @@ static int index_mail_parse_bodystructure(struct index_mail *mail,
}
break;
case MAIL_CACHE_BODY_SNIPPET:
if (data->body_snippet == NULL) {
if (index_mail_write_body_snippet(mail) < 0)
return -1;

if (index_mail_want_cache(mail, MAIL_CACHE_BODY_SNIPPET))
index_mail_cache_add(mail, MAIL_CACHE_BODY_SNIPPET,
mail->data.body_snippet,
strlen(mail->data.body_snippet) + 1);
}
i_assert(data->body_snippet != NULL &&
data->body_snippet[0] != '\0');
break;
Expand Down Expand Up @@ -2383,6 +2393,8 @@ void index_mail_save_finish(struct mail_save_context *ctx)
{
struct index_mail *imail = INDEX_MAIL(ctx->dest_mail);

index_mail_save_finish_make_snippet(imail);

if (ctx->data.from_envelope != NULL &&
imail->data.from_envelope == NULL) {
imail->data.from_envelope =
Expand Down

0 comments on commit eb34def

Please sign in to comment.