Package jodd.mail
Class EmailAttachment<T extends javax.activation.DataSource>
- java.lang.Object
-
- jodd.mail.EmailAttachment<T>
-
public class EmailAttachment<T extends javax.activation.DataSource> extends java.lang.Object
Email attachment.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EmailAttachment(java.lang.String name, java.lang.String contentId, boolean isInline, T dataSource)
Creates new attachment with given name and content id for inline attachments.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getContentId()
Returns content id for inline attachments.java.lang.String
getContentType()
Returns content type ofDataSource
.T
getDataSource()
ReturnsDataSource
implementation, depending on attachment source.java.lang.String
getEncodedName()
Returns encoded attachment name.java.lang.String
getName()
Returns attachment name.int
getSize()
Returns size of attachment.boolean
isEmbedded()
Returnstrue
if the attachment is embedded.boolean
isEmbeddedInto(EmailMessage emailMessage)
Returnstrue
if attachment is embedded into provided message.boolean
isInline()
Returnstrue
if it is an inline attachment.protected EmailAttachment<T>
setContentId(java.lang.String contentId)
Sets content ID.EmailAttachment<T>
setEmbeddedMessage(EmailMessage emailMessage)
Sets target message for embedded attachments.protected EmailAttachment<T>
setInline(boolean isInline)
Sets whether attachment is inline.protected EmailAttachment<T>
setSize(int size)
Sets size of attachment.byte[]
toByteArray()
Returns byte content of the attachment.static EmailAttachmentBuilder
with()
Returns new/emptyEmailAttachmentBuilder
.void
writeToFile(java.io.File destination)
Saves attachment to a file.void
writeToStream(java.io.OutputStream out)
Saves attachment to the output stream.
-
-
-
Constructor Detail
-
EmailAttachment
protected EmailAttachment(java.lang.String name, java.lang.String contentId, boolean isInline, T dataSource)
Creates new attachment with given name and content id for inline attachments.- Parameters:
contentId
- Value may benull
if attachment is not embedded.isInline
-true
if the attachment is inline.name
- Email name may benull
as well.- See Also:
MimeUtility.decodeText(String)
-
-
Method Detail
-
with
public static EmailAttachmentBuilder with()
Returns new/emptyEmailAttachmentBuilder
.- Returns:
EmailAttachmentBuilder
.
-
getName
public java.lang.String getName()
Returns attachment name.- Returns:
- attachment name. Value may be
null
.
-
getEncodedName
public java.lang.String getEncodedName()
Returns encoded attachment name.- Returns:
- encoded attachment name. Value may be
null
.
-
getContentId
public java.lang.String getContentId()
Returns content id for inline attachments.Value is
null
when attachment is not embedded.- Returns:
- content id for inline attachments
- See Also:
isEmbedded()
-
isEmbedded
public boolean isEmbedded()
Returnstrue
if the attachment is embedded.Embedded attachment is one when
getContentId()
is notnull
.- Returns:
true
if the attachment is embedded.
-
isInline
public boolean isInline()
Returnstrue
if it is an inline attachment.- Returns:
true
if it is an inline attachment.
-
setInline
protected EmailAttachment<T> setInline(boolean isInline)
Sets whether attachment is inline.- Parameters:
isInline
-true
for inline.- Returns:
- this
-
setContentId
protected EmailAttachment<T> setContentId(java.lang.String contentId)
Sets content ID.- Parameters:
contentId
- content ID ofEmailAttachment
.- Returns:
- this
-
setEmbeddedMessage
public EmailAttachment<T> setEmbeddedMessage(EmailMessage emailMessage)
Sets target message for embedded attachments.- Parameters:
emailMessage
- targetEmailMessage
.
-
isEmbeddedInto
public boolean isEmbeddedInto(EmailMessage emailMessage)
Returnstrue
if attachment is embedded into provided message.- Parameters:
emailMessage
- targetEmailMessage
.- Returns:
true
if attachment is embedded into provided message.
-
getDataSource
public T getDataSource()
ReturnsDataSource
implementation, depending on attachment source.
-
getContentType
public java.lang.String getContentType()
Returns content type ofDataSource
.- Returns:
- content type of
DataSource
.
-
getSize
public int getSize()
Returns size of attachment.- Returns:
- size of attachment or -1 if not yet calculated from
DataSource
.
-
setSize
protected EmailAttachment<T> setSize(int size)
Sets size of attachment.- Parameters:
size
- the size of the attachment.- Returns:
- this
-
toByteArray
public byte[] toByteArray()
Returns byte content of the attachment.- Returns:
- byte array with content of the attachment.
-
writeToFile
public void writeToFile(java.io.File destination)
Saves attachment to a file.- Parameters:
destination
- The destination file to be written.
-
writeToStream
public void writeToStream(java.io.OutputStream out)
Saves attachment to the output stream.- Parameters:
out
- OutputStream where attachment should be copied to.
-
-