com.sun.slamd.scripting.mail
Class MailMessageVariable

java.lang.Object
  extended bycom.sun.slamd.scripting.engine.Variable
      extended bycom.sun.slamd.scripting.mail.MailMessageVariable
All Implemented Interfaces:
Argument

public class MailMessageVariable
extends Variable

This class defines a variable that stores a mail message, including headers. This message may be either retrieved via POP or IMAP or send via SMTP. A mail message has the following methods:


Field Summary
static java.lang.String ADD_BODY_LINE_METHOD_NAME
          The name of the method that can be used to add a line to the body of this message.
static int ADD_BODY_LINE_METHOD_NUMBER
          The method number for the "addBodyLine" method.
static java.lang.String ADD_BODY_LINES_METHOD_NAME
          The name of the method that can be used to add multiple lines to the body of this message.
static int ADD_BODY_LINES_METHOD_NUMBER
          The method number for the "addBodyLines" method.
static java.lang.String ADD_CC_RECIPIENT_METHOD_NAME
          The name of the method that can be used to add a CC recipient to this message.
static int ADD_CC_RECIPIENT_METHOD_NUMBER
          The method number for the "addCCRecipient" method.
static java.lang.String ADD_HEADER_LINE_METHOD_NAME
          The name of the method that can be used to add a line to the set of headers for this message.
static int ADD_HEADER_LINE_METHOD_NUMBER
          The method number for the "addHeaderLine" method.
static java.lang.String ADD_TO_RECIPIENT_METHOD_NAME
          The name of the method that can be used to add a To recipient to this message.
static int ADD_TO_RECIPIENT_METHOD_NUMBER
          The method number for the "addToRecipient" method.
static java.lang.String ASSIGN_METHOD_NAME
          The name of the method that can be used to assign a value to this message.
static int ASSIGN_METHOD_NUMBER
          The method number for the "assign" method.
static java.lang.String CLEAR_BODY_METHOD_NAME
          The name of the method that can be used to clear the contents of the message body.
static int CLEAR_BODY_METHOD_NUMBER
          The method number for the "clearBody" method.
static java.lang.String CLEAR_HEADER_METHOD_NAME
          The name of the method that can be used to clear the contents of the message header.
static int CLEAR_HEADER_METHOD_NUMBER
          The method number for the "clearHeader" method.
static java.lang.String CLEAR_METHOD_NAME
          The name of the method that can be used to clear the contents of this message.
static int CLEAR_METHOD_NUMBER
          The method number for the "clear" method.
static java.lang.String GET_BODY_LINES_METHOD_NAME
          The name of the method that can be used to retrieve the lines of the body of this message.
static int GET_BODY_LINES_METHOD_NUMBER
          The method number for the "getBodyLines" method.
static java.lang.String GET_CC_RECIPIENTS_METHOD_NAME
          The name of the method that can be used to retrieve the list of CC recipients for this message.
static int GET_CC_RECIPIENTS_METHOD_NUMBER
          The method number for the "getCCRecipients" method.
static java.lang.String GET_HEADER_LINES_METHOD_NAME
          The name of the method that can be used to retrieve the list of header lines for this message.
static int GET_HEADER_LINES_METHOD_NUMBER
          The method number for the "getHeaderLines" method.
static java.lang.String GET_HEADER_METHOD_NAME
          The name of the method that can be used to retrieve a specific header for this message.
static int GET_HEADER_METHOD_NUMBER
          The method number for the "getHeader" method.
static java.lang.String GET_SENDER_METHOD_NAME
          The name of the method that can be used to clear the address of the sender for this message.
static int GET_SENDER_METHOD_NUMBER
          The method number for the "getSender" method.
static java.lang.String GET_SUBJECT_METHOD_NAME
          The name of the method that can be used to retrieve the subject of this message.
static int GET_SUBJECT_METHOD_NUMBER
          The method number for the "getSubject" method.
static java.lang.String GET_TO_RECIPIENTS_METHOD_NAME
          The name of the method that can be used to retrieve the list of "To" recipients for this message.
static int GET_TO_RECIPIENTS_METHOD_NUMBER
          The method number for the "getToRecipients" method.
static Method[] MAIL_MESSAGE_VARIABLE_METHODS
          The set of methods associated with mail message variables.
static java.lang.String MAIL_MESSAGE_VARIABLE_TYPE
          The name that will be used for the data type of mail message variables.
static java.lang.String SET_SENDER_METHOD_NAME
          The name of the method that can be used to specify the address of the sender for this message.
static int SET_SENDER_METHOD_NUMBER
          The method number for the "setSender" message.
static java.lang.String SET_SUBJECT_METHOD_NAME
          The name of the method that can be used to specify the subject for this message.
static int SET_SUBJECT_METHOD_NUMBER
          The method number for the "setSubject" message.
 
Constructor Summary
MailMessageVariable()
          Creates a new variable with no name, to be used only when creating a variable with Class.newInstance(), and only when setName() is called after that to set the name.
 
Method Summary
 void addBodyLine(java.lang.String line)
          Adds the specified line to the body for this message.
 void addCCRecipient(java.lang.String address)
          Adds the specified address to the list of CC recipients for this message.
 void addHeaderLine(java.lang.String line)
          Adds the specified line to the list of headers for this message.
 void addToRecipient(java.lang.String address)
          Adds the specified address to the list of To recipients for this message.
 void assign(Argument argument)
          Assigns the value of the provided argument to this variable.
 void clear()
          Clears the contents of this message.
 void clearBody()
          Clears the body of this message.
 void clearHeader()
          Clears the header of this message.
 Variable executeMethod(int lineNumber, int methodNumber, Argument[] arguments)
          Executes the specified method, using the provided variables as arguments to the method, and makes the return value available to the caller.
 java.util.ArrayList getBodyLines()
          Retrieves the lines that make up the body of this message.
 java.util.ArrayList getCCList()
          Retrieves the list of CC recipients for this message.
 java.util.ArrayList getHeaderLines()
          Retrieves the lines that make up the header of this message.
 int getMethodNumber(java.lang.String methodName, java.lang.String[] argumentTypes)
          Retrieves the method number for the method that has the specified name and argument types, or -1 if there is no such method.
 Method[] getMethods()
          Retrieves a list of all methods defined for this variable.
 java.lang.String[] getRecipients()
          Retrieves an array with all recipients (both To and CC) for this message.
 java.lang.String getReturnTypeForMethod(java.lang.String methodName, java.lang.String[] argumentTypes)
          Retrieves the return type for the method with the specified name and argument types.
 java.lang.String getSender()
          Retrieves the address of the sender for this message.
 java.lang.String getSubject()
          Retrieves the subject for this message.
 java.util.ArrayList getToList()
          Retrieves the list of To recipients for this message.
 java.lang.String getValueAsString()
          Retrieves a string representation of the value of this argument.
 java.lang.String getVariableTypeName()
          Retrieves the name of the variable type for this variable.
 boolean hasMethod(java.lang.String methodName)
          Indicates whether this variable type has a method with the specified name.
static boolean isEmailAddress(java.lang.String stringValue)
          Indicates whether the provided string value is a valid e-mail address.
 void setSender(java.lang.String sender)
          Specifies the sender address for this message.
 void setSubject(java.lang.String subject)
          Specifies the subject for this message.
 
Methods inherited from class com.sun.slamd.scripting.engine.Variable
getArgumentAsString, getArgumentType, getArgumentValue, getName, getStatTrackers, isValidIdentifier, setName, startStatTrackers, stopStatTrackers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAIL_MESSAGE_VARIABLE_TYPE

public static final java.lang.String MAIL_MESSAGE_VARIABLE_TYPE
The name that will be used for the data type of mail message variables.

See Also:
Constant Field Values

ADD_BODY_LINE_METHOD_NAME

public static final java.lang.String ADD_BODY_LINE_METHOD_NAME
The name of the method that can be used to add a line to the body of this message.

See Also:
Constant Field Values

ADD_BODY_LINE_METHOD_NUMBER

public static final int ADD_BODY_LINE_METHOD_NUMBER
The method number for the "addBodyLine" method.

See Also:
Constant Field Values

ADD_BODY_LINES_METHOD_NAME

public static final java.lang.String ADD_BODY_LINES_METHOD_NAME
The name of the method that can be used to add multiple lines to the body of this message.

See Also:
Constant Field Values

ADD_BODY_LINES_METHOD_NUMBER

public static final int ADD_BODY_LINES_METHOD_NUMBER
The method number for the "addBodyLines" method.

See Also:
Constant Field Values

ADD_CC_RECIPIENT_METHOD_NAME

public static final java.lang.String ADD_CC_RECIPIENT_METHOD_NAME
The name of the method that can be used to add a CC recipient to this message.

See Also:
Constant Field Values

ADD_CC_RECIPIENT_METHOD_NUMBER

public static final int ADD_CC_RECIPIENT_METHOD_NUMBER
The method number for the "addCCRecipient" method.

See Also:
Constant Field Values

ADD_HEADER_LINE_METHOD_NAME

public static final java.lang.String ADD_HEADER_LINE_METHOD_NAME
The name of the method that can be used to add a line to the set of headers for this message.

See Also:
Constant Field Values

ADD_HEADER_LINE_METHOD_NUMBER

public static final int ADD_HEADER_LINE_METHOD_NUMBER
The method number for the "addHeaderLine" method.

See Also:
Constant Field Values

ADD_TO_RECIPIENT_METHOD_NAME

public static final java.lang.String ADD_TO_RECIPIENT_METHOD_NAME
The name of the method that can be used to add a To recipient to this message.

See Also:
Constant Field Values

ADD_TO_RECIPIENT_METHOD_NUMBER

public static final int ADD_TO_RECIPIENT_METHOD_NUMBER
The method number for the "addToRecipient" method.

See Also:
Constant Field Values

ASSIGN_METHOD_NAME

public static final java.lang.String ASSIGN_METHOD_NAME
The name of the method that can be used to assign a value to this message.

See Also:
Constant Field Values

ASSIGN_METHOD_NUMBER

public static final int ASSIGN_METHOD_NUMBER
The method number for the "assign" method.

See Also:
Constant Field Values

CLEAR_METHOD_NAME

public static final java.lang.String CLEAR_METHOD_NAME
The name of the method that can be used to clear the contents of this message.

See Also:
Constant Field Values

CLEAR_METHOD_NUMBER

public static final int CLEAR_METHOD_NUMBER
The method number for the "clear" method.

See Also:
Constant Field Values

CLEAR_BODY_METHOD_NAME

public static final java.lang.String CLEAR_BODY_METHOD_NAME
The name of the method that can be used to clear the contents of the message body.

See Also:
Constant Field Values

CLEAR_BODY_METHOD_NUMBER

public static final int CLEAR_BODY_METHOD_NUMBER
The method number for the "clearBody" method.

See Also:
Constant Field Values

CLEAR_HEADER_METHOD_NAME

public static final java.lang.String CLEAR_HEADER_METHOD_NAME
The name of the method that can be used to clear the contents of the message header.

See Also:
Constant Field Values

CLEAR_HEADER_METHOD_NUMBER

public static final int CLEAR_HEADER_METHOD_NUMBER
The method number for the "clearHeader" method.

See Also:
Constant Field Values

GET_BODY_LINES_METHOD_NAME

public static final java.lang.String GET_BODY_LINES_METHOD_NAME
The name of the method that can be used to retrieve the lines of the body of this message.

See Also:
Constant Field Values

GET_BODY_LINES_METHOD_NUMBER

public static final int GET_BODY_LINES_METHOD_NUMBER
The method number for the "getBodyLines" method.

See Also:
Constant Field Values

GET_CC_RECIPIENTS_METHOD_NAME

public static final java.lang.String GET_CC_RECIPIENTS_METHOD_NAME
The name of the method that can be used to retrieve the list of CC recipients for this message.

See Also:
Constant Field Values

GET_CC_RECIPIENTS_METHOD_NUMBER

public static final int GET_CC_RECIPIENTS_METHOD_NUMBER
The method number for the "getCCRecipients" method.

See Also:
Constant Field Values

GET_HEADER_METHOD_NAME

public static final java.lang.String GET_HEADER_METHOD_NAME
The name of the method that can be used to retrieve a specific header for this message.

See Also:
Constant Field Values

GET_HEADER_METHOD_NUMBER

public static final int GET_HEADER_METHOD_NUMBER
The method number for the "getHeader" method.

See Also:
Constant Field Values

GET_HEADER_LINES_METHOD_NAME

public static final java.lang.String GET_HEADER_LINES_METHOD_NAME
The name of the method that can be used to retrieve the list of header lines for this message.

See Also:
Constant Field Values

GET_HEADER_LINES_METHOD_NUMBER

public static final int GET_HEADER_LINES_METHOD_NUMBER
The method number for the "getHeaderLines" method.

See Also:
Constant Field Values

GET_SENDER_METHOD_NAME

public static final java.lang.String GET_SENDER_METHOD_NAME
The name of the method that can be used to clear the address of the sender for this message.

See Also:
Constant Field Values

GET_SENDER_METHOD_NUMBER

public static final int GET_SENDER_METHOD_NUMBER
The method number for the "getSender" method.

See Also:
Constant Field Values

GET_SUBJECT_METHOD_NAME

public static final java.lang.String GET_SUBJECT_METHOD_NAME
The name of the method that can be used to retrieve the subject of this message.

See Also:
Constant Field Values

GET_SUBJECT_METHOD_NUMBER

public static final int GET_SUBJECT_METHOD_NUMBER
The method number for the "getSubject" method.

See Also:
Constant Field Values

GET_TO_RECIPIENTS_METHOD_NAME

public static final java.lang.String GET_TO_RECIPIENTS_METHOD_NAME
The name of the method that can be used to retrieve the list of "To" recipients for this message.

See Also:
Constant Field Values

GET_TO_RECIPIENTS_METHOD_NUMBER

public static final int GET_TO_RECIPIENTS_METHOD_NUMBER
The method number for the "getToRecipients" method.

See Also:
Constant Field Values

SET_SENDER_METHOD_NAME

public static final java.lang.String SET_SENDER_METHOD_NAME
The name of the method that can be used to specify the address of the sender for this message.

See Also:
Constant Field Values

SET_SENDER_METHOD_NUMBER

public static final int SET_SENDER_METHOD_NUMBER
The method number for the "setSender" message.

See Also:
Constant Field Values

SET_SUBJECT_METHOD_NAME

public static final java.lang.String SET_SUBJECT_METHOD_NAME
The name of the method that can be used to specify the subject for this message.

See Also:
Constant Field Values

SET_SUBJECT_METHOD_NUMBER

public static final int SET_SUBJECT_METHOD_NUMBER
The method number for the "setSubject" message.

See Also:
Constant Field Values

MAIL_MESSAGE_VARIABLE_METHODS

public static final Method[] MAIL_MESSAGE_VARIABLE_METHODS
The set of methods associated with mail message variables.

Constructor Detail

MailMessageVariable

public MailMessageVariable()
                    throws ScriptException
Creates a new variable with no name, to be used only when creating a variable with Class.newInstance(), and only when setName() is called after that to set the name.

Throws:
ScriptException - If a problem occurs while initializing the new variable.
Method Detail

getVariableTypeName

public java.lang.String getVariableTypeName()
Retrieves the name of the variable type for this variable.

Specified by:
getVariableTypeName in class Variable
Returns:
The name of the variable type for this variable.

clear

public void clear()
Clears the contents of this message.


clearBody

public void clearBody()
Clears the body of this message.


clearHeader

public void clearHeader()
Clears the header of this message.


addHeaderLine

public void addHeaderLine(java.lang.String line)
Adds the specified line to the list of headers for this message.

Parameters:
line - The line to add to the list of headers for this message.

isEmailAddress

public static boolean isEmailAddress(java.lang.String stringValue)
Indicates whether the provided string value is a valid e-mail address. Note that this doesn't do strict validation, but rather just determines whether it meets the basic requirements for an address.

Parameters:
stringValue - The string value for which to make the determination.
Returns:
true if the provided string does represent a valid e-mail address, or false if not.

addBodyLine

public void addBodyLine(java.lang.String line)
Adds the specified line to the body for this message.

Parameters:
line - The line to add to the body of this message.

getCCList

public java.util.ArrayList getCCList()
Retrieves the list of CC recipients for this message.

Returns:
The list of CC recipients for this message.

addCCRecipient

public void addCCRecipient(java.lang.String address)
Adds the specified address to the list of CC recipients for this message.

Parameters:
address - The address to add to the list of CC recipients for this message.

getToList

public java.util.ArrayList getToList()
Retrieves the list of To recipients for this message.

Returns:
The list of To recipients for this message.

addToRecipient

public void addToRecipient(java.lang.String address)
Adds the specified address to the list of To recipients for this message.

Parameters:
address - The address to add to the list of To recipients for this message.

getRecipients

public java.lang.String[] getRecipients()
Retrieves an array with all recipients (both To and CC) for this message.

Returns:
An array with all recipients for this message.

getSender

public java.lang.String getSender()
Retrieves the address of the sender for this message.

Returns:
The address of the sender for this message.

setSender

public void setSender(java.lang.String sender)
Specifies the sender address for this message.

Parameters:
sender - The sender address to use for the message.

getSubject

public java.lang.String getSubject()
Retrieves the subject for this message.

Returns:
The subject for this message.

setSubject

public void setSubject(java.lang.String subject)
Specifies the subject for this message.

Parameters:
subject - The subject to use for the message.

getHeaderLines

public java.util.ArrayList getHeaderLines()
Retrieves the lines that make up the header of this message.

Returns:
The lines that make up the header of this message.

getBodyLines

public java.util.ArrayList getBodyLines()
Retrieves the lines that make up the body of this message.

Returns:
The lines that make up the body of this message.

getMethods

public Method[] getMethods()
Retrieves a list of all methods defined for this variable.

Specified by:
getMethods in class Variable
Returns:
A list of all methods defined for this variable.

hasMethod

public boolean hasMethod(java.lang.String methodName)
Indicates whether this variable type has a method with the specified name.

Specified by:
hasMethod in class Variable
Parameters:
methodName - The name of the method.
Returns:
true if this variable has a method with the specified name, or false if it does not.

getMethodNumber

public int getMethodNumber(java.lang.String methodName,
                           java.lang.String[] argumentTypes)
Retrieves the method number for the method that has the specified name and argument types, or -1 if there is no such method.

Specified by:
getMethodNumber in class Variable
Parameters:
methodName - The name of the method.
argumentTypes - The list of argument types for the method.
Returns:
The method number for the method that has the specified name and argument types.

getReturnTypeForMethod

public java.lang.String getReturnTypeForMethod(java.lang.String methodName,
                                               java.lang.String[] argumentTypes)
Retrieves the return type for the method with the specified name and argument types.

Specified by:
getReturnTypeForMethod in class Variable
Parameters:
methodName - The name of the method.
argumentTypes - The set of argument types for the method.
Returns:
The return type for the method, or null if there is no such method defined.

executeMethod

public Variable executeMethod(int lineNumber,
                              int methodNumber,
                              Argument[] arguments)
                       throws ScriptException
Executes the specified method, using the provided variables as arguments to the method, and makes the return value available to the caller.

Specified by:
executeMethod in class Variable
Parameters:
lineNumber - The line number of the script in which the method call occurs.
methodNumber - The method number of the method to execute.
arguments - The set of arguments to use for the method.
Returns:
The value returned from the method, or null if it does not return a value.
Throws:
ScriptException - If the specified method does not exist, or if a problem occurs while attempting to execute it.

assign

public void assign(Argument argument)
            throws ScriptException
Assigns the value of the provided argument to this variable. The value of the provided argument must be of the same type as this variable.

Specified by:
assign in class Variable
Parameters:
argument - The argument whose value should be assigned to this variable.
Throws:
ScriptException - If a problem occurs while performing the assignment.

getValueAsString

public java.lang.String getValueAsString()
Retrieves a string representation of the value of this argument.

Returns:
A string representation of the value of this argument.