// Assemble Assets
Map assetMap = message.getAssetMap();
Iterator i = assetMap.keySet().iterator();
String mimeReference;
MarinerURL url;
MessageAsset messageAsset;
// Sizes are in bytes
Integer maxImageSize = message.getMaxFileSize();
Integer maxMessageSize = message.getMaxMMSize();
int actualMessageSize = 0;
ArrayList imageAssets = new ArrayList();
// Process each of the assets
while( i.hasNext() ) {
mimeReference = ( String ) i.next();
// We can only retrieve assets that reside on the
// server.
messageAsset = ( MessageAsset ) assetMap.get( mimeReference );
// Set appropriate headers
asset = new MimeBodyPart();
asset.setHeader( "Content-Disposition",
"inline; filename=\"" + mimeReference + "\"" );
asset.setHeader( "Content-ID", "<" + mimeReference + ">" );
if (messageAsset.isTextMessage()) {
// Handle simple textual content
String contentType = "text/plain";
if (message.getCharacterEncoding() != null) {
contentType += "; charset=" +
message.getCharacterEncoding();
}
asset.setContent( messageAsset.getText(), contentType);
mimeMultipart.addBodyPart( asset );
actualMessageSize += determineAssetSize( asset );
} else {
// Handle other content, but only if they reside on the
// server
if( messageAsset.getLocationType() ==
MessageAsset.ON_SERVER ) {
url = fixupURL( message.getBaseURL(),
new MarinerURL( messageAsset.getUrl() ) );
URL assetURL = new URL( url.getExternalForm() );
// Now sort out the content type and whether the asset
// exists or not...
try {
URLConnection connection =
assetURL.openConnection();
// Check to see if a connection object has been
// successfully obtained
if( connection != null ) {
// Set the connection up
connection.setDoInput( true );
connection.setDoOutput( false );
connection.setAllowUserInteraction( false );
// Actually connect
connection.connect();
// Force the connection to be used
connection.getInputStream();
// Grab the content type from the stream to
// use in the mime body part of the asset
String contentType =
connection.getContentType();
// By getting here, the asset exists and the
// connection succesfully opened so add the
// asset
asset.setDataHandler( new DataHandler( assetURL ) );
asset.setHeader( "Content-location",
url.getExternalForm() );
asset.setHeader( "Content-Type", contentType );
mimeMultipart.addBodyPart( asset );
// Store the images for later size processing
imageAssets.add( asset );
}
} catch( MalformedURLException mue ) {
// Quietly ignore this asset
if( logger.isDebugEnabled() ) {
logger.debug( "Ignoring asset with malformed URL: " +
url.toString() );
}
} catch( IOException ioe ) {
// Quietly ignore this asset
if( logger.isDebugEnabled() ) {
logger.debug( "Ignoring asset with URL that " +
"doesn't exist: " + assetURL +
" (" + url.toString() + ")" );
}
}
} else {
// For device based assets there's not much that can
// be set apart from where it is!