diff --git a/em-format/em-format.c b/em-format/em-format.c
index 071403d..86fafdd 100644
--- a/em-format/em-format.c
+++ b/em-format/em-format.c
@@ -2481,7 +2481,8 @@ em_format_build_mail_uri (CamelFolder *folder,
 		folder_name = "generic";
 		service_uid = "generic";
 	} else {
-		folder_name = camel_folder_get_full_name (folder);
+		tmp = (gchar *) camel_folder_get_full_name (folder);
+		folder_name = (const gchar *) soup_uri_encode (tmp, NULL);
 		store = camel_folder_get_parent_store (folder);
 		if (store)
 			service_uid = camel_service_get_uid (CAMEL_SERVICE (store));
@@ -2494,6 +2495,10 @@ em_format_build_mail_uri (CamelFolder *folder,
 			folder_name,
 			message_uid);
 
+	if (folder) {
+		g_free ((gchar *) folder_name);
+	}
+
 	va_start (ap, first_param_name);
 	name = first_param_name;
 	separator = '?';
@@ -2539,14 +2544,15 @@ em_format_build_mail_uri (CamelFolder *folder,
 	va_end (ap);
 
 	uri = tmp;
+	if (uri == NULL)
+		return NULL;
 
 	/* For some reason, webkit won't accept URL with username, but
 	 * without password (mail://store@host/folder/mail), so we
 	 * will replace the '@' symbol by '/' to get URL like
 	 * mail://store/host/folder/mail which is OK
 	 */
-	tmp = strchr (tmp, '@');
-	if (tmp) {
+	while ((tmp = strchr (uri, '@')) != NULL) {
 		tmp[0] = '/';
 	}
 
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index a99240e..9124b95 100644
--- a/mail/e-mail-request.c
+++ b/mail/e-mail-request.c
@@ -643,9 +643,7 @@ mail_request_send_async (SoupRequest *request,
 
 		uri_str = g_strdup_printf (
 			"%s://%s%s", uri->scheme, uri->host, uri->path);
-		decoded_uri = soup_uri_decode (uri_str);
-		emr->priv->efh = g_hash_table_lookup (formatters, decoded_uri);
-		g_free (decoded_uri);
+		emr->priv->efh = g_hash_table_lookup (formatters, uri_str);
 		g_free (uri_str);
 
 		g_return_if_fail (emr->priv->efh);
