bb.net
Class EmailUtil

java.lang.Object
  extended by bb.net.EmailUtil

public final class EmailUtil
extends Object

Provides static email utility methods.

This class is multithread safe: it is stateless.

Author:
Brent Boyer
See Also:
"The 2001/October/23 JDC newsletter for tips on JavaMail", http://java.sun.com/products/javamail/javadocs/

Constructor Summary
private EmailUtil()
          This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class.
 
Method Summary
private static void appendAddresses(String label, Address[] addresses, StringBuilder sb)
           
static void checkHeaderFieldBody(String fieldBody, String fieldBodyLabel)
          Checks whether or not fieldBody is a valid email field body as specified by RFC #822 (especially section 3.1.2.
static String eventToString(ConnectionEvent connectionEvent)
          Returns a String representation of the information inside connectionEvent.
static String eventToString(TransportEvent transportEvent)
          Returns a String representation of the information inside transportEvent.
static String getAddressesStatus(SendFailedException sendFailedException)
          Returns a String which contains the invalid, valid unsent, and valid sent addresses that are contained inside the sendFailedException argument.
static String getExceptionInfo(MessagingException messagingException)
          Converts the information in a MessagingException to a more readable String form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmailUtil

private EmailUtil()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class.

Method Detail

checkHeaderFieldBody

public static void checkHeaderFieldBody(String fieldBody,
                                        String fieldBodyLabel)
                                 throws IllegalArgumentException
Checks whether or not fieldBody is a valid email field body as specified by RFC #822 (especially section 3.1.2. STRUCTURE OF HEADER FIELDS).

Special case: if fieldBody is null, the method immediately returns, so null is an acceptable value.

Warning: unfolding of whitespace (see the RFC #822 spec) is not performed by this method; the caller should do this before calling calling this method.

Throws:
IllegalArgumentException - if any syntax error is found in fieldBody

getExceptionInfo

public static String getExceptionInfo(MessagingException messagingException)
                               throws IllegalArgumentException
Converts the information in a MessagingException to a more readable String form.

Throws:
IllegalArgumentException - if messagingException == null
See Also:
"The program /demo/msgsendsample.java"

getAddressesStatus

public static String getAddressesStatus(SendFailedException sendFailedException)
                                 throws IllegalArgumentException
Returns a String which contains the invalid, valid unsent, and valid sent addresses that are contained inside the sendFailedException argument.

Throws:
IllegalArgumentException - if sendFailedException == null
See Also:
"The program /demo/msgsendsample.java"

eventToString

public static String eventToString(ConnectionEvent connectionEvent)
                            throws IllegalArgumentException,
                                   IllegalStateException
Returns a String representation of the information inside connectionEvent. The result does not end in a new line ('\n') char, so if the result is printed, a printls instead of print call should be made.

Throws:
IllegalArgumentException - if connectionEvent == null
IllegalStateException - if an unsupported event type is encountered

eventToString

public static String eventToString(TransportEvent transportEvent)
                            throws IllegalArgumentException,
                                   IllegalStateException,
                                   MessagingException
Returns a String representation of the information inside transportEvent. The result does not end in a new line ('\n') char, so if the result is printed, a printls instead of print call should be made.

Throws:
IllegalArgumentException - if transportEvent == null
IllegalStateException - if an unsupported event type is encountered
MessagingException - if some error in processing transportEvent occurs

appendAddresses

private static void appendAddresses(String label,
                                    Address[] addresses,
                                    StringBuilder sb)