Пример #1
0
        private int GetIndex(TnefNameId nameId)
        {
            TnefNameTag key = new TnefNameTag(nameId, TnefPropertyType.Null);
            int         result;

            this.supportedNamedProperties.TryGetValue(key, out result);
            return(result);
        }
Пример #2
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));
        }
Пример #3
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);
        }
Пример #4
0
        public bool TryGetValue(TnefPropertyId propertyId, out TnefNameId namedId)
        {
            TnefNameIdWrapper tnefNameIdWrapper = null;

            if (!this.idToName.TryGetValue(propertyId, out tnefNameIdWrapper))
            {
                namedId = default(TnefNameId);
                return(false);
            }
            namedId = tnefNameIdWrapper.TnefNameId;
            return(true);
        }
Пример #5
0
        private bool TryAdd(TnefPropertyId id, TnefNameId namedProperty)
        {
            TnefNameIdWrapper tnefNameIdWrapper;

            if (this.idToName.TryGetValue(id, out tnefNameIdWrapper))
            {
                return(false);
            }
            tnefNameIdWrapper = new TnefNameIdWrapper(namedProperty);
            this.idToName[id] = tnefNameIdWrapper;
            this.nameToId[tnefNameIdWrapper] = id;
            return(true);
        }
Пример #6
0
 internal object this[TnefNameId nameId]
 {
     get
     {
         return(this[this.GetIndex(nameId)]);
     }
     set
     {
         if (this[nameId] != value)
         {
             this.SetDirty();
             this.Touch(nameId);
         }
         this[this.GetIndex(nameId)] = value;
     }
 }
Пример #7
0
        public TnefPropertyId Add(TnefNameId namedProperty)
        {
            if (!this.canModify)
            {
                throw new InvalidOperationException("Cannot modify the property list");
            }
            TnefNameIdWrapper tnefNameIdWrapper = new TnefNameIdWrapper(namedProperty);
            TnefPropertyId    tnefPropertyId;

            if (!this.nameToId.TryGetValue(tnefNameIdWrapper, out tnefPropertyId))
            {
                tnefPropertyId = (TnefPropertyId)(this.lastPropertyId++);
                this.idToName.Add(tnefPropertyId, tnefNameIdWrapper);
                this.nameToId.Add(tnefNameIdWrapper, tnefPropertyId);
            }
            return(tnefPropertyId);
        }
Пример #8
0
 internal static void WriteUnicodeProperty(TnefWriter writer, TnefPropertyReader propertyReader, TnefPropertyTag tag, ref char[] buffer)
 {
     if (tag.IsNamed)
     {
         TnefNameId propertyNameId = propertyReader.PropertyNameId;
         writer.StartProperty(tag, propertyNameId.PropertySetGuid, propertyNameId.Id);
     }
     else
     {
         writer.StartProperty(tag);
     }
     if (tag.IsMultiValued)
     {
         while (propertyReader.ReadNextValue())
         {
             writer.StartPropertyValue();
             TnefPropertyBag.WriteUnicodePropertyValue(writer, propertyReader, ref buffer);
         }
         return;
     }
     TnefPropertyBag.WriteUnicodePropertyValue(writer, propertyReader, ref buffer);
 }
Пример #9
0
        private void LoadProperty(TnefPropertyReader propertyReader, DataStorage tnefStorage, long tnefStart, long tnefEnd, TnefAttributeLevel level, int embeddingDepth, Charset binaryCharset)
        {
            TnefPropertyTag propertyTag = propertyReader.PropertyTag;

            if (propertyTag.IsMultiValued)
            {
                return;
            }
            if (TnefPropertyType.Null == propertyTag.ValueTnefType)
            {
                return;
            }
            if (propertyReader.IsNamedProperty)
            {
                TnefNameId  propertyNameId = propertyReader.PropertyNameId;
                TnefNameTag key            = new TnefNameTag(propertyNameId, propertyTag.ValueTnefType);
                if (this.supportedNamedProperties.ContainsKey(key))
                {
                    if (propertyReader.IsLargeValue)
                    {
                        return;
                    }
                    this[this.GetIndex(propertyNameId)] = propertyReader.ReadValue();
                }
                return;
            }
            if (!this.supportedProperties.ContainsKey(propertyTag))
            {
                return;
            }
            TnefPropertyId id    = propertyTag.Id;
            int            index = this.GetIndex(id);

            if (TnefPropertyId.Body == id || TnefPropertyId.RtfCompressed == id || TnefPropertyId.BodyHtml == id)
            {
                tnefStart  += (long)propertyReader.RawValueStreamOffset;
                tnefEnd     = tnefStart + (long)propertyReader.RawValueLength;
                this[index] = new StoragePropertyValue(propertyTag, tnefStorage, tnefStart, tnefEnd);
                return;
            }
            if (TnefPropertyId.AttachData == id)
            {
                tnefStart  += (long)propertyReader.RawValueStreamOffset;
                tnefEnd     = tnefStart + (long)propertyReader.RawValueLength;
                this[index] = new StoragePropertyValue(propertyTag, tnefStorage, tnefStart, tnefEnd);
                if (!propertyReader.IsEmbeddedMessage)
                {
                    return;
                }
                if (++embeddingDepth > 100)
                {
                    throw new MimeException(EmailMessageStrings.NestingTooDeep(embeddingDepth, 100));
                }
                using (TnefReader embeddedMessageReader = propertyReader.GetEmbeddedMessageReader())
                {
                    PureTnefMessage pureTnefMessage = new PureTnefMessage(this.attachmentData, tnefStorage, tnefStart, tnefEnd);
                    pureTnefMessage.Load(embeddedMessageReader, embeddingDepth, binaryCharset);
                    EmailMessage embeddedMessage = new EmailMessage(pureTnefMessage);
                    this.attachmentData.EmbeddedMessage = embeddedMessage;
                    return;
                }
            }
            if (propertyReader.IsLargeValue)
            {
                return;
            }
            if (TnefPropertyId.InternetCPID == id)
            {
                if (TnefPropertyType.Long == propertyTag.TnefType)
                {
                    int num = propertyReader.ReadValueAsInt32();
                    this[index] = num;
                    return;
                }
            }
            else
            {
                this[index] = propertyReader.ReadValue();
            }
        }
Пример #10
0
        internal bool Write(TnefReader reader, TnefWriter writer, TnefAttributeLevel level, bool dropRecipientTable, bool forceUnicode, byte[] scratchBuffer)
        {
            IDictionary <TnefPropertyTag, object> dictionary = null;

            char[] array = null;
            bool   result;

            for (;;)
            {
                TnefPropertyReader propertyReader = reader.PropertyReader;
                if (0 >= propertyReader.PropertyCount)
                {
                    goto IL_37A;
                }
                TnefAttributeTag   attributeTag   = reader.AttributeTag;
                TnefAttributeLevel attributeLevel = reader.AttributeLevel;
                bool flag = true;
                while (propertyReader.ReadNextProperty())
                {
                    TnefPropertyTag propertyTag = propertyReader.PropertyTag;
                    if (TnefPropertyType.Null != propertyTag.ValueTnefType)
                    {
                        if (propertyReader.IsNamedProperty)
                        {
                            TnefNameId  propertyNameId = propertyReader.PropertyNameId;
                            TnefNameTag key            = new TnefNameTag(propertyNameId, propertyTag.ValueTnefType);
                            int         num;
                            if (this.supportedNamedProperties.TryGetValue(key, out num) && this.properties[num].IsDirty)
                            {
                                object obj = this[propertyNameId];
                                if (obj != null)
                                {
                                    TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref flag);
                                    writer.StartProperty(propertyTag, propertyNameId.PropertySetGuid, propertyNameId.Id);
                                    writer.WritePropertyValue(obj);
                                    continue;
                                }
                                continue;
                            }
                        }
                        else
                        {
                            TnefPropertyId id = propertyTag.Id;
                            int            num2;
                            if (this.supportedProperties.TryGetValue(propertyTag, out num2) && this.properties[num2].IsDirty && (this.attachmentData == null || this.attachmentData.EmbeddedMessage == null || TnefAttributeLevel.Attachment != level || TnefAttributeTag.AttachData != attributeTag || TnefPropertyId.AttachData != id))
                            {
                                object obj = this[id];
                                if (obj == null)
                                {
                                    continue;
                                }
                                if (!this.WriteModifiedProperty(writer, reader, propertyTag, obj, forceUnicode, ref flag, scratchBuffer))
                                {
                                    if (dictionary == null)
                                    {
                                        dictionary = new Dictionary <TnefPropertyTag, object>(TnefPropertyBag.PropertyTagComparer);
                                    }
                                    if (!dictionary.ContainsKey(propertyTag))
                                    {
                                        dictionary.Add(propertyTag, obj);
                                        continue;
                                    }
                                    continue;
                                }
                                else
                                {
                                    if (dictionary != null && dictionary.ContainsKey(propertyTag))
                                    {
                                        dictionary.Remove(propertyTag);
                                        continue;
                                    }
                                    continue;
                                }
                            }
                        }
                        if (propertyTag.ValueTnefType == TnefPropertyType.String8 && forceUnicode)
                        {
                            if (!TnefPropertyBag.IsLegacyAttribute(attributeTag))
                            {
                                TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref flag);
                                TnefPropertyBag.WriteUnicodeProperty(writer, propertyReader, propertyTag.ToUnicode(), ref array);
                            }
                        }
                        else if (propertyTag.IsTnefTypeValid)
                        {
                            TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref flag);
                            writer.WriteProperty(propertyReader);
                        }
                    }
                }
                if ((TnefAttributeTag.MapiProperties == attributeTag && level == TnefAttributeLevel.Message) || (TnefAttributeTag.Attachment == attributeTag && level == TnefAttributeLevel.Attachment))
                {
                    if (this.newProperties != null)
                    {
                        foreach (KeyValuePair <TnefPropertyTag, object> keyValuePair in this.newProperties)
                        {
                            object obj = keyValuePair.Value;
                            if (obj != null)
                            {
                                this.WriteModifiedProperty(writer, reader, keyValuePair.Key, obj, forceUnicode, ref flag, scratchBuffer);
                            }
                        }
                    }
                    if (dictionary != null)
                    {
                        foreach (KeyValuePair <TnefPropertyTag, object> keyValuePair2 in dictionary)
                        {
                            this.WriteModifiedProperty(writer, reader, keyValuePair2.Key, keyValuePair2.Value, forceUnicode, ref flag, scratchBuffer);
                        }
                    }
                    if (this.newNamedProperties != null)
                    {
                        using (IEnumerator <KeyValuePair <TnefNameTag, object> > enumerator3 = this.newNamedProperties.GetEnumerator())
                        {
                            while (enumerator3.MoveNext())
                            {
                                KeyValuePair <TnefNameTag, object> keyValuePair3 = enumerator3.Current;
                                object obj = keyValuePair3.Value;
                                if (obj != null)
                                {
                                    TnefPropertyTag tag = new TnefPropertyTag((TnefPropertyId)(-32768), keyValuePair3.Key.Type);
                                    if (forceUnicode)
                                    {
                                        tag = tag.ToUnicode();
                                    }
                                    TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref flag);
                                    writer.StartProperty(tag, keyValuePair3.Key.Id.PropertySetGuid, keyValuePair3.Key.Id.Id);
                                    writer.WritePropertyValue(obj);
                                }
                            }
                            goto IL_3AC;
                        }
                        goto IL_37A;
                    }
                }
IL_3AC:
                if (!(result = reader.ReadNextAttribute()) || level != reader.AttributeLevel || TnefAttributeTag.AttachRenderData == reader.AttributeTag)
                {
                    break;
                }
                continue;
IL_37A:
                if (level != TnefAttributeLevel.Message || TnefAttributeTag.RecipientTable != reader.AttributeTag)
                {
                    writer.WriteAttribute(reader);
                    goto IL_3AC;
                }
                if (!dropRecipientTable)
                {
                    this.parentMessage.WriteRecipients(reader.PropertyReader, writer, ref array);
                    goto IL_3AC;
                }
                goto IL_3AC;
            }
            return(result);
        }
Пример #11
0
 private void Touch(TnefNameId nameId)
 {
     this.Touch(this.GetIndex(nameId));
 }
Пример #12
0
 public TnefNameIdWrapper(TnefNameId nameId)
 {
     this.nameId = nameId;
     this.ComputeHashCode();
 }
Пример #13
0
        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);
        }
Пример #14
0
 public TnefNameTag(TnefNameId id, TnefPropertyType type)
 {
     this.id   = id;
     this.type = type;
 }