private static Dictionary <TnefPropertyTag, int> GetAttachmentProperties(ref int index) { Dictionary <TnefPropertyTag, int> dictionary = new Dictionary <TnefPropertyTag, int>(25, TnefPropertyBag.PropertyTagComparer); dictionary.Add(TnefPropertyTag.AttachDataBin, index); dictionary.Add(TnefPropertyTag.AttachDataObj, index++); dictionary.Add(TnefPropertyTag.AttachMethod, index++); dictionary.Add(TnefPropertyTag.AttachLongFilenameA, index); dictionary.Add(TnefPropertyTag.AttachLongFilenameW, index++); dictionary.Add(TnefPropertyTag.AttachFilenameA, index); dictionary.Add(TnefPropertyTag.AttachFilenameW, index++); dictionary.Add(TnefPropertyTag.AttachExtensionA, index); dictionary.Add(TnefPropertyTag.AttachExtensionW, index++); dictionary.Add(TnefPropertyTag.DisplayNameA, index); dictionary.Add(TnefPropertyTag.DisplayNameW, index++); dictionary.Add(TnefPropertyTag.AttachTransportNameA, index); dictionary.Add(TnefPropertyTag.AttachTransportNameW, index++); dictionary.Add(TnefPropertyTag.AttachPathnameA, index); dictionary.Add(TnefPropertyTag.AttachPathnameW, index++); dictionary.Add(TnefPropertyTag.AttachMimeTagA, index); dictionary.Add(TnefPropertyTag.AttachMimeTagW, index++); dictionary.Add(TnefPropertyTag.RenderingPosition, index++); dictionary.Add(TnefPropertyTag.AttachRendering, index++); dictionary.Add(TnefPropertyTag.AttachContentIdA, index++); dictionary.Add(TnefPropertyTag.AttachContentIdW, index++); dictionary.Add(TnefPropertyTag.AttachContentLocationA, index++); dictionary.Add(TnefPropertyTag.AttachContentLocationW, index++); dictionary.Add(TnefPropertyTag.AttachmentFlags, index++); dictionary.Add(TnefPropertyTag.AttachHidden, index++); TnefPropertyBag.AddLookupEntries(dictionary); return(dictionary); }
internal static AttachmentMethod GetAttachmentMethod(TnefPropertyBag properties) { AttachmentMethod result = AttachmentMethod.AttachByValue; object obj = properties[TnefPropertyId.AttachMethod]; if (obj is int) { result = (AttachmentMethod)((int)obj); } return(result); }
static TnefPropertyBag() { int num = 0; TnefPropertyBag.MessageProperties = TnefPropertyBag.GetMessageProperties(ref num); TnefPropertyBag.NamedMessageProperties = TnefPropertyBag.GetNamedMessageProperties(ref num); TnefPropertyBag.MessagePropertyCount = num; num = 0; TnefPropertyBag.AttachmentProperties = TnefPropertyBag.GetAttachmentProperties(ref num); TnefPropertyBag.NamedAttachmentProperties = new Dictionary <TnefNameTag, int>(0, TnefPropertyBag.NameTagComparer); TnefPropertyBag.AttachmentPropertyCount = num; }
private static Dictionary <TnefNameTag, int> GetNamedMessageProperties(ref int index) { Dictionary <TnefNameTag, int> dictionary = new Dictionary <TnefNameTag, int>(9, TnefPropertyBag.NameTagComparer); dictionary.Add(TnefPropertyBag.TnefNameTagIsClassified, index++); dictionary.Add(TnefPropertyBag.TnefNameTagClassification, index++); dictionary.Add(TnefPropertyBag.TnefNameTagClassificationDescription, index++); dictionary.Add(TnefPropertyBag.TnefNameTagClassificationGuid, index++); dictionary.Add(TnefPropertyBag.TnefNameTagClassificationKeep, index++); dictionary.Add(TnefPropertyBag.TnefNameTagContentTypeA, index); dictionary.Add(TnefPropertyBag.TnefNameTagContentTypeW, index++); dictionary.Add(TnefPropertyBag.TnefNameTagContentClassA, index); dictionary.Add(TnefPropertyBag.TnefNameTagContentClassW, index++); TnefPropertyBag.AddNamedLookupEntries(dictionary); return(dictionary); }
internal static string GetRawFileName(TnefPropertyBag properties, bool stnef) { AttachmentMethod attachmentMethod = Utility.GetAttachmentMethod(properties); if (attachmentMethod == AttachmentMethod.EmbeddedMessage) { return(properties.GetProperty(TnefPropertyTag.DisplayNameA, stnef) as string); } string text = properties.GetProperty(TnefPropertyTag.AttachLongFilenameA, stnef) as string; if (string.IsNullOrEmpty(text)) { text = (properties.GetProperty(TnefPropertyTag.AttachFilenameA, stnef) as string); } return(text); }
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); }
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); }
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); }
private static Dictionary <TnefPropertyTag, int> GetMessageProperties(ref int index) { Dictionary <TnefPropertyTag, int> dictionary = new Dictionary <TnefPropertyTag, int>(61, TnefPropertyBag.PropertyTagComparer); dictionary.Add(TnefPropertyTag.TnefCorrelationKey, index++); dictionary.Add(TnefPropertyTag.MessageCodepage, index++); dictionary.Add(TnefPropertyTag.InternetCPID, index++); dictionary.Add(TnefPropertyTag.MessageLocaleID, index++); dictionary.Add(TnefPropertyTag.ContentIdentifierA, index); dictionary.Add(TnefPropertyTag.ContentIdentifierW, index++); dictionary.Add(TnefPropertyTag.ReadReceiptRequested, index++); dictionary.Add(TnefPropertyTag.ReadReceiptDisplayNameA, index); dictionary.Add(TnefPropertyTag.ReadReceiptDisplayNameW, index++); dictionary.Add(TnefPropertyTag.ReadReceiptEmailAddressA, index); dictionary.Add(TnefPropertyTag.ReadReceiptEmailAddressW, index++); dictionary.Add(TnefPropertyTag.ReadReceiptAddrtypeA, index); dictionary.Add(TnefPropertyTag.ReadReceiptAddrtypeW, index++); dictionary.Add(TnefPropertyTag.ReadReceiptSmtpAddressA, index); dictionary.Add(TnefPropertyTag.ReadReceiptSmtpAddressW, index++); dictionary.Add(TnefPropertyTag.ReadReceiptEntryId, index++); dictionary.Add(TnefPropertyTag.SenderNameA, index); dictionary.Add(TnefPropertyTag.SenderNameW, index++); dictionary.Add(TnefPropertyTag.SenderEmailAddressA, index); dictionary.Add(TnefPropertyTag.SenderEmailAddressW, index++); dictionary.Add(TnefPropertyTag.SenderAddrtypeA, index); dictionary.Add(TnefPropertyTag.SenderAddrtypeW, index++); dictionary.Add(TnefPropertyTag.SenderEntryId, index++); dictionary.Add(TnefPropertyTag.SentRepresentingNameA, index); dictionary.Add(TnefPropertyTag.SentRepresentingNameW, index++); dictionary.Add(TnefPropertyTag.SentRepresentingEmailAddressA, index); dictionary.Add(TnefPropertyTag.SentRepresentingEmailAddressW, index++); dictionary.Add(TnefPropertyTag.SentRepresentingAddrtypeA, index); dictionary.Add(TnefPropertyTag.SentRepresentingAddrtypeW, index++); dictionary.Add(TnefPropertyTag.SentRepresentingEntryId, index++); dictionary.Add(TnefPropertyTag.ClientSubmitTime, index++); dictionary.Add(TnefPropertyTag.LastModificationTime, index++); dictionary.Add(TnefPropertyTag.ExpiryTime, index++); dictionary.Add(TnefPropertyTag.ReplyTime, index++); dictionary.Add(TnefPropertyTag.SubjectA, index); dictionary.Add(TnefPropertyTag.SubjectW, index++); dictionary.Add(TnefPropertyTag.NormalizedSubjectA, index); dictionary.Add(TnefPropertyTag.NormalizedSubjectW, index++); dictionary.Add(TnefPropertyTag.SubjectPrefixA, index); dictionary.Add(TnefPropertyTag.SubjectPrefixW, index++); dictionary.Add(TnefPropertyTag.ConversationTopicA, index); dictionary.Add(TnefPropertyTag.ConversationTopicW, index++); dictionary.Add(TnefPropertyTag.InternetMessageIdA, index); dictionary.Add(TnefPropertyTag.InternetMessageIdW, index++); dictionary.Add(TnefPropertyTag.Importance, index++); dictionary.Add(TnefPropertyTag.Priority, index++); dictionary.Add(TnefPropertyTag.Sensitivity, index++); dictionary.Add(TnefPropertyTag.MessageClassA, index); dictionary.Add(TnefPropertyTag.MessageClassW, index++); dictionary.Add(new TnefPropertyTag(TnefPropertyId.Body, TnefPropertyType.Binary), index); dictionary.Add(TnefPropertyTag.BodyA, index); dictionary.Add(TnefPropertyTag.BodyW, index++); dictionary.Add(TnefPropertyTag.RtfCompressed, index++); dictionary.Add(TnefPropertyTag.BodyHtmlB, index); dictionary.Add(TnefPropertyTag.BodyHtmlA, index); dictionary.Add(TnefPropertyTag.BodyHtmlW, index++); dictionary.Add(TnefPropertyTag.SendRecallReport, index++); dictionary.Add(TnefPropertyTag.OofReplyType, index++); dictionary.Add(TnefPropertyTag.AutoForwarded, index++); dictionary.Add(TnefPropertyTag.INetMailOverrideFormat, index++); dictionary.Add(TnefPropertyTag.INetMailOverrideCharset, index++); TnefPropertyBag.AddLookupEntries(dictionary); return(dictionary); }