Package org.silverpeas.core.mail
Class MailContent
- java.lang.Object
-
- org.silverpeas.core.mail.MailContent
-
public class MailContent extends Object
- Author:
- Yohann Chastagnier
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
MailContent.AttachedFile
Representation of an attached file.
-
Field Summary
Fields Modifier and Type Field Description static MailContent
EMPTY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyOn(javax.mail.internet.MimeMessage message)
Applies the content information on aMimeMessage
.static javax.mail.internet.MimeBodyPart
extractTextBodyPartFromHtmlContent(String htmlContent)
Gets aMimeBodyPart
filled with text content extracted from given HTML content.static javax.mail.internet.MimeBodyPart
getHtmlBodyPartFromHtmlContent(String htmlContent)
Gets aMimeBodyPart
initialized with given HTML content into UTF8 encoding.static String
normalizeHtmlContent(String htmlContent)
Normalizes the given HTML content in order to be sent safely by mail infrastructure.MailContent
notHtml()
Forces the information that the content is not an HTML one.static MailContent
of(String content)
Gets a new instance ofMimeMessage
by specifying a content as a string.static MailContent
of(javax.mail.Multipart multipart)
Gets a new instance ofMimeMessage
by specifying a content as aMultipart
.String
toString()
MailContent
withContentType(String contentType)
Sets the content type.
-
-
-
Field Detail
-
EMPTY
public static final MailContent EMPTY
-
-
Method Detail
-
of
public static MailContent of(String content)
Gets a new instance ofMimeMessage
by specifying a content as a string.- Parameters:
content
- the string content- Returns:
- a new instance of
MimeMessage
.
-
of
public static MailContent of(javax.mail.Multipart multipart)
Gets a new instance ofMimeMessage
by specifying a content as aMultipart
.- Parameters:
multipart
- theMultipart
content- Returns:
- a new instance of
MimeMessage
.
-
normalizeHtmlContent
public static String normalizeHtmlContent(String htmlContent)
Normalizes the given HTML content in order to be sent safely by mail infrastructure.If HTML TAG container does not exists, then the normalization is performed. HTML, HEAD and BODY are created and all declared styles in BODY are moved to HEAD part in order to get as most as possible compatibility email reader.
- Parameters:
htmlContent
- an HTML content.- Returns:
- a string representing the normalized HTML content.
-
extractTextBodyPartFromHtmlContent
public static javax.mail.internet.MimeBodyPart extractTextBodyPartFromHtmlContent(String htmlContent)
Gets aMimeBodyPart
filled with text content extracted from given HTML content.- Parameters:
htmlContent
- an HTML content.- Returns:
- a
MimeBodyPart
.
-
getHtmlBodyPartFromHtmlContent
public static javax.mail.internet.MimeBodyPart getHtmlBodyPartFromHtmlContent(String htmlContent)
Gets aMimeBodyPart
initialized with given HTML content into UTF8 encoding.- Parameters:
htmlContent
- an HTML content as UTF8 encoding.- Returns:
- a
MimeBodyPart
.
-
notHtml
public MailContent notHtml()
Forces the information that the content is not an HTML one. By default, the content is considered as an HTML one.- Returns:
- the instance of
MailContent
.
-
withContentType
public MailContent withContentType(String contentType)
Sets the content type.- Parameters:
contentType
- the content type to set.- Returns:
- the instance of
MailContent
.
-
applyOn
public void applyOn(javax.mail.internet.MimeMessage message) throws javax.mail.MessagingException
Applies the content information on aMimeMessage
. If the content is a string and contains<html>
TAG, then the content is considered as an HTML one, even ifisHtml()
returns false.- Parameters:
message
- theMimeMessage
.- Throws:
javax.mail.MessagingException
- if an error occurs with the message
-
-