if (plainText.length() != 0) {
if (_editable) {
addTextFieldToTableAndScreen(new EditField("",
plainText), BODY);
} else {
addTextFieldToTableAndScreen(new RichTextField(
plainText), BODY);
}
}
} else if (bodyPart instanceof MimeBodyPart) {
final MimeBodyPart mimeBodyPart = (MimeBodyPart) bodyPart;
// If the content is text then display it
final String contentType = mimeBodyPart.getContentType();
if (contentType
.startsWith(BodyPart.ContentType.TYPE_TEXT_HTML_STRING)) {
final Object obj = mimeBodyPart.getContent();
if (obj != null) {
final String htmlText = new String((byte[]) obj);
addTextFieldToTableAndScreen(
new RichTextField(htmlText), BODY);
}
} else if (contentType
.equals(BodyPart.ContentType.TYPE_MULTIPART_ALTERNATIVE_STRING)) {
// If the body part is a multi-part and it has the the
// content type of TYPE_MULTIPART_ALTERNATIVE_STRING, then
// recursively display the multi-part.
final Object obj = mimeBodyPart.getContent();
if (obj instanceof Multipart) {
final Multipart childMultipart = (Multipart) obj;
final String childMultipartType =
childMultipart.getContentType();
if (childMultipartType
.equals(BodyPart.ContentType.TYPE_MULTIPART_ALTERNATIVE_STRING)) {
displayMultipart(childMultipart);
}
}
}
} else if (bodyPart instanceof SupportedAttachmentPart
|| bodyPart instanceof UnsupportedAttachmentPart) {
// Extract the content type and name from the attachments
final String contentType = bodyPart.getContentType();
String name;
if (bodyPart instanceof UnsupportedAttachmentPart) {
final UnsupportedAttachmentPart uap =
(UnsupportedAttachmentPart) bodyPart;
name = uap.getName();
} else // The bodyPart is a SupportedAttachmentPart
{
final SupportedAttachmentPart sap =
(SupportedAttachmentPart) bodyPart;
name = sap.getName();
}
// Format the content type and name to display and store
// the field.
final StringBuffer sb =
new StringBuffer(contentType.length() + name.length()
+ 2);
sb.append(contentType);
sb.append('[');
sb.append(name);
sb.append(']');
delayedFields.addElement(new RichTextField(sb.toString()));
} else if (bodyPart instanceof PDAPContactAttachmentPart) {
final Contact contact = (Contact) bodyPart.getContent();
// Build the contact name
final StringBuffer sb = new StringBuffer("Contact: ");
if (contact.countValues(Contact.NAME) > 0) {
final String[] name =
contact.getStringArray(Contact.NAME, 0);
if (name[Contact.NAME_PREFIX] != null) {
sb.append(name[Contact.NAME_PREFIX]);
sb.append(' ');
}
if (name[Contact.NAME_GIVEN] != null) {
sb.append(name[Contact.NAME_GIVEN]);
sb.append(' ');
}
if (name[Contact.NAME_FAMILY] != null) {
sb.append(name[Contact.NAME_FAMILY]);
}
// Trim the last space of the name if it exists
final int lastChar = sb.length() - 1;
if (sb.charAt(lastChar) == ' ') {
sb.deleteCharAt(lastChar);
}
} else {
sb.append(UNKNOWN_NAME);
}
// Create the contact attachment field and store it
final RichTextField contactAttachment =
new RichTextField(sb.toString());
contactAttachment.setCookie(contact);
delayedFields.addElement(contactAttachment);
}
}
// Now that the body parts have been displayed, display the queued