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

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

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.

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.

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

I have added a new method for this issue.

Attachment.SaveRawContent(Stream stream);

Please check it out.

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

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

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

Thanks,
Jeremy