]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add error reporting to mail_set_attachment_keywords
authorAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 19 Apr 2018 07:19:15 +0000 (10:19 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 27 Apr 2018 06:29:44 +0000 (09:29 +0300)
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail.c

index d08959970f025d21e33eca1e24595336979a2e69..20d22ab3ca08225c8337f614c4d11ed6aa159bdb 100644 (file)
@@ -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);
index 52317bb9a8b31091f81829e33dcc921192f25314..72ee4a66c8d58f8cd09b898710c8e61a3d19a61f 100644 (file)
@@ -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);
index ac9ca5a0700cb4e1e0595b080bacc5f1bc5fb77d..9564fcf99947ff433a87df5253430a9c31b93442 100644 (file)
@@ -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;
 }