Skip to content

Commit

Permalink
lib-storage: Add error reporting to mail_set_attachment_keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse authored and sirainen committed Apr 30, 2018
1 parent 60af6cf commit 750d79a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/lib-storage/mail-storage-private.h
Expand Up @@ -784,8 +784,9 @@ void mail_set_seq_saving(struct mail *mail, uint32_t seq);
/* Returns true IF and only IF the mail has EITHER one of the
attachment keywords set. If it has both, or none, it will return FALSE. */
bool mail_has_attachment_keywords(struct mail *mail);
/* Sets attachment keywords. */
void mail_set_attachment_keywords(struct mail *mail);
/* Sets attachment keywords. Returns -1 on error, 0 when no attachment(s) found,
and 1 if attachment was found. */
int mail_set_attachment_keywords(struct mail *mail);

void mailbox_set_deleted(struct mailbox *box);
int mailbox_mark_index_deleted(struct mailbox *box, bool del);
Expand Down
2 changes: 1 addition & 1 deletion src/lib-storage/mail-storage.c
Expand Up @@ -2458,7 +2458,7 @@ int mailbox_save_finish(struct mail_save_context **_ctx)

if (mail_set->parsed_mail_attachment_detection_add_flags_on_save &&
!mail_has_attachment_keywords(ctx->dest_mail))
mail_set_attachment_keywords(ctx->dest_mail);
(void)mail_set_attachment_keywords(ctx->dest_mail);

if (keywords != NULL)
mailbox_keywords_unref(&keywords);
Expand Down
19 changes: 12 additions & 7 deletions src/lib-storage/mail.c
Expand Up @@ -496,8 +496,9 @@ bool mail_has_attachment_keywords(struct mail *mail)
str_array_icase_find(kw, MAIL_KEYWORD_HAS_NO_ATTACHMENT));
}

void mail_set_attachment_keywords(struct mail *mail)
int mail_set_attachment_keywords(struct mail *mail)
{
int ret;
const struct mail_storage_settings *mail_set =
mail_storage_get_settings(mailbox_get_storage(mail->box));

Expand All @@ -524,24 +525,28 @@ void mail_set_attachment_keywords(struct mail *mail)
"Failed to add attachment keywords: "
"mail_get_parts() failed: %s",
mail_storage_get_last_internal_error(mail->box->storage, NULL));
return;
ret = -1;
} else if (mailbox_keywords_create(mail->box, keyword_has_attachment, &kw_has) < 0 ||
mailbox_keywords_create(mail->box, keyword_has_no_attachment, &kw_has_not) < 0) {
if (mail_set->mail_debug) {
i_debug("Failed to add attachment keywords: mailbox_keyword_create(%s) failed: %s",
mailbox_get_vname(mail->box),
mail_storage_get_last_error(mail->box->storage, NULL));
}
mail_storage_set_critical(mail->box->storage,
"Failed to add attachment keywords: "
"mailbox_keywords_create(%s) failed: %s",
mailbox_get_vname(mail->box),
mail_storage_get_last_internal_error(mail->box->storage, NULL));
ret = -1;
} else {
bool has_attachment = mail_message_has_attachment(parts, &set);

/* make sure only one of the keywords gets set */
mail_update_keywords(mail, MODIFY_REMOVE, has_attachment ? kw_has_not : kw_has);
mail_update_keywords(mail, MODIFY_ADD, has_attachment ? kw_has : kw_has_not);
ret = has_attachment ? 1 : 0;
}

if (kw_has != NULL)
mailbox_keywords_unref(&kw_has);
if (kw_has_not != NULL)
mailbox_keywords_unref(&kw_has_not);

return ret;
}

0 comments on commit 750d79a

Please sign in to comment.