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
skysoft_dev
Posts: 7
Registered: ‎01-17-2009

CSV file arrives Empty when sent from device -Intermittant-

Hello, and thanks in advance for helping us out!!

 

We've been trying to debug an interesting problem.  Depending on the device and network, when we programatically try to create and send a .CSV attachment from the device, the Attachment arrives as an Empty CSV file, with no data.  This happens on some networks/devices and not others.  On some networks the functionality works as expected.

 

The problem is that our code works 70% of the time.  For example, on my own Curve 8900 on Rogers, it works great, but on my Storm 9500 on Telus, we get the message from the device but the .CSV file is Empty.  Both are running in BIS.

 

We've added debugging that shows us the CSV contents even after sending the message, and STILL, the data appears.  So, we're wondering if something funny in is happening between BIS and the target email address.

 

We've tried several differnet contet types and always get the same results.

 

We're using JDE 4.2.1.

 

Here is our code:

 

               att = new SupportedAttachmentPart(content, asBinary ? "application/msword"
                    : "text/csv", attachName, attachText.getBytes());                       
                                                           
            content.addBodyPart(att);           
           
            msg.setContent(content);                              
                       
            Transport.send(msg);

           for (int i = 0; i < content.getCount(); i++) {
                net.rim.blackberry.api.mail.Multipart mp = (net.rim.blackberry.api.mail.Multipart)msg.getContent();
                if (mp.getBodyPart(i) instanceof SupportedAttachmentPart){
                    SupportedAttachmentPart bp = (SupportedAttachmentPart)mp.getBodyPart(i);
                    Utils.getLogger().println("CONTENT FROM SENT MESSAGE:\n"+new String((byte[])bp.getContent()));
                }
            }   


Another interesting note that the date on the sent message shows as December 21, 1969, 4:00 PM when you view it on the device.  Don't know if this is related or not.

 

 Any help/suggestions that you can give would be tremendously appreciated.

 

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,065
Registered: ‎07-09-2008
My Carrier: Bell

Re: CSV file arrives Empty when sent from device -Intermittant-

What BlackBerry handheld software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.

 

Are you seeing the problems on all BlackBerry handhelds for a particular carrier (i.e. all Telus users), all users on a specific model and handheld software version or is it a mixture of both?  Does it always fail for specific users?  Are the users able to send attachments from the Messages application?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
skysoft_dev
Posts: 7
Registered: ‎01-17-2009

Re: CSV file arrives Empty when sent from device -Intermittant-

Hi Mark,

 

Thanks for your response.  We first noticed this issue on Verizon on all devices.  We can reproduce on Telus.

 

It would appear from other companies experiancing the same problem that this is a known BIS 2.6 issue? 

  http://www.shrunkenhead.biz/blog/2009/04/08/workaround-in-biztrackit-to-rim-bis-26-empty-file-attach...

 

 

We've tried many things like changing attachment type, encoding types etc, but to no avail.  Quite simply, BIS seems to be dropping attachments.

 

Please confirm if you know this to be a known issue and more importantly if you know of any work arounds.

 

 Thanks very much for your help!

Please use plain text.
Developer
martijnbrinkers
Posts: 155
Registered: ‎02-18-2009

Re: CSV file arrives Empty when sent from device -Intermittant-

to I seem suffer the same problem. The body (base64) of a binary attachment (with application/content-type) is removed when sent from an actual device. It works with the simulator though. Is there a workaround? why has this not been fixed?? 

 

Kind regards,

 

Martijn Brinkers

Please use plain text.
Developer
martijnbrinkers
Posts: 155
Registered: ‎02-18-2009

Re: CSV file arrives Empty when sent from device -Intermittant-

never mind...

 

The problem was caused by something else. I am able to send a binary attachment.

Please use plain text.
Developer
jhw1701
Posts: 176
Registered: ‎11-06-2008

Re: CSV file arrives Empty when sent from device -Intermittant-

Hello martijnbrinkers,

 

I'm getting a similar problem where programmatically created emails with attachements of a custom extension are removed from emails sent from the device.

 

My registration and content handler for the XYZ extension is correct and working so I can open XYZ file attachments that are received on the device. But if my app on the device generates an attachment of file type xyz the file is removed from the attachment.

 

I've read all the samples and forum posts on attachements and I'm on the verge of giving up. What did you do to remedy your issue of disappearing attachments?

Please use plain text.
Developer
martijnbrinkers
Posts: 155
Registered: ‎02-18-2009

Re: CSV file arrives Empty when sent from device -Intermittant-

can you post a code snippet?

 

This works for me:

 

Multipart mp = new Multipart(); String messageData = "Mail Attachment Demo"; byte[] encrypted = new byte[]{1, 2, 3}; //create the file SupportedAttachmentPart sap = new SupportedAttachmentPart(mp); sap.setContentType("application/octet-stream"); sap.setFilename("x-rimdevicesmime.p7m"); sap.setContent(encrypted); TextBodyPart tbp = new TextBodyPart(mp,messageData); //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]); message.setContent(mp); //add recipients to the message and send Address toAdd = new Address("example@djigzo.com","martijn"); Address toAdds[] = new Address[1]; toAdds[0] = toAdd; message.addRecipients(Message.RecipientType.TO,toAdds); message.setSubject("test 123"); message.setFrom(new Address("example@djigzo.com","martijn")); message.setSentDate(new Date()); Transport.send(message);

 Is the attachment removed completely or is just the body of the attachment empty?

 

 

Please use plain text.
Developer
jhw1701
Posts: 176
Registered: ‎11-06-2008

Re: CSV file arrives Empty when sent from device -Intermittant-

Here's the code in question. Instead of sending the email immediately I open a composition window so the user can enter notes and comments in the email body. I wonder if that's the reason why my attachments are disappearing from the email as it's sent. 

 

I've tried this with and without adding a text body part and I get the same result.

 

 

String dataXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><some_xml_data/>"; byte[] data = dataXML.getBytes("UTF-8"); Message emailMessage = new Message(); Multipart multipart = new Multipart(); TextBodyPart textPart = new TextBodyPart(multipart); textPart.setContent(""); multipart.addBodyPart(textPart); SupportedAttachmentPart attachmentPart = new SupportedAttachmentPart(multipart); attachmentPart.setContentType("text/xml"); attachmentPart.setContent(data); attachmentPart.setFilename("data.xyz"); multipart.addBodyPart(attachmentPart); emailMessage.setContent(multipart); MessageArguments messageArgs = new MessageArguments(emailMessage); Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, messageArgs);

 

I did manage to create and alternate version below that writes the xml to a file first and that works. The email attachment is not removed from the email when it's sent. But this approach leaves files laying around after the email is sent.

 

 

String dataXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><some_xml_data/>"; byte[] data = dataXML.getBytes("UTF-8"); Message emailMessage = new Message(); Multipart multipart = new Multipart(); TextBodyPart textPart = new TextBodyPart(multipart); textPart.setContent(""); multipart.addBodyPart(textPart); FileConnection fileConn = (FileConnection) Connector.open("file:///store/data.xyz", Connector.READ_WRITE); if (fileConn.exists()) { fileConn.delete(); } fileConn.create(); OutputStream outStream = fileConn.openOutputStream(); outStream.write(data); outStream.flush(); outStream.close(); fileConn.close(); FileSupportedAttachmentPart attachmentPart = new FileSupportedAttachmentPart(multipart, "text/xml", "file:///store/data.xyz"); multipart.addBodyPart(attachmentPart); emailMessage.setContent(multipart); MessageArguments messageArgs = new MessageArguments(emailMessage); Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, messageArgs);

 

I have my content handler for the xyz file type registered and working,  that's not a problem. When I do get the attachment to stay attached to the email using the file based approach I'm able to open and process the XYZ file attachment without a problem. So there's no error messages about unsupported file types.

 

Please use plain text.
Developer
martijnbrinkers
Posts: 155
Registered: ‎02-18-2009

Re: CSV file arrives Empty when sent from device -Intermittant-

Could you try to see if prepending your filename with "x-rimdevice" helps?

 

attachmentPart.setFilename("x-rimdevicedata.xyz");

 

Have you tried it with .xml extension instead of .xyz?

Please use plain text.
Developer
jhw1701
Posts: 176
Registered: ‎11-06-2008

Re: CSV file arrives Empty when sent from device -Intermittant-

I've tried with xml as the extension. Besides, I need the custom extension for the custom content handler.

 

I've tried x-rimdevice prefix but that's doesn't solve the issue. Looks like I'm stuck with the approach that requires me to write out the data to a file first.

 

 

Please use plain text.