org.starhope.appius.messaging
Class Mail

java.lang.Object
  extended by org.starhope.appius.messaging.Mail

public class Mail
extends Object

Author:
brpocock@star-hope.org, Tim Heys

Constructor Summary
Mail()
           
 
Method Summary
static String getDomainPart(String address)
          This extracts the mail domain from the address.
static String getLocalPart(String address)
          Extracts the local-part specification out of an eMail address, removing any comment strings, and returns something like what people naïvely assume is a valid eMail address.
private static boolean isBadMail(String address)
           Determine whether an eMail address is known to be bad (because we've received a 5xx series bounce from the MX recently)
private static boolean isBouncedMail(String address)
          WRITEME: Document this method brpocock@star-hope.org
static boolean isValidMail(String address)
          Determine whether an eMail address might be valid.
static String readTemplate(String templateName)
          Reads in a template file from the appropriate folder
static void sendChildSignupMail(User kid)
          Send an eMail notification to a parent, advising them that their child has signed up, and requesting authorization.
static void sendMail(String toAddress, String subject, String body)
           twheys@gmail.com Feb 3, 2010
static void sendMail(String toAddress, String subject, String body, String... ccAddresses)
           twheys@gmail.com Feb 3, 2010
static void sendPasswordRecoveryMail(AbstractPerson user)
          Send a user's or parent's password out, after they have successfully completed the forgotten password recovery question.
static void sendPremiumMail(User user)
           This method is called when a member has signed up to be a VIT (Very Important Toot) member.
static void sendSignupMail(AbstractPerson user)
          Update the email address for the user and then send an enrollment email to the address.
static void sendStaffPaswordResetMail(AbstractPerson person)
          WRITEME: Don't know why this would be sent.
static void sendTemplateMail(AbstractPerson user, String templateName, boolean isChildNotification, String subject)
           
static void validateMail(String address)
          Forbids recently-bounced addresses from being used as well.
static void validateMXDomain(String domainName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mail

public Mail()
Method Detail

getDomainPart

public static String getDomainPart(String address)
                            throws DataException
This extracts the mail domain from the address. Note that the mail domain is not implicitly validated in this routine: it is only extracted as a string. Note that, unlike "real" mail systems, this will NOT add an implicit "@tootsville.com" or similar to the end of a local-part-only address. (Personally, I think that's a bad idea in this case. ~BRP)

Parameters:
address - An eMail address in RFC-2822 format
Returns:
The domain-part string
Throws:
DataException - if the domain-part can't be found, doesn't conform to DNS requirements for a domain string, or the address doesn't have an @ sign to declare a domain part at all.

getLocalPart

public static String getLocalPart(String address)
                           throws DataException
Extracts the local-part specification out of an eMail address, removing any comment strings, and returns something like what people naïvely assume is a valid eMail address. This follows the RFC-2822 requirements for a valid address, instead of imposing some arbitrary limits upon what we'll accept.

Parameters:
address - An eMail address string
Returns:
The local-part (mailbox or delivery instructions part) of the address
Throws:
DataException - if the address does not conform to RFC-822 requirements

isBadMail

private static boolean isBadMail(String address)

Determine whether an eMail address is known to be bad (because we've received a 5xx series bounce from the MX recently)

The definition of “recently” is (org.starhope.appius.mail.bounceBadDays) days; default of 7.

XXX: also monitor sexual offender databases

Parameters:
address - The eMail address to be checked
Returns:
true, if the eMail address is known to be bad due to a bounce

isBouncedMail

private static boolean isBouncedMail(String address)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
address - WRITEME
Returns:
WRITEME

isValidMail

public static boolean isValidMail(String address)
Determine whether an eMail address might be valid.

Parameters:
address - eMail address string
Returns:
false, if the address is provably invalid. true, if it might be valid.

readTemplate

public static String readTemplate(String templateName)
                           throws FileNotFoundException,
                                  IOException,
                                  NotFoundException
Reads in a template file from the appropriate folder

Parameters:
templateName - the template file
Returns:
the contents of the template file
Throws:
FileNotFoundException - If the template file can't be found
IOException - If the template file can't be read
NotFoundException - If the name of the template file can't be found in AppiusConfig

sendChildSignupMail

public static void sendChildSignupMail(User kid)
                                throws FileNotFoundException,
                                       IOException,
                                       NotFoundException,
                                       DataException,
                                       NamingException
Send an eMail notification to a parent, advising them that their child has signed up, and requesting authorization.

Parameters:
kid - WRITEME
Throws:
FileNotFoundException - WRITEME
IOException - WRITEME
NotFoundException - WRITEME
DataException - WRITEME
NamingException - WRITEME

sendMail

public static void sendMail(String toAddress,
                            String subject,
                            String body)
                     throws javax.mail.MessagingException
 twheys@gmail.com Feb 3, 2010
 
TO sendMail WRITEME...

Parameters:
toAddress - WRITEME twheys@gmail.com
subject - WRITEME twheys@gmail.com
body - WRITEME twheys@gmail.com
Throws:
javax.mail.MessagingException - WRITEME twheys@gmail.com

sendMail

public static void sendMail(String toAddress,
                            String subject,
                            String body,
                            String... ccAddresses)
                     throws javax.mail.MessagingException
 twheys@gmail.com Feb 3, 2010
 
TO sendMail WRITEME...

Parameters:
toAddress - WRITEME twheys@gmail.com
subject - WRITEME twheys@gmail.com
body - WRITEME twheys@gmail.com
ccAddresses - WRITEME twheys@gmail.com
Throws:
javax.mail.MessagingException - WRITEME twheys@gmail.com

sendPasswordRecoveryMail

public static void sendPasswordRecoveryMail(AbstractPerson user)
                                     throws FileNotFoundException,
                                            IOException,
                                            NotFoundException
Send a user's or parent's password out, after they have successfully completed the forgotten password recovery question.

Parameters:
user - The user who forgot his/her password
Throws:
NotFoundException - ?? WRITEME
IOException - if the template can't be read
FileNotFoundException - if the template isn't found

sendPremiumMail

public static void sendPremiumMail(User user)
                            throws FileNotFoundException,
                                   IOException,
                                   NotFoundException,
                                   DataException,
                                   NamingException

This method is called when a member has signed up to be a VIT (Very Important Toot) member.

Update the email address for the user and then send an enrollment email to the address.

Parameters:
user - User name that should be updated.
Throws:
IOException - if the template can't be read or something similar
FileNotFoundException - if the template file is missing
NotFoundException - if the template file is not found
NamingException - if the eMail address is invalid
DataException - if something else bad happens

sendSignupMail

public static void sendSignupMail(AbstractPerson user)
                           throws FileNotFoundException,
                                  IOException,
                                  NotFoundException,
                                  DataException,
                                  NamingException
Update the email address for the user and then send an enrollment email to the address.

Parameters:
user - User name that should be updated.
Throws:
IOException - if the template can't be read or something similar
FileNotFoundException - if the template file is missing
NotFoundException - if the template file is not found
NamingException - if the eMail address is invalid
DataException - if something else bad happens

sendStaffPaswordResetMail

public static void sendStaffPaswordResetMail(AbstractPerson person)
                                      throws FileNotFoundException,
                                             IOException,
                                             NotFoundException
WRITEME: Don't know why this would be sent. twheys needs to document this method.

Parameters:
person - WRITEME
Throws:
FileNotFoundException - WRITEME
IOException - WRITEME
NotFoundException - WRITEME

sendTemplateMail

public static void sendTemplateMail(AbstractPerson user,
                                    String templateName,
                                    boolean isChildNotification,
                                    String subject)
                             throws FileNotFoundException,
                                    IOException,
                                    NotFoundException,
                                    javax.mail.MessagingException
Parameters:
user - The user to whom the mail should be sent (or, the user's parent, if selected)
templateName - The name of the mail message template file
isChildNotification - WRITEME
subject - The subject to apply to the eMail.
Throws:
FileNotFoundException - if the template is not found
IOException - failure reading template
NotFoundException - ... WRITEME?
javax.mail.MessagingException - WRITEME

validateMail

public static void validateMail(String address)
                         throws DataException,
                                NamingException
Forbids recently-bounced addresses from being used as well.

Parameters:
address - Any RFC-2822-valid eMail address string
Throws:
DataException - if the address isn't appropriate somehow (e.g. bad format)
NamingException - if the JNDI DNS provider fails (bubble up)
See Also:
BadMailList

validateMXDomain

public static void validateMXDomain(String domainName)
                             throws NamingException,
                                    DataException
Parameters:
domainName - the domain name for which we're looking for a mail exchanger
Throws:
NamingException - if the JNDI provider fails
DataException - if the domain does not have an MX record in DNS