changeset 22925:8307cbdd18bc

lib-storage: Add error reporting to mail_set_attachment_keywords
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Thu, 19 Apr 2018 10:19:15 +0300
parents 517b40c65bc5
children 1e7e7ea7482d
files src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail.c
diffstat 3 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage-private.h	Wed Apr 25 15:20:58 2018 +0300
+++ b/src/lib-storage/mail-storage-private.h	Thu Apr 19 10:19:15 2018 +0300
@@ -784,8 +784,9 @@
 /* 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);
--- a/src/lib-storage/mail-storage.c	Wed Apr 25 15:20:58 2018 +0300
+++ b/src/lib-storage/mail-storage.c	Thu Apr 19 10:19:15 2018 +0300
@@ -2458,7 +2458,7 @@
 
 	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);
--- a/src/lib-storage/mail.c	Wed Apr 25 15:20:58 2018 +0300
+++ b/src/lib-storage/mail.c	Thu Apr 19 10:19:15 2018 +0300
@@ -496,8 +496,9 @@
 		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 @@
 			"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;
 }