private static void StartAttributeIfNecessary(TnefWriter writer, TnefAttributeTag attributeTag, TnefAttributeLevel attributeLevel, ref bool startAttribute) { if (startAttribute) { writer.StartAttribute(attributeTag, attributeLevel); startAttribute = false; } }
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 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); } }