|
||||||||||
| 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 |
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.util.List<java.lang.String> |
getContentIDs(java.lang.String htmlContent)
Gathers all occurring content IDs in HTML content and returns them as a list |
static java.lang.String |
getFileName(MailPart mailPart)
Get the decoded filename associated with specified mail part. |
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.String htmlContent)
Detects if given HTML content contains inlined images |
static boolean |
hasReferencedLocalImages(java.lang.String 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?action=get&session=abcdefg&id=123dfr567zh">
Example for a stored image file referenced within a composed mail:
<img src="/ajax/image?uid=12gf356j7">
|
static javax.mail.internet.InternetAddress[] |
parseAddressList(java.lang.String addresslist,
boolean strict)
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 boolean hasEmbeddedImages(java.lang.String 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.String 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.String 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 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 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)
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 false
InternetAddress objects
javax.mail.internet.AddressException - - if parsing failspublic 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 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 | |||||||||