Class MimicMultipartAlternativeRelatedHandler

  • All Implemented Interfaces:
    MultipartRelatedHandler

    public class MimicMultipartAlternativeRelatedHandler
    extends Object
    implements MultipartRelatedHandler
    Mimics the multipart/alternative handling

    INTERNAL USE ONLY

    Some libraries generate uncommon/incorrect message structures in cases, where multipart/alternate should be used. To handle those kind of messages, this class can be used to mimic the multipart/alternate handling.

    Typical message structures look like the following:

    • multipart/alternative
    • text/plain
    • multipart/related
      • text/html (may reference images using cids)
      • image/jpeg
      • ...
    or
    • multipart/related
      • multipart/alternative
        • text/plain
        • text/html (may reference images using cids)
      • image/jpeg
      • ...
    The cases described above can be handled using the MultipartAlternativeWorker.

    This implementation supports cases where the messages is formed like the following:

    • multipart/related
      • text/plain
      • text/html (may reference images using cids)
      • image/jpeg
      • ...
    • Constructor Detail

      • MimicMultipartAlternativeRelatedHandler

        public MimicMultipartAlternativeRelatedHandler()
    • Method Detail

      • handleMultipartRelated

        public MultipartRelatedHandlerResult handleMultipartRelated​(Stream stream,
                                                                    javax.mail.Multipart m,
                                                                    NodeWorker nodeWorker)
                                                             throws javax.mail.MessagingException
        Description copied from interface: MultipartRelatedHandler
        Processes the multipart/related stream.
        Specified by:
        handleMultipartRelated in interface MultipartRelatedHandler
        Parameters:
        stream - the provided multipart/related stream.
        m - the mail multipart object that is extracted from the stream.
        nodeWorker - the worker calling this handler. Used for executing functions in the context of the worker (e.g. warn())
        Throws:
        javax.mail.MessagingException - if a mail object related exception occurs.
      • determineRootPartByMimeTypePreference

        public javax.mail.Part determineRootPartByMimeTypePreference​(Map<String,​javax.mail.internet.MimeBodyPart> rootPartCandidates,
                                                                     String[] bodyMimeTypePriority)
        This method determines and returns the part that is considered to be the root part for this multipart/related stream.
        Parameters:
        rootPartCandidates - the current map of available root part candidates.
        bodyMimeTypePriority - the provided preference for choosing the root part.
        Returns:
        the root part if a suitable root part is available.
      • collectRootPartCandidates

        public boolean collectRootPartCandidates​(javax.mail.BodyPart bodyPart,
                                                 Map<String,​javax.mail.internet.MimeBodyPart> rootPartCandidates,
                                                 String[] bodyMimeTypePriority)
                                          throws javax.mail.MessagingException
        Adds the first body part to the root part candidates when there isn't already a body part declared as "first-part". Adds the current body part to the root part candidates when the mime type is a viable body part (determined by the bodyMimeTypePriority) and there wasn't already one declared for this mime type.
        Parameters:
        bodyPart - the current body part that shall be analyzed by the root part collection logic.
        rootPartCandidates - the current map of root part candidates the have been found.
        bodyMimeTypePriority - the declared mime type priority.
        Returns:
        true when a root part candidate was found. Otherwise false.
        Throws:
        javax.mail.MessagingException - if retrieving the bodyParts's Content-Type fails
      • getBodyMimeTypePriority

        public String[] getBodyMimeTypePriority()
      • setBodyMimeTypePriority

        public void setBodyMimeTypePriority​(String[] bodyMimeTypePriority)
        This changes the priority of the preferred root type for streams with the multipart/related mime type.
        Parameters:
        bodyMimeTypePriority - the preferred root type for streams with multipart/related.