Handle unsupported attachment-file-types in EML conversion

@BSkoloda

We investigated the project you shared and it’s been observed that GroupDocs.Conversion object creates 2 memory streams in your code which you are trying to merge via GroupDocs.Merger object and getting the corrupt file exception. This exception is expected because the second memory stream is really not a PDF file (rather it is a piece of the PDF file).

Please take a look at this sample.zip (443.8 KB) code and output files. It contains MERGERNET_1465_0.PDF and MERGERNET_1465_1.pdf which are created from two memory streams mentioned above. If you are trying to open these files then you will see that the first file is opened correctly, but the second one is corrupted.
You can also see Program.cs modified by me and the output MERGERNET_1465.pdf file that is the correct PDF one.
Please let us know if this information was helpful for you.

When trying to view the sample.zip when logged in I get this error message ‘Sorry, this file is private. Only visible to topic owner and staff members.’

@BSkoloda

Please try to download attachments from this drive link.

I see what you are saying but why does the converter create a corrupted memory stream? I am trying to loop a number of documents of all sorts of types and create one pdf of them all. So I wanted to just save them all in to a memory stream and then when completed with the loop then save the memory stream to the destination file

Also is there some way I can tell if the Memory Stream is corrupted before performing the merge and if so can I tell what file the memory stream is from because if the email has 4 attachments in it and only one caused an issue I would like to let the user know which file would not be apart of the combined pdf

1 Like

@BSkoloda

We have initiated an investigation, and a ticket with the ID CONVERSIONNET-6118 has been created. We will diligently look into the matter and provide you with updates as soon as possible. Your patience and understanding are greatly appreciated.

I believe with the last update I am now able to resolve this issue by catching what the sourceFileName is in the function like below. I was not able to do that before the update. So I should be good to go

Thanks for all the help!!

                        converter.Convert(() => new MemoryStream(), (Stream convertedStream, string sourceFileName) =>
                        {
                            if
                            (
                                (!string.Equals(sourceFileName, "smime.p7m", StringComparison.OrdinalIgnoreCase)) &&
                                (!string.Equals(sourceFileName, "smime.p7s", StringComparison.OrdinalIgnoreCase))
                            )
                            { 
                                ms.Add(new MemoryStream());
                                convertedStream.CopyTo(ms[index++]);
                            }

                        }, new PdfConvertOptions());
1 Like

@BSkoloda

Good to know that your issue is resolved.