ERJavaMail Class Reference

Inherits er::extensions::ERXFrameworkPrincipal.

Collaboration diagram for ERJavaMail:

Collaboration graph
[legend]

List of all members.

Classes

interface  Delegate

Public Member Functions

String adminEmail ()
NSArray< StringblackListEmailAddressPatterns ()
EOOrQualifier blackListQualifier ()
boolean centralize ()
boolean debugEnabled ()
javax.mail.Session defaultSession ()
String defaultXMailerHeader ()
NSArray< StringfilterEmailAddresses (NSArray< String > emailAddresses)
void finishInitialization ()
boolean hasBlackList ()
boolean hasWhiteList ()
void initializeFrameworkFromSystemProperties ()
synchronized boolean isValidEmail (String email)
int milliSecondsWaitIfSenderOverflowed ()
javax.mail.Session newSession ()
javax.mail.Session newSession (Properties props)
javax.mail.Session newSessionForContext (Properties properties, String contextString)
javax.mail.Session newSessionForMessage (ERMessage message)
int senderQueueSize ()
javax.mail.Session sessionForMessage (ERMessage message)
void setAdminEmail (String adminEmail)
void setCentralize (boolean centralize)
void setDebugEnabled (boolean debug)
void setDefaultSession (javax.mail.Session session)
void setDefaultXMailerHeader (String header)
void setDelegate (Delegate delegate)
void setMilliSecondsWaitIfSenderOverflowed (int value)
void setSenderQueueSize (int value)
String smtpProtocolForContext (String contextString)
String validateEmail (EOEnterpriseObject object, String key, String email)
NSArray< StringwhiteListEmailAddressPatterns ()
EOOrQualifier whiteListQualifier ()

Static Public Member Functions

static ERJavaMail sharedInstance ()

Static Public Attributes

static final Class<?> REQUIRES [] = new Class[] { ERXExtensions.class }

Protected Member Functions

javax.mail.Session newSessionForContext (String contextString)
EOOrQualifier qualifierArrayForEmailPatterns (NSArray< String > emailPatterns)
javax.mail.Session sessionForContext (String contextString)
void setupSmtpHostSafely ()
void setupSmtpProperties (Properties properties, String contextString)

Protected Attributes

String _adminEmail
boolean _centralize = true
boolean _debugEnabled = true
javax.mail.Session _defaultSession
String _defaultXMailerHeader = null
int _milliSecondsWaitIfSenderOverflowed = 6000
Pattern _pattern = null
int _senderQueueSize = 50
EOOrQualifier blackListQualifier
NSArray< StringblakListEmailAddressPatterns
NSArray< StringwhiteListEmailAddressPatterns
EOOrQualifier whiteListQualifier

Static Protected Attributes

static ERJavaMail sharedInstance

Static Package Functions

 [static initializer]

Private Attributes

Delegate _delegate
Map< String, javax.mail.Session > _sessions = new ConcurrentHashMap<String, javax.mail.Session>()

Static Private Attributes

static final String atext = "[a-zA-Z0-9" + sp + "]"
static final String atom = atext + "+"
static final String domain = rfcLabel + "((\\." + rfcLabel + ")*\\." + letter + "{2,6}){0,1}"
static final String dotAtom = "\\." + atom
static final String EMAIL_VALIDATION_PATTERN = "^" + localPart + "@" + domain + "$"
static final String letDig = "[a-zA-Z0-9]"
static final String letDigHyp = "[a-zA-Z0-9\\-]"
static final String letter = "[a-zA-Z]"
static final String localPart = atom + "(" + dotAtom + ")*"
static final Logger log = Logger.getLogger(ERJavaMail.class)
static final String rfcLabel = letDig + "(" + letDigHyp + "{0,61}" + letDig + "){0,1}"
static final String sp = "!#$%&'*+\\-/=?^_`{|}~"


Member Function Documentation

[static initializer] (  )  [static, package]

String adminEmail (  ) 

admin email accessor. The admin email is the email address where centralized mail go to.

Returns:
a String value

NSArray<String> blackListEmailAddressPatterns (  ) 

Gets the array of black list email address patterns.

Returns:
array of black list email address patterns

EOOrQualifier blackListQualifier (  ) 

Gets the Or qualifier to match any of the patterns in the black list.

Returns:
or qualifier

boolean centralize (  ) 

Centralize is used to send all the outbound email to a single address which is useful when debugging.

Returns:
a boolean value

boolean debugEnabled (  ) 

Returns true if JavaMail is debug enabled.

Returns:
a boolean value

javax.mail.Session defaultSession (  ) 

This is the deafult JavaMail Session accessor. It is shared among all deliverers for immediate deliveries. Deferred deliverers, use their own JavaMail session.

Returns:
the default javax.mail.Session instance

String defaultXMailerHeader (  ) 

Gets the default X-Mailer header to use for sending mails. Pulls the value out of the property: er.javamail.XMailerHeader

Returns:
default X-Mailer header

NSArray<String> filterEmailAddresses ( NSArray< String emailAddresses  ) 

Filters an array of email addresses by the black and white lists.

Parameters:
emailAddresses array of email addresses to be filtered
Returns:
array of filtered email addresses

void finishInitialization (  )  [virtual]

Specialized implementation of the method from ERXPrincipalClass.

Implements ERXFrameworkPrincipal.

boolean hasBlackList (  ) 

Determines if a black list has been specified

Returns:
if the black list has any elements in it

boolean hasWhiteList (  ) 

Determines if a white list has been specified

Returns:
if the white list has any elements in it

void initializeFrameworkFromSystemProperties (  ) 

This method is used to initialize ERJavaMail from System properties. Later, we will implement a way to initialize those properties everytime the propertis are changed. The observer will call this method whenever appropriate.

synchronized boolean isValidEmail ( String  email  ) 

Predicate used to validate email well-formness.

Returns:
true if the email is valid
Parameters:
email the email String value to validate
Returns:
a boolean value

int milliSecondsWaitIfSenderOverflowed (  ) 

This method return the time spent waiting if the mail queue if overflowed. During that time, mails are sent and the queue lowers. When the duration is spent, and the queue is under the overflow limit, the mails are being sent again.

Returns:
an int value

javax.mail.Session newSession (  ) 

Returns a newly allocated Session object from the System Properties

Returns:
a javax.mail.Session value

javax.mail.Session newSession ( Properties  props  ) 

Returns a newly allocated Session object from the given Properties

Parameters:
props a Properties value
Returns:
a javax.mail.Session value initialized from the given properties

javax.mail.Session newSessionForContext ( Properties  properties,
String  contextString 
)

Returns a newly allocated Session object from the given Properties

Parameters:
properties a Properties value
Returns:
a javax.mail.Session value initialized from the given properties

javax.mail.Session newSessionForContext ( String  contextString  )  [protected]

Returns a new Session object that is appropriate for the given context.

Parameters:
contextString the message context
Returns:
a new javax.mail.Session value

javax.mail.Session newSessionForMessage ( ERMessage  message  ) 

Returns a newly allocated Session object for the given message.

Parameters:
message the message
Returns:
a new javax.mail.Session value

EOOrQualifier qualifierArrayForEmailPatterns ( NSArray< String emailPatterns  )  [protected]

Constructs an Or qualifier for filtering an array of strings that might have the * wildcard character. Will be nice when we have regex in Java 1.4.

Parameters:
emailPatterns array of email patterns
Returns:
or qualifier to match any of the given patterns

int senderQueueSize (  ) 

javax.mail.Session sessionForContext ( String  contextString  )  [protected]

Returns the Session object that is appropriate for the given context.

Parameters:
contextString the message context
Returns:
a javax.mail.Session value

javax.mail.Session sessionForMessage ( ERMessage  message  ) 

Returns the Session object that is appropriate for the given message.

Returns:
a javax.mail.Session value

void setAdminEmail ( String  adminEmail  ) 

Sets the admin email to another value. This value is set at initialization from the er.javamail.adminEmail Property.

Parameters:
adminEmail a String value

void setCentralize ( boolean  centralize  ) 

Sets the value of the er.javamail.centralize Property.

Parameters:
centralize if the boolean value is true, then all the outbound mails will be sent to adminEmail email address.

void setDebugEnabled ( boolean  debug  ) 

Sets the debug mode of JavaMail.

Parameters:
debug a boolean value sets JavaMail in debug mode

void setDefaultSession ( javax.mail.Session  session  ) 

Sets the default JavaMail session to a particular value. This value is set by default at initialization of the framework but you can specify a custom one by using this method. Note that a new deliverer need to be instanciated for changes to be taken in account.

Parameters:
session the default javax.mail.Session

void setDefaultXMailerHeader ( String  header  ) 

Sets the default value of the XMailer header used when sending mails.

Parameters:
header a String value

void setDelegate ( Delegate  delegate  ) 

void setMilliSecondsWaitIfSenderOverflowed ( int  value  ) 

Sets the value of the er.javamail.milliSecondsWaitIfSenderOverflowed Property.

Parameters:
value an int value in milli-seconds.

void setSenderQueueSize ( int  value  ) 

void setupSmtpHostSafely (  )  [protected]

Helper method to init the smtpHost property. This method first check is er.javamail.smtpHost is set. If it is not set, then it looks for mail.smtp.host (standard JavaMail property) and finally the WOSMTPHost property. When a correct property is found, then it sets both properties to the found value. If no properties are found, a RuntimeException is thrown.

Exceptions:
RuntimeException if neither one of er.javamail.smtpHost, mail.smtp.host or WOSMTPHost is set.

void setupSmtpProperties ( Properties  properties,
String  contextString 
) [protected]

static ERJavaMail sharedInstance (  )  [static]

Accessor to the ERJavaMail singleton.

Returns:
the one ERJavaMail instance

String smtpProtocolForContext ( String  contextString  ) 

Returns the SMTP protocol to use for connections.

String validateEmail ( EOEnterpriseObject  object,
String  key,
String  email 
)

Validates an enterprise object's email attribute (accessed via key).

Parameters:
object the object to be validated
key the attribute's name
email the email value
Returns:
the email if the validation didn't failed

Gets the array of white list email address patterns.

Returns:
array of white list email address patterns

EOOrQualifier whiteListQualifier (  ) 

Whilte list Or qualifier to match any of the patterns in the white list.

Returns:
Or qualifier for the white list


Member Data Documentation

String _adminEmail [protected]

email address used when centralizeMails == true
Needed when debugging application so that mails are always sent to only one destination.

boolean _centralize = true [protected]

Used to send mail to adminEmail only. Useful for debugging issues

boolean _debugEnabled = true [protected]

This property specify wether JavaMail is debug enabled or not.

javax.mail.Session _defaultSession [protected]

This is the default JavaMail Session. It is shared among all deliverers for immediate deliveries. Deferred deliverers, use their own JavaMail session.

This property sets the default header for the X-Mailer property

Delegate _delegate [private]

int _milliSecondsWaitIfSenderOverflowed = 6000 [protected]

Wait n milliseconds (by default this value is 6000) if the mail sender is overflowed

Pattern _pattern = null [protected]

The compiled form of the EMAIL_VALIDATION_PATTERN pattern.

int _senderQueueSize = 50 [protected]

Number of messages that the sender queue can hold at a time; default to 50 messages and can be configured by er.javamail.senderQueue.size system property.

Map<String, javax.mail.Session> _sessions = new ConcurrentHashMap<String, javax.mail.Session>() [private]

final String atext = "[a-zA-Z0-9" + sp + "]" [static, private]

final String atom = atext + "+" [static, private]

EOOrQualifier blackListQualifier [protected]

holds the black list qualifier

NSArray<String> blakListEmailAddressPatterns [protected]

holds the array of black list email addresses

final String domain = rfcLabel + "((\\." + rfcLabel + ")*\\." + letter + "{2,6}){0,1}" [static, private]

final String dotAtom = "\\." + atom [static, private]

final String EMAIL_VALIDATION_PATTERN = "^" + localPart + "@" + domain + "$" [static, private]

final String letDig = "[a-zA-Z0-9]" [static, private]

final String letDigHyp = "[a-zA-Z0-9\\-]" [static, private]

final String letter = "[a-zA-Z]" [static, private]

final String localPart = atom + "(" + dotAtom + ")*" [static, private]

final Logger log = Logger.getLogger(ERJavaMail.class) [static, private]

Class logger

Reimplemented from ERXFrameworkPrincipal.

final Class<?> REQUIRES[] = new Class[] { ERXExtensions.class } [static]

final String rfcLabel = letDig + "(" + letDigHyp + "{0,61}" + letDig + "){0,1}" [static, private]

ERJavaMail sharedInstance [static, protected]

ERJavaMail class singleton.

final String sp = "!#$%&'*+\\-/=?^_`{|}~" [static, private]

EMAIL_VALIDATION_PATTERN is a regexp pattern that is used to validate emails.

NSArray<String> whiteListEmailAddressPatterns [protected]

holds the array of white list email addresses

EOOrQualifier whiteListQualifier [protected]

holds the white list qualifier


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:22 2012 for Project Wonder by  doxygen 1.5.8