Package org.apache.james.mime4j.dom
Class Message.Builder
- java.lang.Object
-
- org.apache.james.mime4j.internal.AbstractEntityBuilder
-
- org.apache.james.mime4j.dom.Message.Builder
-
- Enclosing interface:
- Message
public static class Message.Builder extends AbstractEntityBuilder
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Message.Builder
addField(Field field)
Adds a field to the end of the list of fields.Message
build()
Message.Builder
clearFields()
Clears all fields.Message.Builder
copy(Message other)
Message.Builder
disableContentDecoding()
Enables disable content decoding forparse(java.io.InputStream)
operation.Message.Builder
disableFlatMode()
Disables flat parsing mode forparse(java.io.InputStream)
operation.Message.Builder
enableContentDecoding()
Enables automatic content decoding forparse(java.io.InputStream)
operation.Message.Builder
enableFlatMode()
Enables flat parsing mode forparse(java.io.InputStream)
operation.Message.Builder
generateMessageId(String hostname)
Generates and sets message ID for this message.AddressList
getBcc()
Returns the value of the Bcc header field of this message asAddressList
object ornull
if it is not present.AddressList
getCc()
Returns the value of the Cc header field of this message asAddressList
object ornull
if it is not present.Date
getDate()
Returns the value of the Date header field of this message asDate
object ornull
if it is not present.MailboxList
getFrom()
Returns the value of the From header field of this message asMailboxList
object ornull
if it is not present.String
getMessageId()
Returns the value of the Message-ID header field of this message ornull
if it is not present.AddressList
getReplyTo()
Returns the value of the Reply-To header field of this message asAddressList
object ornull
if it is not present.Mailbox
getSender()
Returns the value of the Sender header field of this message asMailbox
object ornull
if it is not present.String
getSubject()
Returns the (decoded) value of the Subject header field of this message ornull
if it is not present.AddressList
getTo()
Returns the value of the To header field of this message asAddressList
object ornull
if it is not present.static Message.Builder
of()
static Message.Builder
of(InputStream is)
static Message.Builder
of(Message other)
Message.Builder
parse(InputStream is)
Message.Builder
removeFields(String name)
Removes allField
s having the specified field name.Message.Builder
setBcc(Collection<? extends Address> bcc)
Sets Bcc header field of this message to the specified addresses.Message.Builder
setBcc(Address bcc)
Sets Bcc header field of this message to the specified address.Message.Builder
setBcc(Address... bcc)
Sets Bcc header field of this message to the specified addresses.Message.Builder
setBody(byte[] bin, String mimeType)
Sets binary content of this message with the given MIME type.Message.Builder
setBody(String text, String subtype, Charset charset)
Sets text of this message with the given MIME subtype and charset.Message.Builder
setBody(String text, Charset charset)
Sets text of this message with the charset.Message.Builder
setBody(BinaryBody binaryBody)
Sets binaryBody of this message.Message.Builder
setBody(Body body)
Sets body of this message.Message.Builder
setBody(Message message)
Sets body of this message.Message.Builder
setBody(Multipart multipart)
Sets body of this message.Message.Builder
setBody(TextBody textBody)
Sets body of this message.Message.Builder
setCc(Collection<? extends Address> cc)
Sets Cc header field of this message to the specified addresses.Message.Builder
setCc(Address cc)
Sets Cc header field of this message to the specified address.Message.Builder
setCc(Address... cc)
Sets Cc header field of this message to the specified addresses.Message.Builder
setContentDisposition(String dispositionType)
Sets content disposition of this message to the specified disposition type.Message.Builder
setContentDisposition(String dispositionType, String filename)
Sets content disposition of this message to the specified disposition type and filename.Message.Builder
setContentDisposition(String dispositionType, String filename, long size)
Sets content disposition of this message to the specified values.Message.Builder
setContentDisposition(String dispositionType, String filename, long size, Date creationDate, Date modificationDate, Date readDate)
Sets content disposition of this message to the specified values.Message.Builder
setContentTransferEncoding(String contentTransferEncoding)
Sets transfer encoding of this message.Message.Builder
setContentType(String mimeType, NameValuePair... parameters)
Sets transfer encoding of this message.Message.Builder
setDate(Date date)
Sets Date header field for this message.Message.Builder
setDate(Date date, TimeZone zone)
Sets Date header field for this message.Message.Builder
setField(Field field)
Sets or replaces a field.Message.Builder
setFrom(String from)
Sets From header field of this message to the specified mailbox address.Message.Builder
setFrom(String... from)
Sets From header field of this message to the specified mailbox addresses.Message.Builder
setFrom(Collection<Mailbox> from)
Sets From header field of this message to the specified mailbox addresses.Message.Builder
setFrom(Mailbox from)
Sets From header field of this message to the specified mailbox address.Message.Builder
setFrom(Mailbox... from)
Sets From header field of this message to the specified mailbox addresses.Message.Builder
setMessageId(String messageId)
Sets message ID for this message.Message.Builder
setReplyTo(Collection<? extends Address> replyTo)
Sets Reply-To header field of this message to the specified addresses.Message.Builder
setReplyTo(Address replyTo)
Sets Reply-To header field of this message to the specified address.Message.Builder
setReplyTo(Address... replyTo)
Sets Reply-To header field of this message to the specified addresses.Message.Builder
setSender(String sender)
Sets Sender header field of this message to the specified mailbox address.Message.Builder
setSender(Mailbox sender)
Sets Sender header field of this message to the specified mailbox address.Message.Builder
setSubject(String subject)
Sets Subject header field for this message.Message.Builder
setTo(String to)
Sets To header field of this message to the specified address.Message.Builder
setTo(String... to)
Sets To header field of this message to the specified addresses.Message.Builder
setTo(Collection<? extends Address> to)
Sets To header field of this message to the specified addresses.Message.Builder
setTo(Address to)
Sets To header field of this message to the specified address.Message.Builder
setTo(Address... to)
Sets To header field of this message to the specified addresses.Message.Builder
use(DecodeMonitor monitor)
SetsDecodeMonitor
that will be used to handle malformed data when executingparse(java.io.InputStream)
.Message.Builder
use(FieldParser<?> fieldParser)
SetsFieldParser
that will be used to generate parse message fields when executingparse(java.io.InputStream)
.Message.Builder
use(BodyFactory bodyFactory)
SetsBodyFactory
that will be used to generate message body.Message.Builder
use(BodyDescriptorBuilder bodyDescBuilder)
SetsBodyDescriptorBuilder
that will be used to generate body descriptors when executingparse(java.io.InputStream)
.Message.Builder
use(MimeConfig config)
Sets MIME configuration.-
Methods inherited from class org.apache.james.mime4j.internal.AbstractEntityBuilder
containsField, getBody, getCharset, getContentTransferEncoding, getCreationDate, getDispositionType, getField, getField, getFields, getFields, getFields, getFilename, getMimeType, getModificationDate, getReadDate, getSize, obtainField, setBody, setBody, setBody
-
-
-
-
Method Detail
-
of
public static Message.Builder of()
-
of
public static Message.Builder of(Message other)
-
of
public static Message.Builder of(InputStream is) throws IOException
- Throws:
IOException
-
use
public Message.Builder use(MimeConfig config)
Sets MIME configuration.- Parameters:
config
- the configuration.
-
use
public Message.Builder use(DecodeMonitor monitor)
SetsDecodeMonitor
that will be used to handle malformed data when executingparse(java.io.InputStream)
.- Parameters:
monitor
- the decoder monitor.
-
use
public Message.Builder use(BodyDescriptorBuilder bodyDescBuilder)
SetsBodyDescriptorBuilder
that will be used to generate body descriptors when executingparse(java.io.InputStream)
.- Parameters:
bodyDescBuilder
- the body descriptor builder.
-
use
public Message.Builder use(FieldParser<?> fieldParser)
SetsFieldParser
that will be used to generate parse message fields when executingparse(java.io.InputStream)
.- Parameters:
fieldParser
- the field parser.
-
use
public Message.Builder use(BodyFactory bodyFactory)
SetsBodyFactory
that will be used to generate message body.- Parameters:
bodyFactory
- the body factory.
-
enableFlatMode
public Message.Builder enableFlatMode()
Enables flat parsing mode forparse(java.io.InputStream)
operation.
-
disableFlatMode
public Message.Builder disableFlatMode()
Disables flat parsing mode forparse(java.io.InputStream)
operation.
-
enableContentDecoding
public Message.Builder enableContentDecoding()
Enables automatic content decoding forparse(java.io.InputStream)
operation.
-
disableContentDecoding
public Message.Builder disableContentDecoding()
Enables disable content decoding forparse(java.io.InputStream)
operation.
-
copy
public Message.Builder copy(Message other)
-
setField
public Message.Builder setField(Field field)
Description copied from class:AbstractEntityBuilder
Sets or replaces a field. This method is useful for header fields such as Subject or Message-ID that should not occur more than once in a message. If this builder does not already contain a header field of the same name as the given field then it is added to the end of the list of fields (same behavior asAbstractEntityBuilder.addField(org.apache.james.mime4j.stream.Field)
). Otherwise the first occurrence of a field with the same name is replaced by the given field and all further occurrences are removed.- Overrides:
setField
in classAbstractEntityBuilder
- Parameters:
field
- the field to set.
-
addField
public Message.Builder addField(Field field)
Description copied from class:AbstractEntityBuilder
Adds a field to the end of the list of fields.- Overrides:
addField
in classAbstractEntityBuilder
- Parameters:
field
- the field to add.
-
removeFields
public Message.Builder removeFields(String name)
Description copied from class:AbstractEntityBuilder
Removes allField
s having the specified field name.- Overrides:
removeFields
in classAbstractEntityBuilder
- Parameters:
name
- the field name (e.g. From, Subject).
-
clearFields
public Message.Builder clearFields()
Description copied from class:AbstractEntityBuilder
Clears all fields.- Overrides:
clearFields
in classAbstractEntityBuilder
-
setContentTransferEncoding
public Message.Builder setContentTransferEncoding(String contentTransferEncoding)
Description copied from class:AbstractEntityBuilder
Sets transfer encoding of this message.- Overrides:
setContentTransferEncoding
in classAbstractEntityBuilder
- Parameters:
contentTransferEncoding
- transfer encoding to use.
-
setContentType
public Message.Builder setContentType(String mimeType, NameValuePair... parameters)
Description copied from class:AbstractEntityBuilder
Sets transfer encoding of this message.- Overrides:
setContentType
in classAbstractEntityBuilder
- Parameters:
mimeType
- MIME type of this message the MIME type to use.parameters
- content type parameters to use.
-
setContentDisposition
public Message.Builder setContentDisposition(String dispositionType)
Description copied from class:AbstractEntityBuilder
Sets content disposition of this message to the specified disposition type. No filename, size or date parameters are included in the content disposition.- Overrides:
setContentDisposition
in classAbstractEntityBuilder
- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).
-
setContentDisposition
public Message.Builder setContentDisposition(String dispositionType, String filename)
Description copied from class:AbstractEntityBuilder
Sets content disposition of this message to the specified disposition type and filename. No size or date parameters are included in the content disposition.- Overrides:
setContentDisposition
in classAbstractEntityBuilder
- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).filename
- filename parameter value ornull
if the parameter should not be included.
-
setContentDisposition
public Message.Builder setContentDisposition(String dispositionType, String filename, long size)
Description copied from class:AbstractEntityBuilder
Sets content disposition of this message to the specified values. No date parameters are included in the content disposition.- Overrides:
setContentDisposition
in classAbstractEntityBuilder
- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).filename
- filename parameter value ornull
if the parameter should not be included.size
- size parameter value or-1
if the parameter should not be included.
-
setContentDisposition
public Message.Builder setContentDisposition(String dispositionType, String filename, long size, Date creationDate, Date modificationDate, Date readDate)
Description copied from class:AbstractEntityBuilder
Sets content disposition of this message to the specified values.- Overrides:
setContentDisposition
in classAbstractEntityBuilder
- Parameters:
dispositionType
- disposition type value (usuallyinline
orattachment
).filename
- filename parameter value ornull
if the parameter should not be included.size
- size parameter value or-1
if the parameter should not be included.creationDate
- creation-date parameter value ornull
if the parameter should not be included.modificationDate
- modification-date parameter value ornull
if the parameter should not be included.readDate
- read-date parameter value ornull
if the parameter should not be included.
-
setBody
public Message.Builder setBody(Body body)
Description copied from class:AbstractEntityBuilder
Sets body of this message. Also sets the content type based on properties of the givenBody
.- Overrides:
setBody
in classAbstractEntityBuilder
- Parameters:
body
- the body.
-
setBody
public Message.Builder setBody(TextBody textBody)
Description copied from class:AbstractEntityBuilder
Sets body of this message. Also sets the content type based on properties of the givenBody
.- Overrides:
setBody
in classAbstractEntityBuilder
- Parameters:
textBody
- the body.
-
setBody
public Message.Builder setBody(BinaryBody binaryBody)
Description copied from class:AbstractEntityBuilder
Sets binaryBody of this message. Also sets the content type based on properties of the givenBody
.- Overrides:
setBody
in classAbstractEntityBuilder
- Parameters:
binaryBody
- the binaryBody.
-
setBody
public Message.Builder setBody(Multipart multipart)
Description copied from class:AbstractEntityBuilder
Sets body of this message. Also sets the content type based on properties of the givenMultipart
.- Overrides:
setBody
in classAbstractEntityBuilder
- Parameters:
multipart
- the body.
-
setBody
public Message.Builder setBody(Message message)
Description copied from class:AbstractEntityBuilder
Sets body of this message. Also sets the content type based on properties of the givenMessage
.- Overrides:
setBody
in classAbstractEntityBuilder
- Parameters:
message
- the body.
-
setBody
public Message.Builder setBody(String text, Charset charset) throws IOException
Sets text of this message with the charset.- Parameters:
text
- the text.charset
- the charset of the text.- Throws:
IOException
-
setBody
public Message.Builder setBody(String text, String subtype, Charset charset) throws IOException
Sets text of this message with the given MIME subtype and charset.- Parameters:
text
- the text.charset
- the charset of the text.subtype
- the text subtype (e.g. "plain", "html" or "xml").- Throws:
IOException
-
setBody
public Message.Builder setBody(byte[] bin, String mimeType) throws IOException
Sets binary content of this message with the given MIME type.- Parameters:
bin
- the body.mimeType
- the MIME media type of the specified body ("type/subtype").- Throws:
IOException
-
getMessageId
public String getMessageId()
Returns the value of the Message-ID header field of this message ornull
if it is not present.- Returns:
- the identifier of this message.
-
generateMessageId
public Message.Builder generateMessageId(String hostname)
Generates and sets message ID for this message.- Parameters:
hostname
- host name to be included in the identifier ornull
if no host name should be included.
-
setMessageId
public Message.Builder setMessageId(String messageId)
Sets message ID for this message.- Parameters:
messageId
- the message ID.
-
getSubject
public String getSubject()
Returns the (decoded) value of the Subject header field of this message ornull
if it is not present.- Returns:
- the subject of this message.
-
setSubject
public Message.Builder setSubject(String subject)
Sets Subject header field for this message. The specified string may contain non-ASCII characters, in which case it gets encoded as an 'encoded-word' automatically.- Parameters:
subject
- subject to set ornull
to remove the subject header field.
-
getDate
public Date getDate()
Returns the value of the Date header field of this message asDate
object ornull
if it is not present.- Returns:
- the date of this message.
-
setDate
public Message.Builder setDate(Date date)
Sets Date header field for this message. This method uses the defaultTimeZone
of this host to encode the specifiedDate
object into a string.- Parameters:
date
- date to set ornull
to remove the date header field.
-
setDate
public Message.Builder setDate(Date date, TimeZone zone)
Sets Date header field for this message. The specifiedTimeZone
is used to encode the specifiedDate
object into a string.- Parameters:
date
- date to set ornull
to remove the date header field.zone
- a time zone.
-
getSender
public Mailbox getSender()
Returns the value of the Sender header field of this message asMailbox
object ornull
if it is not present.- Returns:
- the sender of this message.
-
setSender
public Message.Builder setSender(Mailbox sender)
Sets Sender header field of this message to the specified mailbox address.- Parameters:
sender
- address to set ornull
to remove the header field.
-
setSender
public Message.Builder setSender(String sender) throws ParseException
Sets Sender header field of this message to the specified mailbox address.- Parameters:
sender
- address to set ornull
to remove the header field.- Throws:
ParseException
-
getFrom
public MailboxList getFrom()
Returns the value of the From header field of this message asMailboxList
object ornull
if it is not present.- Returns:
- value of the from field of this message.
-
setFrom
public Message.Builder setFrom(Mailbox from)
Sets From header field of this message to the specified mailbox address.- Parameters:
from
- address to set ornull
to remove the header field.
-
setFrom
public Message.Builder setFrom(String from) throws ParseException
Sets From header field of this message to the specified mailbox address.- Parameters:
from
- address to set ornull
to remove the header field.- Throws:
ParseException
-
setFrom
public Message.Builder setFrom(Mailbox... from)
Sets From header field of this message to the specified mailbox addresses.- Parameters:
from
- addresses to set ornull
or no arguments to remove the header field.
-
setFrom
public Message.Builder setFrom(String... from) throws ParseException
Sets From header field of this message to the specified mailbox addresses.- Parameters:
from
- addresses to set ornull
or no arguments to remove the header field.- Throws:
ParseException
-
setFrom
public Message.Builder setFrom(Collection<Mailbox> from)
Sets From header field of this message to the specified mailbox addresses.- Parameters:
from
- addresses to set ornull
or an empty collection to remove the header field.
-
getTo
public AddressList getTo()
Returns the value of the To header field of this message asAddressList
object ornull
if it is not present.- Returns:
- value of the to field of this message.
-
setTo
public Message.Builder setTo(Address to)
Sets To header field of this message to the specified address.- Parameters:
to
- address to set ornull
to remove the header field.
-
setTo
public Message.Builder setTo(String to) throws ParseException
Sets To header field of this message to the specified address.- Parameters:
to
- address to set ornull
to remove the header field.- Throws:
ParseException
-
setTo
public Message.Builder setTo(Address... to)
Sets To header field of this message to the specified addresses.- Parameters:
to
- addresses to set ornull
or no arguments to remove the header field.
-
setTo
public Message.Builder setTo(String... to) throws ParseException
Sets To header field of this message to the specified addresses.- Parameters:
to
- addresses to set ornull
or no arguments to remove the header field.- Throws:
ParseException
-
setTo
public Message.Builder setTo(Collection<? extends Address> to)
Sets To header field of this message to the specified addresses.- Parameters:
to
- addresses to set ornull
or an empty collection to remove the header field.
-
getCc
public AddressList getCc()
Returns the value of the Cc header field of this message asAddressList
object ornull
if it is not present.- Returns:
- value of the cc field of this message.
-
setCc
public Message.Builder setCc(Address cc)
Sets Cc header field of this message to the specified address.- Parameters:
cc
- address to set ornull
to remove the header field.
-
setCc
public Message.Builder setCc(Address... cc)
Sets Cc header field of this message to the specified addresses.- Parameters:
cc
- addresses to set ornull
or no arguments to remove the header field.
-
setCc
public Message.Builder setCc(Collection<? extends Address> cc)
Sets Cc header field of this message to the specified addresses.- Parameters:
cc
- addresses to set ornull
or an empty collection to remove the header field.
-
getBcc
public AddressList getBcc()
Returns the value of the Bcc header field of this message asAddressList
object ornull
if it is not present.- Returns:
- value of the bcc field of this message.
-
setBcc
public Message.Builder setBcc(Address bcc)
Sets Bcc header field of this message to the specified address.- Parameters:
bcc
- address to set ornull
to remove the header field.
-
setBcc
public Message.Builder setBcc(Address... bcc)
Sets Bcc header field of this message to the specified addresses.- Parameters:
bcc
- addresses to set ornull
or no arguments to remove the header field.
-
setBcc
public Message.Builder setBcc(Collection<? extends Address> bcc)
Sets Bcc header field of this message to the specified addresses.- Parameters:
bcc
- addresses to set ornull
or an empty collection to remove the header field.
-
getReplyTo
public AddressList getReplyTo()
Returns the value of the Reply-To header field of this message asAddressList
object ornull
if it is not present.- Returns:
- value of the reply to field of this message.
-
setReplyTo
public Message.Builder setReplyTo(Address replyTo)
Sets Reply-To header field of this message to the specified address.- Parameters:
replyTo
- address to set ornull
to remove the header field.
-
setReplyTo
public Message.Builder setReplyTo(Address... replyTo)
Sets Reply-To header field of this message to the specified addresses.- Parameters:
replyTo
- addresses to set ornull
or no arguments to remove the header field.
-
setReplyTo
public Message.Builder setReplyTo(Collection<? extends Address> replyTo)
Sets Reply-To header field of this message to the specified addresses.- Parameters:
replyTo
- addresses to set ornull
or an empty collection to remove the header field.
-
parse
public Message.Builder parse(InputStream is) throws IOException
- Throws:
IOException
-
build
public Message build()
-
-