From: Aki Tuomi Date: Thu, 19 Apr 2018 07:19:15 +0000 (+0300) Subject: lib-storage: Add error reporting to mail_set_attachment_keywords X-Git-Tag: 2.3.2.rc1~158 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=86e5047a0d609b63f00ef491b71ca04d94146c0f;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Add error reporting to mail_set_attachment_keywords --- diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index d08959970f..20d22ab3ca 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -780,8 +780,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); diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 52317bb9a8..72ee4a66c8 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -2516,7 +2516,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); diff --git a/src/lib-storage/mail.c b/src/lib-storage/mail.c index ac9ca5a070..9564fcf999 100644 --- a/src/lib-storage/mail.c +++ b/src/lib-storage/mail.c @@ -471,8 +471,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)); @@ -498,24 +499,27 @@ void mail_set_attachment_keywords(struct mail *mail) mail_set_critical(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_set_critical(mail, "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; }