Class MaildirMailboxStore

java.lang.Object
org.bluezoo.gumdrop.mailbox.maildir.MaildirMailboxStore
All Implemented Interfaces:
MailboxStore

public class MaildirMailboxStore extends Object implements MailboxStore
Mail store implementation using Maildir++ format.

This implementation provides multi-folder mailbox support for IMAP using the Maildir++ format. Each mailbox is a directory containing cur/, new/, and tmp/ subdirectories.

Directory structure (Maildir++):

 root/
   username/
     cur/               (INBOX messages)
     new/               (INBOX new messages)
     tmp/               (INBOX temp files)
     .Sent/
       cur/ new/ tmp/   (Sent folder)
     .Drafts/
       cur/ new/ tmp/   (Drafts folder)
     .folder.subfolder/
       cur/ new/ tmp/   (nested folder)
     .subscriptions     (subscribed mailboxes)
 

The hierarchy delimiter is "/" but folder directories use "." prefix and "." as separator (Maildir++ convention).

Security: All paths are sandboxed to prevent directory traversal attacks. Paths containing ".." or absolute references are rejected.

Author:
Chris Burdess
See Also:
  • Constructor Details

    • MaildirMailboxStore

      public MaildirMailboxStore(Path rootDirectory)
      Creates a new Maildir mail store.
      Parameters:
      rootDirectory - the root directory for all user mailboxes
  • Method Details

    • open

      public void open(String username) throws IOException
      Description copied from interface: MailboxStore
      Opens the mail store for the specified user. This should be called after successful authentication.
      Specified by:
      open in interface MailboxStore
      Parameters:
      username - the user whose mail store to open
      Throws:
      IOException - if the store cannot be opened
    • close

      public void close() throws IOException
      Description copied from interface: MailboxStore
      Closes the mail store and releases any resources. All open mailboxes should be closed before calling this.
      Specified by:
      close in interface MailboxStore
      Throws:
      IOException - if the store cannot be closed properly
    • getHierarchyDelimiter

      public char getHierarchyDelimiter()
      Description copied from interface: MailboxStore
      Returns the hierarchy delimiter character used by this store. This separates levels in mailbox names (e.g., "INBOX/Subfolder").
      Specified by:
      getHierarchyDelimiter in interface MailboxStore
      Returns:
      the hierarchy delimiter (typically "/" or ".")
    • listMailboxes

      public List<String> listMailboxes(String reference, String pattern) throws IOException
      Description copied from interface: MailboxStore
      Lists mailboxes matching the given reference and pattern.

      The reference is a prefix that is prepended to the pattern. The pattern may contain wildcards:

      • "*" matches any characters including hierarchy delimiter
      • "%" matches any characters except hierarchy delimiter
      Specified by:
      listMailboxes in interface MailboxStore
      Parameters:
      reference - the reference name (prefix)
      pattern - the mailbox name pattern with optional wildcards
      Returns:
      list of matching mailbox names
      Throws:
      IOException - if the list cannot be retrieved
    • listSubscribed

      public List<String> listSubscribed(String reference, String pattern) throws IOException
      Description copied from interface: MailboxStore
      Returns subscription status for mailboxes matching the pattern. For IMAP LSUB command support.
      Specified by:
      listSubscribed in interface MailboxStore
      Parameters:
      reference - the reference name (prefix)
      pattern - the mailbox name pattern with optional wildcards
      Returns:
      list of subscribed mailbox names matching the pattern
      Throws:
      IOException - if the list cannot be retrieved
    • subscribe

      public void subscribe(String mailboxName) throws IOException
      Description copied from interface: MailboxStore
      Subscribes to a mailbox.
      Specified by:
      subscribe in interface MailboxStore
      Parameters:
      mailboxName - the name of the mailbox to subscribe to
      Throws:
      IOException - if the subscription fails
    • unsubscribe

      public void unsubscribe(String mailboxName) throws IOException
      Description copied from interface: MailboxStore
      Unsubscribes from a mailbox.
      Specified by:
      unsubscribe in interface MailboxStore
      Parameters:
      mailboxName - the name of the mailbox to unsubscribe from
      Throws:
      IOException - if the unsubscription fails
    • openMailbox

      public Mailbox openMailbox(String mailboxName, boolean readOnly) throws IOException
      Description copied from interface: MailboxStore
      Opens a mailbox by name. For POP3 compatibility, "INBOX" should always be available.
      Specified by:
      openMailbox in interface MailboxStore
      Parameters:
      mailboxName - the name of the mailbox to open
      readOnly - true to open in read-only mode
      Returns:
      the opened mailbox
      Throws:
      IOException - if the mailbox cannot be opened
    • createMailbox

      public void createMailbox(String mailboxName) throws IOException
      Description copied from interface: MailboxStore
      Creates a new mailbox.
      Specified by:
      createMailbox in interface MailboxStore
      Parameters:
      mailboxName - the name of the mailbox to create
      Throws:
      IOException - if the mailbox cannot be created
    • deleteMailbox

      public void deleteMailbox(String mailboxName) throws IOException
      Description copied from interface: MailboxStore
      Deletes a mailbox. The mailbox must be empty and not currently selected.
      Specified by:
      deleteMailbox in interface MailboxStore
      Parameters:
      mailboxName - the name of the mailbox to delete
      Throws:
      IOException - if the mailbox cannot be deleted
    • renameMailbox

      public void renameMailbox(String oldName, String newName) throws IOException
      Description copied from interface: MailboxStore
      Renames a mailbox.
      Specified by:
      renameMailbox in interface MailboxStore
      Parameters:
      oldName - the current mailbox name
      newName - the new mailbox name
      Throws:
      IOException - if the mailbox cannot be renamed
    • getMailboxAttributes

      public Set<MailboxAttribute> getMailboxAttributes(String mailboxName) throws IOException
      Description copied from interface: MailboxStore
      Returns the mailbox attributes for the specified mailbox. These are IMAP mailbox attributes like \Noselect, \Noinferiors, etc.
      Specified by:
      getMailboxAttributes in interface MailboxStore
      Parameters:
      mailboxName - the mailbox name
      Returns:
      set of mailbox attributes
      Throws:
      IOException - if attributes cannot be retrieved
    • getQuotaRoot

      public String getQuotaRoot(String mailboxName) throws IOException
      Description copied from interface: MailboxStore
      Returns the quota root for the specified mailbox. For IMAP QUOTA extension support.
      Specified by:
      getQuotaRoot in interface MailboxStore
      Parameters:
      mailboxName - the mailbox name
      Returns:
      the quota root name, or null if quotas are not supported
      Throws:
      IOException - if the quota root cannot be determined
    • getQuota

      public MailboxStore.Quota getQuota(String quotaRoot) throws IOException
      Description copied from interface: MailboxStore
      Returns the quota information for the specified quota root. For IMAP QUOTA extension support.
      Specified by:
      getQuota in interface MailboxStore
      Parameters:
      quotaRoot - the quota root name
      Returns:
      the quota information, or null if not available
      Throws:
      IOException - if quota information cannot be retrieved