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
Developer
Posts: 250
Registered: ‎07-18-2008
My Device: Not Specified
Accepted Solution

Change message body content and keep attachments using a FolderListener

Hi,

 

I need to change the content of particular emails when they are received on the device. I'm using a FolderListener to detect when the message arrives and I'm able to change the message content. The problem is, attachments are lost in the process but I need to keep them. I just want to change the message body.

 

Here's my code :

 

 

public void messagesAdded(FolderEvent e) {
  
  Message m = e.getMessage();
  Object content = m.getContent();
  
  if (content instanceof Multipart) {
    
    Multipart mp = (Multipart) content;
    
    for (int idx = 0; idx < mp.getCount(); idx++) {
      
      Object part = mp.getBodyPart(idx);				

      if (part instanceof TextBodyPart) {
        
        mp.removeBodyPart(idx);
        break;
      }
    }
    TextBodyPart tbp = new TextBodyPart(mp, _res.getString(MSG_MAIL_CONTENT));
    mp.addBodyPart(tbp);
    m.setContent(mp);
  }
}

Any idea?

 

Regards,

 

Pierre

 

Highlighted
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Change message body content and keep attachments using a FolderListener

Have you tried cloning the message? Then you can just copy the attachment from te original if it is lost.

Developer
Posts: 250
Registered: ‎07-18-2008
My Device: Not Specified

Re: Change message body content and keep attachments using a FolderListener

Hi,

 

This is what I've done. I loop through the parts and only keep the attachments (SupportedAttachmentPart and UnsupportedAttachmentPart). Thanks for your help.

 

Pierre

New Contributor
Posts: 2
Registered: ‎10-07-2011
My Device: Blackberry 9700
My Carrier: at&t

Re: Change message body content and keep attachments using a FolderListener

Hi,i have same issue, can you please describe how to save both SupportedAttachmentPart and UnsupportedAttachmentPart? i need to change message content.

Thanks