Пример #1
0
 private object this[int index]
 {
     get
     {
         return(this.properties[index].Value);
     }
     set
     {
         StoragePropertyValue storagePropertyValue = this.properties[index].Value as StoragePropertyValue;
         if (storagePropertyValue != null)
         {
             storagePropertyValue.DisposeStorage();
         }
         this.properties[index].Value = value;
     }
 }
Пример #2
0
 internal void Dispose()
 {
     foreach (TnefPropertyBag.PropertyData propertyData in this.properties)
     {
         StoragePropertyValue storagePropertyValue = propertyData.Value as StoragePropertyValue;
         if (storagePropertyValue != null)
         {
             storagePropertyValue.DisposeStorage();
         }
     }
     if (this.newProperties != null)
     {
         foreach (KeyValuePair <TnefPropertyTag, object> keyValuePair in this.newProperties)
         {
             StoragePropertyValue storagePropertyValue2 = keyValuePair.Value as StoragePropertyValue;
             if (storagePropertyValue2 != null)
             {
                 storagePropertyValue2.DisposeStorage();
             }
         }
         this.newProperties = null;
     }
     this.newNamedProperties = null;
 }
Пример #3
0
        private bool WriteModifiedProperty(TnefWriter writer, TnefReader reader, TnefPropertyTag propertyTag, object value, bool forceUnicode, ref bool startAttribute, byte[] scratchBuffer)
        {
            TnefPropertyReader   propertyReader       = reader.PropertyReader;
            TnefAttributeTag     attributeTag         = reader.AttributeTag;
            TnefAttributeLevel   attributeLevel       = reader.AttributeLevel;
            StoragePropertyValue storagePropertyValue = value as StoragePropertyValue;

            if (storagePropertyValue != null)
            {
                if (this.attachmentData != null && this.attachmentData.EmbeddedMessage != null && propertyReader.IsEmbeddedMessage)
                {
                    using (TnefReader embeddedMessageReader = propertyReader.GetEmbeddedMessageReader())
                    {
                        TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref startAttribute);
                        writer.StartProperty(propertyTag);
                        EmailMessage    embeddedMessage = this.attachmentData.EmbeddedMessage;
                        PureTnefMessage pureTnefMessage = embeddedMessage.PureTnefMessage;
                        Charset         textCharset     = pureTnefMessage.TextCharset;
                        using (TnefWriter embeddedMessageWriter = writer.GetEmbeddedMessageWriter(textCharset.CodePage))
                        {
                            pureTnefMessage.WriteMessage(embeddedMessageReader, embeddedMessageWriter, scratchBuffer);
                        }
                        return(true);
                    }
                }
                using (Stream readStream = storagePropertyValue.GetReadStream())
                {
                    int num = readStream.Read(scratchBuffer, 0, scratchBuffer.Length);
                    if (num > 0)
                    {
                        propertyTag = storagePropertyValue.PropertyTag;
                        if (propertyTag.ValueTnefType == TnefPropertyType.Unicode && TnefPropertyBag.IsLegacyAttribute(attributeTag))
                        {
                            return(false);
                        }
                        TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref startAttribute);
                        writer.StartProperty(propertyTag);
                        do
                        {
                            writer.WritePropertyRawValue(scratchBuffer, 0, num);
                            num = readStream.Read(scratchBuffer, 0, scratchBuffer.Length);
                        }while (num > 0);
                    }
                    return(true);
                }
            }
            if (propertyTag.ValueTnefType == TnefPropertyType.String8 && forceUnicode)
            {
                if (TnefPropertyBag.IsLegacyAttribute(attributeTag))
                {
                    return(false);
                }
                TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref startAttribute);
                writer.WriteProperty(propertyTag.ToUnicode(), value);
            }
            else
            {
                TnefPropertyBag.StartAttributeIfNecessary(writer, attributeTag, attributeLevel, ref startAttribute);
                writer.WriteProperty(propertyTag, value);
            }
            return(true);
        }
Пример #4
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();
            }
        }