Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 5
Registered: ‎05-10-2009
My Device: Not Specified

How to embed multipart/alternative in multipart/mixed

[ Edited ]

I'm having a problem understanding how I might implement the RFC 2046 concept of embedding multiparts within multiparts.

 

For example, I would like to build a multipart message that contains both alternative message formatting and file attachments.  If I read the RFC 2046 correctly I would do this by declaring a multipart/mixed, containing a multipart/alternative (with Content-Types of text/plain and text/html, for example) and a Content-Type of say application/x-zip-compressed for the file attachment.

 

I'm able to do one or the other - multipart/mixed or multipart/alternative, and they work great.  But no luck determining how to do both. 

 

Thanks, in advance.

 

Blackberry 8100 and 8120

JDE version 4.7.0.41

 

Here is one try that doesn't work:

 

                String fileData = "<html>just a simple test</html/";
                String messageData = "Mail Attachment Demo";
                Multipart mpMixed = new Multipart("mixed");
                mpMixed.setParent(msg);
                Multipart mpAlternative = new Multipart("alternative");
                mpAlternative.setParent(mpMixed);
                TextBodyPart tbp1 = new TextBodyPart(mpAlternative, messageData);
                TextBodyPart tbp2 = new TextBodyPart(mpAlternative, messageData);
                SupportedAttachmentPart sap = new SupportedAttachmentPart(mpMixed, "text/html", "file.html", fileData.getBytes());
                mpAlternative.addBodyPart(tbp1);
                mpAlternative.addBodyPart(tbp2);
                mpMixed.addBodyPart(mpAlternative);
                mpMixed.addBodyPart(sap);
                msg.setContent(mpMixed);
                msg.writeTo(System.out );

Message Edited by bborup on 08-02-2009 10:57 AM
New Developer
Posts: 5
Registered: ‎05-10-2009
My Device: Not Specified

Re: How to embed multipart/alternative in multipart/mixed

Let me try another example.  In other environments I can do this:

 

   // parent multipart (mixed)
   MimeMultipart mixedPart = new MimeMultipart("mixed");
 
   // child alternative html/text multipart
   MimeMultipart alternativeMultiPart = new MimeMultipart( "alternative");
   BodyPart alternativeBodyPart = new MimeBodyPart();
 
   // set the text
   alternativeBodyPart.setText("text only version");
   alternativeMultiPart.addBodyPart(alternativeBodyPart);
 
   // set the html
   alternativeBodyPart = new MimeBodyPart();
   alternativeBodyPart.setContent( "<h1>HTML</h1><strong>only</strong> version", "text/html");
   alternativeMultiPart.addBodyPart(alternativeBodyPart);
 
   // set the content in the mixed part
   alternativeBodyPart = new MimeBodyPart();
   alternativeBodyPart.setContent(alternativeMultiPart);
   mixedPart.addBodyPart(alternativeBodyPart);
 
   // attach the file
   BodyPart mixedBodyPart = new MimeBodyPart();
   String filename = "C:\test.gif";
   mixedBodyPart = new MimeBodyPart();
   DataSource source = new FileDataSource(filename);
   mixedBodyPart.setDataHandler(new DataHandler(source));
   mixedBodyPart.setFileName(filename);
   mixedPart.addBodyPart(mixedBodyPart);
 
   // set the content in the message
   msg.setContent(mixedPart);
 
Please note that the "alternativeBodyPart", or "alternativeMultiPart", is added to the "mixedPart".

 

How can I accomplish this in the Blackberry world?

 

Thanks.

 

Highlighted
Regular Contributor
Posts: 73
Registered: ‎12-30-2011
My Device: All devices
My Carrier: RIM

Re: How to embed multipart/alternative in multipart/mixed

Please i want to do same, if u have proper solution code please post it

Thanks

Mohd Farhan