Ejemplo n.º 1
0
        private Stream InternalOpenPropertyStream(TnefPropertyTag propertyTag)
        {
            if (propertyTag == TnefPropertyTag.AttachDataObj)
            {
                return(this.InternalOpenOleAttachmentStream());
            }
            MsgStoragePropertyTypeRule msgStoragePropertyTypeRule;

            MsgStorageRulesTable.TryFindRule(propertyTag, out msgStoragePropertyTypeRule);
            if (!msgStoragePropertyTypeRule.CanOpenStream)
            {
                throw new InvalidOperationException(MsgStorageStrings.NonStreamableProperty);
            }
            Stream stream = this.propertiesStorage.OpenStream(Util.PropertyStreamName(propertyTag), ComStorage.OpenMode.Read);

            if (propertyTag.TnefType == TnefPropertyType.String8)
            {
                stream = new ConverterStream(stream, new TextToText(TextToTextConversionMode.ConvertCodePageOnly)
                {
                    InputEncoding  = this.MessageEncoding,
                    OutputEncoding = Util.UnicodeEncoding
                }, ConverterStreamAccess.Read);
            }
            return(stream);
        }
Ejemplo n.º 2
0
        internal void WriteProperty(TnefPropertyTag propertyTag, object propertyValue)
        {
            if (propertyTag == TnefPropertyTag.AttachMethod && this.subStorageType == MsgSubStorageType.Attachment)
            {
                int?num = propertyValue as int?;
                if (num != null)
                {
                    this.attachMethod = num.Value;
                }
            }
            MsgStoragePropertyTypeRule msgStoragePropertyTypeRule;

            MsgStorageRulesTable.TryFindRule(propertyTag, out msgStoragePropertyTypeRule);
            msgStoragePropertyTypeRule.WriteValue(this, propertyTag, propertyValue);
        }
Ejemplo n.º 3
0
        private void ReadCurrentProperty()
        {
            TnefPropertyTag            tnefPropertyTag = MsgStoragePropertyData.ReadPropertyTag(this.propertiesContent, this.currentOffset);
            int                        propertyLength  = 0;
            MsgStoragePropertyTypeRule msgStoragePropertyTypeRule;

            if (!MsgStorageRulesTable.TryFindRule(tnefPropertyTag, out msgStoragePropertyTypeRule))
            {
                throw new MsgStorageException(MsgStorageErrorCode.InvalidPropertyType, MsgStorageStrings.CorruptData);
            }
            if (!msgStoragePropertyTypeRule.IsFixedValue)
            {
                propertyLength = MsgStoragePropertyData.ReadPropertyByteCount(this.propertiesContent, this.currentOffset);
            }
            this.currentProperty                = default(MsgSubStorageReader.PropertyInfo);
            this.currentProperty.Tag            = tnefPropertyTag;
            this.currentProperty.Rule           = msgStoragePropertyTypeRule;
            this.currentProperty.PropertyLength = propertyLength;
        }
Ejemplo n.º 4
0
 internal static bool TryFindRule(TnefPropertyTag propertyTag, out MsgStoragePropertyTypeRule rule)
 {
     return(MsgStorageRulesTable.TryFindRule(propertyTag.TnefType, out rule));
 }
Ejemplo n.º 5
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);
        }