SK.gnome.dwarf.mail.mime
Class MimeMessageBuilder

java.lang.Object
  extended bySK.gnome.dwarf.mail.mime.MimePartBuilder
      extended bySK.gnome.dwarf.mail.mime.MimeMessageBuilder
All Implemented Interfaces:
MimePart

public final class MimeMessageBuilder
extends MimePartBuilder

Provides a helper class to build MIME messages.

This class may be used to construct a MIME mail message, which can be sent over the network or stored to an external file. Both single and multipart messages are supported.


Field Summary
 
Fields inherited from class SK.gnome.dwarf.mail.mime.MimePartBuilder
allow8bit, DEFAULT_CHARSET, charset
 
Constructor Summary
MimeMessageBuilder()
          Creates a new MimeMessageBuilder.
MimeMessageBuilder(boolean allow8bit)
          Creates a new MimeMessageBuilder with 8bit transfer enabled.
MimeMessageBuilder(boolean allow8bit, java.lang.String charset)
          Creates a new MimeMessageBuilder.
MimeMessageBuilder(java.lang.String charset)
          Creates a new MimeMessageBuilder with the given charset.
 
Method Summary
 java.util.Collection getRecipients()
          Returns a collection of all recipient addresses.
 void setCc(java.lang.String addresses)
          Sets the "Cc" header.
 void setCc(java.lang.String[] addresses)
          Sets the "Cc" header.
 void setDate(java.util.Date date)
          Sets the "Date" header.
 void setFrom(java.lang.String address)
          Sets the "From" header.
 java.lang.String setMessageId(java.lang.String hostname)
          Sets the "Message-Id" header.
 void setReplyTo(java.lang.String addresses)
          Sets the "Reply-To" header.
 void setReplyTo(java.lang.String[] addresses)
          Sets the "Reply-To" header.
 void setSender(java.lang.String address)
          Sets the "Sender" header.
 void setSubject(java.lang.String subject)
          Sets the "Subject" header.
 void setTo(java.lang.String addresses)
          Sets the "To" header.
 void setTo(java.lang.String[] addresses)
          Sets the "To" header.
 
Methods inherited from class SK.gnome.dwarf.mail.mime.MimePartBuilder
addHeader, addMimePart, getContentInputStream, getContentSize, getDecodedInputStream, getHeader, getHeader, getHeaderLines, getHeaderNames, getLineCount, getMatchingHeaderLines, getMimePart, getMimePartCount, getNonMatchingHeaderLines, getRawInputStream, getRawSize, isMimeType, removeHeader, removeMimePart, setAddressHeader, setAddressHeader, setContent, setContent, setContent, setContentDescription, setContentLanguage, setContentTransferEncoding, setContentType, setHeader, setName, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeMessageBuilder

public MimeMessageBuilder()
                   throws java.io.IOException,
                          MailException
Creates a new MimeMessageBuilder.

It calls MimeMessageBuilder(boolean, String) with false and MimePartBuilder.DEFAULT_CHARSET default values.


MimeMessageBuilder

public MimeMessageBuilder(boolean allow8bit)
                   throws java.io.IOException,
                          MailException
Creates a new MimeMessageBuilder with 8bit transfer enabled.

If the allow8bit parameter is true, the message will be created assuming that the target MTA is capable to transfer 8bit content. If it is false, the message content will be always converted to pure 7bit ASCII format.

It calls MimeMessageBuilder(boolean, String) with allow8bit and MimePartBuilder.DEFAULT_CHARSET values.

Parameters:
allow8bit - whether to enable 8bit content

MimeMessageBuilder

public MimeMessageBuilder(java.lang.String charset)
                   throws java.io.IOException,
                          MailException
Creates a new MimeMessageBuilder with the given charset.

The charset parameter specifies the MIME charset used to encode the headers as per RFC 2047.

It calls MimeMessageBuilder(boolean, String) with false and charset values.

Parameters:
charset - the MIME charset

MimeMessageBuilder

public MimeMessageBuilder(boolean allow8bit,
                          java.lang.String charset)
                   throws java.io.IOException,
                          MailException
Creates a new MimeMessageBuilder.

If the allow8bit parameter is true, the message will be created assuming that the target MTA is capable to transfer 8bit content. If it is false, the content will be always converted to pure 7bit ASCII format.

The charset parameter specifies the MIME charset used to encode the headers as per RFC 2047.

This constructor sets the "Date" header to the current system time, the "MIME-Version" header to "1.0" and the "Message-Id" header to an internally generated message id using the actual local host name. The "Date" and "Message-Id" headers may be changed later via the corresponding setter methods.

Parameters:
allow8bit - whether to enable 8bit content
charset - the MIME charset
Method Detail

setCc

public void setCc(java.lang.String addresses)
           throws MailException
Sets the "Cc" header.

Parameters:
addresses - comma-separated list of addresses
Throws:
MailException - if an error occured

setCc

public void setCc(java.lang.String[] addresses)
           throws MailException
Sets the "Cc" header.

Parameters:
addresses - the array of addresses
Throws:
MailException - if an error occured

setDate

public void setDate(java.util.Date date)
             throws MailException
Sets the "Date" header.

Parameters:
date - the sent date
Throws:
MailException - if an error occured

setFrom

public void setFrom(java.lang.String address)
             throws MailException
Sets the "From" header.

Parameters:
address - the sender's address
Throws:
MailException - if an error occured

setMessageId

public java.lang.String setMessageId(java.lang.String hostname)
                              throws MailException
Sets the "Message-Id" header.

The hostname parameter should reflect the actual hostname used by the mail server. You can use the "localhost" name if the server's name is not known for any reason.

Parameters:
hostname - the actual hostname
Returns:
the message id
Throws:
MailException - if an error occured

setReplyTo

public void setReplyTo(java.lang.String addresses)
                throws MailException
Sets the "Reply-To" header.

Parameters:
addresses - comma-separated list of addresses
Throws:
MailException - if an error occured

setReplyTo

public void setReplyTo(java.lang.String[] addresses)
                throws MailException
Sets the "Reply-To" header.

Parameters:
addresses - the array of addresses
Throws:
MailException - if an error occured

setSender

public void setSender(java.lang.String address)
               throws MailException
Sets the "Sender" header.

Parameters:
address - the sender's address
Throws:
MailException - if an error occured

setSubject

public void setSubject(java.lang.String subject)
                throws MailException
Sets the "Subject" header.

Parameters:
subject - the message subject
Throws:
MailException - if an error occured

setTo

public void setTo(java.lang.String addresses)
           throws MailException
Sets the "To" header.

Parameters:
addresses - comma-separated list of addresses
Throws:
MailException - if an error occured

setTo

public void setTo(java.lang.String[] addresses)
           throws MailException
Sets the "To" header.

Parameters:
addresses - the array of addresses
Throws:
MailException - if an error occured

getRecipients

public java.util.Collection getRecipients()
                                   throws MailException
Returns a collection of all recipient addresses.

This method collects together all recipient addresses from the "To" and "Cc" headers and returns them in a new collection. The returned collection contains only internet addresses without the personal names.

Returns:
the actual recipients
Throws:
MailException - if an error occured


Copyright (c) 2004-2005, Gnome Ltd. All rights reserved.