public final class MailMessageHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
ANONYMOUS_EMAIL_ADDRESS_SUFFIX
Suffix of an email address (starting with @) of an anonymized user.
|
Modifier and Type | Method and Description |
---|---|
static void |
assertNonAnonymousRecipients(javax.mail.Message message)
Verifies that no email address in TO, BCC and CC headers ends with
ANONYMOUS_EMAIL_ADDRESS_SUFFIX . |
static String |
createMessageIdHeaderValue(String identifier)
Creates a value for the Message-ID header.
|
static String |
extractMessageIdentifierFromReplyHeaders(javax.mail.Message message)
Extracts the message identifier from the reply headers.
|
static Map<String,javax.mail.Part> |
extractMessagePartsMatchingMimeTypes(javax.mail.Message message,
String... mimeTypes)
Extracts all parts (especially in case of a multipart message) of a message that have one of
the supplied MIME types.
|
static Collection<User> |
filterAnonymousUsers(Collection<User> receivers) |
static String[] |
getAllRecipients(javax.mail.Message message)
Shorthand for calling
getAllRecipients(Message, boolean, boolean, String) with
arguments message, true, true, null |
static String[] |
getAllRecipients(javax.mail.Message message,
boolean evaluateBoth,
boolean startWithStandardHeaders,
String suffixFilter)
Gets all recipients found in X-Original-To header field and/or the standard recipient headers
(TO,CC,Delivered-To - where the latter is useful for emails received because of a Bcc
header).
|
static Collection<AttachmentTO> |
getAttachments(javax.mail.Message message)
Extracts the attachments from the mail.
|
static String |
getMessageText(javax.mail.Message message,
boolean plainTextOnly,
boolean cleanup)
Returns the text content of a email message.
|
static String[] |
getRecipients(javax.mail.Message message,
javax.mail.Message.RecipientType recipientType)
Returns the recipients found by evaluating the provided header.
|
static boolean |
isAnonymousEmailAddress(String email) |
static boolean |
isOutlookMessage(javax.mail.Message message)
Tries to determine whether a message was created using a MS Outlook Mail-Client.
|
static void |
sendMessage(Collection<User> receivers,
String template,
Map<String,Object> model)
Sends a mail message to the defined receivers with the correct locale.
|
static void |
sendMessage(Collection<User> receivers,
String messageKey,
Map<String,Object> model,
String replyToAddress,
String replyToName)
Sends a mail message to the defined receivers with the correct locale.
|
static void |
sendMessageToManagers(String template,
Map<String,Object> model)
Sends a message to all Managers.
|
static void |
sendMessageToManagers(String template,
Map<String,Object> model,
String replyToAddress,
String replyToName)
Sends a message to all Managers.
|
public static final String ANONYMOUS_EMAIL_ADDRESS_SUFFIX
public static void assertNonAnonymousRecipients(javax.mail.Message message) throws javax.mail.MessagingException, InvalidRecipientMailAddressException
ANONYMOUS_EMAIL_ADDRESS_SUFFIX
. In case such an email address is
encountered an InvalidRecipientMailAddressException
will be thrown.message
- the message to checkjavax.mail.MessagingException
- in case the message has no recipients or getting the recipients failedInvalidRecipientMailAddressException
- in case an anonymous recipient is encounteredpublic static String createMessageIdHeaderValue(String identifier)
identifier
- the identifier to convert to the header value. The identifier must be in
dot-atom-text format as defined in RFC 2822public static String extractMessageIdentifierFromReplyHeaders(javax.mail.Message message) throws javax.mail.MessagingException
createMessageIdHeaderValue(String)
.message
- the message to evaluatejavax.mail.MessagingException
- in case of an error while reading the email headerspublic static Map<String,javax.mail.Part> extractMessagePartsMatchingMimeTypes(javax.mail.Message message, String... mimeTypes) throws javax.mail.MessagingException, IOException
message
- the message to processmimeTypes
- the MIME types to search forjavax.mail.MessagingException
- in case of an error while reading the email dataIOException
- if accessing the content of the part failedpublic static Collection<User> filterAnonymousUsers(Collection<User> receivers)
receivers
- public static String[] getAllRecipients(javax.mail.Message message) throws javax.mail.MessagingException
getAllRecipients(Message, boolean, boolean, String)
with
arguments message, true, true, nullmessage
- the message to checkjavax.mail.MessagingException
- in case of an error while reading the recipientspublic static String[] getAllRecipients(javax.mail.Message message, boolean evaluateBoth, boolean startWithStandardHeaders, String suffixFilter) throws javax.mail.MessagingException
message
- the message to checkevaluateBoth
- whether to check both header types. If false the other header type will only be
evaluated if the first header type was empty.startWithStandardHeaders
- when true the TO/CC/BCC headers will be evaluated first, otherwise the
X-Original-To headersuffixFilter
- optional filter to restrict results to email addresses that end with the suffix.
If null all values will be accepted.javax.mail.MessagingException
- in case of an error while reading the recipientspublic static Collection<AttachmentTO> getAttachments(javax.mail.Message message) throws javax.mail.MessagingException, IOException
message
- The message.AttachmentTO
.IOException
- Exception.javax.mail.MessagingException
- Exception.public static String getMessageText(javax.mail.Message message, boolean plainTextOnly, boolean cleanup) throws javax.mail.MessagingException, IOException
message
- the message to processplainTextOnly
- when false this method will first look for an HTML message part and return it. If
there is no such part a plain text part is searched and returned. In case this
parameter is true this method will first search for a plain text message part and
return it. If none exists a HTML message part is searched and cleaned from HTML
markup before it is returned.cleanup
- if true some cleanup operations will be done before returning. This only applies
when returning HTML from an HTML part or plain text from a HTML part (here the
cleanup will replace paragraphs with newlines).javax.mail.MessagingException
- in case of an error while reading the email dataIOException
- if accessing the content of the part failedpublic static String[] getRecipients(javax.mail.Message message, javax.mail.Message.RecipientType recipientType) throws javax.mail.MessagingException
message
- the message to checkrecipientType
- the recipient header to evaluatejavax.mail.MessagingException
- in case of an error while reading the recipientspublic static boolean isAnonymousEmailAddress(String email)
email
- true if it is an anonymous email and hence no mail should be send herepublic static boolean isOutlookMessage(javax.mail.Message message) throws javax.mail.MessagingException
message
- the message to checkjavax.mail.MessagingException
- in case of an error while reading the email datapublic static void sendMessage(Collection<User> receivers, String template, Map<String,Object> model)
receivers
- List of receivers.template
- The template.model
- The model.public static void sendMessage(Collection<User> receivers, String messageKey, Map<String,Object> model, String replyToAddress, String replyToName)
receivers
- List of receivers.messageKey
- The message key of the template.model
- The model.replyToAddress
- Address for reply to (optional).replyToName
- Name for reply to (optional).public static void sendMessageToManagers(String template, Map<String,Object> model)
template
- The template.model
- The model.public static void sendMessageToManagers(String template, Map<String,Object> model, String replyToAddress, String replyToName)
template
- The template.model
- The model.replyToAddress
- Address for reply to (optional).replyToName
- Name for reply to (optional).Copyright © 2019 Communote team. All rights reserved.