|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.cert.cc.jira.email.MessageUtils
public final class MessageUtils
MessageUtils provides of set of static methods that perform various operations on a Message
.
© 2009 Carnegie Mellon University
Field Summary | |
---|---|
static String |
CONTENT_TYPE_HEADER
Content-Type header |
static String |
DEFAULT_MIME_TYPE
Default MIME type |
static String |
MULTIPART_MIME_TYPE
Multi-Part MIME type |
static String |
PLAIN_TEXT_MIME_TYPE
Plain text MIME type |
static List<Message.RecipientType> |
RECIPIENT_TYPES
Holds all of the Message.RecipientType s |
Method Summary | |
---|---|
static Message |
copyHeaders(Message message)
Creates a new Message with headers from message . |
static Message |
copyHeaders(Message source,
Message destination)
Copies headers from source to destination . |
static Message |
create()
Constructs a new empty Message |
static Message |
create(InputStream is)
Constructs a new Message from an InputStream of
RFC 822 data. |
static Message |
createFromAttachment(Part p)
Creates and returns a new Message from a Part . |
static void |
debug(Logger log,
Message message)
Logs a mail Message at debug Level . |
static List<InternetAddress> |
getAllRecipients(Message message,
boolean includeBCC)
Returns all recipients as InternetAddress objects. |
static int |
getAttachmentCount(Message message,
boolean emailsOnly)
Returns the number of non-PKCS7 signature attachments for a Message |
static String |
getAttachmentFileName(Part p)
Returns the filename for a Part or null if the Part does not have an
attachment. |
static int |
getFileAttachmentCount(Message message)
Returns the number of actual file attachments. |
static Set<String> |
getFilenames(Message m)
Returns all of the non-S/MIME signature filenames associated with the Message m . |
static Set<String> |
getFilenames(Multipart m)
Returns all of the non-S/MIME signature filenames associated with the Multipart m . |
static Part |
getFirstEmailAttachment(Message message)
Returns the first RFC-822 compatible attachment found. |
static InternetAddress |
getFrom(Message message)
Returns the From address. |
static String |
getHeaderValue(Message message,
String headerName)
Returns an header value if and only if there is only one. |
static byte[] |
getPartContent(Part p)
Returns the raw content from a Part |
static List<InternetAddress> |
getRecipients(Message message,
Message.RecipientType type)
Returns all recipients of a specific type as a List of InternetAddress objects. |
static void |
info(Logger log,
Message message)
Logs a mail Message at info Level . |
static boolean |
isPKCS7Signature(Part p)
Returns if the Part is an S/MIME signature attachment |
static void |
logAllHeaders(Logger log,
Level level,
Part message)
Logs all of the headers for a Part at the specified logging Level using log |
static void |
logMessage(Logger log,
Level level,
Message message)
Logs a mail Message at the specified logging Level using log |
static void |
logPart(Logger log,
Level level,
Part part)
Logs a mail Part at the specified logging Level using log |
static void |
setAllContentTypes(Multipart mp)
Sets the Content-Type for all BodyPart s contained |
static void |
setContentType(Part p)
Sets the Content-Type on a Part based on the Part 's filename |
static void |
setContentType(Part p,
String contentType)
Sets the Content-Type on a Part . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PLAIN_TEXT_MIME_TYPE
public static final String DEFAULT_MIME_TYPE
public static final String MULTIPART_MIME_TYPE
public static final String CONTENT_TYPE_HEADER
public static final List<Message.RecipientType> RECIPIENT_TYPES
Message.RecipientType
s
Method Detail |
---|
public static Message create() throws MessagingException
Message
Message
MessagingException
- If unable to create a Message
from the InputStream
public static Message create(InputStream is) throws MessagingException
Message
from an InputStream
of
RFC 822 data.
is
- InputStream
of data
Message
MessagingException
- If unable to create a Message
from the InputStream
public static Message copyHeaders(Message message) throws MessagingException
Message
with headers from message
. The following
headers are copied:
message
- Input Message
data
Message
data
MessagingException
- If unable to interroage the input Message
datapublic static Message copyHeaders(Message source, Message destination) throws MessagingException
source
to destination
. If destination
is null, a new Message
is created. The following
headers are copied:
source
- Source Message
destination
- Destination Message
Message
with Source's headers
MessagingException
- If unable to interroage the input Message
datapublic static InternetAddress getFrom(Message message) throws MessagingException
null
is
returned. If there is only one, it is returned as an InternetAddress
.
message
- Email Message
InternetAddress
.
MessagingException
- If unable to interrogate the Message
public static List<InternetAddress> getAllRecipients(Message message, boolean includeBCC) throws MessagingException
InternetAddress
objects. The resulting List
is returned in a specific
order: TO recipients, CC recipients, and then BCC recipients (if includeBCC
is true
).
The order within each group is JavaMail dependent.
message
- Email Message
includeBCC
- Include BCC recipients in the returned List
InternetAddress
objects
MessagingException
- If unable to interrogate the Message
public static List<InternetAddress> getRecipients(Message message, Message.RecipientType type) throws MessagingException
type
as a List
of InternetAddress
objects.
message
- Email Message
type
- Type of Recipients to be returned
InternetAddress
objects
MessagingException
- If unable to interrogate the Message
public static String getHeaderValue(Message message, String headerName) throws MessagingException
null
is returned.
message
- Email Message
headerName
- Header name
String
or null
MessagingException
- If unable to interrogate the Message
public static int getAttachmentCount(Message message, boolean emailsOnly) throws MessagingException
Message
message
- Email Message
emailsOnly
- Count RFC-822 attachments only?
MessagingException
- If unable to interrogate the Message
public static int getFileAttachmentCount(Message message) throws MessagingException
message
- Email Message
MessagingException
- If unable to interrogate the Message
public static boolean isPKCS7Signature(Part p) throws MessagingException
Part
is an S/MIME signature attachment
p
- Part
to be inspected
Part
is an S/MIME signature attachment
MessagingException
- If unable to inspect the Part
public static String getAttachmentFileName(Part p) throws MessagingException
Part
or null if the Part
does not have an
attachment.
p
- Part
data
MessagingException
- If unable to interrogate the Part
public static Message createFromAttachment(Part p) throws IOException, MessagingException
Message
from a Part
. If unable to create the Message
or the
part isn't RFC-822 compatible, null will be returned.
p
- Part
data
Message
IOException
- If unable to interrogate the Part
MessagingException
- If unable to interrogate the Part
public static Part getFirstEmailAttachment(Message message) throws IOException, MessagingException
message
- Email Message
to be searched
IOException
- If unable to interrogate the Message
MessagingException
- If unable to interrogate the Message
public static byte[] getPartContent(Part p) throws IOException, MessagingException
Part
p
- Part
data
IOException
- If unable to retrieve the raw data
MessagingException
- If unable to retrieve the raw datapublic static void setAllContentTypes(Multipart mp) throws MessagingException
BodyPart
s contained
mp
- Multipart
data
MessagingException
- If unable to set the Content-Typepublic static void setContentType(Part p) throws MessagingException
Part
based on the Part
's filename
p
- Part
data
MessagingException
- If unable to set the Content-Typepublic static void setContentType(Part p, String contentType) throws MessagingException
Part
. If contentType
is null and the Part
has
a filename, the Content-Type is calculated from the filename.
p
- Part
datacontentType
- Content-Type or null
MessagingException
- If unable to set the Content-Typepublic static Set<String> getFilenames(Message m) throws MessagingException, IOException
Message
m
.
If the message is not multi-part or there are no non-S/MIME signature attachments,
an empty Set
will be returned.
m
- Message
to be interrogated
Set
of filenames
MessagingException
- If unable to interrogate the Message
IOException
public static Set<String> getFilenames(Multipart m) throws MessagingException
Multipart
m
.
If there are no non-S/MIME signature attachments, an empty Set
will be returned.
m
- Multipart
to be interrogated
Set
of filenames
MessagingException
- If unable to interrogate the Multipart
public static void debug(Logger log, Message message)
Message
at debug Level
.
log
- Logger
instancesmessage
- Email Message
public static void info(Logger log, Message message)
Message
at info Level
.
log
- Logger
instancesmessage
- Email Message
public static void logMessage(Logger log, Level level, Message message)
Message
at the specified logging Level
using log
log
- Logger
instanceslevel
- Logging Level
message
- Email Message
public static void logAllHeaders(Logger log, Level level, Part message)
Part
at the specified logging Level
using log
log
- Logger
instanceslevel
- Logging Level
message
- Part
datapublic static void logPart(Logger log, Level level, Part part)
Part
at the specified logging Level
using log
log
- Logger
instanceslevel
- Logging Level
part
- Email Part
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |