org.abstracthorizon.mercury.common
Class SimpleStorageManager

java.lang.Object
  extended by org.abstracthorizon.mercury.common.SimpleStorageManager
All Implemented Interfaces:
StorageManager
Direct Known Subclasses:
MaildirKeystoreStorageManager, SimpleJAASStorageManager

public class SimpleStorageManager
extends Object
implements StorageManager

This class is simple implementation of SMTPManager that uses properties file to read (and write) domain names to served, mail boxes that exist and aliases that point to existing mailboxes.

Format of properties file is as described in Properties and this class uses special prefixes and property names to denote domain names, mailboxes and aliases:

Author:
Daniel Sendula

Nested Class Summary
protected static class SimpleStorageManager.Entry
          Entry
protected static class SimpleStorageManager.URLNameFix
          Fix for url name
 
Field Summary
protected  boolean autosave
          Shell changes in properties automatically trigger saving values back to the file
protected  boolean caseSensitive
          Mail box is case sensitive flag
protected static org.slf4j.Logger logger
          Logger
protected  File propertiesFile
          Properties file
protected  Properties props
          Properties to keep all elements in
protected  javax.mail.Session session
          Maildir session to work in
 
Constructor Summary
SimpleStorageManager()
          Constructor
 
Method Summary
 void addAlias(String mailbox, String destMailbox)
          Utility method that adds new alias to this manager.
 void addDomain(String domain)
          Adds new domain to this manager.
 void addEntry(String mailbox, String entry)
          Adds new "raw" entry to properties.
 void addMailbox(String mailbox, String store)
          Utility method to add new mailbox to this manager.
protected  javax.mail.URLName createURLName(String username, String password, String storeString)
           
protected  String decorateStoreString(String mailbox, String domain, String storeString)
           
 javax.mail.Folder findInbox(String mailbox, String domain, char[] password)
          Updates path parameter with local mailbox (folder from JavaMail if mailbox/alias exists.
 javax.mail.Store findStore(String mailbox, String domain, char[] password)
          Returns local store if user is local or null otherwise.
 String[] getAliases()
          Returns all aliases
 String[] getDomains()
          Returns all domains that are served
 javax.mail.Session getJavaMailSession()
          Returns java mail session
 String[] getMailboxNames()
          Returns all mailbox urls
 String[] getMailboxNames(String domain)
          Returns all mailbox urls
 String getMainDomain()
          Returns main domain as it appears in HELO/EHLO command response
 File getPropertiesFile()
          Returns properties file
protected  InputStream getPropertiesInputStream()
          Returns input stream to read properties from
protected  OutputStream getPropertiesOutputStream()
          Returns output stream to write properties to
 boolean hasDomain(String domain)
          Returns true if domain is served by this server
 void init()
          This method loads properties and sets the session if not already defined
 boolean isAutosave()
          Returns autosave flag
 boolean isCaseSensitive()
          Returns case senstive
 void load()
          This method loads the properties
protected  String makeEntry(String mailbox, String domain)
           
protected  javax.mail.Store obtainStore(javax.mail.URLName urlName)
           
protected  String obtainStoreString(String mailbox, String domain)
           
 void removeAlias(String mailbox)
          Removes the alias.
 boolean removeDomain(String domain)
          Deletes domain
 boolean removeMailbox(String mailbox, String domain)
          Removes mailbox
 void save()
          This method saves the properties
 void setAutosave(boolean autosave)
          Sets autosave flag
 void setCaseSensitive(boolean caseSensitive)
          Sets case sensitive flag
 void setJavaMailSession(javax.mail.Session session)
          Sets java mail session
 void setMainDomain(String domain)
          Sets main domain name
 void setPropertiesFile(File propertiesFile)
          Setter for file
protected  void toLowerCase()
          Converts all entries to lower case
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

caseSensitive

protected boolean caseSensitive
Mail box is case sensitive flag


props

protected Properties props
Properties to keep all elements in


session

protected javax.mail.Session session
Maildir session to work in


propertiesFile

protected File propertiesFile
Properties file


autosave

protected boolean autosave
Shell changes in properties automatically trigger saving values back to the file


logger

protected static final org.slf4j.Logger logger
Logger

Constructor Detail

SimpleStorageManager

public SimpleStorageManager()
Constructor

Method Detail

setPropertiesFile

public void setPropertiesFile(File propertiesFile)
Setter for file

Parameters:
propertiesFile - file

getPropertiesFile

public File getPropertiesFile()
Returns properties file

Returns:
properties file

setAutosave

public void setAutosave(boolean autosave)
Sets autosave flag

Parameters:
autosave - autosave flag
See Also:
autosave

isAutosave

public boolean isAutosave()
Returns autosave flag

Returns:
autosave flag
See Also:
autosave

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)
Sets case sensitive flag

Parameters:
caseSensitive - case sensitive
See Also:
caseSensitive

isCaseSensitive

public boolean isCaseSensitive()
Returns case senstive

Returns:
case sensitive
See Also:
caseSensitive

getJavaMailSession

public javax.mail.Session getJavaMailSession()
Returns java mail session

Returns:
java mail session

setJavaMailSession

public void setJavaMailSession(javax.mail.Session session)
Sets java mail session

Parameters:
session - java mail session

init

public void init()
          throws IOException
This method loads properties and sets the session if not already defined

Throws:
IOException

load

public void load()
          throws IOException
This method loads the properties

Throws:
IOException

save

public void save()
This method saves the properties

Throws:
IOException

getPropertiesInputStream

protected InputStream getPropertiesInputStream()
                                        throws IOException
Returns input stream to read properties from

Returns:
input stream to read properties from
Throws:
IOException

getPropertiesOutputStream

protected OutputStream getPropertiesOutputStream()
                                          throws IOException
Returns output stream to write properties to

Returns:
output stream to write properties to
Throws:
IOException

getMainDomain

public String getMainDomain()
Returns main domain as it appears in HELO/EHLO command response

Specified by:
getMainDomain in interface StorageManager
Returns:
main domain

setMainDomain

public void setMainDomain(String domain)
Sets main domain name

Parameters:
domain - main domain name

hasDomain

public boolean hasDomain(String domain)
Returns true if domain is served by this server

Specified by:
hasDomain in interface StorageManager
Parameters:
true - if domain is served by this server
Returns:
true in case supplied domain is local for this SMTP server

findStore

public javax.mail.Store findStore(String mailbox,
                                  String domain,
                                  char[] password)
                           throws UserRejectedException,
                                  javax.mail.MessagingException
Description copied from interface: StorageManager
Returns local store if user is local or null otherwise. In case that user is to be rejected an exception is thrown.

Specified by:
findStore in interface StorageManager
Parameters:
mailbox - user's mailbox
domain - user's domain
Throws:
UserRejectedException - in case that user is rejected for any reason
javax.mail.MessagingException - in case there is a problem accessing user's mailbox

findInbox

public javax.mail.Folder findInbox(String mailbox,
                                   String domain,
                                   char[] password)
                            throws UserRejectedException,
                                   javax.mail.MessagingException
Updates path parameter with local mailbox (folder from JavaMail if mailbox/alias exists.

Specified by:
findInbox in interface StorageManager
Parameters:
mailbox - mailbox to be accesses
domain - domain
domain - domain where mailbox is supposed ot be defined.
Throws:
UserRejectedException - thrown in user is rejected
javax.mail.MessagingException - if error happens while accessing the folder

obtainStoreString

protected String obtainStoreString(String mailbox,
                                   String domain)
                            throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

decorateStoreString

protected String decorateStoreString(String mailbox,
                                     String domain,
                                     String storeString)

obtainStore

protected javax.mail.Store obtainStore(javax.mail.URLName urlName)
                                throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

createURLName

protected javax.mail.URLName createURLName(String username,
                                           String password,
                                           String storeString)

addMailbox

public void addMailbox(String mailbox,
                       String store)
Utility method to add new mailbox to this manager. It saves properties if autosave is on.

Parameters:
mailbox - mailbox (name@domain).
store - url
Throws:
IOException

addAlias

public void addAlias(String mailbox,
                     String destMailbox)
              throws IOException
Utility method that adds new alias to this manager. It saves properties if autosave is on.

Parameters:
mailbox - mailbox (name@domain)
destMailbox - destination mailbox (name@domain)
Throws:
IOException

removeAlias

public void removeAlias(String mailbox)
Removes the alias. It won't remove anything else.

Parameters:
mailbox - removes the alias

addDomain

public void addDomain(String domain)
Adds new domain to this manager. It saves properties if autosave is on.

Parameters:
domain - domain name.
Throws:
IOException

addEntry

public void addEntry(String mailbox,
                     String entry)
              throws IOException
Adds new "raw" entry to properties.

Parameters:
mailbox - key that is automatically prefixed with "-"
entry - entry
Throws:
IOException

removeMailbox

public boolean removeMailbox(String mailbox,
                             String domain)
Removes mailbox

Parameters:
mailbox - mailbox
Throws:
IOException

removeDomain

public boolean removeDomain(String domain)
Deletes domain

Parameters:
domain - domain name
Throws:
IOException

getDomains

public String[] getDomains()
Returns all domains that are served

Returns:
all domains that are served

getMailboxNames

public String[] getMailboxNames()
Returns all mailbox urls

Returns:
mailbox urls

getMailboxNames

public String[] getMailboxNames(String domain)
Returns all mailbox urls

Parameters:
domain - domain name
Returns:
mailbox urls

getAliases

public String[] getAliases()
Returns all aliases

Returns:
all aliases

toLowerCase

protected void toLowerCase()
Converts all entries to lower case


makeEntry

protected String makeEntry(String mailbox,
                           String domain)


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.