Package jodd.mail

Class EmailAttachment<T extends javax.activation.DataSource>


  • public class EmailAttachment<T extends javax.activation.DataSource>
    extends java.lang.Object
    Email attachment.
    • 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 be null if attachment is not embedded.
        isInline - true if the attachment is inline.
        name - Email name may be null as well.
        See Also:
        MimeUtility.decodeText(String)
    • Method Detail

      • 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()
        Returns true if the attachment is embedded.

        Embedded attachment is one when getContentId() is not null.

        Returns:
        true if the attachment is embedded.
      • isInline

        public boolean isInline()
        Returns true 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 of EmailAttachment.
        Returns:
        this
      • isEmbeddedInto

        public boolean isEmbeddedInto​(EmailMessage emailMessage)
        Returns true if attachment is embedded into provided message.
        Parameters:
        emailMessage - target EmailMessage.
        Returns:
        true if attachment is embedded into provided message.
      • getDataSource

        public T getDataSource()
        Returns DataSource implementation, depending on attachment source.
      • getContentType

        public java.lang.String getContentType()
        Returns content type of DataSource.
        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.