MultipartReportpublic class MultipartReport extends MimeMultipart A multipart/report message content, as defined in
RFC 3462.
A multipart/report content is a container for mail reports
of any kind, and is most often used to return a delivery
status report. This class only supports that most common
usage.
A MultipartReport object is a special type of MimeMultipart
object with a restricted set of body parts. A MultipartReport
object contains:
- [Required] A human readable text message describing the
reason the report was generated.
- [Required] A {@link DeliveryStatus} object containing the
details for why the report was generated.
- [Optional] A returned copy of the entire message, or just
its headers, which caused the generation of this report.
Many of the normal MimeMultipart operations are restricted to
ensure that the MultipartReport object always follows this
structure. |
Fields Summary |
---|
protected boolean | constructed |
Constructors Summary |
---|
public MultipartReport()Construct a multipart/report object with no content.
super("report");
// always at least two body parts
MimeBodyPart mbp = new MimeBodyPart();
setBodyPart(mbp, 0);
mbp = new MimeBodyPart();
setBodyPart(mbp, 1);
constructed = true;
| public MultipartReport(String text, DeliveryStatus status)Construct a multipart/report object with the specified plain
text and delivery status to be returned to the user.
super("report");
ContentType ct = new ContentType(contentType);
ct.setParameter("report-type", "delivery-status");
contentType = ct.toString();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText(text);
setBodyPart(mbp, 0);
mbp = new MimeBodyPart();
mbp.setContent(status, "message/delivery-status");
setBodyPart(mbp, 1);
constructed = true;
| public MultipartReport(String text, DeliveryStatus status, MimeMessage msg)Construct a multipart/report object with the specified plain
text, delivery status, and original message to be returned to the user.
this(text, status);
if (msg != null) {
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(msg, "message/rfc822");
setBodyPart(mbp, 2);
}
| public MultipartReport(String text, DeliveryStatus status, InternetHeaders hdr)Construct a multipart/report object with the specified plain
text, delivery status, and headers from the original message
to be returned to the user.
this(text, status);
if (hdr != null) {
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(new MessageHeaders(hdr), "text/rfc822-headers");
setBodyPart(mbp, 2);
}
| public MultipartReport(DataSource ds)Constructs a MultipartReport object and its bodyparts from the
given DataSource.
super(ds);
parse();
constructed = true;
/*
* Can't fail to construct object because some programs just
* want to treat this as a Multipart and examine the parts.
*
if (getCount() < 2 || getCount() > 3) // XXX allow extra parts
throw new MessagingException(
"Wrong number of parts in multipart/report: " + getCount());
*/
|
Methods Summary |
---|
public synchronized void | addBodyPart(javax.mail.BodyPart part)Adds a Part to the multipart.
Not allowed on a multipart/report object.
// Once constructor is done, don't allow this anymore.
if (!constructed)
super.addBodyPart(part);
else
throw new MessagingException(
"Can't add body parts to multipart/report 1");
| public synchronized void | addBodyPart(javax.mail.BodyPart part, int index)Adds a BodyPart at position index .
Not allowed on a multipart/report object.
throw new MessagingException(
"Can't add body parts to multipart/report 2");
| public synchronized DeliveryStatus | getDeliveryStatus()Get the delivery status associated with this multipart/report.
if (getCount() < 2)
return null;
BodyPart bp = getBodyPart(1);
if (!bp.isMimeType("message/delivery-status"))
return null;
try {
return (DeliveryStatus)bp.getContent();
} catch (IOException ex) {
throw new MessagingException("IOException getting DeliveryStatus",
ex);
}
| public synchronized javax.mail.internet.MimeMessage | getReturnedMessage()Get the original message that is being returned along with this
multipart/report. If no original message is included, null is
returned. In some cases only the headers of the original
message will be returned as an object of type MessageHeaders.
if (getCount() < 3)
return null;
BodyPart bp = getBodyPart(2);
if (!bp.isMimeType("message/rfc822") &&
!bp.isMimeType("text/rfc822-headers"))
return null;
try {
return (MimeMessage)bp.getContent();
} catch (IOException ex) {
throw new MessagingException("IOException getting ReturnedMessage",
ex);
}
| public synchronized java.lang.String | getText()Get the plain text to be presented to the user, if there is any.
Rarely, the message may contain only HTML text, or no text at
all. If the text body part of this multipart/report object is
of type text/plain, or if it is of type multipart/alternative
and contains a text/plain part, the text from that part is
returned. Otherwise, null is return and the {@link #getTextBodyPart
getTextBodyPart} method may be used to extract the data.
try {
BodyPart bp = getBodyPart(0);
if (bp.isMimeType("text/plain"))
return (String)bp.getContent();
if (bp.isMimeType("multipart/alternative")) {
Multipart mp = (Multipart)bp.getContent();
for (int i = 0; i < mp.getCount(); i++) {
bp = mp.getBodyPart(i);
if (bp.isMimeType("text/plain"))
return (String)bp.getContent();
}
}
} catch (IOException ex) {
throw new MessagingException("Exception getting text content", ex);
}
return null;
| public synchronized javax.mail.internet.MimeBodyPart | getTextBodyPart()Return the body part containing the message to be presented to
the user, usually just a text/plain part.
return (MimeBodyPart)getBodyPart(0);
| public boolean | removeBodyPart(javax.mail.BodyPart part)Remove the specified part from the multipart message.
Not allowed on a multipart/report object.
throw new MessagingException(
"Can't remove body parts from multipart/report");
| public void | removeBodyPart(int index)Remove the part at specified location (starting from 0).
Not allowed on a multipart/report object.
throw new MessagingException(
"Can't remove body parts from multipart/report");
| private synchronized void | setBodyPart(javax.mail.BodyPart part, int index)
if (parts == null) // XXX - can never happen?
parts = new Vector();
if (index < parts.size())
super.removeBodyPart(index);
super.addBodyPart(part, index);
| public synchronized void | setDeliveryStatus(DeliveryStatus status)Set the delivery status associated with this multipart/report.
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(status, "message/delivery-status");
setBodyPart(mbp, 2);
ContentType ct = new ContentType(contentType);
ct.setParameter("report-type", "delivery-status");
contentType = ct.toString();
| public synchronized void | setReturnedMessage(javax.mail.internet.MimeMessage msg)Set the original message to be returned as part of the
multipart/report. If msg is null, any previously set
returned message or headers is removed.
if (msg == null) {
BodyPart part = (BodyPart)parts.elementAt(2);
super.removeBodyPart(2);
return;
}
MimeBodyPart mbp = new MimeBodyPart();
if (msg instanceof MessageHeaders)
mbp.setContent(msg, "text/rfc822-headers");
else
mbp.setContent(msg, "message/rfc822");
setBodyPart(mbp, 2);
| public synchronized void | setSubType(java.lang.String subtype)Set the subtype. Throws MessagingException.
throw new MessagingException("Can't change subtype of MultipartReport");
| public synchronized void | setText(java.lang.String text)Set the message to be presented to the user as just a text/plain
part containing the specified text.
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText(text);
setBodyPart(mbp, 0);
| public synchronized void | setTextBodyPart(javax.mail.internet.MimeBodyPart mbp)Set the body part containing the text to be presented to the
user. Usually this a text/plain part, but it might also be
a text/html part or a multipart/alternative part containing
text/plain and text/html parts. Any type is allowed here
but these types are most common.
setBodyPart(mbp, 0);
|
|