Sign In  Sign Up Live-Chat

Binary Attachments getting Corrupted in Aspose.Network.MailMessage

Last post 05-20-2008, 1:46 PM by Jeremyfelix. 8 replies.
Sort Posts: Previous Next
  •  05-13-2008, 12:51 PM 126747

    Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    Hi,

    I'm seeing a problem when reading in a MailMessage from a stream containing MIME. The problem is if the attachment's MIME header states that it's "text/plain", the attachment comes back to me with all NUL (hex 00) bytes stripped out. This is a problem if the attachment is a binary file, such as a zip. Unfortunately, i have no control over what content-type is provided in the original MIME stream. Every email client seems to be able to open these attachments with no problems, so is there a way i can force Aspose to treat all attachments as "application/octet"?

    Here's some sample code that demonstrates my issue:

    using System;
    using System.IO;
    using Aspose.Network.Mail;

    namespace AsposeTest
    {
        internal class TestAspose
        {
            public static void AsposeQuickTest()
            {
                byte[] originalAttachment = new byte[] {0xaa, 0xbb, 0xcc, 0xdd,
                                                        0x00, 0x01, 0x02, 0x03};
                byte[] processedAttachment;

                using (MemoryStream messageStream = new MemoryStream())
                {
                    using (
                        MailMessage message =
                            new MailMessage("user@fromdomain.com", "user@todomain.com", "test",
                                            "testing 1 2 3"))
                    {
                        using (
                            MemoryStream attachmentStream = new MemoryStream(originalAttachment))
                        {
                            message.Attachments.Add(new Attachment(attachmentStream, "filename",
                                                                   "text/plain"));
                        }

                        message.Save(messageStream);
                    }

                    messageStream.Position = 0;

                    using (MailMessage newMessage = MailMessage.Load(messageStream))
                    {
                        using (MemoryStream newAttachmentStream = new MemoryStream())
                        {
                            newMessage.Attachments[0].Save(newAttachmentStream);
                            processedAttachment = newAttachmentStream.ToArray();
                        }
                    }
                }

                Console.WriteLine("Original attachment:  {0}",
                                  BitConverter.ToString(originalAttachment));
                Console.WriteLine("Processed attachment: {0}",
                                  BitConverter.ToString(processedAttachment));
            }
        }
    }

    Thanks in advance!
    Jeremy

     
  •  05-13-2008, 12:54 PM 126748 in reply to 126747

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    BTW, the output of the sample program is:

    Original attachment:  AA-BB-CC-DD-00-01-02-03
    Processed attachment: AA-BB-CC-DD-01-02-03

    Jeremy

     
  •  05-14-2008, 2:28 AM 126834 in reply to 126747

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    Hi,

    Thanks for considering Aspose.

    We have tested the code above. It ignores the 0 byte values if the type is "text/plain".

    We are looking into this issue and the possibility of forcing all attachments as "binary/octet" and get back to you shortly.

    I think you are receiving attachments from stream and adding it to the mail message.


    Best Regards,

    Saqib Razzaq
    Support Developer
    Aspose Guangzhou Team

     
  •  05-14-2008, 11:02 AM 126972 in reply to 126834

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    Attachment: Present (inaccessible)

    Hello,

    I have made something to fix the issue. Now we don't filter out the nil even for text/plain mime parts. Please check it out.


    Team Lead
    Aspose Guangzhou Team
    About Us

    Contact Us
     
  •  05-14-2008, 11:50 AM 126981 in reply to 126972

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    Thanks for the quick turnaround. This fixes the NUL byte issue.

    I'm seeing another issue though, where I believe plain 0x0A bytes are getting transformed to 0x0D 0x0A, and plain 0x0D bytes are getting stripped out.

    If you change the byte array at the beginning to:

                byte[] originalAttachment = new byte[] {0x0a, 0x0b, 0x0c, 0x0d,
                                                        0x00, 0x01, 0x02, 0x03};

    You'll get the following output:

    Original attachment:  0A-0B-0C-0D-00-01-02-03
    Processed attachment: 0D-0A-0B-0C-00-01-02-03

    Thanks,
    Jeremy
     
  •  05-15-2008, 10:43 AM 127247 in reply to 126981

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    Attachment: Present (inaccessible)

    I have added a new method for this issue.

    Attachment.SaveRawContent(Stream stream);

    Please check it out.


    Team Lead
    Aspose Guangzhou Team
    About Us

    Contact Us
     
  •  05-15-2008, 1:31 PM 127281 in reply to 127247

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    This is perfect, thanks again for the quick response!

    Is this a release build? If not, would it be possible to get one? I can provide our license invoice number if needed.

    Thanks,
    Jeremy
     
  •  05-18-2008, 9:18 PM 127612 in reply to 127281

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    Hello, Jeremy,

    1. What's your license? Do you have the license for Aspose.Network?

    2. You can take it in your product, I will release an official release and keep you posted.

    Thanks


    Team Lead
    Aspose Guangzhou Team
    About Us

    Contact Us
     
  •  05-20-2008, 1:46 PM 127901 in reply to 127612

    Re: Binary Attachments getting Corrupted in Aspose.Network.MailMessage

    Yes, we have a Developer Enterprise Subscription for Aspose.Network. Our order number was 070617110550.

    Thanks,
    Jeremy
     
View as RSS news feed in XML