Project Wonder 2.0

er.javamail
Class ERJavaMail

java.lang.Object
  extended byer.extensions.ERXFrameworkPrincipal
      extended byer.javamail.ERJavaMail

public class ERJavaMail
extends ERXFrameworkPrincipal

ERJavaMail is the prinicpal class for the ERJavaMail framework.

Version:
$Id: ERJavaMail.java,v 1.17 2004/02/04 18:21:06 anjo Exp $
Author:
Camille Troillard, Max Muller

Field Summary
protected  String _adminEmail
          email address used when centralizeMails == true
Needed when debugging application so that mails are always sent to only one destination.
protected  boolean _centralize
          Used to send mail to adminEmail only.
protected  boolean _debugEnabled
          This property specify wether JavaMail is debug enabled or not.
protected  javax.mail.Session _defaultSession
          This is the deafult JavaMail Session.
protected  String _defaultXMailerHeader
          This property sets the default header for the X-Mailer property
protected  org.apache.oro.text.regex.Perl5Matcher _matcher
          The Jakarta ORO regexp matcher.
protected  int _milliSecondsWaitIfSenderOverflowed
          Wait n milliseconds (by default this value is 6000) if the mail sender is overflowed
protected  org.apache.oro.text.regex.Pattern _pattern
          The compiled form of the EMAIL_VALIDATION_PATTERN pattern.
protected  int _senderQueueSize
          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.
protected  EOOrQualifier blackListQualifier
          holds the black list qualifier
protected  NSArray blakListEmailAddressPatterns
          holds the array of black list email addresses
protected static String EMAIL_VALIDATION_PATTERN
          EMAIL_VALIDATION_PATTERN is a regexp pattern that is used to validate emails.
protected static ERJavaMail sharedInstance
          ERJavaMail class singleton.
protected  NSArray whiteListEmailAddressPatterns
          holds the array of white list email addresses
protected  EOOrQualifier whiteListQualifier
          holds the white list qualifier
 
Constructor Summary
ERJavaMail()
           
 
Method Summary
 String adminEmail()
          admin email accessor.
 NSArray blackListEmailAddressPatterns()
          Gets the array of black list email address patterns.
 EOOrQualifier blackListQualifier()
          Gets the Or qualifier to match any of the patterns in the black list.
 boolean centralize()
          Centralize is used to send all the outbound email to a single address which is useful when debugging.
 boolean debugEnabled()
          Returns true if JavaMail is debug enabled.
 javax.mail.Session defaultSession()
          This is the deafult JavaMail Session accessor.
 String defaultXMailerHeader()
          Gets the default X-Mailer header to use for sending mails.
 NSArray filterEmailAddresses(NSArray emailAddresses)
          Filters an array of email addresses by the black and white lists.
 void finishInitialization()
          Specialized implementation of the method from ERXPrincipalClass.
 boolean hasBlackList()
          Determines if a black list has been specified
 boolean hasWhiteList()
          Determines if a white list has been specified
 void initializeFrameworkFromSystemProperties()
          This method is used to initialize ERJavaMail from System properties.
 boolean isValidEmail(String email)
          Predicate used to validate email well-formness.
 int milliSecondsWaitIfSenderOverflowed()
          This method return the time spent waiting if the mail queue if overflowed.
 javax.mail.Session newSession()
          Returns a newly allocated Session object from the System Properties
 javax.mail.Session newSession(Properties props)
          Returns a newly allocated Session object from the given Properties
protected  EOOrQualifier qualifierArrayForEmailPatterns(NSArray emailPatterns)
          Constructs an Or qualifier for filtering an array of strings that might have the * wildcard character.
 int senderQueueSize()
           
 void setAdminEmail(String adminEmail)
          Sets the admin email to another value.
 void setCentralize(boolean centralize)
          Sets the value of the er.javamail.centralize Property.
 void setDebugEnabled(boolean debug)
          Sets the debug mode of JavaMail.
 void setDefaultSession(javax.mail.Session session)
          Sets the default JavaMail session to a particular value.
 void setDefaultXMailerHeader(String header)
          Sets the default value of the XMailer header used when sending mails.
 void setMilliSecondsWaitIfSenderOverflowed(int value)
          Sets the value of the er.javamail.milliSecondsWaitIfSenderOverflowed Property.
 void setSenderQueueSize(int value)
           
protected  void setupSmtpHostSafely()
          Helper method to init the smtpHost property.
static ERJavaMail sharedInstance()
          Accessor to the ERJavaMail singleton.
 String validateEmail(EOEnterpriseObject object, String key, String email)
          Validates an enterprise object's email attribute (accessed via key).
 NSArray whiteListEmailAddressPatterns()
          Gets the array of white list email address patterns.
 EOOrQualifier whiteListQualifier()
          Whilte list Or qualifier to match any of the patterns in the white list.
 
Methods inherited from class er.extensions.ERXFrameworkPrincipal
finishInitialization, log, setUpFrameworkPrincipalClass, sharedInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sharedInstance

protected static ERJavaMail sharedInstance
ERJavaMail class singleton.


EMAIL_VALIDATION_PATTERN

protected static final String EMAIL_VALIDATION_PATTERN
EMAIL_VALIDATION_PATTERN is a regexp pattern that is used to validate emails.

See Also:
Constant Field Values

_matcher

protected org.apache.oro.text.regex.Perl5Matcher _matcher
The Jakarta ORO regexp matcher.


_pattern

protected org.apache.oro.text.regex.Pattern _pattern
The compiled form of the EMAIL_VALIDATION_PATTERN pattern.


_defaultSession

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


_adminEmail

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


_debugEnabled

protected boolean _debugEnabled
This property specify wether JavaMail is debug enabled or not.


_defaultXMailerHeader

protected String _defaultXMailerHeader
This property sets the default header for the X-Mailer property


_centralize

protected boolean _centralize
Used to send mail to adminEmail only. Useful for debugging issues


_senderQueueSize

protected int _senderQueueSize
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.


_milliSecondsWaitIfSenderOverflowed

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


whiteListEmailAddressPatterns

protected NSArray whiteListEmailAddressPatterns
holds the array of white list email addresses


blakListEmailAddressPatterns

protected NSArray blakListEmailAddressPatterns
holds the array of black list email addresses


whiteListQualifier

protected EOOrQualifier whiteListQualifier
holds the white list qualifier


blackListQualifier

protected EOOrQualifier blackListQualifier
holds the black list qualifier

Constructor Detail

ERJavaMail

public ERJavaMail()
Method Detail

sharedInstance

public static ERJavaMail sharedInstance()
Accessor to the ERJavaMail singleton.

Returns:
the one ERJavaMail instance

finishInitialization

public void finishInitialization()
Specialized implementation of the method from ERXPrincipalClass.

Specified by:
finishInitialization in class ERXFrameworkPrincipal

initializeFrameworkFromSystemProperties

public 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.


setupSmtpHostSafely

protected void setupSmtpHostSafely()
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.

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

setDefaultSession

public 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

defaultSession

public 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

newSession

public 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

newSession

public javax.mail.Session newSession()
Returns a newly allocated Session object from the System Properties

Returns:
a javax.mail.Session value

adminEmail

public String adminEmail()
admin email accessor. The admin email is the email address where centralized mail go to.

Returns:
a String value

setAdminEmail

public 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

debugEnabled

public boolean debugEnabled()
Returns true if JavaMail is debug enabled.

Returns:
a boolean value

setDebugEnabled

public void setDebugEnabled(boolean debug)
Sets the debug mode of JavaMail.

Parameters:
debug - a boolean value sets JavaMail in debug mode

defaultXMailerHeader

public 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

setDefaultXMailerHeader

public void setDefaultXMailerHeader(String header)
Sets the default value of the XMailer header used when sending mails.

Parameters:
header - a String value

centralize

public boolean centralize()
Centralize is used to send all the outbound email to a single address which is useful when debugging.

Returns:
a boolean value

setCentralize

public 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.

senderQueueSize

public int senderQueueSize()

setSenderQueueSize

public void setSenderQueueSize(int value)

milliSecondsWaitIfSenderOverflowed

public 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

setMilliSecondsWaitIfSenderOverflowed

public void setMilliSecondsWaitIfSenderOverflowed(int value)
Sets the value of the er.javamail.milliSecondsWaitIfSenderOverflowed Property.

Parameters:
value - an int value in milli-seconds.

validateEmail

public 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

isValidEmail

public boolean isValidEmail(String email)
Predicate used to validate email well-formness.

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

hasWhiteList

public boolean hasWhiteList()
Determines if a white list has been specified

Returns:
if the white list has any elements in it

hasBlackList

public boolean hasBlackList()
Determines if a black list has been specified

Returns:
if the black list has any elements in it

whiteListEmailAddressPatterns

public NSArray whiteListEmailAddressPatterns()
Gets the array of white list email address patterns.

Returns:
array of white list email address patterns

blackListEmailAddressPatterns

public NSArray blackListEmailAddressPatterns()
Gets the array of black list email address patterns.

Returns:
array of black list email address patterns

whiteListQualifier

public EOOrQualifier whiteListQualifier()
Whilte list Or qualifier to match any of the patterns in the white list.

Returns:
Or qualifier for the white list

blackListQualifier

public EOOrQualifier blackListQualifier()
Gets the Or qualifier to match any of the patterns in the black list.

Returns:
or qualifier

qualifierArrayForEmailPatterns

protected EOOrQualifier qualifierArrayForEmailPatterns(NSArray emailPatterns)
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

filterEmailAddresses

public NSArray filterEmailAddresses(NSArray 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

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.