atg.service.email.examiner
Class SendmailEmailExaminer

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.email.examiner.EmailExaminerImpl
              extended by atg.service.email.examiner.SendmailEmailExaminer
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, atg.service.email.examiner.AdditionalHeadersEmailExaminer, EmailExaminer, java.util.EventListener

public class SendmailEmailExaminer
extends atg.service.email.examiner.EmailExaminerImpl

This is a service that determines properties of a bounced message created by a sendmail MTA. It looks for specific string expressions inside the text of the bounced message. Specifically, the following example line would be used to obtain information from a bounced email in sendmail format: <<< 550 5.1.1 ... User unknown Here the String "<<< 550" indicates the message is bounced. The reply code used in this example, 550, can be any one of the reply codes in the getMonitoredBounceReplyCodes array. A message is considered bounced if the String "<<< " + exists in the text of the email. The enhanced status code appears after the bounce indicator String. In this example, the value is "5.1.1". This implementation assumes a space char after the reply code, and that the status code is 5 chars long after that. The bounced email address appears between the '<' and '>' chars after the bounced indicator. In this example, it is "noone@atg.com". The error message appears after the first "... " that is found after the bounce indicator. In this example, this turns out to be "User unknown"


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.service.email.examiner.EmailExaminerImpl
mEmailTrackingTools, mExtractOriginalMessageIDFromMessageText, mScanningContentForAdditionalHeaders, X_ATG_HEADER_PREFIX
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
SendmailEmailExaminer()
           
 
Method Summary
 java.lang.Object examineEmail(javax.mail.Message pMessage)
          This method examines the given message in some implementation specific manner.
 java.lang.String getBouncedEmailAddress(javax.mail.Message pMessage)
          This method gets the email address from a presumed bounced email in sendmail format.
 java.lang.String getBouncedEmailAddress(java.lang.String pContent)
          This method gets any associated error message that is given from a bounced email.
 java.lang.String getBouncedEnhancedStatusCode(javax.mail.Message pMessage)
          Gets the enhanced status code according to RFC 1893 that gives more detail on the nature of the error.
 java.lang.String getBouncedEnhancedStatusCode(java.lang.String pContent)
          Gets the enhanced status code according to RFC 1893 that gives more detail on the nature of the error.
 java.lang.String getBouncedErrorMessage(javax.mail.Message pMessage)
          This method gets any associated error message that is given from a bounced email.
 java.lang.String getBouncedErrorMessage(java.lang.String pContent)
          This method gets any associated error message that is given from a bounced email.
 int getBouncedIndicatorEndIndex(java.lang.String pContent)
          This method gets the ending index of the bounced indicator For this implementation, it is expected that there are 7 chars in the bounced indicator, and this the end index is 7 chars after the start
 int getBouncedIndicatorStartIndex(java.lang.String pContent)
          This method takes the given string of email content and looks for the pattern that indicates that this email is bounced.
 java.lang.String getBouncedReplyCode(javax.mail.Message pMessage)
          Gets the reply code (RFC 821) of the given bounced message.
 java.lang.String getBouncedReplyCode(java.lang.String pContent)
          Gets the reply code (RFC 821) of the given bounced message.
 java.lang.String[] getMonitoredBounceReplyCodes()
          Gets the MonitoredReplyCodes property
 boolean isBouncedEmail(javax.mail.Message pMessage)
          Determines whether the passed in message was bounced by a sendmail MTA.
 boolean isBouncedEmail(java.lang.String pContent)
          Determines whether the passed in message was bounced by a sendmail MTA.
 void setMonitoredBounceReplyCodes(java.lang.String[] pMonitoredBounceReplyCodes)
          Sets the MonitoredBounceReplyCodes property
 
Methods inherited from class atg.service.email.examiner.EmailExaminerImpl
getAdditionalHeaderPrefixes, getAdditionalHeaders, getConfiguredSoftBounceCodes, getEmailTrackingTools, getMTAName, getOriginalMessageID, getSoftBounceEnhancedStatusCodes, getSoftBounceReplyCodes, getTrackingData, isExtractOriginalMessageIDFromMessageText, isScanningContentForAdditionalHeaders, isSoftBouncedEmail, setAdditionalHeaderPrefixes, setEmailTrackingTools, setExtractOriginalMessageIDFromMessageText, setMTAName, setScanningContentForAdditionalHeaders, setSoftBounceEnhancedStatusCodes, setSoftBounceReplyCodes
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
Class version string

See Also:
Constant Field Values
Constructor Detail

SendmailEmailExaminer

public SendmailEmailExaminer()
Method Detail

setMonitoredBounceReplyCodes

public void setMonitoredBounceReplyCodes(java.lang.String[] pMonitoredBounceReplyCodes)
Sets the MonitoredBounceReplyCodes property

Parameters:
pMonitoredBounceReplyCodes - an array of RFC 821 reply codes that will indicate an email is bounced. The isBouncedEmail method will only return true if the reply code set in the bounced email matches one of the values of this property

getMonitoredBounceReplyCodes

public java.lang.String[] getMonitoredBounceReplyCodes()
Gets the MonitoredReplyCodes property

Returns:
an array of RFC 821 reply codes that will indicate an email is bounced. The isBouncedEmail method will only return true if the reply code set in the bounced email matches one of the values of this property

isBouncedEmail

public boolean isBouncedEmail(javax.mail.Message pMessage)
                       throws javax.mail.MessagingException,
                              EmailException
Determines whether the passed in message was bounced by a sendmail MTA. This implementation looks for the string ">>> xxx" where xxx is the reply code. If xxx is one of the reply codes set in the monitoredBounceReplyCodes property, then this message will be considered bounced

Parameters:
pMessage - the message to examine
Returns:
true if the message is in sendmail format and is bounced. False if the message is in sendmail format and is not bounced, or is not in sendmail format.
Throws:
javax.mail.MessagingException - if a problem occurs while calling methods on the pMessage object
EmailException - if a problem occurs during the parsing of the content, of invalid arguments are specified

getBouncedEmailAddress

public java.lang.String getBouncedEmailAddress(javax.mail.Message pMessage)
                                        throws javax.mail.MessagingException,
                                               EmailException
This method gets the email address from a presumed bounced email in sendmail format. This implementation looks for the address in a specific location in the email's content Specifically: "<<< xxx x.x.x " where xxx is the reply code and x.x.x is the enhanced status code.

Parameters:
pMessage - the message to examine
Returns:
the email address of the intended recipient, or null if the message is not bounced, or is not in sendmail format
Throws:
javax.mail.MessagingException - if a problem occurs while calling methods on the pMessage object
EmailException - if a problem occurs during the parsing of the content, of invalid arguments are specified

getBouncedReplyCode

public java.lang.String getBouncedReplyCode(javax.mail.Message pMessage)
                                     throws javax.mail.MessagingException,
                                            EmailException
Gets the reply code (RFC 821) of the given bounced message. This reply code should exist in the getMonitoredBounceReplyCodes array. This implementation looks for the reply code after the sendmail session transcript line that starts with "<<< "

Parameters:
pMessage - the bounced message to examine
Returns:
the reply code of the bounced email, indicating why it was bounced, or null if the message cannot be determined from the give pMessage i.e. the formatting is not what was expected, or the message has not been determined as bounced
Throws:
javax.mail.MessagingException - if a problem occurs while calling methods on the pMessage object
EmailException - if a problem occurs during the parsing of the content, of invalid arguments are specified NOTE: An exception should NOT be thrown if the given message is not in a format recognized by this examiner. In most cases, a list of examiners will be called upon to see if any consider the message as bounced in a given operation. Developers are expected to return null in this case.

getBouncedErrorMessage

public java.lang.String getBouncedErrorMessage(javax.mail.Message pMessage)
                                        throws javax.mail.MessagingException,
                                               EmailException
This method gets any associated error message that is given from a bounced email. In sendmail, this is located typically after a "... " pattern in the line that indicates the message is bounced. For example: "<<< xxx x.x.x ... Error Message" where xxx is the reply code and x.x.x is the enhanced status code

Parameters:
pMessage - the message to examine
Returns:
the error message that indicates why the email was bounced or null if the email is not in sendmail format, or if there is no error message to get
Throws:
javax.mail.MessagingException - if a problem occurs while calling methods on the pMessage object
EmailException - if a problem occurs during the parsing of the content, of invalid arguments are specified

getBouncedEnhancedStatusCode

public java.lang.String getBouncedEnhancedStatusCode(javax.mail.Message pMessage)
                                              throws javax.mail.MessagingException,
                                                     EmailException
Gets the enhanced status code according to RFC 1893 that gives more detail on the nature of the error.

Parameters:
pMessage - the message to examine
Returns:
an enhanced status code of the bounced email, indicating why it was bounced, or null if the given message is not in sendmail format
Throws:
javax.mail.MessagingException - if a problem occurs while calling methods on the pMessage object
EmailException - if a problem occurs during the parsing of the content, of invalid arguments are specified

examineEmail

public java.lang.Object examineEmail(javax.mail.Message pMessage)
                              throws javax.mail.MessagingException,
                                     EmailException
This method examines the given message in some implementation specific manner. This implementation is a no-op

Parameters:
pMessage - the message to examine
Returns:
null
Throws:
javax.mail.MessagingException - if a problem occurs while calling methods on the pMessage object
EmailException - if a problem occurs during the parsing of the content, of invalid arguments are specified

getBouncedIndicatorStartIndex

public int getBouncedIndicatorStartIndex(java.lang.String pContent)
This method takes the given string of email content and looks for the pattern that indicates that this email is bounced. It will cycle through all of the monitoredBounceReplyCodes and will substitute them into the pattern to see if the given string contains it.

Parameters:
pContent - the email content to examine
Returns:
the starting index at which the pattern appears in the given content. -1 if the pattern does not appear at all

getBouncedIndicatorEndIndex

public int getBouncedIndicatorEndIndex(java.lang.String pContent)
This method gets the ending index of the bounced indicator For this implementation, it is expected that there are 7 chars in the bounced indicator, and this the end index is 7 chars after the start

Parameters:
pContent - the content to examine
Returns:
the ending index of the bounced indicator, or -1 if the pattern does not appear

isBouncedEmail

public boolean isBouncedEmail(java.lang.String pContent)
Determines whether the passed in message was bounced by a sendmail MTA. This implementation looks for the string ">>> xxx" where xxx is the reply code. If xxx is one of the reply codes set in the monitoredBounceReplyCodes property, then this message will be considered bounced

Parameters:
pContent - the content to examine
Returns:
true if the content is in sendmail format and is bounced. False if the content is in sendmail format and is not bounced, or is not in sendmail format.

getBouncedEmailAddress

public java.lang.String getBouncedEmailAddress(java.lang.String pContent)
This method gets any associated error message that is given from a bounced email. In sendmail, this is located typically after a "... " pattern in the line that indicates the message is bounced. For example: "<<< xxx x.x.x ... Error Message" where xxx is the reply code and x.x.x is the enhanced status code

Parameters:
pContent - the content to examine
Returns:
the error message that indicates why the email was bounced or null if the email is not in sendmail format, or if there is no error message to get

getBouncedReplyCode

public java.lang.String getBouncedReplyCode(java.lang.String pContent)
Gets the reply code (RFC 821) of the given bounced message. This reply code should exist in the getMonitoredBounceReplyCodes array. This implementation looks for the reply code after the sendmail session transcript line that starts with "<<< "

Parameters:
pConte - the bounced content to examine
Returns:
the reply code of the bounced email, indicating why it was bounced, or null if the message cannot be determined from the give pMessage i.e. the formatting is not what was expected, or the message has not been determined as bounced

getBouncedEnhancedStatusCode

public java.lang.String getBouncedEnhancedStatusCode(java.lang.String pContent)
Gets the enhanced status code according to RFC 1893 that gives more detail on the nature of the error.

Parameters:
pContent - the content to examine
Returns:
an enhanced status code of the bounced email, indicating why it was bounced, or null if the given message is not in sendmail format

getBouncedErrorMessage

public java.lang.String getBouncedErrorMessage(java.lang.String pContent)
This method gets any associated error message that is given from a bounced email. In sendmail, this is located typically after a "... " pattern in the line that indicates the message is bounced. For example: "<<< xxx x.x.x ... Error Message" where xxx is the reply code and x.x.x is the enhanced status code

Parameters:
pContent - the content to examine
Returns:
the error message that indicates why the email was bounced or null if the email is not in sendmail format, or if there is no error message to get