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