Exemplo n.º 1
0
        internal bool TryGetMapiProperty <T>(TnefPropertyTag propertyTag, out T propValue)
        {
            this.ThrowIfDisposed();
            bool result;

            using (ThreadAccessGuard.EnterPublic(this.accessToken))
            {
                propValue = default(T);
                if (this.message.MapiProperties == null)
                {
                    result = false;
                }
                else
                {
                    object property = this.message.MapiProperties.GetProperty(propertyTag);
                    if (property is T)
                    {
                        propValue = (T)((object)property);
                        result    = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            return(result);
        }
        private void WriteProperty(NativeStorePropertyDefinition property, object value)
        {
            value = ExTimeZoneHelperForMigrationOnly.ToLegacyUtcIfDateTime(value);
            switch (property.SpecifiedWith)
            {
            case PropertyTypeSpecifier.PropertyTag:
            {
                PropertyTagPropertyDefinition propertyTagPropertyDefinition = (PropertyTagPropertyDefinition)property;
                TnefPropertyTag propertyTag = (int)propertyTagPropertyDefinition.PropertyTag;
                this.PropertyWriter.WriteProperty(propertyTag, value);
                return;
            }

            case PropertyTypeSpecifier.GuidString:
            {
                GuidNamePropertyDefinition guidNamePropertyDefinition = (GuidNamePropertyDefinition)property;
                TnefPropertyType           propertyType = (TnefPropertyType)guidNamePropertyDefinition.MapiPropertyType;
                this.PropertyWriter.WriteProperty(guidNamePropertyDefinition.Guid, guidNamePropertyDefinition.PropertyName, propertyType, value);
                return;
            }

            case PropertyTypeSpecifier.GuidId:
            {
                GuidIdPropertyDefinition guidIdPropertyDefinition = (GuidIdPropertyDefinition)property;
                TnefPropertyType         propertyType2            = (TnefPropertyType)guidIdPropertyDefinition.MapiPropertyType;
                this.PropertyWriter.WriteProperty(guidIdPropertyDefinition.Guid, guidIdPropertyDefinition.Id, propertyType2, value);
                return;
            }

            default:
                throw new InvalidOperationException(string.Format("Invalid native property specifier: {0}", property.SpecifiedWith));
            }
        }
        protected NativeStorePropertyDefinition CreatePropertyDefinition(TnefPropertyTag propertyTag, TnefNameId?namedProperty)
        {
            PropType tnefType = (PropType)propertyTag.TnefType;

            if (tnefType == PropType.Error || tnefType == PropType.Null || tnefType == PropType.ObjectArray || tnefType == PropType.Unspecified)
            {
                return(null);
            }
            if (tnefType == PropType.Object && propertyTag != TnefPropertyTag.AttachDataObj)
            {
                return(null);
            }
            if (namedProperty == null)
            {
                return(PropertyTagPropertyDefinition.InternalCreateCustom(string.Empty, (PropTag)propertyTag, PropertyFlags.None, NativeStorePropertyDefinition.TypeCheckingFlag.DoNotCreateInvalidType));
            }
            Guid propertySetGuid = namedProperty.Value.PropertySetGuid;

            if (namedProperty.Value.Kind == TnefNameIdKind.Id)
            {
                return(GuidIdPropertyDefinition.InternalCreateCustom(string.Empty, tnefType, propertySetGuid, namedProperty.Value.Id, PropertyFlags.None, NativeStorePropertyDefinition.TypeCheckingFlag.DoNotCreateInvalidType, new PropertyDefinitionConstraint[0]));
            }
            string name = namedProperty.Value.Name;

            if (!GuidNamePropertyDefinition.IsValidName(propertySetGuid, name))
            {
                return(null);
            }
            return(GuidNamePropertyDefinition.InternalCreateCustom(string.Empty, tnefType, propertySetGuid, name, PropertyFlags.None, NativeStorePropertyDefinition.TypeCheckingFlag.DoNotCreateInvalidType, new PropertyDefinitionConstraint[0]));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
            private void WriteTnefWriterPropertyValue(TnefPropertyTag propertyTag, object propertyValue)
            {
                TnefPropertyType tnefType = propertyTag.TnefType;

                if (tnefType == TnefPropertyType.AppTime || tnefType == (TnefPropertyType)4103)
                {
                    DateTime dateTime = (DateTime)Util.Date1601Utc.ToUtc();
                    try
                    {
                        dateTime = ConvertUtils.GetDateTimeFromOADate((double)propertyValue);
                    }
                    catch (ArgumentException arg)
                    {
                        StorageGlobals.ContextTraceError <double, ArgumentException>(ExTraceGlobals.CcOutboundTnefTracer, "TnefContentWriter::WriteTnefWriterPropertyValue: ArgumentException processing date {0}, {1}.", (double)propertyValue, arg);
                    }
                    propertyValue = dateTime;
                }
                propertyValue = ExTimeZoneHelperForMigrationOnly.ToLegacyUtcIfDateTime(propertyValue);
                if (propertyValue is DateTime)
                {
                    DateTime dateTime2 = (DateTime)propertyValue;
                    if ((ExDateTime)dateTime2 < Util.Date1601Utc)
                    {
                        propertyValue = (DateTime)Util.Date1601Utc;
                    }
                }
                this.tnefWriter.WritePropertyValue(propertyValue);
            }
 internal static int WriteProperty(BinaryWriter writer, TnefPropertyTag propertyTag, double propertyValue)
 {
     writer.Write(propertyTag);
     writer.Write(6);
     writer.Write(propertyValue);
     return(16);
 }
Exemplo n.º 7
0
 internal static string PropertyStreamName(TnefPropertyTag propertyTag)
 {
     return(string.Format(CultureInfo.InvariantCulture, "__substg1.0_{0:X8}", new object[]
     {
         (uint)propertyTag
     }));
 }
Exemplo n.º 8
0
        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);
        }
 internal static int WriteProperty(BinaryWriter writer, TnefPropertyTag propertyTag, float propertyValue)
 {
     writer.Write(propertyTag);
     writer.Write(6);
     writer.Write(propertyValue);
     writer.Write(MsgStoragePropertyData.padding, 0, 4);
     return(16);
 }
Exemplo n.º 10
0
        private int GetIndex(TnefPropertyId id)
        {
            TnefPropertyTag key = new TnefPropertyTag(id, TnefPropertyType.Null);
            int             result;

            this.supportedProperties.TryGetValue(key, out result);
            return(result);
        }
Exemplo n.º 11
0
 public void SetProperty(TnefPropertyTag tag, bool toUnicode, object value)
 {
     if (toUnicode && TnefPropertyType.String8 == tag.TnefType)
     {
         tag = tag.ToUnicode();
     }
     this[tag] = value;
 }
Exemplo n.º 12
0
 public object GetProperty(TnefPropertyTag tag, bool toUnicode)
 {
     if (toUnicode && TnefPropertyType.String8 == tag.TnefType)
     {
         tag = tag.ToUnicode();
     }
     return(this[tag]);
 }
Exemplo n.º 13
0
        internal byte[] ReadPropertyLengthsStream(TnefPropertyTag propertyTag, int bytesToRead)
        {
            byte[] lengthsBuffer = this.Buffers.GetLengthsBuffer(bytesToRead);
            string streamName    = Util.PropertyStreamName(propertyTag);

            this.InternalReadStream(streamName, lengthsBuffer, bytesToRead, 0);
            return(lengthsBuffer);
        }
 internal static int WriteStream(BinaryWriter writer, TnefPropertyTag propertyTag, int streamSize)
 {
     writer.Write(propertyTag);
     writer.Write(6);
     writer.Write(streamSize);
     writer.Write(3);
     writer.Write(MsgStoragePropertyData.padding, 0, 2);
     return(16);
 }
 internal static int WriteObject(BinaryWriter writer, TnefPropertyTag propertyTag, MsgStoragePropertyData.ObjectType objectType)
 {
     writer.Write(propertyTag);
     writer.Write(6);
     writer.Write(uint.MaxValue);
     writer.Write((ushort)objectType);
     writer.Write(MsgStoragePropertyData.padding, 0, 2);
     return(16);
 }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
 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);
 }
Exemplo n.º 18
0
        private static void WriteDouble(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            double?num = value as double?;

            if (num == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(double), value.GetType()));
            }
            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, num.Value);
        }
Exemplo n.º 19
0
 private static void WriteBinary(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     byte[] array = value as byte[];
     if (array == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(byte[]), value.GetType()));
     }
     writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array);
     MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, array.Length);
 }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        internal object GetMapiProperty(TnefPropertyTag tag)
        {
            this.ThrowIfDisposed();
            object mapiProperty;

            using (ThreadAccessGuard.EnterPublic(this.accessToken))
            {
                mapiProperty = this.message.GetMapiProperty(tag);
            }
            return(mapiProperty);
        }
Exemplo n.º 22
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));
        }
Exemplo n.º 23
0
 public StoragePropertyValue(TnefPropertyTag propertyTag, DataStorage storage, long start, long end)
 {
     if (storage != null)
     {
         storage.AddRef();
     }
     this.propertyTag = propertyTag;
     this.storage     = storage;
     this.start       = start;
     this.end         = end;
 }
Exemplo n.º 24
0
        private static void InternalWriteString(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, string value)
        {
            MsgSubStorageWriter.WriterBuffer valueBuffer = writer.ValueBuffer;
            int unicodeByteCount = Util.GetUnicodeByteCount(value);

            byte[] array = valueBuffer.PreallocateBuffer(unicodeByteCount);
            int    num   = Util.StringToUnicodeBytes(value, array);

            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array, num);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, num);
        }
Exemplo n.º 25
0
        private static void WriteBoolean(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            bool?flag = value as bool?;

            if (flag == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(bool), value.GetType()));
            }
            short propertyValue = flag.Value ? 1 : 0;

            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, propertyValue);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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);
 }
Exemplo n.º 28
0
        private static void WriteGuid(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            Guid?guid = value as Guid?;

            if (guid == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(Guid), value.GetType()));
            }
            byte[] array = guid.Value.ToByteArray();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, array.Length);
        }
Exemplo n.º 29
0
 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());
     });
 }
Exemplo n.º 30
0
        private static void WriteArray(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, int arrayLength, MsgStorageRulesTable.WriteValueDelegate writeValue)
        {
            MsgSubStorageWriter.WriterBuffer valueBuffer = writer.ValueBuffer;
            for (int num = 0; num != arrayLength; num++)
            {
                writeValue(valueBuffer.Writer, num);
            }
            int length = valueBuffer.GetLength();

            byte[] buffer = valueBuffer.GetBuffer();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), buffer, length);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, length);
        }