Saving message from server as eml throws format exception

Hi,

we are experiencing an issue where some emails fetched from server throw a format exception when saved to disk using DefaultEmlSaveOptions.

Stack trace excerpt:

class com.aspose.email.system.exceptions.FormatException: An invalid character was found in the 7-bit stream.
com.aspose.email.arc.a(SourceFile:119)
com.aspose.email.arc.write(SourceFile:100)
com.aspose.email.agc.a(SourceFile:341)
com.aspose.email.afb.a(SourceFile:757)
com.aspose.email.MailMessage.a(SourceFile:3120)
com.aspose.email.MailMessage.a(SourceFile:2257)
com.aspose.email.MailMessage.save(SourceFile:2191)

We have found a workaround

  • saving the file to disk first as MHTML
  • load the file from disk using defaults
  • save the file to disk as EML
SaveOptions saveOptions = null;

try {
    saveOptions = SaveOptions.getDefaultEml();
    eml.save(filePath.toString(), saveOptions);
} catch (FormatException formatException) {
    if (formatException.getMessage().contains("7-bit")) {
        // START DS-585 workaround
        saveOptions = SaveOptions.getDefaultMhtml();
        ((MhtSaveOptions) saveOptions).setMhtFormatOptions(MhtFormatOptions.NoEncodeCharacters);
        eml.save(filePath.toString(), saveOptions);

        eml = MailMessage.load(filePath.toString());

        saveOptions = SaveOptions.getDefaultEml();
        eml.save(filePath.toString(), saveOptions);
        // END DS-585 workaround
    } else {
        throw formatException;
    }
}

This is quite a convoluted and inefficient way of saving a mail Message to eml. Is this a bug in Aspose, or is there a better way to save these emails as eml?

this zip contains two emails that are affected:

https://drive.google.com/open?id=0BwoC2lomjtLdZUxBZlM2T1BHSzQ

We are using Aspose.Email for Java 17.7

regards

@Docbyte,

Thank you for contacting Aspose support team.

We have tried to reproduce the issue using sample EML but could not succeed. Following sample code is used for testing:

MailMessage mail1 =  MailMessage.Load(@"5211_4_1a_c89276fefa5213be971de324439ac.0_9563.eml",
new EmlLoadOptions());
mail1.Save(@"\mail1.eml", EmlSaveOptions.DefaultEml);
MailMessage mail2 = MailMessage.Load(@"5221_a_44_f4115cdda38e5894465eda228dfe8.0_241103.eml",
new EmlLoadOptions());
mail1.Save(@"mail2.eml", EmlSaveOptions.DefaultEml);

Is it possible for you to save the original stream (fetched email from server) in a file and provide us before saving it as EML? This original data stream will help us to observe the problem and provide assistance.

Hi, we save the messageStream to file

using the following code:

				FileOutputStream fos = new FileOutputStream("C:\\temp\\aspose10mb\\imap\\" + fileName + ".ser");
				imapClient.saveMessage(msgId, fos);

resulting file:
2017_VDF_03774_-_Opvragen_Info.zip (7.4 KB)

@Docbyte,

Thank you for providing the sample data. This issue is reproduced and logged under Id: EMAILJAVA-34299 for further investigation by the product team. You will be automatically notified once any update is received in this regard.

@Docbyte,

The issue has been fixed. Please download the latest version of Aspose.Email for Java 17.8 for trying it at your end and let us know if you have any further inquiry in this regard.

Thank you.

updating to the newer version did fix this issue.

@Docbyte,

Thanks for the feedback. It’s good to know that we could be of help to you in resolving this issue. Please feel free to write to us in case of any further query related to the API.