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):
OS: Debian GNU/Linux 12 (bookworm)
Linux version 6.10.0-linuxkit (root@buildkitsandbox) (gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, GNU ld (GNU Binutils) 2.42) #1 SMP Wed Jul 17 10:51:09 UTC 2024
.NET: 8.0.8
MSGReader: 5.7.0
Smartphone (please complete the following information):
N/A
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:Expected behavior
The attached
.msg
file is written successfully tomsgFilePath
.Screenshots N/A
Desktop (please complete the following information):
Smartphone (please complete the following information): N/A
Additional context N/A