org.apache.james.core
Class MailImpl

java.lang.Object
  |
  +--org.apache.james.core.MailImpl
All Implemented Interfaces:
Cloneable, Disposable, Mail, Serializable

public class MailImpl
extends Object
implements Disposable, Mail

Wraps a MimeMessage adding routing information (from SMTP) and some simple API enhancements.

Version:
0.9
Author:
Federico Barbieri , Serge Knystautas , Stuart Roebuck
See Also:
Serialized Form

Field Summary
static long serialVersionUID
          We hardcode the serialVersionUID so that from James 1.2 on, MailImpl will be deserializable (so your mail doesn't get lost)
 
Fields inherited from interface org.apache.mailet.Mail
DEFAULT, ERROR, GHOST, TRANSPORT
 
Constructor Summary
MailImpl()
          A constructor that creates a new, uninitialized MailImpl
MailImpl(MimeMessage message)
          A constructor which will attempt to obtain sender and recipients from the headers of the MimeMessage supplied.
MailImpl(String name, MailAddress sender, Collection recipients)
          A constructor that creates a MailImpl with the specified name, sender, and recipients.
MailImpl(String name, MailAddress sender, Collection recipients, InputStream messageIn)
          A constructor that creates a MailImpl with the specified name, sender, recipients, and message data.
MailImpl(String name, MailAddress sender, Collection recipients, MimeMessage message)
          A constructor that creates a MailImpl with the specified name, sender, recipients, and MimeMessage.
 
Method Summary
 Mail bounce(String bounceText)
          Generates a bounce mail that is a bounce of the original message.
 void dispose()
           
 Mail duplicate()
          Duplicate the MailImpl.
 Mail duplicate(String newName)
          Duplicate the MailImpl, replacing the mail name with the one passed in as an argument.
 String getErrorMessage()
          Get the error message associated with this MailImpl.
 Date getLastUpdated()
          Get the last updated time for this MailImpl.
 MimeMessage getMessage()
          Get the MimeMessage associated with this MailImpl.
 long getMessageSize()
          Return the size of the message including its headers.
 String getName()
          Get the name of this MailImpl.
 Collection getRecipients()
          Get the recipients of this MailImpl.
 String getRemoteAddr()
          Get the remote address associated with this MailImpl.
 String getRemoteHost()
          Get the remote host associated with this MailImpl.
 MailAddress getSender()
          Get the sender of this MailImpl.
 String getState()
          Get the state of this MailImpl.
 void setErrorMessage(String msg)
          Set the error message associated with this MailImpl.
 void setLastUpdated(Date lastUpdated)
          Set the date this mail was last updated.
 void setMessage(MimeMessage message)
          Set the MimeMessage associated with this MailImpl.
 void setName(String name)
          Set the name of this MailImpl.
 void setRecipients(Collection recipients)
          Set the recipients for this MailImpl.
 void setRemoteAddr(String remoteAddr)
          Set the remote address associated with this MailImpl.
 void setRemoteHost(String remoteHost)
          Set the remote address associated with this MailImpl.
 void setSender(MailAddress sender)
          Set the sender of this MailImpl.
 void setState(String state)
          Set the state of this MailImpl.
 void writeContentTo(OutputStream out, int lines)
          Writes the content of the message, up to a total number of lines, out to an OutputStream.
 void writeMessageTo(OutputStream out)
          Writes the message out to an OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
We hardcode the serialVersionUID so that from James 1.2 on, MailImpl will be deserializable (so your mail doesn't get lost)

See Also:
Constant Field Values
Constructor Detail

MailImpl

public MailImpl()
A constructor that creates a new, uninitialized MailImpl


MailImpl

public MailImpl(String name,
                MailAddress sender,
                Collection recipients)
A constructor that creates a MailImpl with the specified name, sender, and recipients.

Parameters:
name - the name of the MailImpl
sender - the sender for this MailImpl
recipients - the collection of recipients of this MailImpl

MailImpl

public MailImpl(String name,
                MailAddress sender,
                Collection recipients,
                InputStream messageIn)
         throws MessagingException
A constructor that creates a MailImpl with the specified name, sender, recipients, and message data.

Parameters:
name - the name of the MailImpl
sender - the sender for this MailImpl
recipients - the collection of recipients of this MailImpl
messageIn - a stream containing the message source

MailImpl

public MailImpl(String name,
                MailAddress sender,
                Collection recipients,
                MimeMessage message)
A constructor that creates a MailImpl with the specified name, sender, recipients, and MimeMessage.

Parameters:
name - the name of the MailImpl
sender - the sender for this MailImpl
recipients - the collection of recipients of this MailImpl
message - the MimeMessage associated with this MailImpl

MailImpl

public MailImpl(MimeMessage message)
         throws MessagingException
A constructor which will attempt to obtain sender and recipients from the headers of the MimeMessage supplied.

Parameters:
message - - a MimeMessage from which to construct a Mail
Method Detail

duplicate

public Mail duplicate()
Duplicate the MailImpl.

Returns:
a MailImpl that is a duplicate of this one

duplicate

public Mail duplicate(String newName)
Duplicate the MailImpl, replacing the mail name with the one passed in as an argument.

Parameters:
newName - the name for the duplicated mail
Returns:
a MailImpl that is a duplicate of this one with a different name

getErrorMessage

public String getErrorMessage()
Get the error message associated with this MailImpl.

Specified by:
getErrorMessage in interface Mail
Returns:
the error message associated with this MailImpl

getMessage

public MimeMessage getMessage()
                       throws MessagingException
Get the MimeMessage associated with this MailImpl.

Specified by:
getMessage in interface Mail
Returns:
the MimeMessage associated with this MailImpl
Throws:
MessagingException - - an error occured while loading this object

setName

public void setName(String name)
Set the name of this MailImpl.

Parameters:
name - the name of this MailImpl

getName

public String getName()
Get the name of this MailImpl.

Returns:
the name of this MailImpl

getRecipients

public Collection getRecipients()
Get the recipients of this MailImpl.

Specified by:
getRecipients in interface Mail
Returns:
the recipients of this MailImpl

getSender

public MailAddress getSender()
Get the sender of this MailImpl.

Specified by:
getSender in interface Mail
Returns:
the sender of this MailImpl

getState

public String getState()
Get the state of this MailImpl.

Specified by:
getState in interface Mail
Returns:
the state of this MailImpl

getRemoteHost

public String getRemoteHost()
Get the remote host associated with this MailImpl.

Specified by:
getRemoteHost in interface Mail
Returns:
the remote host associated with this MailImpl

getRemoteAddr

public String getRemoteAddr()
Get the remote address associated with this MailImpl.

Specified by:
getRemoteAddr in interface Mail
Returns:
the remote address associated with this MailImpl

getLastUpdated

public Date getLastUpdated()
Get the last updated time for this MailImpl.

Returns:
the last updated time for this MailImpl

getMessageSize

public long getMessageSize()
                    throws MessagingException

Return the size of the message including its headers. MimeMessage.getSize() method only returns the size of the message body.

Note: this size is not guaranteed to be accurate - see Sun's documentation of MimeMessage.getSize().

Returns:
approximate size of full message including headers.
Throws:
MessagingException - if a problem occurs while computing the message size

setErrorMessage

public void setErrorMessage(String msg)
Set the error message associated with this MailImpl.

Specified by:
setErrorMessage in interface Mail
Parameters:
msg - the new error message associated with this MailImpl

setMessage

public void setMessage(MimeMessage message)
Set the MimeMessage associated with this MailImpl.

Specified by:
setMessage in interface Mail
Parameters:
message - the new MimeMessage associated with this MailImpl

setRecipients

public void setRecipients(Collection recipients)
Set the recipients for this MailImpl.

Parameters:
recipients - the recipients for this MailImpl

setSender

public void setSender(MailAddress sender)
Set the sender of this MailImpl.

Parameters:
sender - the sender of this MailImpl

setState

public void setState(String state)
Set the state of this MailImpl.

Specified by:
setState in interface Mail
Parameters:
state - the state of this MailImpl

setRemoteHost

public void setRemoteHost(String remoteHost)
Set the remote address associated with this MailImpl.

Parameters:
remoteHost - the new remote host associated with this MailImpl

setRemoteAddr

public void setRemoteAddr(String remoteAddr)
Set the remote address associated with this MailImpl.

Parameters:
remoteAddr - the new remote address associated with this MailImpl

setLastUpdated

public void setLastUpdated(Date lastUpdated)
Set the date this mail was last updated.

Parameters:
lastUpdated - the date the mail was last updated

writeMessageTo

public void writeMessageTo(OutputStream out)
                    throws IOException,
                           MessagingException
Writes the message out to an OutputStream.

Parameters:
out - the OutputStream to which to write the content
Throws:
MessagingException - if the MimeMessage is not set for this MailImpl
IOException - if an error occurs while reading or writing from the stream

bounce

public Mail bounce(String bounceText)
            throws MessagingException
Generates a bounce mail that is a bounce of the original message.

Parameters:
bounceText - the text to be prepended to the message to describe the bounce condition
Returns:
the bounce mail
Throws:
MessagingException - if the bounce mail could not be created

writeContentTo

public void writeContentTo(OutputStream out,
                           int lines)
                    throws IOException,
                           MessagingException
Writes the content of the message, up to a total number of lines, out to an OutputStream.

Parameters:
out - the OutputStream to which to write the content
lines - the number of lines to write to the stream
Throws:
MessagingException - if the MimeMessage is not set for this MailImpl
IOException - if an error occurs while reading or writing from the stream

dispose

public void dispose()
Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()


"Copyright © 1999-2002 Apache Jakarta Project. All Rights Reserved."