public void changeBodyOfTnef(MimePart tnefPart, SchedulingInfo schedulingInfo) { TnefReader tnefreader = new TnefReader(tnefPart.GetContentReadStream(), 0, TnefComplianceMode.Loose); while (tnefreader.ReadNextAttribute()) { if (tnefreader.AttributeTag != TnefAttributeTag.MapiProperties) continue; string dialingInfo = schedulingInfo.dialingInfo; TnefWriter writer = new TnefWriter( tnefPart.GetContentWriteStream(tnefPart.ContentTransferEncoding), tnefreader.AttachmentKey, 0, TnefWriterFlags.NoStandardAttributes); writer.StartAttribute(TnefAttributeTag.MapiProperties, TnefAttributeLevel.Message); writer.WriteAllProperties(tnefreader.PropertyReader); writer.StartProperty(TnefPropertyTag.RtfCompressed); if (null != dialingInfo) { dialingInfo = convertToUnicode(dialingInfo); } string body = null == dialingInfo ? schedulingInfo.emailMessage : schedulingInfo.emailMessage + "<br><br>" + dialingInfo; Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(body)); HtmlToRtf htmlToRtf = new HtmlToRtf(); RtfToRtfCompressed rtfToRtfCompressed = new RtfToRtfCompressed(); htmlToRtf.InputEncoding = System.Text.Encoding.UTF8;//GetEncoding("ISO-8859-1"); stream = new ConverterStream(stream, htmlToRtf, ConverterStreamAccess.Read); stream = new ConverterStream(stream, rtfToRtfCompressed, ConverterStreamAccess.Read); writer.WritePropertyValue(stream); if (null != writer) { writer.Close(); } } tnefreader.Close(); RvLogger.DebugWrite("ok**************************************"); }
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); }
internal void ProcessMailItem(MailItem item) { bool isPropertySet = false; int tag; unchecked { tag = (int)0x8000000B; } try { MimePart tnefPart = item.Message.TnefPart; if (tnefPart != null) { TnefReader reader = new TnefReader(tnefPart.GetContentReadStream()); TnefWriter writer = new TnefWriter( tnefPart.GetContentWriteStream(tnefPart.ContentTransferEncoding), reader.AttachmentKey); while (reader.ReadNextAttribute()) { if (reader.AttributeTag == TnefAttributeTag.MapiProperties) { writer.StartAttribute(TnefAttributeTag.MapiProperties, TnefAttributeLevel.Message); while (reader.PropertyReader.ReadNextProperty()) { if (reader.PropertyReader.IsNamedProperty) { switch (reader.PropertyReader.PropertyNameId.Name) { case PropertyTagName: isPropertySet = true; writer.StartProperty(new TnefPropertyTag(tag), PsPublicStrings, PropertyTagName); writer.WritePropertyValue(true); break; default: writer.WriteProperty(reader.PropertyReader); break; } } else { writer.WriteProperty(reader.PropertyReader); } } if (!isPropertySet) { writer.StartProperty(new TnefPropertyTag(tag), PsPublicStrings, PropertyTagName); writer.WritePropertyValue(true); } } else { writer.WriteAttribute(reader); } } if (null != writer) { writer.Close(); } } else { WriteLog("Attempted to process item with null TnefPart. Subject: " + item.Message.Subject, EventLogEntryType.Warning, 2000, EventLogSource); } } catch (Exception ex) { WriteLog(ex.Message + ". Stack Trace: " + ex.StackTrace, EventLogEntryType.Error, 5000, EventLogSource); } }