public MsgStorageWriter(Stream stream) { this.namedPropertyList = new NamedPropertyList(); this.isTopLevelMessage = true; this.messageStorage = ComStorage.CreateStorageOnStream(stream, ComStorage.OpenMode.CreateWrite); this.Initialize(MsgSubStorageType.TopLevelMessage); }
public MsgStorageWriter(string filename) { this.namedPropertyList = new NamedPropertyList(); this.isTopLevelMessage = true; this.messageStorage = ComStorage.CreateFileStorage(filename, ComStorage.OpenMode.CreateWrite); this.Initialize(MsgSubStorageType.TopLevelMessage); }
internal MsgStorageWriter OpenAttachedMessageWriter() { if (this.attachMethod != 5) { throw new InvalidOperationException(MsgStorageStrings.NotAMessageAttachment); } ComStorage comStorage = null; MsgStorageWriter msgStorageWriter = null; try { TnefPropertyTag attachDataObj = TnefPropertyTag.AttachDataObj; string storageName = Util.PropertyStreamName(attachDataObj); MsgStoragePropertyData.WriteObject(this.propertiesWriter, attachDataObj, MsgStoragePropertyData.ObjectType.Message); comStorage = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite); comStorage.StorageClass = Util.ClassIdMessageAttachment; msgStorageWriter = new MsgStorageWriter(this.owner, comStorage); } finally { if (msgStorageWriter == null && comStorage != null) { comStorage.Dispose(); } } return(msgStorageWriter); }
public static ComStorage CreateFileStorage(string filename, ComStorage.OpenMode openMode) { Util.ThrowOnNullArgument(filename, "filename"); ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes); object obj = null; ComStorage result; try { Guid iidistorage = Interop.IIDIStorage; int num = Interop.StgCreateStorageEx(filename, (uint)openMode, 0, 0U, IntPtr.Zero, IntPtr.Zero, ref iidistorage, out obj); if (num != 0) { throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename), num); } Interop.IStorage storage = obj as Interop.IStorage; if (storage == null) { throw new MsgStorageException(MsgStorageErrorCode.CreateFileFailed, MsgStorageStrings.FailedCreateStorage(filename)); } obj = null; result = new ComStorage(storage); } finally { if (obj != null) { Marshal.ReleaseComObject(obj); } } return(result); }
private Stream InternalOpenOleAttachmentStream() { if (this.subStorageType != MsgSubStorageType.Attachment || this.attachMethod != 6) { throw new InvalidOperationException(MsgStorageStrings.NotAnOleAttachment); } ComStorage comStorage = null; ComStorage comStorage2 = null; Stream stream = Streams.CreateTemporaryStorageStream(); try { string storageName = Util.PropertyStreamName(TnefPropertyTag.AttachDataObj); comStorage = this.propertiesStorage.OpenStorage(storageName, ComStorage.OpenMode.Read); comStorage2 = ComStorage.CreateStorageOnStream(stream, ComStorage.OpenMode.CreateWrite); ComStorage.CopyStorageContent(comStorage, comStorage2); comStorage2.Flush(); } finally { if (comStorage != null) { comStorage.Dispose(); } if (comStorage2 != null) { comStorage2.Dispose(); } } stream.Position = 0L; return(stream); }
internal MsgStorageReader(ComStorage storage, NamedPropertyList namedPropertyList, Encoding parentEncoding) { this.isTopLevelMessage = false; this.messageStorage = storage; this.namedPropertyList = namedPropertyList; this.Initialize(parentEncoding); }
public static ComStorage CreateStorageOnStream(Stream stream, ComStorage.OpenMode openMode) { Util.ThrowOnNullArgument(stream, "stream"); ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validCreateModes); ComStorage comStorage = null; Interop.IStorage storage = null; try { LockBytesOnStream lockBytes = new LockBytesOnStream(stream); int num = Interop.StgCreateDocfileOnILockBytes(lockBytes, (uint)openMode, 0, out storage); if (num != 0) { throw new MsgStorageException(MsgStorageErrorCode.CreateStorageOnStreamFailed, MsgStorageStrings.FailedCreateStorage("ILockBytes"), num); } comStorage = new ComStorage(storage); } finally { if (comStorage == null && storage != null) { Marshal.ReleaseComObject(storage); } } return(comStorage); }
internal MsgStorageWriter(MsgStorageWriter parent, ComStorage storage) { this.parent = parent; this.messageStorage = storage; this.namedPropertyList = parent.NamedPropertyList; this.isTopLevelMessage = false; this.Initialize(MsgSubStorageType.AttachedMessage); }
internal MsgSubStorageReader(MsgStorageReader owner, ComStorage propertiesStorage, Encoding messageEncoding, MsgSubStorageType subStorageType) { this.owner = owner; this.propertiesStorage = propertiesStorage; this.messageEncoding = messageEncoding; this.subStorageType = subStorageType; this.ReadPropertiesStream(); }
internal Stream OpenOleAttachmentStream() { if (this.attachMethod != 6) { throw new InvalidOperationException(MsgStorageStrings.NotAnOleAttachment); } Stream cacheStream = Streams.CreateTemporaryStorageStream(); MsgStorageWriteStream msgStorageWriteStream = new MsgStorageWriteStream(cacheStream, 0); msgStorageWriteStream.AddOnCloseNotifier(delegate(MsgStorageWriteStream stream, Exception onCloseException) { if (onCloseException != null) { this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.ComExceptionThrown, onCloseException)); return; } TnefPropertyTag attachDataObj = TnefPropertyTag.AttachDataObj; ComStorage comStorage = null; ComStorage comStorage2 = null; string storageName = Util.PropertyStreamName(attachDataObj); try { cacheStream.Flush(); cacheStream.Position = 0L; comStorage = ComStorage.OpenStorageOnStream(cacheStream, ComStorage.OpenMode.Read); comStorage2 = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite); comStorage2.StorageClass = Util.ClassIdFileAttachment; ComStorage.CopyStorageContent(comStorage, comStorage2); comStorage2.Flush(); MsgStoragePropertyData.WriteObject(this.propertiesWriter, attachDataObj, MsgStoragePropertyData.ObjectType.Storage); } catch (IOException exc) { this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc)); } catch (COMException exc2) { this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc2)); } finally { if (comStorage2 != null) { comStorage2.Dispose(); } if (comStorage != null) { comStorage.Dispose(); } if (cacheStream != null) { cacheStream.Dispose(); } } }); return(msgStorageWriteStream); }
public static void CopyStorageContent(ComStorage source, ComStorage destination) { Util.ThrowOnNullArgument(source, "source"); Util.ThrowOnNullArgument(destination, "destination"); Util.InvokeComCall(MsgStorageErrorCode.FailedCopyStorage, delegate { source.IStorage.CopyTo(0U, null, IntPtr.Zero, destination.IStorage); }); }
internal MsgSubStorageWriter(MsgStorageWriter owner, MsgSubStorageType type, ComStorage subStorage) { this.owner = owner; this.subStorage = subStorage; this.subStorageType = type; this.attachMethod = -1; this.propertiesCache = new MemoryStream(); this.propertiesWriter = new BinaryWriter(this.propertiesCache); this.prefix = new MsgStoragePropertyPrefix(type); this.prefix.Write(this.propertiesWriter); }
public void MoveElement(string sourceElementName, ComStorage targetStorage, string targetElementName) { this.CheckDisposed("ComStorage::OpenStorage"); Util.ThrowOnNullArgument(sourceElementName, "sourceElementName"); Util.ThrowOnNullArgument(targetStorage, "targetStorage"); Util.ThrowOnNullArgument(targetElementName, "targetElementName"); Util.InvokeComCall(MsgStorageErrorCode.FailedCopyStorage, delegate { this.iStorage.MoveElementTo(sourceElementName, targetStorage.IStorage, targetElementName, 0U); }); }
public void WriteTo(ComStorage messageStorage) { using (ComStorage comStorage = messageStorage.CreateStorage("__nameid_version1.0", ComStorage.OpenMode.CreateWrite)) { List <Guid> list = new List <Guid>(32); list.AddRange(NamedPropertyList.StandardGuids); Dictionary <Guid, int> dictionary = new Dictionary <Guid, int>(32); int num = 0; foreach (Guid key in list) { dictionary[key] = num++; } using (BinaryWriter binaryWriter = new BinaryWriter(new BufferedStream(comStorage.CreateStream("__substg1.0_00030102", ComStorage.OpenMode.CreateWrite), 8192))) { using (BinaryWriter binaryWriter2 = new BinaryWriter(new BufferedStream(comStorage.CreateStream("__substg1.0_00040102", ComStorage.OpenMode.CreateWrite), 8192), new UnicodeEncoding(false, false))) { foreach (TnefPropertyId tnefPropertyId in this.idToName.Keys) { bool isString = false; TnefNameIdWrapper tnefNameIdWrapper = this.idToName[tnefPropertyId]; int count; if (!dictionary.TryGetValue(tnefNameIdWrapper.PropertySetGuid, out count)) { count = list.Count; list.Add(tnefNameIdWrapper.PropertySetGuid); dictionary.Add(tnefNameIdWrapper.PropertySetGuid, count); } int namedId; if (tnefNameIdWrapper.Kind == TnefNameIdKind.Id) { namedId = tnefNameIdWrapper.Id; } else { namedId = NamedPropertyList.WriteName(binaryWriter2, tnefNameIdWrapper.Name); isString = true; } NamedPropertyList.NamedPropertyEntry namedPropertyEntry = new NamedPropertyList.NamedPropertyEntry(tnefPropertyId, isString, (ushort)count, namedId); namedPropertyEntry.WriteEntry(binaryWriter); } } } using (Stream stream = new BufferedStream(comStorage.CreateStream("__substg1.0_00020102", ComStorage.OpenMode.CreateWrite), 8192)) { for (int i = 3; i < list.Count; i++) { byte[] array = list[i].ToByteArray(); stream.Write(array, 0, array.Length); } } comStorage.Flush(); } }
public ComStream OpenStream(string streamName, ComStorage.OpenMode openMode) { this.CheckDisposed("ComStorage::OpenStream"); Util.ThrowOnNullArgument(streamName, "streamName"); ComStorage.CheckOpenMode(openMode, "openMode", ComStorage.validOpenModes); Interop.IStream iStream = null; Util.InvokeComCall(MsgStorageErrorCode.FailedOpenStream, delegate { this.iStorage.OpenStream(streamName, IntPtr.Zero, (uint)openMode, 0U, out iStream); }); return(new ComStream(iStream)); }
public ComStorage OpenStorage(string storageName, ComStorage.OpenMode mode) { this.CheckDisposed("ComStorage::OpenStorage"); Util.ThrowOnNullArgument(storageName, "storageName"); ComStorage.CheckOpenMode(mode, "mode", ComStorage.validOpenModes); Interop.IStorage iOpenStorage = null; Util.InvokeComCall(MsgStorageErrorCode.FailedOpenSubstorage, delegate { this.iStorage.OpenStorage(storageName, null, (uint)mode, IntPtr.Zero, 0U, out iOpenStorage); }); return(new ComStorage(iOpenStorage)); }
private static NamedPropertyList.NamedPropertyEntry[] ReadEntryList(ComStorage namedPropertiesStorage) { byte[] array = namedPropertiesStorage.ReadFromStreamMaxLength("__substg1.0_00030102", 262144); int num = 0; int num2 = array.Length / 8; NamedPropertyList.NamedPropertyEntry[] array2 = new NamedPropertyList.NamedPropertyEntry[num2]; for (int num3 = 0; num3 != num2; num3++) { array2[num3] = NamedPropertyList.NamedPropertyEntry.ReadEntry(array, ref num); } return(array2); }
internal MsgSubStorageWriter OpenAttachmentWriter() { int attachmentCount = this.prefix.AttachmentCount; ComStorage comStorage = null; MsgSubStorageWriter msgSubStorageWriter = null; try { string storageName = Util.AttachmentStorageName(attachmentCount); comStorage = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite); msgSubStorageWriter = new MsgSubStorageWriter(this.owner, MsgSubStorageType.Attachment, comStorage); } finally { if (msgSubStorageWriter == null && comStorage != null) { comStorage.Dispose(); } } this.prefix.AttachmentCount++; return(msgSubStorageWriter); }
private static void ReadGuidList(ComStorage namedPropertiesStorage, List <Guid> guids) { Stream stream = new BufferedStream(namedPropertiesStorage.OpenStream("__substg1.0_00020102", ComStorage.OpenMode.Read), 8192); byte[] array = new byte[16]; for (;;) { int num = stream.Read(array, 0, 16); if (num < 16) { break; } guids.Add(new Guid(array)); if (guids.Count > 8192) { goto Block_2; } } return; Block_2: throw new MsgStorageException(MsgStorageErrorCode.NamedPropertiesListTooLong, MsgStorageStrings.LargeNamedPropertyList); }
internal MsgStorageReader OpenAttachedMessage() { if (this.attachMethod != 5) { throw new InvalidOperationException(MsgStorageStrings.NotAMessageAttachment); } ComStorage comStorage = null; MsgStorageReader msgStorageReader = null; try { string storageName = Util.PropertyStreamName(TnefPropertyTag.AttachDataObj); comStorage = this.propertiesStorage.OpenStorage(storageName, ComStorage.OpenMode.Read); msgStorageReader = new MsgStorageReader(comStorage, this.owner.NamedPropertyList, this.MessageEncoding); } finally { if (comStorage != null && msgStorageReader == null) { comStorage.Dispose(); } } return(msgStorageReader); }
private void OpenSubStorage(string subStorageName, MsgSubStorageType type) { ComStorage comStorage = null; try { comStorage = this.messageStorage.OpenStorage(subStorageName, ComStorage.OpenMode.Read); MsgSubStorageReader msgSubStorageReader = new MsgSubStorageReader(this, comStorage, this.encoding, type); if (this.subStorage != null) { this.subStorage.Dispose(); } this.subStorage = comStorage; this.subStorageParser = msgSubStorageReader; comStorage = null; } finally { if (comStorage != null) { comStorage.Dispose(); } } }
public MsgStorageReader(string filename) { this.isTopLevelMessage = true; this.messageStorage = ComStorage.OpenFileStorage(filename, ComStorage.OpenMode.Read); this.Initialize(null); }
public static NamedPropertyList ReadNamedPropertyList(ComStorage messageStorage) { ComStorage comStorage = null; NamedPropertyList.NamedPropertyEntry[] array = null; byte[] array2 = null; List <Guid> list = null; NamedPropertyList namedPropertyList = new NamedPropertyList(); NamedPropertyList result; try { try { comStorage = messageStorage.OpenStorage("__nameid_version1.0", ComStorage.OpenMode.Read); array = NamedPropertyList.ReadEntryList(comStorage); } catch (MsgStorageNotFoundException) { namedPropertyList.canModify = false; return(namedPropertyList); } list = new List <Guid>(32); list.AddRange(NamedPropertyList.StandardGuids); try { NamedPropertyList.ReadGuidList(comStorage, list); } catch (MsgStorageNotFoundException) { } try { array2 = comStorage.ReadFromStreamMaxLength("__substg1.0_00040102", 262144); } catch (MsgStorageNotFoundException) { array2 = Util.EmptyByteArray; } foreach (NamedPropertyList.NamedPropertyEntry namedPropertyEntry in array) { ushort guidIndex = namedPropertyEntry.GuidIndex; if ((int)guidIndex > list.Count) { throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData); } Guid propertySetGuid = list[(int)guidIndex]; TnefPropertyId tnefPropertyId = namedPropertyEntry.TnefPropertyId; TnefNameId namedProperty; if (namedPropertyEntry.IsString) { int num = namedPropertyEntry.NamedId; if (num + 4 > array2.Length) { throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData); } int num2 = BitConverter.ToInt32(array2, num); num += 4; if (num + num2 < num || num + num2 > array2.Length) { throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData); } string @string = Util.UnicodeEncoding.GetString(array2, num, num2); namedProperty = new TnefNameId(propertySetGuid, @string); } else { namedProperty = new TnefNameId(propertySetGuid, namedPropertyEntry.NamedId); } if (!namedPropertyList.TryAdd(tnefPropertyId, namedProperty)) { throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData); } } namedPropertyList.canModify = false; result = namedPropertyList; } finally { if (comStorage != null) { comStorage.Dispose(); } } return(result); }
public MsgStorageReader(Stream contentStream) { this.isTopLevelMessage = true; this.messageStorage = ComStorage.OpenStorageOnStream(contentStream, ComStorage.OpenMode.Read); this.Initialize(null); }