|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.openexchange.mail.mime.utils.MIMEMessageUtility
public final class MIMEMessageUtility
MIMEMessageUtility - Utilities for MIME messages.
| Field Summary | |
|---|---|
static java.util.regex.Pattern |
PATTERN_REF_IMG
|
| Method Summary | |
|---|---|
static java.lang.String |
checkNonAscii(java.lang.String rawHeader)
Checks if given raw header contains non-ascii characters. |
static java.lang.String |
decodeEnvelopeHeader(java.lang.String headerValue)
Decodes a string header obtained from ENVELOPE fetch item. |
static java.lang.String |
decodeMultiEncodedHeader(java.lang.String headerValue)
Decodes a multi-mime-encoded header value using the algorithm specified in RFC 2047, Section 6.1. |
static boolean |
equalsCID(java.lang.String contentId1,
java.lang.String contentId2)
Compares (case insensitive) the given values of message header "Content-ID". |
static java.lang.String |
extractHeader(java.lang.String headerName,
java.io.InputStream inputStream,
boolean closeStream)
Gets the matching header out of RFC 822 data input stream. |
static java.lang.String |
fold(int used,
java.lang.String foldMe)
Folds a string at linear whitespace so that each line is no longer than 76 characters, if possible. |
static java.lang.String |
foldContentDisposition(java.lang.String contentDisposition)
Folds specified Content-Disposition value. |
static java.lang.String |
foldContentType(java.lang.String contentType)
Folds specified Content-Type value. |
static java.util.List<java.lang.String> |
getContentIDs(java.lang.CharSequence htmlContent)
Gathers all occurring content IDs in HTML content and returns them as a list |
static javax.mail.internet.MailDateFormat |
getDefaultMailDateFormat()
Gets the default MailDateFormat. |
static java.lang.String |
getFileName(MailPart mailPart)
Get the decoded filename associated with specified mail part. |
static javax.mail.internet.MailDateFormat |
getMailDateFormat(com.openexchange.session.Session session)
Gets the MailDateFormat for specified session. |
static javax.mail.internet.MailDateFormat |
getMailDateFormat(java.lang.String timeZoneId)
Gets the MailDateFormat for specified time zone identifier. |
static java.lang.String |
getRealFilename(MailPart part)
Determines specified part's real filename if any available. |
static boolean |
hasAttachments(com.sun.mail.imap.protocol.BODYSTRUCTURE bodystructure)
Checks if given BODYSTRUCTURE item indicates to contain (file) attachments |
static boolean |
hasAttachments(javax.mail.Multipart mp,
java.lang.String subtype)
Checks if given multipart contains (file) attachments |
static boolean |
hasEmbeddedImages(java.lang.CharSequence htmlContent)
Detects if given HTML content contains inlined images Example: <img src="cid:s345asd845@12drg"> |
static boolean |
hasReferencedLocalImages(java.lang.CharSequence htmlContent,
com.openexchange.session.Session session)
Detects if given HTML content contains references to local image files Example for an uploaded image file referenced within a composed mail:
<img src="/ajax/file? |
static boolean |
isEmptyHeader(java.lang.String[] headers)
Checks if specified headers are empty. |
static javax.mail.internet.InternetAddress[] |
parseAddressList(java.lang.String addresslist,
boolean strict)
Parse the given sequence of addresses into InternetAddress objects by invoking . |
static javax.mail.internet.InternetAddress[] |
parseAddressList(java.lang.String addresslist,
boolean strict,
boolean failOnError)
Parse the given sequence of addresses into InternetAddress objects by invoking . |
static java.lang.String |
quotePersonal(java.lang.String personal)
Quotes given personal part of an Internet address according to RFC 822 syntax if needed; otherwise the personal is returned unchanged. |
static java.lang.String |
quotePhrase(java.lang.String phrase,
boolean encode)
Quotes given phrase if needed. |
static java.lang.String |
unfold(java.lang.String headerLine)
Unfolds a folded header. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.util.regex.Pattern PATTERN_REF_IMG
| Method Detail |
|---|
public static javax.mail.internet.MailDateFormat getDefaultMailDateFormat()
MailDateFormat.
Note that returned instance of MailDateFormat is shared, therefore use a surrounding synchronized block to preserve thread
safety:
...
final MailDateFormat mdf = MIMEMessageUtility.getMailDateFormat(session);
synchronized(mdf) {
mimeMessage.setHeader("Date", mdf.format(sendDate));
}
...
MailDateFormat for specified session
public static javax.mail.internet.MailDateFormat getMailDateFormat(com.openexchange.session.Session session)
throws MailException
MailDateFormat for specified session.
Note that returned instance of MailDateFormat is shared, therefore use a surrounding synchronized block to preserve thread
safety:
...
final MailDateFormat mdf = MIMEMessageUtility.getMailDateFormat(session);
synchronized(mdf) {
mimeMessage.setHeader("Date", mdf.format(sendDate));
}
...
session - The user session
MailDateFormat for specified session
MailException - If MailDateFormat cannot be returned
public static javax.mail.internet.MailDateFormat getMailDateFormat(java.lang.String timeZoneId)
throws MailException
MailDateFormat for specified time zone identifier.
Note that returned instance of MailDateFormat is shared, therefore use a surrounding synchronized block to preserve thread
safety:
...
final MailDateFormat mdf = MIMEMessageUtility.getMailDateFormat(timeZoneId);
synchronized(mdf) {
mimeMessage.setHeader("Date", mdf.format(sendDate));
}
...
timeZoneId - The time zone identifier
MailDateFormat for specified time zone identifier
MailException - If MailDateFormat cannot be returnedpublic static boolean isEmptyHeader(java.lang.String[] headers)
null
if no headers exist.
headers - The values for a certain header
true if specified headers are empty; otherwise falsepublic static boolean hasEmbeddedImages(java.lang.CharSequence htmlContent)
Example:
<img src="cid:s345asd845@12drg">
htmlContent - The HTML content
true if given HTML content contains inlined images; otherwise falsepublic static java.util.List<java.lang.String> getContentIDs(java.lang.CharSequence htmlContent)
htmlContent - The HTML content
List containing all occurring content IDs
public static boolean equalsCID(java.lang.String contentId1,
java.lang.String contentId2)
<' and
' >' are ignored during comparison
contentId1 - The first content IDcontentId2 - The second content ID
true if both are equal; otherwise false
public static boolean hasReferencedLocalImages(java.lang.CharSequence htmlContent,
com.openexchange.session.Session session)
<img src="/ajax/file?action=get&session=abcdefg&id=123dfr567zh">
<img src="/ajax/image?uid=12gf356j7">
htmlContent - The HTML contentsession - The user session
true if given HTML content contains references to local image files; otherwise falsepublic static java.lang.String getRealFilename(MailPart part)
part - The part whose filename shall be determined
null if none present
public static boolean hasAttachments(javax.mail.Multipart mp,
java.lang.String subtype)
throws javax.mail.MessagingException,
MailException,
java.io.IOException
mp - The multipart to examinesubtype - The multipart's subtype
true if given multipart contains (file) attachments; otherwise false
javax.mail.MessagingException - If a messaging error occurs
MailException - If a mail error occurs
java.io.IOException - If an I/O error occurspublic static boolean hasAttachments(com.sun.mail.imap.protocol.BODYSTRUCTURE bodystructure)
bodystructure - The BODYSTRUCTURE item
true if given BODYSTRUCTURE item indicates to contain (file) attachments; otherwise falsepublic static java.lang.String decodeEnvelopeHeader(java.lang.String headerValue)
headerValue - The header value
public static java.lang.String decodeMultiEncodedHeader(java.lang.String headerValue)
If the charset-conversion fails for any sequence, an UnsupportedEncodingException is thrown.
If the String is not a RFC 2047 style encoded header, it is returned as-is
headerValue - The possibly encoded header value
public static java.lang.String checkNonAscii(java.lang.String rawHeader)
rawHeader - The raw header
public static java.lang.String getFileName(MailPart mailPart)
Returns the value of the "filename" parameter from the "Content-Disposition" header field. If its not available, returns the value of
the "name" parameter from the "Content-Type" header field. Returns null if both are absent.
mailPart - The mail part whose filename shall be returned
null.
public static javax.mail.internet.InternetAddress[] parseAddressList(java.lang.String addresslist,
boolean strict)
InternetAddress.parse(String, boolean). If strict is false, simple email addresses separated by
spaces are also allowed. If strict is true, many (but not all) of the RFC822 syntax rules are enforced. In particular,
even if strict is true, addresses composed of simple names (with no "@domain" part) are allowed. Such "illegal"
addresses are not uncommon in real messages.
Non-strict parsing is typically used when parsing a list of mail addresses entered by a human. Strict parsing is typically used when parsing address headers in mail messages.
Additionally the personal parts are MIME encoded using default MIME charset.
addresslist - - comma separated address stringsstrict - - true to enforce RFC822 syntax; otherwise false
InternetAddress objects
public static javax.mail.internet.InternetAddress[] parseAddressList(java.lang.String addresslist,
boolean strict,
boolean failOnError)
throws javax.mail.internet.AddressException
InternetAddress.parse(String, boolean). If strict is false, simple email addresses separated by
spaces are also allowed. If strict is true, many (but not all) of the RFC822 syntax rules are enforced. In particular,
even if strict is true, addresses composed of simple names (with no "@domain" part) are allowed. Such "illegal"
addresses are not uncommon in real messages.
Non-strict parsing is typically used when parsing a list of mail addresses entered by a human. Strict parsing is typically used when parsing address headers in mail messages.
Additionally the personal parts are MIME encoded using default MIME charset.
addresslist - - comma separated address stringsstrict - - true to enforce RFC822 syntax; otherwise falsefailOnError - - true to fail if parsing fails; otherwise false to get a plain-text representation
InternetAddress objects
javax.mail.internet.AddressException - If parsing fails and failOnError is truepublic static java.lang.String quotePersonal(java.lang.String personal)
This method guarantees that the resulting string can be used to build an Internet address according to RFC 822 syntax so that the
constructor won't throw an instance of InternetAddress.parse(String).
AddressException
final String quotedPersonal = quotePersonal("Doe, Jane");
final String buildAddr = quotedPersonal + " <someone@somewhere.com>";
System.out.println(buildAddr);
//Plain Address: "=?UTF-8?Q?Doe=2C_Jan=C3=A9?=" <someone@somewhere.com>
final InternetAddress ia = new InternetAddress(buildAddr);
System.out.println(ia.toUnicodeString());
//Unicode Address: "Doe, Jane" <someone@somewhere.com>
personal - The personal's string representation
public static java.lang.String quotePhrase(java.lang.String phrase,
boolean encode)
phrase - The phraseencode - true to encode phrase according to RFC 822 syntax if needed; otherwise false
public static java.lang.String foldContentType(java.lang.String contentType)
Content-Type value.
contentDisposition - The Content-Type value
Content-Type valuepublic static java.lang.String foldContentDisposition(java.lang.String contentDisposition)
Content-Disposition value.
contentDisposition - The Content-Disposition value
Content-Disposition value
public static java.lang.String fold(int used,
java.lang.String foldMe)
Note that line breaks in the string aren't escaped; they probably should be.
used - The characters used in line so farfoldMe - The string to fold
public static java.lang.String unfold(java.lang.String headerLine)
headerLine - The header line to unfold
public static java.lang.String extractHeader(java.lang.String headerName,
java.io.InputStream inputStream,
boolean closeStream)
throws java.io.IOException
headerName - The header nameinputStream - The input streamcloseStream - true to close the stream on finish; otherwise false
java.io.IOException - If reading input stream fails
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||