Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save .msg attachment from parent .msg file #425

Open
paulkiernan opened this issue Nov 19, 2024 · 0 comments
Open

Unable to save .msg attachment from parent .msg file #425

paulkiernan opened this issue Nov 19, 2024 · 0 comments

Comments

@paulkiernan
Copy link

Describe the bug
Saving a .msg attachment from a parent .msg file fails.

To Reproduce
Passing a .msg file into the following function that itself contains a .msg attachment produces the following error:

    public void ExtractAttachments(MsgReader.Outlook.Storage.Message message, string outputDirectory)
    {
        foreach (var attachment in message.Attachments)
        {
            if (attachment is MsgReader.Outlook.Storage.Attachment attach)
            {
                string filePath = Path.Combine(outputDirectory, attach.FileName);
                File.WriteAllBytes(filePath, attach.Data);
            }
            else if (attachment is MsgReader.Outlook.Storage.Message msg)
            {
                string msgFileName = msg.FileName;
                string msgFilePath = Path.Combine(outputDirectory, msgFileName);
                msg.Save(msgFilePath);
            }
        }
    }
Error processing message: srcOffset ('-64') must be a non-negative value. (Parameter 'srcOffset')
Actual value was -64.
   at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)
   at OpenMcdf.StreamView.Read(Byte[] buffer, Int32 offset, Int32 count)
   at OpenMcdf.CompoundFile.GetMiniSectorChain(Int32 secID)
   at OpenMcdf.CompoundFile.GetSectorChain(Int32 secID, SectorType chainType)
   at OpenMcdf.CompoundFile.GetData(CFStream cFStream)
   at OpenMcdf.CFStream.GetData()
   at MsgReader.Outlook.Storage.Message.<>c__DisplayClass153_0.<Copy>b__0(CFItem action)
   at OpenMcdf.CFStorage.<>c__DisplayClass13_0.<VisitEntries>b__0(IRBNode targetNode)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.VisitTreeNodes(Action`1 action)
   at OpenMcdf.CFStorage.VisitEntries(Action`1 action, Boolean recursive)
   at MsgReader.Outlook.Storage.Message.Copy(CFStorage source, CFStorage destination)
   at MsgReader.Outlook.Storage.Message.<>c__DisplayClass153_0.<Copy>b__0(CFItem action)
   at OpenMcdf.CFStorage.<>c__DisplayClass13_0.<VisitEntries>b__0(IRBNode targetNode)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.DoVisitTreeNodes(Action`1 action, IRBNode walker)
   at RedBlackTree.RBTree.VisitTreeNodes(Action`1 action)
   at OpenMcdf.CFStorage.VisitEntries(Action`1 action, Boolean recursive)
   at MsgReader.Outlook.Storage.Message.Copy(CFStorage source, CFStorage destination)
   at MsgReader.Outlook.Storage.Message.Save(Stream stream)
   at MsgReader.Outlook.Storage.Message.Save(String fileName)
   at NETMSGExtract.OutlookMessage.ExtractAttachments(String outputDirectory) in /source/OutlookMessage.cs:line 101
   at NETMSGExtract.MSGExtractor.ExtractMSG() in /source/MSGExtractor.cs:line 35
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Expected behavior

The attached .msg file is written successfully to msgFilePath.

Screenshots
N/A

Desktop (please complete the following information):

Smartphone (please complete the following information):
N/A

Additional context
N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant