|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mailster.util.MailUtilities
public class MailUtilities
---
Mailster (C) 2007-2009 De Oliveira Edouard
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
See Mailster
Web Site
---
MailUtilities.java - Various methods to help in message handling, parsing, formatting, writting etc...
| Field Summary | |
|---|---|
private static org.slf4j.Logger |
LOG
Log object for this class. |
static int |
MAX_LINE_LENGTH
Maximum SMTP communication line width (RFC 822 sets it to "72 or 73 characters" so we give some extra characters just to ensure not loosing characters). |
static java.lang.String |
tempDirectory
Temporary directory name used when saving temporary data. |
| Constructor Summary | |
|---|---|
MailUtilities()
|
|
| Method Summary | |
|---|---|
static java.lang.String |
decode(java.lang.String encodedString,
java.lang.String charsetName,
java.lang.String encoding)
Decodes the string encodedString encoded as
encoding with the charset named charsetName. |
static java.lang.String |
decodeHeaderValue(java.lang.String encodedHeaderValue)
Decodes a encoded header value. |
static java.lang.String |
escapeHTMLString(java.lang.String string)
Returns an escaped HTML string. |
static java.lang.String |
formatFlowed(java.lang.String body)
Returns a decorated version of body compliant with RFC
2646 when interpreted in a browser. |
private static java.lang.String |
getFlowedMarkerHMTLColor(int level)
Computes and returns the HTML color string (#xxyyzz) associated with the quote level level. |
static java.lang.String |
getHeaderParameterValue(SmtpHeadersInterface headers,
java.lang.String name,
java.lang.String parameterName)
Returns the value of a specific parameter named parameterName which is a sub value of the header
name from the headers headers. |
private static int |
getLineLevel(java.lang.String line)
Returns the quote level of the format flowed message line line. |
static java.lang.String |
getNonNullHeaderValue(SmtpHeadersInterface headers,
java.lang.String headerName,
boolean decode)
Returns the value of the header headerName. |
private static java.lang.String |
getPartBoundary(SmtpHeadersInterface headers)
Returns the string that delimits sub parts of a MIME multipart message. |
private static SmtpMessagePart |
handleBodyPart(java.io.BufferedReader reader,
SmtpHeadersInterface parentHeaders,
boolean readHeader)
Returns a SmtpMessagePart from parsing reader. |
private static java.util.List<SmtpMessagePart> |
handleMultiPart(java.io.BufferedReader reader,
SmtpHeadersInterface parentHeaders)
Returns a SmtpMessagePart's list from parsing reader. |
private static void |
handleRFC822MessagePart(java.io.BufferedReader reader,
SmtpMessagePart part,
java.lang.String boundary)
Reads an embedded RFC 822 message and writes it to the part
body's part. |
private static boolean |
isMessagePart(SmtpHeadersInterface headers)
Returns true if headers headers represent a message
content. |
static boolean |
isMultiPart(SmtpHeadersInterface headers)
Returns true if headers headers represent a multipart
content. |
static boolean |
outputStreamToFile(java.lang.String directory,
java.lang.String fileName,
java.io.InputStream bin)
Writes the stream to the specified directory and filename. |
static SmtpMessagePart |
parseInternalParts(SmtpMessage msg,
java.lang.String body)
Parses msg and returns a SmtpMessagePart representing the
contents of the message. |
static java.util.HashMap<java.lang.String,java.lang.String> |
saveCIDFilesToTemporaryDirectory(SmtpMessagePart part)
Saves the content of the sub parts of the given message part to the system default temporary directory if they have a Content-ID header. |
static void |
write(java.io.OutputStream os,
java.lang.String encodedString,
java.lang.String charsetName,
java.lang.String encoding)
Outputs the decoded content from the encodedString string to the |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final org.slf4j.Logger LOG
public static final int MAX_LINE_LENGTH
public static final java.lang.String tempDirectory
System.getProperty(String)| Constructor Detail |
|---|
public MailUtilities()
| Method Detail |
|---|
public static java.lang.String getNonNullHeaderValue(SmtpHeadersInterface headers,
java.lang.String headerName,
boolean decode)
headerName. If the parameter
decode is set to true the the value is decoded. If value is
null, returns "" unless required header is of the following types :
Date : returns a RFC 822 compliant string of the current date and time
Subject : returns the "{No subject}" string
This is a convenience method for GUI programs to avoid returning a null value for headers that are not commonly expected to be null but can be according to RFCs.
headers - all the headers in which to searchheaderName - the name of the headerdecode - if true the header value is decoded
public static java.lang.String decodeHeaderValue(java.lang.String encodedHeaderValue)
string is
null. If decoding fails, it returns the original string.
All the encodings defined in RFC 2045 are supported here. They include "base64", "quoted-printable", "7bit", "8bit", and "binary". In addition, "uuencode" is also supported.
encodedHeaderValue - the header value to decode
MimeUtility.decodeText(String)
public static java.lang.String decode(java.lang.String encodedString,
java.lang.String charsetName,
java.lang.String encoding)
encodedString encoded as
encoding with the charset named charsetName.
If decoding fails, it returns the original string.
All the encodings defined in RFC 2045 are supported here. They include "base64", "quoted-printable", "7bit", "8bit", and "binary". In addition, "uuencode" is also supported.
encodedString - the string to decodecharsetName - the name of the charsetencoding - the encoding used for the string
MimeUtility.decode(java.io.InputStream, java.lang.String)public static java.util.HashMap<java.lang.String,java.lang.String> saveCIDFilesToTemporaryDirectory(SmtpMessagePart part)
part - the message part containing relative files to save
public static void write(java.io.OutputStream os,
java.lang.String encodedString,
java.lang.String charsetName,
java.lang.String encoding)
throws java.io.IOException,
javax.mail.MessagingException
encodedString string to the os output stream.
- Parameters:
os - the output streamencodedString - the content to writecharsetName - the name of the charsetencoding - the name of the encoding
- Throws:
java.io.IOException
javax.mail.MessagingException
private static int getLineLevel(java.lang.String line)
line.
line - the text line
private static java.lang.String getFlowedMarkerHMTLColor(int level)
level.
level - the quote level
public static java.lang.String formatFlowed(java.lang.String body)
body compliant with RFC
2646 when interpreted in a browser.
body - the body of the message
public static java.lang.String getHeaderParameterValue(SmtpHeadersInterface headers,
java.lang.String name,
java.lang.String parameterName)
parameterName which is a sub value of the header
name from the headers headers.
headers - the headersname - the header nameparameterName - the parameter name
private static java.lang.String getPartBoundary(SmtpHeadersInterface headers)
headers.
headers - the headers of the part
public static boolean isMultiPart(SmtpHeadersInterface headers)
headers represent a multipart
content.
headers - the headers
private static boolean isMessagePart(SmtpHeadersInterface headers)
headers represent a message
content.
headers - the headers
private static SmtpMessagePart handleBodyPart(java.io.BufferedReader reader,
SmtpHeadersInterface parentHeaders,
boolean readHeader)
throws java.io.IOException
reader. If
readHeader is true then data read from reader
should contain the headers of the part (always the case except for a
simple single part message where headers are set within the message
headers).
reader - the mail body reader streamparentHeaders - the headers of the parent partreadHeader - true if method should read headers from the reader
java.io.IOException
private static void handleRFC822MessagePart(java.io.BufferedReader reader,
SmtpMessagePart part,
java.lang.String boundary)
throws java.io.IOException
part
body's part.
reader - the reader streampart - the target partboundary - the boundary of the part
java.io.IOException
private static java.util.List<SmtpMessagePart> handleMultiPart(java.io.BufferedReader reader,
SmtpHeadersInterface parentHeaders)
throws java.io.IOException
reader.
reader - the mail body reader streamparentHeaders - the headers of the parent part
java.io.IOException
public static SmtpMessagePart parseInternalParts(SmtpMessage msg,
java.lang.String body)
msg and returns a SmtpMessagePart representing the
contents of the message.
msg - the message to be parsedbody - the body of the message
public static java.lang.String escapeHTMLString(java.lang.String string)
string - the string to escape
public static boolean outputStreamToFile(java.lang.String directory,
java.lang.String fileName,
java.io.InputStream bin)
directory - the directory to write tofileName - the image file namebin - the inputstream to read from
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||