[geary/wip/795595-fix-special-folder-creation: 1/6] Don't include empty root folder path segment constructing a mailbox name
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/795595-fix-special-folder-creation: 1/6] Don't include empty root folder path segment constructing a mailbox name
- Date: Wed, 26 Sep 2018 13:31:21 +0000 (UTC)
commit 3e461e7b45543befdec386f8b52d668743679543
Author: Michael Gratton <mike vee net>
Date: Tue Sep 25 23:33:12 2018 +1000
Don't include empty root folder path segment constructing a mailbox name
This fixes attempts to create special mailboxes as "/Special" instead
of "Special".
.../imap/message/imap-mailbox-specifier.vala | 6 +++
.../imap/message/imap-mailbox-specifier-test.vala | 53 ++++++++++++++++++++++
2 files changed, 59 insertions(+)
---
diff --git a/src/engine/imap/message/imap-mailbox-specifier.vala
b/src/engine/imap/message/imap-mailbox-specifier.vala
index a41212bd..1984338b 100644
--- a/src/engine/imap/message/imap-mailbox-specifier.vala
+++ b/src/engine/imap/message/imap-mailbox-specifier.vala
@@ -127,6 +127,12 @@ public class Geary.Imap.MailboxSpecifier : BaseObject, Gee.Hashable<MailboxSpeci
throw new ImapError.INVALID("Path has more than one part but no delimiter given");
}
+ // Don't include the root if it is an empty string so that
+ // mailboxes do not begin with the delim.
+ if (parts.size > 1 && parts[0] == "") {
+ parts.remove_at(0);
+ }
+
StringBuilder builder = new StringBuilder(
is_inbox_name(parts[0]) ? inbox.name : parts[0]);
diff --git a/test/engine/imap/message/imap-mailbox-specifier-test.vala
b/test/engine/imap/message/imap-mailbox-specifier-test.vala
index 21964708..741f279e 100644
--- a/test/engine/imap/message/imap-mailbox-specifier-test.vala
+++ b/test/engine/imap/message/imap-mailbox-specifier-test.vala
@@ -12,6 +12,7 @@ class Geary.Imap.MailboxSpecifierTest : TestCase {
base("Geary.Imap.MailboxSpecifierTest");
add_test("to_parameter", to_parameter);
add_test("from_parameter", from_parameter);
+ add_test("from_folder_path", from_folder_path);
}
public void to_parameter() throws Error {
@@ -57,4 +58,56 @@ class Geary.Imap.MailboxSpecifierTest : TestCase {
);
}
+ public void from_folder_path() throws Error {
+ MockFolderRoot empty_root = new MockFolderRoot("");
+ MailboxSpecifier empty_inbox = new MailboxSpecifier("Inbox");
+ assert_string(
+ "Foo",
+ new MailboxSpecifier.from_folder_path(
+ empty_root.get_child("Foo"), empty_inbox, "$"
+ ).name
+ );
+ assert_string(
+ "Foo$Bar",
+ new MailboxSpecifier.from_folder_path(
+ empty_root.get_child("Foo").get_child("Bar"), empty_inbox, "$"
+ ).name
+ );
+ assert_string(
+ "Inbox",
+ new MailboxSpecifier.from_folder_path(
+ empty_root.get_child(MailboxSpecifier.CANONICAL_INBOX_NAME),
+ empty_inbox,
+ "$"
+ ).name
+ );
+
+ MockFolderRoot non_empty_root = new MockFolderRoot("Root");
+ MailboxSpecifier non_empty_inbox = new MailboxSpecifier("Inbox");
+ assert_string(
+ "Root$Foo",
+ new MailboxSpecifier.from_folder_path(
+ non_empty_root.get_child("Foo"),
+ non_empty_inbox,
+ "$"
+ ).name
+ );
+ assert_string(
+ "Root$Foo$Bar",
+ new MailboxSpecifier.from_folder_path(
+ non_empty_root.get_child("Foo").get_child("Bar"),
+ non_empty_inbox,
+ "$"
+ ).name
+ );
+ assert_string(
+ "Root$INBOX",
+ new MailboxSpecifier.from_folder_path(
+ non_empty_root.get_child(MailboxSpecifier.CANONICAL_INBOX_NAME),
+ non_empty_inbox,
+ "$"
+ ).name
+ );
+ }
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]