Methods Summary |
---|
public java.lang.String | getContentType()Returns the content-type of this DataSource.
This implementation just invokes the getContentType
method on the MimePart.
try {
return part.getContentType();
} catch (MessagingException mex) {
// would like to be able to reflect the exception to the
// application, but since we can't do that we return a
// generic "unknown" value here and hope for another
// exception later.
return "application/octet-stream";
}
|
public java.io.InputStream | getInputStream()Returns an input stream from this MimePart.
This method applies the appropriate transfer-decoding, based
on the Content-Transfer-Encoding attribute of this MimePart.
Thus the returned input stream is a decoded stream of bytes.
This implementation obtains the raw content from the Part
using the getContentStream() method and decodes
it using the MimeUtility.decode() method.
InputStream is;
try {
if (part instanceof MimeBodyPart)
is = ((MimeBodyPart)part).getContentStream();
else if (part instanceof MimeMessage)
is = ((MimeMessage)part).getContentStream();
else
throw new MessagingException("Unknown part");
String encoding = restrictEncoding(part.getEncoding(), part);
if (encoding != null)
return MimeUtility.decode(is, encoding);
else
return is;
} catch (MessagingException mex) {
throw new IOException(mex.getMessage());
}
|
public synchronized javax.mail.MessageContext | getMessageContext()Return the MessageContext for the current part.
if (context == null)
context = new MessageContext(part);
return context;
|
public java.lang.String | getName()DataSource method to return a name.
This implementation just returns an empty string.
try {
if (part instanceof MimeBodyPart)
return ((MimeBodyPart)part).getFileName();
} catch (MessagingException mex) {
// ignore it
}
return "";
|
public java.io.OutputStream | getOutputStream()DataSource method to return an output stream.
This implementation throws the UnknownServiceException.
throw new UnknownServiceException();
|
private static java.lang.String | restrictEncoding(java.lang.String encoding, javax.mail.internet.MimePart part)Restrict the encoding to values allowed for the
Content-Type of the specified MimePart. Returns
either the original encoding or null.
if (!ignoreMultipartEncoding || encoding == null)
return encoding;
if (encoding.equalsIgnoreCase("7bit") ||
encoding.equalsIgnoreCase("8bit") ||
encoding.equalsIgnoreCase("binary"))
return encoding; // these encodings are always valid
String type = part.getContentType();
if (type == null)
return encoding;
try {
/*
* multipart and message types aren't allowed to have
* encodings except for the three mentioned above.
* If it's one of these types, ignore the encoding.
*/
ContentType cType = new ContentType(type);
if (cType.match("multipart/*") || cType.match("message/*"))
return null;
} catch (ParseException pex) {
// ignore it
}
return encoding;
|