Package net.rim.blackberry.api.mail

Examples of net.rim.blackberry.api.mail.BodyPart


            final BodyPart[] bodyParts =
                    _downloadManager.getAttachmentBodyParts(m);

            if (bodyParts != null && bodyParts.length > 0) {
                for (int i = 0; i < bodyParts.length; i++) {
                    final BodyPart bp = bodyParts[i];

                    if (!downloadAll) {
                        // Download png and msword attachments only
                        final String type =
                                _downloadManager.getFileContentType(bp);
View Full Code Here


    /**
     * @see DownloadProgressListener#downloadCancelled(Object)
     */
    public void downloadCancelled(final Object element) {
        final BodyPart bodyPart = (BodyPart) element;
        _screen.displayStatus("Failed to download "
                + _downloadManager.getFileName(bodyPart));
    }
View Full Code Here

    /**
     * @see DownloadProgressListener#downloadCompleted(Object)
     */
    public void downloadCompleted(final Object element) {
        final BodyPart bodyPart = (BodyPart) element;
        _screen.displayStatus(_downloadManager.getFileName(bodyPart)
                + " downloaded.");
    }
View Full Code Here

    protected void displayMessageBody() {
        // Retrieve the parent of the message body
        final Object obj = _message.getContent();
        Multipart parent = null;
        if (obj instanceof MimeBodyPart || obj instanceof TextBodyPart) {
            final BodyPart bp = (BodyPart) obj;
            parent = bp.getParent();
        } else {
            parent = (Multipart) obj;
        }

        // Display the message body
View Full Code Here

        // Process each part of the multi-part, taking the appropriate action
        // depending on the part's type. This loop should: display text and
        // html body parts, recursively display multi-parts and store
        // attachments and contacts to display later.
        for (int index = 0; index < multipart.getCount(); index++) {
            final BodyPart bodyPart = multipart.getBodyPart(index);

            // If this body part is text then display all of it
            if (bodyPart instanceof TextBodyPart) {
                final TextBodyPart textBodyPart = (TextBodyPart) bodyPart;

                // If there are missing parts of the text, try to retrieve the
                // rest of it.
                if (textBodyPart.hasMore()) {
                    try {
                        Transport.more(textBodyPart, true);
                    } catch (final Exception e) {
                        BlackBerryMailDemo
                                .errorDialog("Transport.more(BodyPart, boolean) threw "
                                        + e.toString());
                    }
                }
                final String plainText = (String) textBodyPart.getContent();

                // Display the plain text, using an EditField if the message is
                // editable or a RichTextField if it is not editable. Note: this
                // does not add any empty fields.
                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 =
View Full Code Here

TOP

Related Classes of net.rim.blackberry.api.mail.BodyPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.