org.objectledge.mail
Class MailSystem

java.lang.Object
  extended by org.objectledge.mail.MailSystem

public class MailSystem
extends Object

Mail system component.

Version:
$Id: MailSystem.java,v 1.14 2006/05/05 08:43:11 rafal Exp $
Author:
Rafal Krzewski, Pawel Potempski

Nested Class Summary
private  class MailSystem.DeliverMailTask
          Deaemon task responsible for sending enqueued e-mail messages.
static class MailSystem.LedgeAuthenticator
          The authenticator .
 
Field Summary
private  String debugAddress
          system mail logger
static String DEFAULT_SESSION
          The default session name (default).
private  String defaultSession
          default provider
static String EMAIL_ADDRESS_PATTERN
          The regex email address patter.
private  Pattern emailAddressPattern
          email address validator pattern
private  FileSystem fileSystem
          file service
private  org.jcontainer.dna.Logger logger
          logger
private  LinkedList<LedgeMessage> mailQueue
          mail queue
private  javax.activation.MimetypesFileTypeMap mimeMap
          map with mime types
private  Map<String,javax.mail.Session> sessionsMap
          server list - not implemented
private  String systemAddress
          system address
private  Templating templating
          templating
private  ThreadPool threadPool
          thread pool
 
Constructor Summary
protected MailSystem()
          No-arg ctor for mocking.
  MailSystem(org.jcontainer.dna.Configuration config, org.jcontainer.dna.Logger logger, FileSystem fileSystem, Templating templating, ThreadPool threadPool)
          Initializes the component.
 
Method Summary
 String getContentType(String filename)
          Guess MIME type from file name extension.
 javax.activation.DataSource getDataSource(String name)
          Returns a DataSource backed by the FileSystem.
 javax.mail.Session getSession()
          Returns the default mail session.
 javax.mail.Session getSession(String name)
          Returns a mail session declared in the service configuration.
 String getSystemAddress()
          Get the system address.
 boolean isValidEmailAddress(String address)
          Checks if given address is valid.
 LedgeMessage newMessage()
          Create a new message based on default session.
 LedgeMessage newMessage(javax.mail.Message message)
          Create a new message based on a pre-existing JavaMali message object and the default session.
 LedgeMessage newMessage(String sessionName)
          Create a new message based on session defined in the configuration file.
 LedgeMessage newMessage(String sessionName, javax.mail.Message message)
          Create a new message based on a pre-existing JavaMali message object.
 void send(LedgeMessage message, boolean wait)
          Send the message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SESSION

public static final String DEFAULT_SESSION
The default session name (default).

See Also:
Constant Field Values

EMAIL_ADDRESS_PATTERN

public static final String EMAIL_ADDRESS_PATTERN
The regex email address patter.

See Also:
Constant Field Values

logger

private org.jcontainer.dna.Logger logger
logger


threadPool

private ThreadPool threadPool
thread pool


fileSystem

private FileSystem fileSystem
file service


templating

private Templating templating
templating


mimeMap

private javax.activation.MimetypesFileTypeMap mimeMap
map with mime types


mailQueue

private LinkedList<LedgeMessage> mailQueue
mail queue


sessionsMap

private Map<String,javax.mail.Session> sessionsMap
server list - not implemented


defaultSession

private String defaultSession
default provider


debugAddress

private String debugAddress
system mail logger


systemAddress

private String systemAddress
system address


emailAddressPattern

private Pattern emailAddressPattern
email address validator pattern

Constructor Detail

MailSystem

protected MailSystem()
No-arg ctor for mocking.


MailSystem

public MailSystem(org.jcontainer.dna.Configuration config,
                  org.jcontainer.dna.Logger logger,
                  FileSystem fileSystem,
                  Templating templating,
                  ThreadPool threadPool)
Initializes the component.

Parameters:
config - the configuration.
logger - the logger.
fileSystem - the file system.
templating - the templating.
threadPool - the threadPool.
Method Detail

getSession

public javax.mail.Session getSession()
Returns the default mail session.

Returns:
default mail session.

getSession

public javax.mail.Session getSession(String name)
Returns a mail session declared in the service configuration.

Parameters:
name - the name of the server.
Returns:
the mail session.

getDataSource

public javax.activation.DataSource getDataSource(String name)
Returns a DataSource backed by the FileSystem.

Parameters:
name - the pathname of the file.
Returns:
the data source.

newMessage

public LedgeMessage newMessage()
Create a new message based on default session.

Returns:
the mail message wrapper.

newMessage

public LedgeMessage newMessage(String sessionName)
Create a new message based on session defined in the configuration file.

Parameters:
sessionName - the name of the server.
Returns:
the mail message wrapper.

newMessage

public LedgeMessage newMessage(javax.mail.Message message)
Create a new message based on a pre-existing JavaMali message object and the default session.

Parameters:
message - the JavaMail message.
Returns:
the mail message wrapper.

newMessage

public LedgeMessage newMessage(String sessionName,
                               javax.mail.Message message)
Create a new message based on a pre-existing JavaMali message object.

Parameters:
sessionName - the name of the session.
message - the JavaMail message.
Returns:
the mail message wrapper.

send

public void send(LedgeMessage message,
                 boolean wait)
          throws javax.mail.MessagingException
Send the message.

If the wait parameter is false, the sending process will proceed asynchronosly, and the method will return immediately, otherwise the method will return only after the sending process is complete.

Parameters:
message - the ledge mail message wrapper.
wait - true to wait for operation completion.
Throws:
javax.mail.MessagingException - thrown if message cannot be send.

getContentType

public String getContentType(String filename)
Guess MIME type from file name extension.

If the extension is missing or unknown application/octet-stream type will be returned.

Parameters:
filename - the filename with extension.
Returns:
the content type.

isValidEmailAddress

public boolean isValidEmailAddress(String address)
Checks if given address is valid.

Parameters:
address - the address
Returns:
true if address is valid.

getSystemAddress

public String getSystemAddress()
Get the system address.

Returns:
the system address.


Copyright © 2003-2006 objectledge.org. All Rights Reserved.