Class MimicMultipartAlternativeRelatedHandler
- java.lang.Object
-
- com.levigo.jadice.server.javamail.internal.multipart.related.MimicMultipartAlternativeRelatedHandler
-
- All Implemented Interfaces:
MultipartRelatedHandler
public class MimicMultipartAlternativeRelatedHandler extends Object implements MultipartRelatedHandler
Mimics the multipart/alternative handlingINTERNAL 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
- ...
- multipart/related
- multipart/alternative
- text/plain
- text/html (may reference images using cids)
- image/jpeg
- ...
- multipart/alternative
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 Summary
Constructors Constructor Description MimicMultipartAlternativeRelatedHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
collectRootPartCandidates(javax.mail.BodyPart bodyPart, Map<String,javax.mail.internet.MimeBodyPart> rootPartCandidates, String[] bodyMimeTypePriority)
Adds the first body part to the root part candidates when there isn't already a body part declared as "first-part".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.String[]
getBodyMimeTypePriority()
MultipartRelatedHandlerResult
handleMultipartRelated(Stream stream, javax.mail.Multipart m, NodeWorker nodeWorker)
Processes the multipart/related stream.void
setBodyMimeTypePriority(String[] bodyMimeTypePriority)
This changes the priority of the preferred root type for streams with the multipart/related mime type.
-
-
-
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 interfaceMultipartRelatedHandler
- 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. Otherwisefalse
.- 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.
-
-