Modifier and Type | Field and Description |
---|---|
static String |
ENCRYPTED |
static String |
PLAIN |
static String |
STARTTLS |
static String |
TRUSTED |
Modifier and Type | Method and Description |
---|---|
static String |
adjustImageTags(String htmlString,
List<Part> parts)
This method takes a HTML string that contains inline images
(i.e.
|
static Message |
convertBytesToMessage(byte[] msgContent)
Converts the given Byte Array to a javax.mail.Message
|
static Message |
convertBytesToMessage(byte[] msgContent,
Session s)
Converts the given Byte Array to a javax.mail.Message
|
static byte[] |
convertMessageToBytes(Message msg)
Converts the given message to Byte Array
|
static String[] |
convertToArray(String to)
Converts the given TO addresses (separated by comma) to an array
|
static MimeMessage |
convertToMimeMessage(org.apache.poi.hsmf.MAPIMessage msg)
Method to convert
MAPIMessage to MimeMessage . |
static String |
decodeText(String txt)
Decodes the given encoded text (e.g. mail subjects).
|
static List<Part> |
extractAttachments(Message msg)
This method returns all parts of a given message that are not
of type multipart/*.
|
static List<Part> |
extractAttachmentsWithoutInlineImages(Message msg)
This method returns all parts of a given message that are not
of type multipart/*, but without inline images.
|
static String |
extractHtmlBodyContent(String strHtml)
This method takes a HTML string and extracts the content
of the body tag, i.e. everything between
<body> and </body>.
|
static Part |
extractOriginalHTMLMessage(Part p)
This method returns the first part of a given message
that meets the following conditions:
The part is unnamed
The content type is text/html
|
static Part |
extractOriginalPlainTextMessage(Part p)
This method returns the first part of a given message
that meets the following conditions:
The part is unnamed
The content type is text/plain
|
static InternetAddress |
extractSender(Message msg)
Extracts the sender address of a given message.
|
static String |
extractSubjectId(String text)
The method tries to extract the pattern id of the given text.
|
static String |
getDisplayAddress(Address a)
Returns a HTML encoded string that represents a given email address.
|
static String |
getDisplayAddressList(Address[] addresses)
Returns a string containing a list of email addresses like
<address-1>, <address-2>, ..., <address-n>,
|
static String |
getDisplayAddressList(Message msg,
String field)
Returns a string containing a list of email addresses like
<address-1>, <address-2>, ..., <address-n>,
|
static String |
getDisplayFilename(Part part)
Returns the filename of a given part or "unnamed" if
the part does not have a name.
|
static String |
getDisplayMailContent(Message msg,
boolean htmlPreferred,
boolean onlyBody)
This method returns a HTML-encoded mail-content (not only the html-content between body tags)
The returned string can be displayed within every html file.
|
static Address[] |
getFrom(Message msg)
Return the sender information in message header (From or Sender) of given message.
|
static String |
getMailSocketFactoryName(String communicationType)
Get the socket factory name of given communication type
|
static String |
getMailSubjectPattern()
This method returns the subject prefix defined in @enterprise configuration.
|
static String |
getMessageId(Message msg)
This method returns the message-id of the given message
|
static String |
getSender()
Get the standard sender defined in configuration.
|
static String |
getSMTPCommunicationType()
|
static Pair<String,String> |
getSMTPCredentials()
Get SMTP Credentials from configuration.
|
static String |
getSMTPHost()
Get the standard SMTP-host defined in configuration
|
static boolean |
hasAttachments(Message msg)
Method to check, if the message has real attachments and inline images too,
i.e. the mail body parts (text/plain and text/html) are not considered.
|
static boolean |
hasAttachmentsWithoutInlineImages(Message msg)
Method to check, if the message has real attachments,
i.e. the mail body parts (text/plain and text/html) and the inline images are not considered.
|
static String |
htmlBodyToPlainText(String strHtml)
This method takes the content of a HTML body, i.e. everything
between <body> and
</body>, and removes the tags.
|
static String |
htmlDecode(String content)
This method replaces entities with their real symbols, i.e.
|
static boolean |
isMailReceived(Message msg)
Method to check, if email contains received attribute(s).
|
static boolean |
isSecureSMTP(String type)
|
static boolean |
isValidEmailAddress(String email)
Method to validate given email address.
|
static String |
sanitizeCRLF(String s)
Replace sequences of CRLF characters by single spaces.
|
public static final String PLAIN
public static final String ENCRYPTED
public static final String TRUSTED
public static final String STARTTLS
public static byte[] convertMessageToBytes(Message msg)
msg
- the javax.mail.Messagenull
, if an error occurredpublic static String sanitizeCRLF(String s)
Message.setSubject(String)
c.f. [CSNC-2014-001]s
- the String to sanitizepublic static Message convertBytesToMessage(byte[] msgContent)
msgContent
- the content as byte[]null
, if an error occurredpublic static Message convertBytesToMessage(byte[] msgContent, Session s)
msgContent
- the content as byte[]s
- the SMTP session which shall be used to transport the messagenull
, if an error occurredpublic static String getSMTPHost()
null
, if not defined.public static Pair<String,String> getSMTPCredentials()
Pair
where key contains value of configuration parameter "ep.mail.smtp.username" and
value "ep.mail.smtp.password". If no username is set, null
is returned.public static String getSMTPCommunicationType()
public static boolean isSecureSMTP(String type)
public static String getSender()
public static String[] convertToArray(String to)
to
- the TO addressespublic static String getMailSocketFactoryName(String communicationType)
public static MimeMessage convertToMimeMessage(org.apache.poi.hsmf.MAPIMessage msg) throws Exception
Method to convert MAPIMessage
to MimeMessage
.
msg
- the MAPIMessage
objectMimeMessage
objectException
public static boolean isValidEmailAddress(String email)
email
- the email address to validatetrue
, if email is a correct email addresspublic static String getMailSubjectPattern()
null
,
if no parameter value is availablepublic static String getMessageId(Message msg)
msg
- the MimeMessage
objectnull
, if the id could not be determinedpublic static InternetAddress extractSender(Message msg) throws Exception
Extracts the sender address of a given message.
public static String extractSubjectId(String text)
The method tries to extract the pattern id of the given text.
If such an id is found, it is returned, otherwise null
is returned.
text
- the given textpublic static Part extractOriginalPlainTextMessage(Part p) throws MessagingException, IOException
This method returns the first part of a given message that meets the following conditions:
p
- the message which is to scan, typically of type
Message
, but the method works
for any other objects that implement the
Part
interface.MessagingException
IOException
public static Part extractOriginalHTMLMessage(Part p) throws MessagingException, IOException
This method returns the first part of a given message that meets the following conditions:
p
- the message which is to scan, typically of type
Message
, but the method works
for any other objects that implement the
Part
interface.MessagingException
IOException
public static List<Part> extractAttachments(Message msg) throws MessagingException, IOException
This method returns all parts of a given message that are not of type multipart/*. That means that also the mail body parts (text/plain and text/html) are returned.
msg
- the message which is to scanMessagingException
IOException
public static List<Part> extractAttachmentsWithoutInlineImages(Message msg) throws MessagingException, IOException
This method returns all parts of a given message that are not of type multipart/*, but without inline images. Inline images have a "Content-Id" and in most cases the header attribute "Content-Disposition: inline". This method also returns mail body parts (text/plain and text/html).
msg
- the message which is to scanMessagingException
IOException
public static String htmlBodyToPlainText(String strHtml)
This method takes the content of a HTML body, i.e. everything between <body> and </body>, and removes the tags.
strHtml
- the content of the HTML bodypublic static String extractHtmlBodyContent(String strHtml)
This method takes a HTML string and extracts the content of the body tag, i.e. everything between <body> and </body>.
strHtml
- a HTML stringpublic static String getDisplayFilename(Part part) throws Exception
Returns the filename of a given part or "unnamed" if the part does not have a name.
part
- the partException
public static String getDisplayMailContent(Message msg, boolean htmlPreferred, boolean onlyBody) throws Exception
This method returns a HTML-encoded mail-content (not only the html-content between body tags)
The returned string can be displayed within every html file. Therefore the string does only contain html elements, that can be placed within the body-tag.
msg
- the mail of which to extract the contenthtmlPreferred
- pass true if you prefer the
text/html over the text/plain
variant, otherwise false.onlyBody
- if true
, extract html-content between body tags only; otherwise the whole content (text/html or text/plain).
this parameter is used, if parameter htmlPreferred is true
and message contains a text/html part.Exception
public static String adjustImageTags(String htmlString, List<Part> parts) throws MessagingException
This method takes a HTML string that contains inline images
(i.e. <img> tags with a src
attribute that
points to a part of the mail).
It alters the src
attributes of these
<img> tags because in order to display inline images
within the browser.
htmlString
- the original HTML string that contains inline imagesparts
- all parts of this message.src
attributesMessagingException
public static String decodeText(String txt)
MimeUtility.decodeText(String)
, but with differences:
txt
- the text to decodepublic static String htmlDecode(String content)
content
- public static boolean hasAttachments(Message msg) throws Exception
public static boolean hasAttachmentsWithoutInlineImages(Message msg) throws Exception
public static Address[] getFrom(Message msg) throws MessagingException
getFrom()
of message object itself is called, but in case
of parsing errors the information is extracted manually as done if session property
mail.mime.address.strict
has been set to value false
.msg
- the Message
objectMessagingException
public static String getDisplayAddressList(Address[] addresses)
Returns a string containing a list of email addresses like <address-1>, <address-2>, ..., <address-n>,
addresses
- the mail addressespublic static String getDisplayAddress(Address a)
Returns a HTML encoded string that represents a given email address. The string looks like "someone@somewhere.com" or "Some One <someone@somewhere.com>", if the name of the person is specified.
a
- the addresspublic static String getDisplayAddressList(Message msg, String field) throws MessagingException
Returns a string containing a list of email addresses like <address-1>, <address-2>, ..., <address-n>,
msg
- the Message
objectfield
- the needed address-field of the messageMessagingException
public static boolean isMailReceived(Message msg) throws MessagingException
msg
- the Message
objecttrue
, if "Received" was found in header, otherwise false
MessagingException
@enterprise 10.0.39049 Copyright © 2024 FREQUENTIS AG. All Rights Reserved.