changeset 21814:759962e70148

global: Log internal storage error on failure
author Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
date Thu, 16 Mar 2017 11:15:18 +0200
parents f01959514217
children 920e7214f3b4
files src/doveadm/doveadm-mail-altmove.c src/doveadm/doveadm-mail-copymove.c src/doveadm/doveadm-mail-deduplicate.c src/doveadm/doveadm-mail-expunge.c src/doveadm/doveadm-mail-fetch.c src/doveadm/doveadm-mail-flags.c src/doveadm/doveadm-mail-import.c src/doveadm/doveadm-mail-index.c src/doveadm/doveadm-mail-iter.c src/doveadm/doveadm-mail-mailbox-metadata.c src/doveadm/doveadm-mail-mailbox-status.c src/doveadm/doveadm-mail-mailbox.c src/doveadm/doveadm-mail-save.c src/doveadm/doveadm-mail-search.c src/doveadm/doveadm-mail.c src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c src/doveadm/dsync/dsync-brain-mailbox.c src/doveadm/dsync/dsync-brain.c src/doveadm/dsync/dsync-mailbox-export.c src/doveadm/dsync/dsync-mailbox-import.c src/doveadm/dsync/dsync-mailbox-tree-fill.c src/imap/imap-state.c src/indexer/master-connection.c src/lda/main.c src/lib-imap-urlauth/imap-urlauth-backend.c src/lib-lda/mail-deliver.c src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c src/lib-storage/index/index-mailbox-size.c src/lib-storage/mail-autoexpunge.c src/lib-storage/mail-storage.c src/lib-storage/mailbox-guid-cache.c src/lmtp/commands.c src/plugins/acl/doveadm-acl.c src/plugins/fts-lucene/fts-backend-lucene.c src/plugins/fts-lucene/lucene-wrapper.cc src/plugins/fts/fts-api.c src/plugins/fts/fts-build-mail.c src/plugins/lazy-expunge/lazy-expunge-plugin.c src/plugins/mail-crypt/doveadm-mail-crypt.c src/plugins/mail-crypt/mail-crypt-acl-plugin.c src/plugins/mail-crypt/mail-crypt-key.c src/plugins/mail-crypt/test-mail-key.c src/plugins/pop3-migration/pop3-migration-plugin.c src/plugins/push-notification/push-notification-driver-ox.c src/plugins/push-notification/push-notification-event-mailboxcreate.c src/plugins/quota/quota-count.c src/plugins/quota/quota.c src/pop3/pop3-client.c src/pop3/pop3-commands.c
diffstat 49 files changed, 234 insertions(+), 221 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/doveadm-mail-altmove.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-altmove.c	Thu Mar 16 11:15:18 2017 +0200
@@ -45,7 +45,7 @@
 {
 	if (mail_storage_purge(storage) < 0) {
 		i_error("Purging namespace '%s' failed: %s", ns->prefix,
-			mail_storage_get_last_error(storage, NULL));
+			mail_storage_get_last_internal_error(storage, NULL));
 		doveadm_mail_failed_storage(ctx, storage);
 		return -1;
 	}
--- a/src/doveadm/doveadm-mail-copymove.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-copymove.c	Thu Mar 16 11:15:18 2017 +0200
@@ -52,7 +52,7 @@
 			i_error("%s message UID %u from '%s' failed: %s",
 				ctx->move ? "Moving" : "Copying",
 				mail->uid, info->vname,
-				mailbox_get_last_error(destbox, NULL));
+				mailbox_get_last_internal_error(destbox, NULL));
 			doveadm_mail_failed_mailbox(&ctx->ctx, destbox);
 			ret = -1;
 		}
@@ -61,7 +61,7 @@
 	if (mailbox_transaction_commit(&desttrans) < 0) {
 		i_error("Committing %s mails failed: %s",
 			ctx->move ? "moved" : "copied",
-			mailbox_get_last_error(destbox, NULL));
+			mailbox_get_last_internal_error(destbox, NULL));
 		doveadm_mail_failed_mailbox(&ctx->ctx, destbox);
 		/* rollback expunges */
 		doveadm_mail_iter_deinit_rollback(&iter);
@@ -110,7 +110,7 @@
 	destbox = mailbox_alloc(ns->list, ctx->destname, MAILBOX_FLAG_SAVEONLY);
 	if (mailbox_open(destbox) < 0) {
 		i_error("Can't open mailbox '%s': %s", ctx->destname,
-			mailbox_get_last_error(destbox, NULL));
+			mailbox_get_last_internal_error(destbox, NULL));
 		doveadm_mail_failed_mailbox(&ctx->ctx, destbox);
 		mailbox_free(&destbox);
 		return -1;
@@ -128,7 +128,7 @@
 
 	if (mailbox_sync(destbox, 0) < 0) {
 		i_error("Syncing mailbox '%s' failed: %s", ctx->destname,
-			mailbox_get_last_error(destbox, NULL));
+			mailbox_get_last_internal_error(destbox, NULL));
 		doveadm_mail_failed_mailbox(&ctx->ctx, destbox);
 		ret = -1;
 	}
--- a/src/doveadm/doveadm-mail-deduplicate.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-deduplicate.c	Thu Mar 16 11:15:18 2017 +0200
@@ -51,14 +51,14 @@
 	if (mailbox_search_deinit(&search_ctx) < 0) {
 		i_error("Searching mailbox '%s' failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(_ctx, box);
 		ret = -1;
 	}
 	if (mailbox_transaction_commit(&trans) < 0) {
 		i_error("Committing mailbox '%s' transaction failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(_ctx, box);
 		ret = -1;
 	}
@@ -91,7 +91,7 @@
 	while (doveadm_mail_iter_next(iter, &mail)) {
 		if (ctx->by_msgid) {
 			if (mail_get_first_header(mail, "Message-ID", &key) < 0) {
-				errstr = mailbox_get_last_error(mail->box, &error);
+				errstr = mailbox_get_last_internal_error(mail->box, &error);
 				if (error == MAIL_ERROR_NOTFOUND)
 					continue;
 				i_error("Couldn't lookup Message-ID: for UID=%u: %s",
@@ -102,7 +102,7 @@
 			}
 		} else {
 			if (mail_get_special(mail, MAIL_FETCH_GUID, &key) < 0) {
-				errstr = mailbox_get_last_error(mail->box, &error);
+				errstr = mailbox_get_last_internal_error(mail->box, &error);
 				if (error == MAIL_ERROR_NOTFOUND)
 					continue;
 				i_error("Couldn't lookup GUID: for UID=%u: %s",
@@ -148,7 +148,7 @@
 	if (mailbox_sync(box, 0) < 0) {
 		i_error("Syncing mailbox '%s' failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(_ctx, box);
 		ret = -1;
 	}
--- a/src/doveadm/doveadm-mail-expunge.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-expunge.c	Thu Mar 16 11:15:18 2017 +0200
@@ -43,7 +43,7 @@
 	else if (mailbox_sync(box, 0) < 0) {
 		i_error("Syncing mailbox '%s' failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(_ctx, box);
 		ret = -1;
 	}
@@ -54,7 +54,7 @@
 			if (error != MAIL_ERROR_EXISTS) {
 				i_error("Deleting mailbox '%s' failed: %s",
 					mailbox_get_vname(box),
-					mailbox_get_last_error(box, NULL));
+					mailbox_get_last_internal_error(box, NULL));
 				doveadm_mail_failed_mailbox(_ctx, box);
 				ret = -1;
 			}
@@ -62,7 +62,7 @@
 			if (mailbox_set_subscribed(box, FALSE) < 0) {
 				i_error("Unsubscribing mailbox '%s' failed: %s",
 					mailbox_get_vname(box),
-					mailbox_get_last_error(box, NULL));
+					mailbox_get_last_internal_error(box, NULL));
 				doveadm_mail_failed_mailbox(_ctx, box);
 				ret = -1;
 			}
--- a/src/doveadm/doveadm-mail-fetch.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-fetch.c	Thu Mar 16 11:15:18 2017 +0200
@@ -589,7 +589,7 @@
 				field->name, mailbox_get_vname(mail->box),
 				mail->uid,
 				ctx->print_error != NULL ? ctx->print_error :
-				mailbox_get_last_error(mail->box, NULL));
+				mailbox_get_last_internal_error(mail->box, NULL));
 			doveadm_mail_failed_mailbox(&ctx->ctx, mail->box);
 			ctx->print_error = NULL;
 			ret = -1;
--- a/src/doveadm/doveadm-mail-flags.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-flags.c	Thu Mar 16 11:15:18 2017 +0200
@@ -33,7 +33,7 @@
 	if (ctx->keywords != NULL) {
 		if (mailbox_keywords_create(box, ctx->keywords, &kw) < 0) {
 			i_error("Invalid keywords: %s",
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			(void)doveadm_mail_iter_deinit(&iter);
 			ctx->ctx.exit_code = DOVEADM_EX_NOTPOSSIBLE;
 			return -1;
--- a/src/doveadm/doveadm-mail-import.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-import.c	Thu Mar 16 11:15:18 2017 +0200
@@ -64,7 +64,7 @@
 
 	box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_SAVEONLY);
 	if (mailbox_create(box, NULL, FALSE) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error != MAIL_ERROR_EXISTS) {
 			i_error("Couldn't create mailbox %s: %s", name, errstr);
 			doveadm_mail_failed_mailbox(&ctx->ctx, box);
@@ -75,12 +75,12 @@
 	if (ctx->subscribe) {
 		if (mailbox_set_subscribed(box, TRUE) < 0) {
 			i_error("Couldn't subscribe to mailbox %s: %s",
-				name, mailbox_get_last_error(box, NULL));
+				name, mailbox_get_last_internal_error(box, NULL));
 		}
 	}
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 		i_error("Syncing mailbox %s failed: %s", name,
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(&ctx->ctx, box);
 		mailbox_free(&box);
 		return -1;
@@ -110,14 +110,14 @@
 		if (mailbox_copy(&save_ctx, src_mail) < 0) {
 			i_error("Copying box=%s uid=%u failed: %s",
 				mailbox, src_mail->uid,
-				mailbox_get_last_error(dest_box, NULL));
+				mailbox_get_last_internal_error(dest_box, NULL));
 			ret = -1;
 		}
 	} while (doveadm_mail_iter_next(iter, &src_mail));
 
 	if (mailbox_transaction_commit(&dest_trans) < 0) {
 		i_error("Committing copied mails to %s failed: %s", mailbox,
-			mailbox_get_last_error(dest_box, NULL));
+			mailbox_get_last_internal_error(dest_box, NULL));
 		ret = -1;
 	}
 	return ret;
--- a/src/doveadm/doveadm-mail-index.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-index.c	Thu Mar 16 11:15:18 2017 +0200
@@ -41,12 +41,14 @@
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_PRECACHE_FIELDS,
 				 &metadata) < 0) {
 		i_error("Mailbox %s: Precache-fields lookup failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 	}
 	if (mailbox_get_status(box, STATUS_MESSAGES | STATUS_LAST_CACHED_SEQ,
 			       &status) < 0) {
 		i_error("Mailbox %s: Status lookup failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 
@@ -82,12 +84,14 @@
 		printf("\r%u/%u\n", counter, max);
 	if (mailbox_search_deinit(&ctx) < 0) {
 		i_error("Mailbox %s: Mail search failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 	if (mailbox_transaction_commit(&trans) < 0) {
 		i_error("Mailbox %s: Transaction commit failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 	return ret;
@@ -108,7 +112,7 @@
 		   while with large maildirs. */
 		if (mailbox_open(box) < 0) {
 			i_error("Opening mailbox %s failed: %s", info->vname,
-				mail_storage_get_last_error(mailbox_get_storage(box), NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			doveadm_mail_failed_mailbox(&ctx->ctx, box);
 			mailbox_free(&box);
 			return -1;
@@ -123,7 +127,7 @@
 
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 		i_error("Syncing mailbox %s failed: %s", info->vname,
-			mail_storage_get_last_error(mailbox_get_storage(box), NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(&ctx->ctx, box);
 		ret = -1;
 	} else {
--- a/src/doveadm/doveadm-mail-iter.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-iter.c	Thu Mar 16 11:15:18 2017 +0200
@@ -40,7 +40,7 @@
 	iter->search_args = search_args;
 
 	if (mailbox_sync(iter->box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
-		errstr = mailbox_get_last_error(iter->box, &error);
+		errstr = mailbox_get_last_internal_error(iter->box, &error);
 		if (error == MAIL_ERROR_NOTFOUND) {
 			/* just ignore this mailbox */
 			*iter_r = iter;
@@ -74,7 +74,7 @@
 		if (mailbox_search_deinit(&iter->search_ctx) < 0) {
 			i_error("Searching mailbox %s failed: %s",
 				mailbox_get_vname(iter->box),
-				mailbox_get_last_error(iter->box, NULL));
+				mailbox_get_last_internal_error(iter->box, NULL));
 			ret = -1;
 		}
 	}
@@ -84,7 +84,7 @@
 		if (mailbox_transaction_commit(&iter->t) < 0) {
 			i_error("Committing mailbox %s failed: %s",
 				mailbox_get_vname(iter->box),
-				mailbox_get_last_error(iter->box, NULL));
+				mailbox_get_last_internal_error(iter->box, NULL));
 			ret = -1;
 		}
 	} else {
@@ -109,7 +109,7 @@
 		if (ret < 0) {
 			i_error("Mailbox %s: Mailbox sync failed: %s",
 				mailbox_get_vname(iter->box),
-				mailbox_get_last_error(iter->box, NULL));
+				mailbox_get_last_internal_error(iter->box, NULL));
 		}
 	}
 	if (ret < 0)
--- a/src/doveadm/doveadm-mail-mailbox-metadata.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-mailbox-metadata.c	Thu Mar 16 11:15:18 2017 +0200
@@ -49,7 +49,7 @@
 
 	if (mailbox_open(*box_r) < 0) {
 		i_error("Failed to open mailbox: %s",
-			mailbox_get_last_error(*box_r, NULL));
+			mailbox_get_last_internal_error(*box_r, NULL));
 		doveadm_mail_failed_mailbox(&mctx->ctx, *box_r);
 		mailbox_free(box_r);
 		return -1;
@@ -81,12 +81,12 @@
 		mailbox_attribute_set(trans, ctx->key_type, ctx->key, &ctx->value);
 	if (ret < 0) {
 		i_error("Failed to set attribute: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(_ctx, box);
 		mailbox_transaction_rollback(&trans);
 	} else if (mailbox_transaction_commit(&trans) < 0) {
 		i_error("Failed to commit transaction: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(_ctx, box);
 		ret = -1;
 	}
@@ -210,7 +210,7 @@
 	ret = mailbox_attribute_get_stream(trans, ctx->key_type, ctx->key, &value);
 	if (ret < 0) {
 		i_error("Failed to get attribute: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(_ctx, box);
 	} else if (ret == 0) {
 		/* not found, print as empty */
@@ -269,7 +269,7 @@
 	if (mailbox_attribute_iter_deinit(&iter) < 0) {
 		i_error("Mailbox %s: Failed to iterate mailbox attributes: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 	return 0;
--- a/src/doveadm/doveadm-mail-mailbox-status.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-mailbox-status.c	Thu Mar 16 11:15:18 2017 +0200
@@ -130,7 +130,8 @@
 	if (mailbox_get_status(box, ctx->status_items, &status) < 0 ||
 	    mailbox_get_metadata(box, ctx->metadata_items, &metadata) < 0) {
 		i_error("Mailbox %s: Failed to lookup mailbox status: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(&ctx->ctx, box);
 		mailbox_free(&box);
 		return -1;
--- a/src/doveadm/doveadm-mail-mailbox.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-mailbox.c	Thu Mar 16 11:15:18 2017 +0200
@@ -244,14 +244,14 @@
 		box = mailbox_alloc(ns->list, name, 0);
 		if (mailbox_create(box, &ctx->update, directory) < 0) {
 			i_error("Can't create mailbox %s: %s", name,
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			doveadm_mail_failed_mailbox(_ctx, box);
 			ret = -1;
 		}
 		if (ctx->ctx.subscriptions) {
 			if (mailbox_set_subscribed(box, TRUE) < 0) {
 				i_error("Can't subscribe to mailbox %s: %s", name,
-					mailbox_get_last_error(box, NULL));
+					mailbox_get_last_internal_error(box, NULL));
 				doveadm_mail_failed_mailbox(_ctx, box);
 				ret = -1;
 			}
@@ -377,14 +377,14 @@
 			mailbox_delete(box);
 		if (ret2 < 0) {
 			i_error("Can't delete mailbox %s: %s", name,
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			doveadm_mail_failed_mailbox(_ctx, box);
 			ret = -1;
 		}
 		if (ctx->ctx.subscriptions) {
 			if (mailbox_set_subscribed(box, FALSE) < 0) {
 				i_error("Can't unsubscribe mailbox %s: %s", name,
-					mail_storage_get_last_error(storage, NULL));
+					mail_storage_get_last_internal_error(storage, NULL));
 				doveadm_mail_failed_mailbox(_ctx, box);
 				ret = -1;
 			}
@@ -466,20 +466,20 @@
 	newbox = mailbox_alloc(newns->list, newname, 0);
 	if (mailbox_rename(oldbox, newbox) < 0) {
 		i_error("Can't rename mailbox %s to %s: %s", oldname, newname,
-			mailbox_get_last_error(oldbox, NULL));
+			mailbox_get_last_internal_error(oldbox, NULL));
 		doveadm_mail_failed_mailbox(_ctx, oldbox);
 		ret = -1;
 	}
 	if (ctx->ctx.subscriptions) {
 		if (mailbox_set_subscribed(oldbox, FALSE) < 0) {
 			i_error("Can't unsubscribe mailbox %s: %s", ctx->oldname,
-				mailbox_get_last_error(oldbox, NULL));
+				mailbox_get_last_internal_error(oldbox, NULL));
 			doveadm_mail_failed_mailbox(_ctx, oldbox);
 			ret = -1;
 		}
 		if (mailbox_set_subscribed(newbox, TRUE) < 0) {
 			i_error("Can't subscribe to mailbox %s: %s", ctx->newname,
-				mailbox_get_last_error(newbox, NULL));
+				mailbox_get_last_internal_error(newbox, NULL));
 			doveadm_mail_failed_mailbox(_ctx, newbox);
 			ret = -1;
 		}
@@ -532,7 +532,7 @@
 			i_error("Can't %s mailbox %s: %s", name,
 				ctx->ctx.subscriptions ? "subscribe to" :
 				"unsubscribe",
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			doveadm_mail_failed_mailbox(_ctx, box);
 			ret = -1;
 		}
@@ -659,7 +659,7 @@
 	if ((ret = mailbox_update(box, &(ctx->update))) != 0) {
 		i_error("Cannot update %s: %s",
 			ctx->mailbox,
-			mailbox_get_last_error(box, &mail_error));
+			mailbox_get_last_internal_error(box, &mail_error));
 		doveadm_mail_failed_error(_ctx, mail_error);
 	}
 
--- a/src/doveadm/doveadm-mail-save.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-save.c	Thu Mar 16 11:15:18 2017 +0200
@@ -30,7 +30,8 @@
 
 	if (mailbox_open(box) < 0) {
 		i_error("Failed to open mailbox %s: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_storage(&ctx->ctx, storage);
 		return -1;
 	}
@@ -38,7 +39,8 @@
 	trans = mailbox_transaction_begin(box, MAILBOX_TRANSACTION_FLAG_EXTERNAL);
 	save_ctx = mailbox_save_alloc(trans);
 	if (mailbox_save_begin(&save_ctx, input) < 0) {
-		i_error("Saving failed: %s", mailbox_get_last_error(box, NULL));
+		i_error("Saving failed: %s",
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_storage(&ctx->ctx, storage);
 		mailbox_transaction_rollback(&trans);
 		return -1;
@@ -56,15 +58,16 @@
 		i_error("read(msg input) failed: %s", i_stream_get_error(input));
 		doveadm_mail_failed_error(&ctx->ctx, MAIL_ERROR_TEMP);
 	} else if (save_failed) {
-		i_error("Saving failed: %s", mailbox_get_last_error(box, NULL));
+		i_error("Saving failed: %s",
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_storage(&ctx->ctx, storage);
 	} else if (mailbox_save_finish(&save_ctx) < 0) {
 		i_error("Saving failed: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_storage(&ctx->ctx, storage);
 	} else if (mailbox_transaction_commit(&trans) < 0) {
 		i_error("Save transaction commit failed: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_storage(&ctx->ctx, storage);
 	} else {
 		ret = 0;
--- a/src/doveadm/doveadm-mail-search.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail-search.c	Thu Mar 16 11:15:18 2017 +0200
@@ -28,7 +28,7 @@
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
 		i_error("Couldn't get mailbox '%s' GUID: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 		doveadm_mail_failed_mailbox(ctx, box);
 	} else {
--- a/src/doveadm/doveadm-mail.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/doveadm-mail.c	Thu Mar 16 11:15:18 2017 +0200
@@ -148,7 +148,7 @@
 		storage = mail_namespace_get_default_storage(ns);
 		if (mail_storage_purge(storage) < 0) {
 			i_error("Purging namespace '%s' failed: %s", ns->prefix,
-				mail_storage_get_last_error(storage, NULL));
+				mail_storage_get_last_internal_error(storage, NULL));
 			doveadm_mail_failed_storage(ctx, storage);
 			ret = -1;
 		}
@@ -287,13 +287,13 @@
 			    MAILBOX_FLAG_IGNORE_ACLS);
 	if (mailbox_open(box) < 0) {
 		i_error("Opening mailbox %s failed: %s", info->vname,
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(ctx, box);
 		ret = -1;
 	} else if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC |
 				MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) < 0) {
 		i_error("Forcing a resync on mailbox %s failed: %s",
-			info->vname, mailbox_get_last_error(box, NULL));
+			info->vname, mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(ctx, box);
 		ret = -1;
 	}
--- a/src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c	Thu Mar 16 11:15:18 2017 +0200
@@ -22,7 +22,7 @@
 	update.uid_validity = uid_validity;
 
 	if (mailbox_create(box, &update, FALSE) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error != MAIL_ERROR_EXISTS) {
 			i_error("Can't create mailbox %s: %s",
 				mailbox_get_vname(box), errstr);
@@ -39,7 +39,7 @@
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 		i_error("Can't sync mailbox %s: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, error_r));
+			mailbox_get_last_internal_error(box, error_r));
 		return -1;
 	}
 
@@ -52,7 +52,7 @@
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
 		i_error("Can't get mailbox GUID %s: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, error_r));
+			mailbox_get_last_internal_error(box, error_r));
 		return -1;
 	}
 
@@ -78,7 +78,7 @@
 		if (mailbox_update(box, &update) < 0) {
 			i_error("Can't update mailbox GUID %s: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, error_r));
+				mailbox_get_last_internal_error(box, error_r));
 			return -1;
 		}
 		/* verify that the update worked */
@@ -86,7 +86,7 @@
 					 &metadata) < 0) {
 			i_error("Can't get mailbox GUID %s: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, error_r));
+				mailbox_get_last_internal_error(box, error_r));
 			return -1;
 		}
 		if (memcmp(mailbox_guid, metadata.guid,
@@ -209,7 +209,7 @@
 		break;
 	}
 	if (ret < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error == MAIL_ERROR_EXISTS ||
 		    error == MAIL_ERROR_NOTFOUND) {
 			/* mailbox was already created or was already deleted.
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Thu Mar 16 11:15:18 2017 +0200
@@ -31,7 +31,7 @@
 	box = mailbox_alloc_guid(ns->list, guid, flags);
 	ret = mailbox_exists(box, FALSE, &existence);
 	if (ret < 0) {
-		*errstr_r = mailbox_get_last_error(box, error_r);
+		*errstr_r = mailbox_get_last_internal_error(box, error_r);
 		mailbox_free(&box);
 		return -1;
 	}
@@ -404,7 +404,7 @@
 	/* get metadata first, since it may autocreate the mailbox */
 	if (mailbox_get_metadata(box, metadata_items, &metadata) < 0 ||
 	    mailbox_get_status(box, status_items, &status) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error == MAIL_ERROR_NOTFOUND ||
 		    error == MAIL_ERROR_NOTPOSSIBLE) {
 			/* Mailbox isn't selectable, try the next one. We
@@ -526,7 +526,7 @@
 		if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 			i_error("Can't sync mailbox %s: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, &brain->mail_error));
+				mailbox_get_last_internal_error(box, &brain->mail_error));
 			brain->failed = TRUE;
 			mailbox_free(&box);
 			return -1;
@@ -713,7 +713,7 @@
 	if (mailbox_update(box, &update) < 0) {
 		i_error("Couldn't update mailbox %s metadata: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, &brain->mail_error));
+			mailbox_get_last_internal_error(box, &brain->mail_error));
 		brain->failed = TRUE;
 	}
 	return ret;
@@ -788,7 +788,7 @@
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 		i_error("Can't sync mailbox %s: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, &brain->mail_error));
+			mailbox_get_last_internal_error(box, &brain->mail_error));
 		mailbox_free(&box);
 		brain->failed = TRUE;
 		return TRUE;
--- a/src/doveadm/dsync/dsync-brain.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/dsync/dsync-brain.c	Thu Mar 16 11:15:18 2017 +0200
@@ -318,7 +318,7 @@
 		storage = mail_namespace_get_default_storage(ns);
 		if (mail_storage_purge(storage) < 0) {
 			i_error("Purging namespace '%s' failed: %s", ns->prefix,
-				mail_storage_get_last_error(storage, NULL));
+				mail_storage_get_last_internal_error(storage, NULL));
 		}
 	}
 }
--- a/src/doveadm/dsync/dsync-mailbox-export.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-export.c	Thu Mar 16 11:15:18 2017 +0200
@@ -73,7 +73,7 @@
 	const char *errstr;
 	enum mail_error error;
 
-	errstr = mailbox_get_last_error(exporter->box, &error);
+	errstr = mailbox_get_last_internal_error(exporter->box, &error);
 	if (error == MAIL_ERROR_EXPUNGED)
 		return 0;
 
@@ -423,8 +423,8 @@
 	    exporter->error == NULL) {
 		exporter->error = p_strdup_printf(exporter->pool,
 			"Mail search failed: %s",
-			mailbox_get_last_error(exporter->box,
-					       &exporter->mail_error));
+			mailbox_get_last_internal_error(exporter->box,
+							&exporter->mail_error));
 	}
 }
 
@@ -561,8 +561,8 @@
 						 attr->key, &value) < 0) {
 			exporter->error = p_strdup_printf(exporter->pool,
 				"Mailbox attribute %s lookup failed: %s", attr->key,
-				mailbox_get_last_error(exporter->box,
-						       &exporter->mail_error));
+				mailbox_get_last_internal_error(exporter->box,
+								&exporter->mail_error));
 			break;
 		}
 		if ((value.flags & MAIL_ATTRIBUTE_VALUE_FLAG_READONLY) != 0) {
@@ -614,8 +614,8 @@
 						 &value) < 0) {
 			exporter->error = p_strdup_printf(exporter->pool,
 				"Mailbox attribute %s lookup failed: %s", key,
-				mailbox_get_last_error(exporter->box,
-						       &exporter->mail_error));
+				mailbox_get_last_internal_error(exporter->box,
+								&exporter->mail_error));
 			return -1;
 		}
 		if ((value.flags & MAIL_ATTRIBUTE_VALUE_FLAG_READONLY) != 0) {
@@ -658,8 +658,8 @@
 	if (mailbox_attribute_iter_deinit(&exporter->attr_iter) < 0) {
 		exporter->error = p_strdup_printf(exporter->pool,
 			"Mailbox attribute iteration failed: %s",
-			mailbox_get_last_error(exporter->box,
-					       &exporter->mail_error));
+			mailbox_get_last_internal_error(exporter->box,
+							&exporter->mail_error));
 		return -1;
 	}
 	if (exporter->attr_type == MAIL_ATTRIBUTE_TYPE_PRIVATE) {
@@ -800,8 +800,8 @@
 	    exporter->error == NULL) {
 		exporter->error = p_strdup_printf(exporter->pool,
 			"Mail search failed: %s",
-			mailbox_get_last_error(exporter->box,
-					       &exporter->mail_error));
+			mailbox_get_last_internal_error(exporter->box,
+							&exporter->mail_error));
 	}
 }
 
--- a/src/doveadm/dsync/dsync-mailbox-import.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-import.c	Thu Mar 16 11:15:18 2017 +0200
@@ -334,7 +334,8 @@
 	if (mailbox_attribute_get_stream(importer->trans, type, key, &value) < 0) {
 		i_error("Mailbox %s: Failed to get attribute %s: %s",
 			mailbox_get_vname(importer->box), key,
-			mailbox_get_last_error(importer->box, &importer->mail_error));
+			mailbox_get_last_internal_error(importer->box,
+							&importer->mail_error));
 		importer->failed = TRUE;
 		return -1;
 	}
@@ -537,7 +538,7 @@
 				  attr->key, &value) < 0) {
 		i_error("Mailbox %s: Failed to set attribute %s: %s",
 			mailbox_get_vname(importer->box), attr->key,
-			mailbox_get_last_error(importer->box, NULL));
+			mailbox_get_last_internal_error(importer->box, NULL));
 		/* the attributes aren't vital, don't fail everything just
 		   because of them. */
 	}
@@ -571,7 +572,7 @@
 	const char *errstr;
 	enum mail_error error;
 
-	errstr = mailbox_get_last_error(importer->box, &error);
+	errstr = mailbox_get_last_internal_error(importer->box, &error);
 	if (error == MAIL_ERROR_EXPUNGED)
 		return;
 
@@ -1873,7 +1874,7 @@
 	/* NOTE: Errors are logged, but they don't cause the entire import
 	   to fail. */
 	if (dsync_mail_fill(mail, TRUE, dmail_r, &error_field) < 0) {
-		errstr = mailbox_get_last_error(mail->box, &error);
+		errstr = mailbox_get_last_internal_error(mail->box, &error);
 		if (error == MAIL_ERROR_EXPUNGED)
 			return 0;
 
@@ -2121,7 +2122,7 @@
 	if (mailbox_sync(importer->virtual_all_box, 0) < 0) {
 		i_error("Couldn't sync \\All mailbox '%s': %s",
 			mailbox_get_vname(importer->virtual_all_box),
-			mailbox_get_last_error(importer->virtual_all_box, NULL));
+			mailbox_get_last_internal_error(importer->virtual_all_box, NULL));
 		return;
 	}
 
@@ -2147,7 +2148,7 @@
 	if (mailbox_search_deinit(&search_ctx) < 0) {
 		i_error("Couldn't search \\All mailbox '%s': %s",
 			mailbox_get_vname(importer->virtual_all_box),
-			mailbox_get_last_error(importer->virtual_all_box, NULL));
+			mailbox_get_last_internal_error(importer->virtual_all_box, NULL));
 	}
 
 	importer->virtual_mail = mail_alloc(importer->virtual_trans, 0, NULL);
@@ -2204,8 +2205,8 @@
 		if (mailbox_search_deinit(&importer->search_ctx) < 0) {
 			i_error("Mailbox %s: Search failed: %s",
 				mailbox_get_vname(importer->box),
-				mailbox_get_last_error(importer->box,
-						       &importer->mail_error));
+				mailbox_get_last_internal_error(importer->box,
+								&importer->mail_error));
 			importer->failed = TRUE;
 		}
 	}
@@ -2389,8 +2390,8 @@
 			i_error("Mailbox %s: Failed to read mail %s uid=%u: %s",
 				mailbox_get_vname(importer->box),
 				error_field, mail->uid,
-				mailbox_get_last_error(importer->box,
-						       &importer->mail_error));
+				mailbox_get_last_internal_error(importer->box,
+								&importer->mail_error));
 			importer->failed = TRUE;
 			mailbox_save_cancel(&save_ctx);
 			return TRUE;
@@ -2411,8 +2412,8 @@
 	if (mailbox_save_begin(&save_ctx, input) < 0) {
 		i_error("Mailbox %s: Saving failed: %s",
 			mailbox_get_vname(importer->box),
-			mailbox_get_last_error(importer->box,
-					       &importer->mail_error));
+			mailbox_get_last_internal_error(importer->box,
+							&importer->mail_error));
 		importer->failed = TRUE;
 		return TRUE;
 	}
@@ -2435,8 +2436,8 @@
 	} else if (save_failed) {
 		i_error("Mailbox %s: Saving failed: %s",
 			mailbox_get_vname(importer->box),
-			mailbox_get_last_error(importer->box,
-					       &importer->mail_error));
+			mailbox_get_last_internal_error(importer->box,
+							&importer->mail_error));
 		mailbox_save_cancel(&save_ctx);
 		importer->failed = TRUE;
 	} else {
@@ -2444,8 +2445,8 @@
 		if (mailbox_save_finish(&save_ctx) < 0) {
 			i_error("Mailbox %s: Saving failed: %s",
 				mailbox_get_vname(importer->box),
-				mailbox_get_last_error(importer->box,
-						       &importer->mail_error));
+				mailbox_get_last_internal_error(importer->box,
+								&importer->mail_error));
 			importer->failed = TRUE;
 		} else {
 			dsync_mailbox_import_saved_uid(importer,
@@ -2564,7 +2565,7 @@
 		if (mailbox_move(&save_ctx, mail) < 0) {
 			i_error("Mailbox %s: Couldn't move mail within mailbox: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, &importer->mail_error));
+				mailbox_get_last_internal_error(box, &importer->mail_error));
 			ret = -1;
 		} else if (ret > 0) {
 			ret = 0;
@@ -2574,14 +2575,14 @@
 	if (mailbox_search_deinit(&search_ctx) < 0) {
 		i_error("Mailbox %s: mail search failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, &importer->mail_error));
+			mailbox_get_last_internal_error(box, &importer->mail_error));
 		ret = -1;
 	}
 
 	if (mailbox_transaction_commit(&trans) < 0) {
 		i_error("Mailbox %s: UID reassign commit failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, &importer->mail_error));
+			mailbox_get_last_internal_error(box, &importer->mail_error));
 		ret = -1;
 	}
 	if (ret == 0) {
@@ -2666,7 +2667,7 @@
 						   &changes) < 0) {
 		i_error("Mailbox %s: Save commit failed: %s",
 			mailbox_get_vname(importer->box),
-			mailbox_get_last_error(importer->box, &importer->mail_error));
+			mailbox_get_last_internal_error(importer->box, &importer->mail_error));
 		/* removed wanted_uids that weren't actually saved */
 		array_delete(&importer->wanted_uids,
 			     array_count(&importer->saved_uids),
@@ -2690,8 +2691,8 @@
 		if (mailbox_transaction_commit(&importer->trans) < 0) {
 			i_error("Mailbox %s: Commit failed: %s",
 				mailbox_get_vname(importer->box),
-				mailbox_get_last_error(importer->box,
-						       &importer->mail_error));
+				mailbox_get_last_internal_error(importer->box,
+								&importer->mail_error));
 			ret = -1;
 		}
 	}
@@ -2730,8 +2731,8 @@
 		if (mailbox_update(importer->box, &update) < 0) {
 			i_error("Mailbox %s: Update failed: %s",
 				mailbox_get_vname(importer->box),
-				mailbox_get_last_error(importer->box,
-						       &importer->mail_error));
+				mailbox_get_last_internal_error(importer->box,
+								&importer->mail_error));
 			ret = -1;
 		}
 	}
@@ -2740,8 +2741,8 @@
 	if (mailbox_sync(importer->box, 0) < 0) {
 		i_error("Mailbox %s: Sync failed: %s",
 			mailbox_get_vname(importer->box),
-			mailbox_get_last_error(importer->box,
-					       &importer->mail_error));
+			mailbox_get_last_internal_error(importer->box,
+							&importer->mail_error));
 		ret = -1;
 	}
 	if (ret == 0) {
@@ -2834,8 +2835,8 @@
 		if (mailbox_search_deinit(&importer->search_ctx) < 0) {
 			i_error("Mailbox %s: Search failed: %s",
 				mailbox_get_vname(importer->box),
-				mailbox_get_last_error(importer->box,
-						       &importer->mail_error));
+				mailbox_get_last_internal_error(importer->box,
+								&importer->mail_error));
 			importer->failed = TRUE;
 		}
 	}
@@ -2873,8 +2874,8 @@
 		if (mailbox_delete(importer->box) < 0) {
 			i_error("Couldn't delete mailbox %s: %s",
 				mailbox_get_vname(importer->box),
-				mailbox_get_last_error(importer->box,
-						       &importer->mail_error));
+				mailbox_get_last_internal_error(importer->box,
+								&importer->mail_error));
 			importer->failed = TRUE;
 		}
 		*last_messages_count_r = 0;
--- a/src/doveadm/dsync/dsync-mailbox-tree-fill.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-tree-fill.c	Thu Mar 16 11:15:18 2017 +0200
@@ -95,7 +95,7 @@
 	/* get GUID and UIDVALIDITY for selectable mailbox */
 	box = mailbox_alloc(info->ns->list, info->vname, MAILBOX_FLAG_READONLY);
 	if (dsync_mailbox_tree_get_selectable(box, &metadata, &status) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		switch (error) {
 		case MAIL_ERROR_NOTFOUND:
 			/* mailbox was just deleted? */
@@ -266,7 +266,7 @@
 	box = mailbox_alloc(change_node->ns->list, change_vname, 0);
 	if (mailbox_update(box, &update) < 0) {
 		i_error("Couldn't update mailbox %s GUID: %s",
-			change_vname, mailbox_get_last_error(box, NULL));
+			change_vname, mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	} else {
 		memcpy(change_node->mailbox_guid, update.mailbox_guid,
--- a/src/imap/imap-state.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/imap/imap-state.c	Thu Mar 16 11:15:18 2017 +0200
@@ -184,7 +184,7 @@
 			seq_range_array_add(&recent_uids, mail->uid);
 	}
 	if (mailbox_search_deinit(&search_ctx) < 0) {
-		*error_r = mailbox_get_last_error(box, NULL);
+		*error_r = mailbox_get_last_internal_error(box, NULL);
 		ret = -1;
 	}
 	(void)mailbox_transaction_commit(&trans);
@@ -224,7 +224,7 @@
 	}
 
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
-		*error_r = mailbox_get_last_error(box, &mail_error);
+		*error_r = mailbox_get_last_internal_error(box, &mail_error);
 		/* if the selected mailbox can't have a GUID, fail silently */
 		return mail_error == MAIL_ERROR_NOTPOSSIBLE ? 0 : -1;
 	}
@@ -399,7 +399,7 @@
 	}
 
 	if (mailbox_search_deinit(&search_ctx) < 0) {
-		*error_r = mailbox_get_last_error(client->mailbox, NULL);
+		*error_r = mailbox_get_last_internal_error(client->mailbox, NULL);
 		ret = -1;
 	} else if (seq != state->messages) {
 		*error_r = t_strdup_printf("Message count mismatch after "
@@ -575,7 +575,7 @@
 	box = mailbox_alloc(ns->list, state->vname, flags);
 	if (mailbox_open(box) < 0) {
 		*error_r = t_strdup_printf("Couldn't open mailbox: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		mailbox_free(&box);
 		return -1;
 	}
@@ -584,13 +584,13 @@
 		ret = mailbox_enable(box, client->enabled_features);
 	if (ret < 0 || mailbox_sync(box, 0) < 0) {
 		*error_r = t_strdup_printf("Couldn't sync mailbox: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		mailbox_free(&box);
 		return -1;
 	}
 	/* verify that this still looks like the same mailbox */
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
-		*error_r = mailbox_get_last_error(box, NULL);
+		*error_r = mailbox_get_last_internal_error(box, NULL);
 		mailbox_free(&box);
 		return -1;
 	}
--- a/src/indexer/master-connection.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/indexer/master-connection.c	Thu Mar 16 11:15:18 2017 +0200
@@ -70,13 +70,15 @@
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_PRECACHE_FIELDS,
 				 &metadata) < 0) {
 		i_error("Mailbox %s: Precache-fields lookup failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 	if (mailbox_get_status(box, STATUS_MESSAGES | STATUS_LAST_CACHED_SEQ,
 			       &status) < 0) {
 		i_error("Mailbox %s: Status lookup failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 	seq = status.last_cached_seq + 1;
@@ -108,12 +110,14 @@
 	}
 	if (mailbox_search_deinit(&ctx) < 0) {
 		i_error("Mailbox %s: Mail search failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 	if (mailbox_transaction_commit(&trans) < 0) {
 		i_error("Mailbox %s: Transaction commit failed: %s",
-			mailbox_get_vname(box), mailbox_get_last_error(box, NULL));
+			mailbox_get_vname(box),
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 	if (ret == 0) {
@@ -141,7 +145,7 @@
 	ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path);
 	if (ret < 0) {
 		i_error("Getting path to mailbox %s failed: %s",
-			mailbox, mailbox_get_last_error(box, NULL));
+			mailbox, mailbox_get_last_internal_error(box, NULL));
 		mailbox_free(&box);
 		return -1;
 	}
@@ -158,7 +162,7 @@
 		   while with large maildirs. */
 		if (mailbox_open(box) < 0) {
 			i_error("Opening mailbox %s failed: %s", mailbox,
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			ret = -1;
 		} else {
 			mailbox_get_open_status(box, STATUS_RECENT, &status);
@@ -173,7 +177,7 @@
 		sync_flags |= MAILBOX_SYNC_FLAG_OPTIMIZE;
 
 	if (mailbox_sync(box, sync_flags) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error != MAIL_ERROR_NOTFOUND) {
 			i_error("Syncing mailbox %s failed: %s",
 				mailbox, errstr);
--- a/src/lda/main.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lda/main.c	Thu Mar 16 11:15:18 2017 +0200
@@ -196,7 +196,7 @@
 	}
 	if (ret < 0) {
 		i_fatal("Can't open delivery mail as raw: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 	}
 	mail_user_unref(&raw_mail_user);
 
--- a/src/lib-imap-urlauth/imap-urlauth-backend.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lib-imap-urlauth/imap-urlauth-backend.c	Thu Mar 16 11:15:18 2017 +0200
@@ -107,7 +107,7 @@
 	enum mail_error error;
 
 	if (mailbox_open(box) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error == MAIL_ERROR_NOTFOUND || error == MAIL_ERROR_PERM)
 			return 0;
 		i_error("urlauth key reset: Couldn't open mailbox %s: %s",
--- a/src/lib-lda/mail-deliver.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lib-lda/mail-deliver.c	Thu Mar 16 11:15:18 2017 +0200
@@ -239,13 +239,13 @@
 	if (mailbox_open(box) == 0)
 		return 0;
 
-	*error_str_r = mailbox_get_last_error(box, error_r);
+	*error_str_r = mailbox_get_last_internal_error(box, error_r);
 	if (!ctx->lda_mailbox_autocreate || *error_r != MAIL_ERROR_NOTFOUND)
 		return -1;
 
 	/* try creating it. */
 	if (mailbox_create(box, NULL, FALSE) < 0) {
-		*error_str_r = mailbox_get_last_error(box, error_r);
+		*error_str_r = mailbox_get_last_internal_error(box, error_r);
 		if (*error_r != MAIL_ERROR_EXISTS)
 			return -1;
 		/* someone else just created it */
@@ -257,7 +257,7 @@
 
 	/* and try opening again */
 	if (mailbox_open(box) < 0) {
-		*error_str_r = mailbox_get_last_error(box, error_r);
+		*error_str_r = mailbox_get_last_internal_error(box, error_r);
 		return -1;
 	}
 	return 0;
@@ -422,7 +422,7 @@
 		pool_unref(&changes.pool);
 	} else {
 		mail_deliver_log(ctx, "save failed to %s: %s", mailbox_name,
-			mail_storage_get_last_error(*storage_r, &error));
+			mail_storage_get_last_internal_error(*storage_r, &error));
 	}
 
 	if (ctx->dest_mail == NULL)
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Mar 16 11:15:18 2017 +0200
@@ -559,7 +559,7 @@
 	if (mailbox_open(box) < 0) {
 		error = mailbox_get_last_mail_error(box);
 		i_error("Couldn't open mailbox '%s': %s",
-			vname, mailbox_get_last_error(box, NULL));
+			vname, mailbox_get_last_internal_error(box, NULL));
 		mailbox_free(&box);
 		if (error == MAIL_ERROR_TEMP)
 			return -1;
--- a/src/lib-storage/index/index-mailbox-size.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lib-storage/index/index-mailbox-size.c	Thu Mar 16 11:15:18 2017 +0200
@@ -440,7 +440,7 @@
 			const char *errstr;
 			enum mail_error error;
 
-			errstr = mailbox_get_last_error(box, &error);
+			errstr = mailbox_get_last_internal_error(box, &error);
 			if (error != MAIL_ERROR_EXPUNGED) {
 				i_error("Couldn't get size of mail UID %u in %s: %s",
 					mail->uid, box->vname, errstr);
@@ -451,7 +451,7 @@
 	}
 	if (mailbox_search_deinit(&ctx) < 0) {
 		i_error("Listing mails in %s failed: %s",
-			box->vname, mailbox_get_last_error(box, NULL));
+			box->vname, mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 	(void)mailbox_transaction_commit(&trans);
--- a/src/lib-storage/mail-autoexpunge.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lib-storage/mail-autoexpunge.c	Thu Mar 16 11:15:18 2017 +0200
@@ -153,7 +153,7 @@
 	if (mailbox_autoexpunge(box, autoexpunge, autoexpunge_max_mails) < 0) {
 		i_error("Failed to autoexpunge mailbox '%s': %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 	}
 	mailbox_free(&box);
 }
--- a/src/lib-storage/mail-storage.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lib-storage/mail-storage.c	Thu Mar 16 11:15:18 2017 +0200
@@ -801,7 +801,7 @@
 		i_error("mailbox_alloc_guid(%s): "
 			"Couldn't verify mailbox GUID: %s",
 			guid_128_to_string(guid),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		vname = NULL;
 		mailbox_free(&box);
 	} else {
@@ -833,7 +833,7 @@
 	enum mail_error error;
 
 	if (mailbox_create(box, NULL, FALSE) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error != MAIL_ERROR_EXISTS) {
 			mail_storage_set_critical(box->storage,
 				"Failed to autocreate mailbox %s: %s",
@@ -846,7 +846,8 @@
 		if (mailbox_set_subscribed(box, TRUE) < 0) {
 			mail_storage_set_critical(box->storage,
 				"Failed to autosubscribe to mailbox %s: %s",
-				box->vname, mailbox_get_last_error(box, NULL));
+				box->vname,
+				mailbox_get_last_internal_error(box, NULL));
 			return -1;
 		}
 	}
@@ -867,7 +868,7 @@
 		box->storage->user->inbox_open_error_logged = TRUE;
 		mail_storage_set_critical(box->storage,
 			"Opening INBOX failed: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 	}
 	return ret;
 }
@@ -1843,7 +1844,7 @@
 	ret = box->v.sync_deinit(ctx, status_r);
 	if (ret < 0 && box->inbox_user &&
 	    !box->storage->user->inbox_open_error_logged) {
-		errormsg = mailbox_get_last_error(box, &error);
+		errormsg = mailbox_get_last_internal_error(box, &error);
 		if (error == MAIL_ERROR_NOTPOSSIBLE) {
 			box->storage->user->inbox_open_error_logged = TRUE;
 			i_error("Syncing INBOX failed: %s", errormsg);
--- a/src/lib-storage/mailbox-guid-cache.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lib-storage/mailbox-guid-cache.c	Thu Mar 16 11:15:18 2017 +0200
@@ -71,7 +71,7 @@
 		if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID,
 					 &metadata) < 0) {
 			i_error("Couldn't get mailbox %s GUID: %s",
-				info->vname, mailbox_get_last_error(box, NULL));
+				info->vname, mailbox_get_last_internal_error(box, NULL));
 			list->guid_cache_errors = TRUE;
 		} else if ((rec = hash_table_lookup(list->guid_cache,
 				(const uint8_t *)metadata.guid)) != NULL) {
--- a/src/lmtp/commands.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/lmtp/commands.c	Thu Mar 16 11:15:18 2017 +0200
@@ -1004,7 +1004,7 @@
 				     (time_t)-1, client->state.mail_from,
 				     &box) < 0) {
 		i_error("Can't open delivery mail as raw: %s",
-			mailbox_get_last_error(box, &error));
+			mailbox_get_last_internal_error(box, &error));
 		mailbox_free(&box);
 		client_rcpt_fail_all(client);
 		return -1;
--- a/src/plugins/acl/doveadm-acl.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/acl/doveadm-acl.c	Thu Mar 16 11:15:18 2017 +0200
@@ -41,7 +41,7 @@
 			    MAILBOX_FLAG_READONLY | MAILBOX_FLAG_IGNORE_ACLS);
 	if (mailbox_open(box) < 0) {
 		i_error("Can't open mailbox %s: %s", mailbox,
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_mailbox(ctx, box);
 		mailbox_free(&box);
 		return -1;
@@ -237,7 +237,7 @@
 		i_fatal_status(EX_USAGE, "%s", error);
 	if ((ret = cmd_acl_mailbox_update(box, &update)) < 0) {
 		i_error("Failed to set ACL: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_error(_ctx, MAIL_ERROR_TEMP);
 	}
 	mailbox_free(&box);
@@ -295,7 +295,7 @@
 		i_fatal_status(EX_USAGE, "%s", error);
 	if ((ret = cmd_acl_mailbox_update(box, &update)) < 0) {
 		i_error("Failed to delete ACL: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		doveadm_mail_failed_error(ctx, MAIL_ERROR_TEMP);
 	}
 	mailbox_free(&box);
@@ -363,7 +363,7 @@
 	box = mailbox_alloc(ns->list, mailbox,
 			    MAILBOX_FLAG_READONLY | MAILBOX_FLAG_IGNORE_ACLS);
 	if (mailbox_open(box) < 0) {
-		errstr = mail_storage_get_last_error(box->storage, &error);
+		errstr = mail_storage_get_last_internal_error(box->storage, &error);
 		errstr = t_strdup(errstr);
 		doveadm_mail_failed_error(ctx, error);
 
--- a/src/plugins/fts-lucene/fts-backend-lucene.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/fts-lucene/fts-backend-lucene.c	Thu Mar 16 11:15:18 2017 +0200
@@ -74,7 +74,7 @@
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID,
 				 &metadata) < 0) {
 		i_error("lucene: Couldn't get mailbox %s GUID: %s",
-			box->vname, mailbox_get_last_error(box, NULL));
+			box->vname, mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 	memcpy(guid_r, metadata.guid, GUID_128_SIZE);
--- a/src/plugins/fts-lucene/lucene-wrapper.cc	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/fts-lucene/lucene-wrapper.cc	Thu Mar 16 11:15:18 2017 +0200
@@ -750,7 +750,7 @@
 		enum mail_error error;
 		const char *errstr;
 
-		errstr = mailbox_get_last_error(ctx->box, &error);
+		errstr = mailbox_get_last_internal_error(ctx->box, &error);
 		if (error == MAIL_ERROR_NOTFOUND)
 			ret = 0;
 		else {
@@ -765,7 +765,7 @@
 	if (mailbox_sync(ctx->box, (enum mailbox_sync_flags)0) < 0) {
 		i_error("lucene: Failed to sync mailbox %s: %s",
 			mailbox_get_vname(ctx->box),
-			mailbox_get_last_error(ctx->box, NULL));
+			mailbox_get_last_internal_error(ctx->box, NULL));
 		mailbox_free(&ctx->box);
 		ctx->box_ret = -1;
 		return -1;
--- a/src/plugins/fts/fts-api.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/fts/fts-api.c	Thu Mar 16 11:15:18 2017 +0200
@@ -474,7 +474,7 @@
 	box = mailbox_alloc(list, vname, 0);
 	if (mailbox_sync(box, (enum mailbox_sync_flags)0) < 0) {
 		i_error("fts: Failed to sync mailbox %s: %s", vname,
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	} else {
 		ret = fts_index_get_header(box, &hdr) &&
--- a/src/plugins/fts/fts-build-mail.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/fts/fts-build-mail.c	Thu Mar 16 11:15:18 2017 +0200
@@ -473,7 +473,7 @@
 			return 0;
 		i_error("Failed to read mailbox %s mail UID=%u stream: %s",
 			mailbox_get_vname(mail->box), mail->uid,
-			mailbox_get_last_error(mail->box, NULL));
+			mailbox_get_last_internal_error(mail->box, NULL));
 		return -1;
 	}
 
--- a/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/lazy-expunge/lazy-expunge-plugin.c	Thu Mar 16 11:15:18 2017 +0200
@@ -124,7 +124,7 @@
 		return box;
 	}
 
-	*error_r = mailbox_get_last_error(box, &error);
+	*error_r = mailbox_get_last_internal_error(box, &error);
 	if (error != MAIL_ERROR_NOTFOUND) {
 		*error_r = t_strdup_printf("Failed to open mailbox %s: %s",
 					   name, *error_r);
@@ -136,13 +136,13 @@
 	if (mailbox_create(box, NULL, FALSE) < 0 &&
 	    mailbox_get_last_mail_error(box) != MAIL_ERROR_EXISTS) {
 		*error_r = t_strdup_printf("Failed to create mailbox %s: %s", name,
-					   mailbox_get_last_error(box, NULL));
+					   mailbox_get_last_internal_error(box, NULL));
 		mailbox_free(&box);
 		return NULL;
 	}
 	if (mailbox_open(box) < 0) {
 		*error_r = t_strdup_printf("Failed to open created mailbox %s: %s", name,
-					   mailbox_get_last_error(box, NULL));
+					   mailbox_get_last_internal_error(box, NULL));
 		mailbox_free(&box);
 		return NULL;
 	}
@@ -183,7 +183,7 @@
 	enum mail_error error;
 
 	if (mail_get_special(_mail, MAIL_FETCH_REFCOUNT, &value) < 0) {
-		errstr = mailbox_get_last_error(_mail->box, &error);
+		errstr = mailbox_get_last_internal_error(_mail->box, &error);
 		if (error == MAIL_ERROR_EXPUNGED) {
 			/* already expunged - just ignore it */
 			return 0;
@@ -208,7 +208,7 @@
 		   see the same refcount, so we need to adjust the refcount
 		   by tracking the expunged message GUIDs. */
 		if (mail_get_special(_mail, MAIL_FETCH_GUID, &value) < 0) {
-			errstr = mailbox_get_last_error(_mail->box, &error);
+			errstr = mailbox_get_last_internal_error(_mail->box, &error);
 			if (error == MAIL_ERROR_EXPUNGED) {
 				/* already expunged - just ignore it */
 				return 0;
--- a/src/plugins/mail-crypt/doveadm-mail-crypt.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/mail-crypt/doveadm-mail-crypt.c	Thu Mar 16 11:15:18 2017 +0200
@@ -367,7 +367,7 @@
 			res->name = p_strdup(_ctx->pool, info->vname);
 			res->success = FALSE;
 			res->error = p_strdup(_ctx->pool,
-					   mailbox_get_last_error(box, NULL));
+					mailbox_get_last_internal_error(box, NULL));
 		} else if ((ret = mcp_keypair_generate(ctx, user_key, box,
 							&pair, &pubid,
 							&error)) < 0) {
@@ -458,7 +458,7 @@
 		if (mailbox_open(box) < 0) {
 			i_error("mailbox_open(%s) failed: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			mailbox_free(&box);
 			return;
 		}
@@ -472,7 +472,7 @@
 			i_error("mailbox_get_attribute(%s, %s) failed: %s",
 				mailbox_get_vname(box),
 				USER_CRYPT_PREFIX ACTIVE_KEY_NAME,
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 		}
 
 		iter = mailbox_attribute_iter_init(box,
@@ -494,7 +494,7 @@
 		if (mailbox_attribute_iter_deinit(&iter) < 0)
 			i_error("mailbox_attribute_iter_deinit(%s) failed: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 
 		(void)mailbox_transaction_commit(&t);
 
@@ -522,7 +522,7 @@
 		if (mailbox_open(box) < 0) {
 			i_error("mailbox_open(%s) failed: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			mailbox_free(&box);
 			continue;
 		}
@@ -541,7 +541,7 @@
 			i_error("mailbox_get_attribute(%s, %s) failed: %s",
 				mailbox_get_vname(box),
 				BOX_CRYPT_PREFIX ACTIVE_KEY_NAME,
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 		} else if ((ret = mail_crypt_box_get_pvt_digests(box, pool_datastack_create(),
 								 MAIL_ATTRIBUTE_TYPE_PRIVATE,
 							   	 &ids, &error)) < 0) {
@@ -726,7 +726,7 @@
 	if (mailbox_open(box) < 0) {
 		doveadm_print(t_strdup_printf("mailbox_open(%s) failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL)));
+			mailbox_get_last_internal_error(box, NULL)));
 		_ctx->exit_code = EX_TEMPFAIL;
 		return -1;
 	}
@@ -757,7 +757,7 @@
 						 attr, &value)) < 0) {
 			doveadm_print(t_strdup_printf("mailbox_attribute_get(%s, %s) failed: %s",
 				mailbox_get_vname(box), attr,
-				mailbox_get_last_error(box, NULL)));
+				mailbox_get_last_internal_error(box, NULL)));
 			_ctx->exit_code = EX_TEMPFAIL;
 			break;
 		} else if (ret > 0) {
@@ -816,7 +816,7 @@
 				doveadm_print(t_strdup_printf("mailbox_attribute_set(%s, %s) failed: %s",
 					mailbox_get_vname(box),
 					raw_key->attr,
-					mailbox_get_last_error(box, NULL)));
+					mailbox_get_last_internal_error(box, NULL)));
 				_ctx->exit_code = EX_TEMPFAIL;
 				ret = -1;
 				break;
@@ -831,7 +831,7 @@
 		if (mailbox_transaction_commit(&t) < 0) {
 			doveadm_print(t_strdup_printf("mailbox_transaction_commit(%s) failed: %s",
 				mailbox_get_vname(box),
-				mailbox_get_last_error(box, NULL)));
+				mailbox_get_last_internal_error(box, NULL)));
 		} else {
 			doveadm_print(t_strdup_printf("Changed password for %u key(s)",
 						     count));
--- a/src/plugins/mail-crypt/mail-crypt-acl-plugin.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/mail-crypt/mail-crypt-acl-plugin.c	Thu Mar 16 11:15:18 2017 +0200
@@ -116,7 +116,7 @@
 		*error_r = t_strdup_printf("mail-crypt-acl-plugin: "
 					   "mailbox_transaction_commit(%s) failed: %s",
 					   mailbox_get_vname(src_box),
-					   mailbox_get_last_error(src_box, NULL));
+					   mailbox_get_last_internal_error(src_box, NULL));
 		return -1;
 	}
 	return 0;
@@ -213,7 +213,7 @@
 	}
 
 	if (mailbox_transaction_commit(&t) < 0) {
-		*error_r = mailbox_get_last_error(src_box, NULL);
+		*error_r = mailbox_get_last_internal_error(src_box, NULL);
 		ret = -1;
 	}
 
@@ -247,7 +247,7 @@
 		i_error("mail-crypt-acl-plugin: "
 			"mailbox_open(%s) failed: %s",
 			mailbox_get_vname(box),
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 
--- a/src/plugins/mail-crypt/mail-crypt-key.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/mail-crypt/mail-crypt-key.c	Thu Mar 16 11:15:18 2017 +0200
@@ -322,7 +322,7 @@
 						   shared ? "/shared/" :
 							    "/priv/",
 						   attr_name,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 		return ret;
 	}
@@ -354,7 +354,7 @@
 	if (mailbox_open(box) < 0) {
 		*error_r = t_strdup_printf("mailbox_open(%s) failed: %s",
 					   "INBOX",
-					   mailbox_get_last_error(box, NULL));
+					   mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 
@@ -369,7 +369,7 @@
 				*error_r = t_strdup_printf("mailbox_attribute_get(%s, /shared/%s) failed: %s",
 							   mailbox_get_vname(box),
 							   USER_CRYPT_PREFIX ACTIVE_KEY_NAME,
-							   mailbox_get_last_error(box, NULL));
+							   mailbox_get_last_internal_error(box, NULL));
 			}
 		} else {
 			pubid = value.value;
@@ -402,7 +402,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_get(%s, /shared/%s) failed: %s",
 						   mailbox_get_vname(box),
 						   USER_CRYPT_PREFIX ACTIVE_KEY_NAME,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 		return ret;
 	}
@@ -461,7 +461,7 @@
 			   mailbox_get_vname(mailbox_transaction_get_mailbox(t)),
 			   shared ? "/shared" : "/priv",
 			   attr_name,
-			   mailbox_get_last_error(
+			   mailbox_get_last_internal_error(
 				mailbox_transaction_get_mailbox(t), NULL));
 	}
 
@@ -503,7 +503,7 @@
 	if (mailbox_open(box) < 0) {
 		*error_r = t_strdup_printf("mailbox_open(%s) failed: %s",
 					   "INBOX",
-					   mailbox_get_last_error(box, NULL));
+					   mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 
@@ -515,7 +515,7 @@
 	} else if ((ret = mailbox_transaction_commit(&t)) < 0) {
 		*error_r = t_strdup_printf("mailbox_transaction_commit(%s) failed: %s",
 					  mailbox_get_vname(box),
-					  mailbox_get_last_error(box, NULL));
+					  mailbox_get_last_internal_error(box, NULL));
 	}
 
 	mailbox_free(&box);
@@ -538,7 +538,7 @@
 	} else if ((ret = mailbox_transaction_commit(&t)) < 0) {
 		*error_r = t_strdup_printf("mailbox_transaction_commit(%s) failed: %s",
 					  mailbox_get_vname(box),
-					  mailbox_get_last_error(box, NULL));
+					  mailbox_get_last_internal_error(box, NULL));
 	}
 
 	return ret;
@@ -573,7 +573,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_get(%s, %s) failed: %s",
 						   mailbox_get_vname(box),
 						   attr_name,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 		return ret;
 	}
@@ -629,7 +629,7 @@
 	if (mailbox_open(box) < 0) {
 		*error_r = t_strdup_printf("mailbox_open(%s) failed: %s",
 					   "INBOX",
-					   mailbox_get_last_error(box, NULL));
+					   mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 
@@ -643,7 +643,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_get(%s, /shared/%s) failed: %s",
 						   mailbox_get_vname(box),
 						   USER_CRYPT_PREFIX ACTIVE_KEY_NAME,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 	} else {
 		ret = mail_crypt_get_public_key(t, value.value, TRUE, key_r, error_r);
@@ -669,7 +669,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_get(%s, /shared/%s) failed: %s",
 						   mailbox_get_vname(box),
 						   BOX_CRYPT_PREFIX ACTIVE_KEY_NAME,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 		return ret;
 	}
@@ -705,7 +705,7 @@
 			   mailbox_get_vname(mailbox_transaction_get_mailbox(t)),
 			   "/shared",
 			   attr_name,
-			   mailbox_get_last_error(
+			   mailbox_get_last_internal_error(
 				mailbox_transaction_get_mailbox(t), NULL));
 		return -1;
 	}
@@ -728,7 +728,7 @@
 	if (mailbox_open(box) < 0) {
 		*error_r = t_strdup_printf("mailbox_open(%s) failed: %s",
 					   "INBOX",
-					   mailbox_get_last_error(box, NULL));
+					   mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 
@@ -746,7 +746,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_set(%s, /shared/%s) failed: %s",
 						   mailbox_get_vname(box),
 						   USER_CRYPT_PREFIX ACTIVE_KEY_NAME,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 	}
 
@@ -755,7 +755,7 @@
 	} else if (mailbox_transaction_commit(&t) < 0) {
 		*error_r = t_strdup_printf("mailbox_transaction_commit(%s) failed: %s",
 					  mailbox_get_vname(box),
-					  mailbox_get_last_error(box, NULL));
+					  mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 
@@ -785,7 +785,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_set(%s, /shared/%s) failed: %s",
 						   mailbox_get_vname(box),
 						   BOX_CRYPT_PREFIX ACTIVE_KEY_NAME,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 	}
 
@@ -794,7 +794,7 @@
 	} else if (mailbox_transaction_commit(&t) < 0) {
 		*error_r = t_strdup_printf("mailbox_transaction_commit(%s) failed: %s",
 					  mailbox_get_vname(box),
-					  mailbox_get_last_error(box, NULL));
+					  mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 
@@ -866,7 +866,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_get(%s, %s) failed: %s",
 						mailbox_get_vname(box),
 						attr_name,
-						mailbox_get_last_error(box, NULL));
+						mailbox_get_last_internal_error(box, NULL));
 			return ret;
 		}
 		return mail_crypt_get_private_key(t, pubid, FALSE, TRUE, key_r,
@@ -931,7 +931,7 @@
 					   mailbox_get_vname(
 						mailbox_transaction_get_mailbox(t)),
 					   attr_name,
-					   mailbox_get_last_error(
+					   mailbox_get_last_internal_error(
 						mailbox_transaction_get_mailbox(t),
 						NULL));
 	}
@@ -965,7 +965,7 @@
 						    mailbox_get_vname(
 						    mailbox_transaction_get_mailbox(t)),
 						    attr_name,
-						    mailbox_get_last_error(
+						    mailbox_get_last_internal_error(
 						    mailbox_transaction_get_mailbox(t),
 						    NULL));
 		}
@@ -1094,7 +1094,7 @@
 	}
 	ret = mailbox_attribute_iter_deinit(&iter);
 	if (ret < 0)
-		*error_r = mailbox_get_last_error(box, NULL);
+		*error_r = mailbox_get_last_internal_error(box, NULL);
 	return ret;
 }
 
@@ -1121,7 +1121,7 @@
 
 	ret = mailbox_attribute_iter_deinit(&iter);
 	if (ret < 0)
-		*error_r = mailbox_get_last_error(box, NULL);
+		*error_r = mailbox_get_last_internal_error(box, NULL);
 	return ret;
 }
 
--- a/src/plugins/mail-crypt/test-mail-key.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/mail-crypt/test-mail-key.c	Thu Mar 16 11:15:18 2017 +0200
@@ -78,7 +78,7 @@
 			*error_r = t_strdup_printf("mailbox_attribute_get(%s, %s) failed: %s",
 						   mailbox_get_vname(box),
 						   attr_name,
-						   mailbox_get_last_error(box, NULL));
+						   mailbox_get_last_internal_error(box, NULL));
 		}
 	} else {
 		*value_r = t_strdup(value.value);
@@ -123,8 +123,7 @@
 		*error_r = t_strdup_printf("mailbox_attribute_set(%s, %s) failed: %s",
 					   mailbox_get_vname(mailbox_transaction_get_mailbox(t)),
 					   attr_name,
-					   mailbox_get_last_error(mailbox_transaction_get_mailbox(t), NULL));
-
+					   mailbox_get_last_internal_error(mailbox_transaction_get_mailbox(t), NULL));
 	}
 
 	return ret;
@@ -252,7 +251,7 @@
 					    MAILBOX_FLAG_READONLY);
 	if (mailbox_open(box) < 0)
 		i_fatal("mailbox_open(INBOX) failed: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 	if (mail_crypt_box_generate_keypair(box, &pair, user_key, &pubid,
 					    &error) < 0) {
 		i_error("generate_keypair failed: %s", error);
@@ -313,7 +312,7 @@
 					    MAILBOX_FLAG_READONLY);
 	if (mailbox_open(box) < 0)
 		i_fatal("mailbox_open(INBOX) failed: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 	/* verify links */
 
 	/* user's public key */
@@ -410,7 +409,7 @@
 					    MAILBOX_FLAG_READONLY);
 	if (mailbox_open(box) < 0)
 		i_fatal("mailbox_open(INBOX) failed: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 
 	struct mailbox_transaction_context *t = mailbox_transaction_begin(box, 0);
 
--- a/src/plugins/pop3-migration/pop3-migration-plugin.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/pop3-migration/pop3-migration-plugin.c	Thu Mar 16 11:15:18 2017 +0200
@@ -237,7 +237,7 @@
 	int ret;
 
 	if (mail_get_hdr_stream(mail, NULL, &input) < 0) {
-		errstr = mailbox_get_last_error(mail->box, &error);
+		errstr = mailbox_get_last_internal_error(mail->box, &error);
 		i_error("pop3_migration: Failed to get header for msg %u: %s",
 			mail->seq, errstr);
 		return error == MAIL_ERROR_EXPUNGED ? 0 : -1;
@@ -272,7 +272,7 @@
 	   (and/or RETR) and we'll parse the header ourself from it. This
 	   should work around any similar bugs in all IMAP/POP3 servers. */
 	if (mail_get_stream_because(mail, NULL, NULL, "pop3-migration", &input) < 0) {
-		errstr = mailbox_get_last_error(mail->box, &error);
+		errstr = mailbox_get_last_internal_error(mail->box, &error);
 		i_error("pop3_migration: Failed to get body for msg %u: %s",
 			mail->seq, errstr);
 		return error == MAIL_ERROR_EXPUNGED ? 0 : -1;
@@ -342,7 +342,7 @@
 
 	if (mailbox_sync(pop3_box, 0) < 0) {
 		i_error("pop3_migration: Couldn't sync mailbox %s: %s",
-			pop3_box->vname, mailbox_get_last_error(pop3_box, NULL));
+			pop3_box->vname, mailbox_get_last_internal_error(pop3_box, NULL));
 		return -1;
 	}
 
@@ -363,7 +363,7 @@
 		else if (mail_get_physical_size(mail, &size) < 0) {
 			i_error("pop3_migration: Failed to get size for msg %u: %s",
 				mail->seq,
-				mailbox_get_last_error(pop3_box, NULL));
+				mailbox_get_last_internal_error(pop3_box, NULL));
 			ret = -1;
 			break;
 		}
@@ -372,7 +372,7 @@
 		if (mail_get_special(mail, MAIL_FETCH_UIDL_BACKEND, &uidl) < 0) {
 			i_error("pop3_migration: Failed to get UIDL for msg %u: %s",
 				mail->seq,
-				mailbox_get_last_error(pop3_box, NULL));
+				mailbox_get_last_internal_error(pop3_box, NULL));
 			ret = -1;
 			break;
 		}
@@ -390,7 +390,7 @@
 
 	if (mailbox_search_deinit(&ctx) < 0) {
 		i_error("pop3_migration: Failed to search all POP3 mails: %s",
-			mailbox_get_last_error(pop3_box, NULL));
+			mailbox_get_last_internal_error(pop3_box, NULL));
 		ret = -1;
 	}
 	(void)mailbox_transaction_commit(&t);
@@ -419,7 +419,7 @@
 
 	if (mailbox_search_deinit(&ctx) < 0) {
 		i_warning("pop3_migration: Failed to search all cached POP3 header hashes: %s - ignoring",
-			  mailbox_get_last_error(t->box, NULL));
+			  mailbox_get_last_internal_error(t->box, NULL));
 	}
 }
 
@@ -475,7 +475,7 @@
 
 	if (mailbox_search_deinit(&ctx) < 0) {
 		i_error("pop3_migration: Failed to search all mail headers: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 	(void)mailbox_transaction_commit(&t);
@@ -539,7 +539,7 @@
 		else if (mail_get_physical_size(mail, &psize) < 0) {
 			i_error("pop3_migration: Failed to get psize for imap uid %u: %s",
 				mail->uid,
-				mailbox_get_last_error(box, NULL));
+				mailbox_get_last_internal_error(box, NULL));
 			ret = -1;
 			break;
 		}
@@ -551,7 +551,7 @@
 
 	if (mailbox_search_deinit(&ctx) < 0) {
 		i_error("pop3_migration: Failed to search all IMAP mails: %s",
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		ret = -1;
 	}
 	(void)mailbox_transaction_commit(&t);
--- a/src/plugins/push-notification/push-notification-driver-ox.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/push-notification/push-notification-driver-ox.c	Thu Mar 16 11:15:18 2017 +0200
@@ -164,7 +164,7 @@
         inbox = mailbox_alloc(ns->list, "INBOX", MAILBOX_FLAG_READONLY);
         if (mailbox_open(inbox) < 0) {
             i_error(OX_LOG_LABEL "Skipped because unable to open INBOX: %s",
-                    mailbox_get_last_error(inbox, NULL));
+                    mailbox_get_last_internal_error(inbox, NULL));
         } else {
             mctx = mailbox_transaction_begin(inbox, 0);
         }
@@ -175,7 +175,7 @@
                                     OX_METADATA_KEY, &attr);
         if (ret < 0) {
             i_error(OX_LOG_LABEL "Skipped because unable to get attribute: %s",
-                    mailbox_get_last_error(inbox, NULL));
+                    mailbox_get_last_internal_error(inbox, NULL));
         } else if (ret == 0) {
             push_notification_driver_debug(OX_LOG_LABEL, dtxn->ptxn->muser,
                                            "Skipped because not active (/private/"OX_METADATA_KEY" METADATA not set)");
@@ -185,7 +185,7 @@
 
         if (!use_existing_txn && (mailbox_transaction_commit(&mctx) < 0)) {
             i_error(OX_LOG_LABEL "Transaction commit failed: %s",
-                    mailbox_get_last_error(inbox, NULL));
+                    mailbox_get_last_internal_error(inbox, NULL));
             /* the commit doesn't matter though. */
         }
     }
@@ -327,7 +327,7 @@
     /* open and sync new instance of the same mailbox to get most recent status */
     box = mailbox_alloc(mailbox_get_namespace(mbox)->list, mailbox_get_name(mbox), MAILBOX_FLAG_READONLY);
     if (mailbox_sync(box, 0) < 0) {
-        i_error("mailbox_sync(%s) failed: %s", mailbox_get_vname(mbox), mailbox_get_last_error(box, NULL));
+        i_error("mailbox_sync(%s) failed: %s", mailbox_get_vname(mbox), mailbox_get_last_internal_error(box, NULL));
         ret = -1;
     } else {
         /* only 'unseen' is needed at the moment */
--- a/src/plugins/push-notification/push-notification-event-mailboxcreate.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/push-notification/push-notification-event-mailboxcreate.c	Thu Mar 16 11:15:18 2017 +0200
@@ -29,7 +29,7 @@
     if (mailbox_get_status(ptxn->mbox, STATUS_UIDVALIDITY, &status) < 0) {
         i_error(EVENT_NAME "Failed to get created mailbox '%s' uidvalidity: %s",
                 mailbox_get_vname(ptxn->mbox),
-                mailbox_get_last_error(ptxn->mbox, NULL));
+                mailbox_get_last_internal_error(ptxn->mbox, NULL));
         status.uidvalidity = 0;
     }
 
--- a/src/plugins/quota/quota-count.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/quota/quota-count.c	Thu Mar 16 11:15:18 2017 +0200
@@ -50,7 +50,7 @@
 					MAILBOX_METADATA_PHYSICAL_SIZE,
 					&metadata) < 0 ||
 	    mailbox_get_status(box, STATUS_MESSAGES, &status) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error == MAIL_ERROR_TEMP) {
 			i_error("quota: Couldn't get size of mailbox %s: %s",
 				vname, errstr);
@@ -252,7 +252,7 @@
 	enum mail_error error;
 
 	if (mailbox_open(box) < 0) {
-		errstr = mailbox_get_last_error(box, &error);
+		errstr = mailbox_get_last_internal_error(box, &error);
 		if (error != MAIL_ERROR_TEMP) {
 			/* non-temporary error, e.g. ACLs denied access. */
 			return 0;
@@ -273,13 +273,13 @@
 	if (mailbox_get_metadata(box, MAILBOX_METADATA_VIRTUAL_SIZE,
 				 &metadata) < 0) {
 		i_error("Couldn't get mailbox %s vsize: %s", box->vname,
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 	/* call sync to write the change to mailbox list index */
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FAST) < 0) {
 		i_error("Couldn't sync mailbox %s: %s", box->vname,
-			mailbox_get_last_error(box, NULL));
+			mailbox_get_last_internal_error(box, NULL));
 		return -1;
 	}
 	return 0;
--- a/src/plugins/quota/quota.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/plugins/quota/quota.c	Thu Mar 16 11:15:18 2017 +0200
@@ -1195,7 +1195,7 @@
 
 	if (mail_get_physical_size(mail, &size) < 0) {
 		enum mail_error error;
-		const char *errstr = mailbox_get_last_error(mail->box, &error);
+		const char *errstr = mailbox_get_last_internal_error(mail->box, &error);
 
 		if (error == MAIL_ERROR_EXPUNGED) {
 			/* mail being copied was already expunged. it'll fail,
--- a/src/pop3/pop3-client.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/pop3/pop3-client.c	Thu Mar 16 11:15:18 2017 +0200
@@ -247,7 +247,7 @@
 		*error_r = t_strdup_printf(
 			"pop3_deleted_flags: Invalid keyword '%s': %s",
 			client->set->pop3_deleted_flag,
-			mailbox_get_last_error(client->mailbox, NULL));
+			mailbox_get_last_internal_error(client->mailbox, NULL));
 		return -1;
 	}
 	return 0;
@@ -277,7 +277,7 @@
 	}
 
 	if (ret < 0) {
-		*error_r = mailbox_get_last_error(client->mailbox, NULL);
+		*error_r = mailbox_get_last_internal_error(client->mailbox, NULL);
 		client_send_storage_error(client);
 	} else {
 		if (failed_uid == last_failed_uid && failed_uid != 0) {
@@ -467,7 +467,7 @@
 	client->mailbox = mailbox_alloc(client->inbox_ns->list, "INBOX", flags);
 	if (mailbox_open(client->mailbox) < 0) {
 		*error_r = t_strdup_printf("Couldn't open INBOX: %s",
-			mailbox_get_last_error(client->mailbox, NULL));
+			mailbox_get_last_internal_error(client->mailbox, NULL));
 		client_send_storage_error(client);
 		return -1;
 	}
--- a/src/pop3/pop3-commands.c	Fri Mar 17 09:23:00 2017 +0200
+++ b/src/pop3/pop3-commands.c	Thu Mar 16 11:15:18 2017 +0200
@@ -611,7 +611,7 @@
 		if (mail_get_special(mail, MAIL_FETCH_HEADER_MD5,
 				     &tab[2].value) < 0) {
 			i_error("UIDL: Header MD5 lookup failed: %s",
-				mailbox_get_last_error(mail->box, NULL));
+				mailbox_get_last_internal_error(mail->box, NULL));
 			return -1;
 		} else if (*tab[2].value == '\0') {
 			i_error("UIDL: Header MD5 not found "
@@ -623,7 +623,7 @@
 		if (mail_get_special(mail, MAIL_FETCH_STORAGE_ID,
 				     &tab[3].value) < 0) {
 			i_error("UIDL: File name lookup failed: %s",
-				mailbox_get_last_error(mail->box, NULL));
+				mailbox_get_last_internal_error(mail->box, NULL));
 			return -1;
 		} else if (*tab[3].value == '\0') {
 			i_error("UIDL: File name not found "
@@ -635,7 +635,7 @@
 		if (mail_get_special(mail, MAIL_FETCH_GUID,
 				     &tab[4].value) < 0) {
 			i_error("UIDL: Message GUID lookup failed: %s",
-				mailbox_get_last_error(mail->box, NULL));
+				mailbox_get_last_internal_error(mail->box, NULL));
 			return -1;
 		} else if (*tab[4].value == '\0') {
 			i_error("UIDL: Message GUID not found "