Package net.rim.blackberry.api.mail

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


      } catch (Exception ex) {
         Dialog.inform("Error in file path: " + ex.toString());
         return new Boolean(false);
      }
      //create a multipart
        Multipart mp = new Multipart();

        //create the file
        SupportedAttachmentPart sap = new SupportedAttachmentPart(mp,"application/x-example",attachment,data);

        TextBodyPart tbp = new TextBodyPart(mp, body);

        //add the file to the multipart
        mp.addBodyPart(tbp);
        mp.addBodyPart(sap);

        //create a message in the sent items folder
        Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);

        Message message = new Message(folders[0]);
View Full Code Here


                             
                              html = processRawBodyPart(content);
                        }
                        //If it's a multipart container, we need to iterate and recurse over its parts to extract nested html content
                        else if(contentType.startsWith(ContentType.TYPE_MULTIPART_ALTERNATIVE_STRING)) {
                              Multipart mp = (Multipart) content.getContent();
                              //Iterate over parts and call this function recursively
                              for(int i = 0; i < mp.getCount(); i++) {
                                    html += getHtmlContent(mp.getBodyPart(i));
                              }
                        }
                  }
                 
                  return html;
View Full Code Here

                        msg.setContent(body.getActualContent());
                    }
                }
            } else {

                Multipart mp = new Multipart();
                TextBodyPart bodypart = new TextBodyPart(mp);
                int bodyPartIndex = 0;

                if (body.getActualContent() != null) {

                    String encoding = body.getContentTransferEncoding();

                    bodypart.setContentType(body.getContentType());

                    String content = null;
                    if (encoding != null && encoding.trim().equalsIgnoreCase("base64")){
                        content = new String(Base64.decode(body.getActualContent().getBytes()));
                    } else {
                        content = body.getActualContent();
                    }

                    bodypart.setContent(content);
                    mp.addBodyPart(bodypart,bodyPartIndex);
                    ++bodyPartIndex;
                }

                for (int i = 0; i < attachment.size(); i++) {

                    SupportedAttachmentPart sp =  new SupportedAttachmentPart(mp);

                    MailAttachment mailAttachment = (MailAttachment)attachment.elementAt(i);
                    sp.setFilename(mailAttachment.getFileName());

                    if (mailAttachment.getContentTransferEncoding().equals("base64")){
                        sp.setContent(new String(Base64.decode(mailAttachment.getactualContent().getBytes())));
                    }
                    else {
                        sp.setContent(mailAttachment.getactualContent());
                    }

                    sp.setContentType(mailAttachment.getContentType());
                    mp.addBodyPart(sp,bodyPartIndex);
                    ++bodyPartIndex;
                }

                msg.setContent(mp);
            }
View Full Code Here

            PIMDemo.errorDialog("Message#addRecipients(int, Address[]) threw "
                    + me.toString());
        }

        // Create a new multipart object to hold the calendar attachment
        final Multipart multipart = new Multipart("mixed");

        // Create a new calendar attachment with meeting request as body
        final ByteArrayOutputStream bouts = new ByteArrayOutputStream();
        try {
            final String[] formats =
                    PIM.getInstance().supportedSerialFormats(PIM.EVENT_LIST);

            for (int i = 0;; ++i) {
                if (formats[i].indexOf("2.0") != -1) {
                    PIM.getInstance().toSerialFormat(_event, bouts, null,
                            formats[i]); // Use the 2.0 format.
                    break;
                }
            }
        } catch (final PIMException e) {
            PIMDemo.errorDialog(e.toString());
        } catch (final UnsupportedEncodingException e) {
            PIMDemo.errorDialog("Serial format conversion failure: "
                    + e.toString()); // We couldn't find the proper format for
                                     // encoding!

        }

        final SupportedAttachmentPart bodypart =
                new SupportedAttachmentPart(multipart,
                        "text/calendar; component=vevent", "event.ics", bouts
                                .toByteArray());

        // Add attachment to multipart
        multipart.addBodyPart(new TextBodyPart(multipart, bouts.toString()));
        multipart.addBodyPart(bodypart);

        try {
            // Set multipart as message content
            msg.setContent(multipart);
View Full Code Here

     *            Recipient email address
     */
    public void upload(final FileHolder fileHolder, final String email)
            throws FolderNotFoundException, AddressException,
            MessagingException, IOException {
        final Multipart mp = new Multipart();

        if (fileHolder == null || email == null || email.length() == 0) {
            throw new IllegalArgumentException("Invalid arguments");
        }

        if (fileHolder.getPath().lastIndexOf('/') == -1) {
            throw new FolderNotFoundException(fileHolder.getPath(),
                    "Directory not found.");
        }

        final byte[] stream =
                readStream(fileHolder.getPath() + "/"
                        + fileHolder.getFileName());
        final String messageData =
                "See attachment: " + fileHolder.getFileName();

        if (stream == null || stream.length == 0) {
            throw new IOException("Failed to read the file stream");
        }

        final SupportedAttachmentPart sap =
                new SupportedAttachmentPart(mp, MIMETypeAssociations
                        .getMIMEType(fileHolder.getFileName()), fileHolder
                        .getFileName(), stream);

        final TextBodyPart tbp = new TextBodyPart(mp, messageData);
        mp.addBodyPart(tbp);
        mp.addBodyPart(sap);
        final Folder folders[] =
                Session.getDefaultInstance().getStore().list(Folder.SENT);
        final Message message = new Message(folders[0]);
        final Address[] toAdds = new Address[1];
        toAdds[0] = new Address(email, email);
View Full Code Here

     * Displays the message body
     */
    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
        final String mpType = parent.getContentType();
        if (mpType
                .equals(BodyPart.ContentType.TYPE_MULTIPART_ALTERNATIVE_STRING)
                || mpType
                        .equals(BodyPart.ContentType.TYPE_MULTIPART_MIXED_STRING)) {
            displayMultipart(parent);
View Full Code Here

                    // 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);
                        }
                    }
View Full Code Here

        // Add the body by adding all the body fields into one multipart
        final Vector bodyFields = (Vector) _fieldTable.get(BODY);
        if (bodyFields != null) {
            final int size = bodyFields.size();
            final Multipart content = new Multipart();
            for (int fieldNo = 0; fieldNo < size; fieldNo++) {
                final TextField body =
                        (TextField) bodyFields.elementAt(fieldNo);
                content.addBodyPart(new TextBodyPart(content, body.getText()));
            }
            try {
                message.setContent(content);
            } catch (final MessagingException e) {
                BlackBerryMailDemo
View Full Code Here

TOP

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

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.