예제 #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);
        }
 private static void WriteString8Array(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     string[] array = value as string[];
     if (array == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(string[]), value.GetType()));
     }
     MsgStorageRulesTable.InternalWriteStringArray(writer, propertyTag.ToUnicode(), array);
 }
        private static void WriteString8(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            string text = value as string;

            if (text == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(string), value.GetType()));
            }
            MsgStorageRulesTable.InternalWriteString(writer, propertyTag.ToUnicode(), text);
        }
예제 #4
0
        public Stream OpenPropertyStream(Guid propertyGuid, int namedId, TnefPropertyType propertyType)
        {
            this.CheckDisposed("MsgStorageWriter::OpenPropertyStream(3)");
            MsgStorageRulesTable.ThrowOnInvalidPropertyType(propertyType);
            this.CheckFailure();
            TnefNameId      namedProperty = new TnefNameId(propertyGuid, namedId);
            TnefPropertyId  id            = this.NamedPropertyList.Add(namedProperty);
            TnefPropertyTag propertyTag   = new TnefPropertyTag(id, propertyType);

            return(this.CurrentWriter.OpenPropertyStream(propertyTag));
        }
예제 #5
0
        public void WriteProperty(Guid propertyGuid, int namedId, TnefPropertyType propertyType, object propertyValue)
        {
            this.CheckDisposed("MsgStorageWriter::WriteProperty(3)");
            MsgStorageRulesTable.ThrowOnInvalidPropertyType(propertyType);
            Util.ThrowOnNullArgument(propertyValue, "propertyValue");
            this.CheckFailure();
            TnefNameId      namedProperty = new TnefNameId(propertyGuid, namedId);
            TnefPropertyId  id            = this.NamedPropertyList.Add(namedProperty);
            TnefPropertyTag propertyTag   = new TnefPropertyTag(id, propertyType);

            this.CurrentWriter.WriteProperty(propertyTag, propertyValue);
        }
예제 #6
0
 public void WriteProperty(TnefPropertyTag propertyTag, object propertyValue)
 {
     this.CheckDisposed("MsgStorageWriter::WriteProperty(1)");
     if (propertyTag.IsNamed)
     {
         throw new ArgumentException(MsgStorageStrings.InvalidPropertyTag(propertyTag), "propertyTag");
     }
     MsgStorageRulesTable.ThrowOnInvalidPropertyType(propertyTag);
     Util.ThrowOnNullArgument(propertyValue, "propertyValue");
     this.CheckFailure();
     this.CurrentWriter.WriteProperty(propertyTag, propertyValue);
 }
 private static void WriteGuidArray(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     Guid[] arrayValue = value as Guid[];
     if (arrayValue == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(Guid[]), value.GetType()));
     }
     MsgStorageRulesTable.WriteArray(writer, propertyTag, arrayValue.Length, delegate(BinaryWriter binaryWriter, int index)
     {
         binaryWriter.Write(arrayValue[index].ToByteArray());
     });
 }
예제 #8
0
 public Stream OpenPropertyStream(TnefPropertyTag propertyTag)
 {
     this.CheckDisposed("MsgStorageWriter::OpenPropertyStream(1)");
     if (propertyTag.IsNamed)
     {
         throw new ArgumentException(MsgStorageStrings.InvalidPropertyTag(propertyTag), "propertyTag");
     }
     MsgStorageRulesTable.ThrowOnInvalidPropertyType(propertyTag);
     this.CheckFailure();
     if (propertyTag == TnefPropertyTag.AttachDataObj)
     {
         return(this.CurrentWriter.OpenOleAttachmentStream());
     }
     return(this.CurrentWriter.OpenPropertyStream(propertyTag));
 }
예제 #9
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);
        }
예제 #10
0
        private static object ReadString8Array(MsgSubStorageReader parser, MsgSubStorageReader.PropertyInfo propertyInfo)
        {
            int stringArrayLengthEntrySize = MsgStorageRulesTable.StringArrayLengthEntrySize;
            int num;

            byte[]   value = MsgStorageRulesTable.InternalReadLengthList(parser, propertyInfo, stringArrayLengthEntrySize, out num);
            string[] array = new string[num];
            int      num2  = 0;

            for (int num3 = 0; num3 != num; num3++)
            {
                int    num4  = BitConverter.ToInt32(value, num2);
                byte[] bytes = parser.ReadPropertyIndexStream(propertyInfo.Tag, num3, num4, 1);
                array[num3] = Util.AnsiBytesToString(bytes, num4, parser.MessageEncoding);
                num2       += stringArrayLengthEntrySize;
            }
            return(array);
        }
예제 #11
0
        private static object ReadArrayOfBinary(MsgSubStorageReader parser, MsgSubStorageReader.PropertyInfo propertyInfo)
        {
            int binaryArrayLengthEntrySize = MsgStorageRulesTable.BinaryArrayLengthEntrySize;
            int num;

            byte[]   value = MsgStorageRulesTable.InternalReadLengthList(parser, propertyInfo, binaryArrayLengthEntrySize, out num);
            byte[][] array = new byte[num][];
            int      num2  = 0;

            for (int num3 = 0; num3 != num; num3++)
            {
                int num4 = BitConverter.ToInt32(value, num2);
                array[num3] = new byte[num4];
                parser.ReadPropertyIndexStream(propertyInfo.Tag, num3, array[num3], num4, 0);
                num2 += binaryArrayLengthEntrySize;
            }
            return(array);
        }
예제 #12
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;
        }
예제 #13
0
 private static void WriteSysTimeArray(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     DateTime[] arrayValue = value as DateTime[];
     if (arrayValue == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(DateTime[]), value.GetType()));
     }
     MsgStorageRulesTable.WriteArray(writer, propertyTag, arrayValue.Length, delegate(BinaryWriter binaryWriter, int index)
     {
         long value2 = 0L;
         try
         {
             value2 = arrayValue[index].ToFileTimeUtc();
         }
         catch (ArgumentOutOfRangeException)
         {
             value2 = 0L;
         }
         binaryWriter.Write(value2);
     });
 }
예제 #14
0
 internal static bool TryFindRule(TnefPropertyTag propertyTag, out MsgStoragePropertyTypeRule rule)
 {
     return(MsgStorageRulesTable.TryFindRule(propertyTag.TnefType, out rule));
 }
예제 #15
0
 internal static void ThrowOnInvalidPropertyType(TnefPropertyTag tag)
 {
     MsgStorageRulesTable.ThrowOnInvalidPropertyType(tag.TnefType);
 }
예제 #16
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);
        }