]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 30 Apr 2018 12:42:08 +0000 (15:42 +0300)
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c
src/lib-storage/mail.c

index a6c0ce2aad501ca2a3b6b50691a6e7d3d474ecfb..e86698073732b7784e2815813cbc0803432c36d4 100644 (file)
@@ -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);
index da3553251f02edee87d78701c698aeec6ab3f899..458b0e31d2e12fd12fb30ec2c3c0ed430cb624a0 100644 (file)
@@ -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);
index 1f7d60db6965461b676f292431307dc0e1ac1415..586fc587ad2323c8731b58876b5df8c71db25184 100644 (file)
@@ -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));
 
@@ -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;
 }