Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        internal Stream OpenPropertyStream(TnefPropertyTag propertyTag)
        {
            if (this.subStorageType == MsgSubStorageType.Recipient)
            {
                throw new InvalidOperationException(MsgStorageStrings.RecipientPropertiesNotStreamable);
            }
            MsgStoragePropertyTypeRule msgStoragePropertyTypeRule;

            MsgStorageRulesTable.TryFindRule(propertyTag, out msgStoragePropertyTypeRule);
            if (!msgStoragePropertyTypeRule.CanOpenStream)
            {
                throw new InvalidOperationException(MsgStorageStrings.NonStreamableProperty);
            }
            Stream stream3 = null;
            Stream stream2 = null;

            try
            {
                int addStringTerminators = 0;
                if (propertyTag.TnefType == TnefPropertyType.Unicode)
                {
                    addStringTerminators = 2;
                }
                else if (propertyTag.TnefType == TnefPropertyType.String8)
                {
                    addStringTerminators = 1;
                }
                string streamName = Util.PropertyStreamName(propertyTag);
                stream3 = this.subStorage.CreateStream(streamName, ComStorage.OpenMode.CreateWrite);
                MsgStorageWriteStream msgStorageWriteStream = new MsgStorageWriteStream(stream3, addStringTerminators);
                stream3 = msgStorageWriteStream;
                stream3 = new BufferedStream(msgStorageWriteStream, 32768);
                msgStorageWriteStream.AddOnCloseNotifier(delegate(MsgStorageWriteStream stream, Exception onCloseException)
                {
                    if (onCloseException != null)
                    {
                        this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.ComExceptionThrown, onCloseException));
                        return;
                    }
                    try
                    {
                        MsgStoragePropertyData.WriteStream(this.propertiesWriter, propertyTag, (int)stream.Length);
                    }
                    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));
                    }
                });
                stream2 = stream3;
            }
            finally
            {
                if (stream2 == null && stream3 != null)
                {
                    stream3.Dispose();
                }
            }
            return(stream2);
        }