How do I create separate mailbox configurations per virtual user with Dovecot?

Let's say I have two virtual users: [email protected] and [email protected].

I want the mailboxes for bugs to be configured like this...:

mailbox Sent {
  special_use = \Sent
}
mailbox Drafts {
  special_use = \Drafts
}
mailbox "Priority 1" {
  auto = subscribe
}
mailbox "Priority 2" {
  auto = subscribe
}
mailbox "Priority 3" {
  auto = subscribe
}
mailbox Unreplied {
  auto = subscribe
}
mailbox Resolved {
  auto = subscribe
}

...but have the mailboxes for admin have some different folders configured:

mailbox Sent {
  special_use = \Sent
}
mailbox Drafts {
  special_use = \Drafts
}
mailbox System {
  auto = subscribe
}
mailbox DMARC {
  auto = subscribe
}
mailbox Archives {
  auto = create
  special_use = \Archive
}
mailbox Trash {
  special_use = \Trash
}
mailbox Spam {
  auto = create
  special_use = \Junk
}

I don't want the folders for the bugs email to be copied over to the admin email, and vice versa.

What I've tried is using namespaces and then setting each virtual user's inbox namespace name via my passwd file, like this:

admin:<password>::::::userdb_mail=maildir:/home/mail/admin NAMESPACE=primary userdb_namespace/primary/inbox=yes userdb_namespace/primary/list=yes userdb_namespace/primary/prefix=primary/

bugs:<password>::::::userdb_mail=maildir:/home/mail/bugs NAMESPACE=bugs userdb_namespace/bugs/inbox=yes userdb_namespace/bugs/list=yes userdb_namespace/bugs/prefix=bugs/

but Dovecot's logs say:

namespace configuration error: Duplicate namespace prefix: "" in=0 out=408 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0

My full 15-mailboxes.conf:

namespace bugs {
  list = no
  type = private
  mailbox Sent {
    special_use = \Sent
  }
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox "Priority 1" {
    auto = subscribe
  }
  mailbox "Priority 2" {
    auto = subscribe
  }
  mailbox "Priority 3" {
    auto = subscribe
  }
  mailbox Unreplied {
    auto = subscribe
  }
  mailbox Resolved {
    auto = subscribe
  }
}
namespace primary {
  list = no
  type = private
  mailbox Sent {
    special_use = \Sent
  }
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox System {
    auto = subscribe
  }
  mailbox DMARC {
    auto = subscribe
  }
  mailbox Archives {
    auto = create
    special_use = \Archive
  }
  mailbox Trash {
    special_use = \Trash
  }
  mailbox Spam {
    auto = create
    special_use = \Junk
  }
}

Solution 1:

Disable & move duplicate prefixes out of the way, then revert these changes from userdb.

While you cannot have two namespaces defined with the same prefix - you do not have to define them that way if you are overriding via userdb anyway.

# in global configuration
namespace primary {
  disabled = yes
  prefix = /disable-namespace
  ...
}

# in userdb: newlines for readability
userdb_mail=maildir:/home/mail/admin
userdb_namespace=primary
userdb_namespace/primary/disabled=no
userdb_namespace/primary/prefix=
userdb_namespace/primary/inbox=yes

Careful with list=no, it does not prevent access. It merely removes the folders from the LIST output, the folder is still there (and thus precludes a second one with matching prefix!)

It is still possible to list the namespace’s folders by explicitly asking for them.

Note: That NAMESPACE=primary in your question looks out of place, why is that in the userdb (but not prefixed userdb_)?