/// <summary> /// A <see cref="ParseEmbeddedObject" /> or <see cref="ParseLinkedObject" /> always contain /// a presentation object, this is used to present the embedded link or object in the host /// application. This method will extract this data. /// </summary> /// <param name="binaryReader"></param> public void GetAndSetPresentationObject(BinaryReader binaryReader) { var po = new Ole10(binaryReader); Width = po.Width; Height = po.Height; StringFormat = po.StringFormat; ClipboardFormat = po.ClipboardFormat; PresentationData = po.PresentationData; }
/// <summary> /// Extracts a Outlook File Attachment object from the given <paramref name="stream"/> /// </summary> /// <param name="stream"></param> /// <param name="outputFolder">The output folder</param> internal static string ExtractOutlookAttachmentObject(Stream stream, string outputFolder) { // Outlook attachments embedded in RTF are firstly embedded in an OLE v1.0 object var ole10 = new Ole10(stream); // After that it is wrapped in a compound document using (var internalStream = new MemoryStream(ole10.NativeData)) using (var compoundFile = new CompoundFile(internalStream)) { string fileName = null; if (compoundFile.RootStorage.ExistsStream("AttachDesc")) { var attachDescStream = compoundFile.RootStorage.GetStream("AttachDesc") as CFStream; fileName = GetFileNameFromAttachDescStream(attachDescStream); } if (string.IsNullOrEmpty(fileName)) fileName = Extraction.DefaultEmbeddedObjectName; fileName = FileManager.RemoveInvalidFileNameChars(fileName); fileName = Path.Combine(outputFolder, fileName); fileName = FileManager.FileExistsMakeNew(fileName); if (compoundFile.RootStorage.ExistsStream("AttachContents")) { var data = compoundFile.RootStorage.GetStream("AttachContents").GetData(); return Extraction.SaveByteArrayToFile(data, fileName); } if (compoundFile.RootStorage.ExistsStorage("MAPIMessage")) { fileName = Path.Combine(outputFolder, fileName); var storage = compoundFile.RootStorage.GetStorage("MAPIMessage") as CFStorage; return Extraction.SaveStorageTreeToCompoundFile(storage, fileName); } return null; } }
/// <summary> /// Extracts a OLE v1.0 object from the given <paramref name="stream"/> /// </summary> /// <param name="stream"></param> /// <param name="outputFolder">The output folder</param> internal static string ExtractOle10(Stream stream, string outputFolder) { var ole10 = new Ole10(stream); if (ole10.Format != OleFormat.File) return null; switch (ole10.ClassName) { case "Package": var package = new Package(ole10.NativeData); if (package.Format == OleFormat.Link) return null; var fileName = Path.GetFileName(package.FileName); if (string.IsNullOrWhiteSpace(fileName)) fileName = Extraction.DefaultEmbeddedObjectName; fileName = Path.Combine(outputFolder, fileName); return Extraction.SaveByteArrayToFile(package.Data, fileName); default: if (Extraction.IsCompoundFile(ole10.NativeData)) return Extraction.SaveFromStorageNode(ole10.NativeData, outputFolder, ole10.ItemName); throw new OEObjectTypeNotSupported("Unsupported OleNative ClassName '" + ole10.ClassName + "' found"); } }