private static TextWriter CreateTextWriter(IItem item, BodyType type, bool update, out HtmlUpdateBodyCallback htmlUpdateBodyCallback) { Body body = IrmUtils.GetBody(item); BodyWriteConfiguration bodyWriteConfiguration = new BodyWriteConfiguration(type.ToStorageType()); if (update && type == BodyType.Html) { htmlUpdateBodyCallback = new HtmlUpdateBodyCallback(item); bodyWriteConfiguration.SetHtmlOptions(HtmlStreamingFlags.None, htmlUpdateBodyCallback); return(body.OpenTextWriter(bodyWriteConfiguration)); } htmlUpdateBodyCallback = null; return(body.OpenTextWriter(bodyWriteConfiguration)); }
internal static ItemBody GetEntityBody(this IItem input, char[] buffer) { Body body; BodyType bodyType; try { body = IrmUtils.GetBody(input); BodyFormat format = body.Format; bodyType = format.ToEntityType(); } catch (PropertyErrorException ex) { ExTraceGlobals.CommonTracer.TraceDebug <string, string>(0L, "[BodyConverter::GetEntityBody] Encountered exception - Class: {0}; Message: {1}", ex.GetType().FullName, ex.Message); throw new CorruptDataException(Strings.ErrorItemCorrupt, ex); } catch (StoragePermanentException ex2) { if (ex2.InnerException is MapiExceptionNoSupport) { throw new CorruptDataException(Strings.ErrorItemCorrupt, ex2); } ExTraceGlobals.CommonTracer.TraceDebug(0L, "[BodyConverter::GetEntityBody] Encountered exception - Class: {0}, Message: {1} Inner exception was not MapiExceptionNoSupport but rather Class: {2}; Message: {3}", new object[] { ex2.GetType().FullName, ex2.Message, (ex2.InnerException == null) ? "<NULL>" : ex2.InnerException.GetType().FullName, (ex2.InnerException == null) ? "<NULL>" : ex2.InnerException.Message }); throw; } ItemBody itemBody = new ItemBody { ContentType = bodyType }; using (TextWriter textWriter = new StringWriter()) { if (bodyType == BodyType.Html) { BodyConverter.WriteHtmlContent(textWriter, input, buffer); } else { BodyConverter.WriteTextContent(textWriter, body, buffer); } itemBody.Content = textWriter.ToString(); } return(itemBody); }
public void FromLeftToRightType(TStorageItem left, TItem right) { List <IAttachment> list = new List <IAttachment>(); AttachmentCollection attachmentCollection = IrmUtils.GetAttachmentCollection(left); IList <AttachmentHandle> handles = attachmentCollection.GetHandles(); foreach (AttachmentHandle handle in handles) { using (Attachment attachment = attachmentCollection.Open(handle)) { IAttachment item = this.AttachmentConverter.Convert(attachment); list.Add(item); } } right.Attachments = list; }
private static void WriteHtmlContent(TextWriter writer, IItem item, char[] charBuffer) { BodyReadConfiguration bodyReadConfiguration = new BodyReadConfiguration(BodyFormat.TextHtml, "utf-8"); bodyReadConfiguration.HtmlFlags &= ~HtmlStreamingFlags.FilterHtml; item.Load(StoreObjectSchema.ContentConversionProperties); bodyReadConfiguration.ConversionCallback = new DefaultHtmlCallbacks(item, true); Body body = IrmUtils.GetBody(item); using (Stream stream = body.OpenReadStream(bodyReadConfiguration)) { using (StreamReader streamReader = new StreamReader(stream, Encoding.UTF8)) { BodyConverter.CopyContent(streamReader, writer, charBuffer); } } }
// Token: 0x0600010E RID: 270 RVA: 0x00004984 File Offset: 0x00002B84 public Stream GetAllAttachmentsAsZipStream(AttachmentHandler.IAttachmentRetriever attachmentRetriever) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "AttachmentHandler.GetAttachmentStream: Getting attachment stream for id={0}", this.id); if (string.IsNullOrEmpty(this.id)) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug((long)this.GetHashCode(), "Item id is empty or null. returning null stream."); throw new FaultException("Id cannot be null or empty."); } Item rootItem = attachmentRetriever.RootItem; if (rootItem is ReportMessage || ObjectClass.IsSmsMessage(rootItem.ClassName)) { return(null); } Stream stream = null; Stream result; try { AttachmentHandler.IAttachmentPolicyChecker attachmentPolicyChecker = AttachmentPolicyChecker.CreateInstance(this.configurationContext.AttachmentPolicy); AttachmentCollection attachmentCollection = IrmUtils.GetAttachmentCollection(rootItem); BlockStatus itemBlockStatus = AttachmentHandler.GetItemBlockStatus(rootItem); string subject = AttachmentHandler.GetSubject(rootItem); ZipFileAttachments zipFileAttachments = new ZipFileAttachments(itemBlockStatus, subject); foreach (AttachmentHandle handle in attachmentCollection) { using (Attachment attachment = attachmentCollection.Open(handle)) { if (attachment is OleAttachment || attachment.IsInline || attachment is ReferenceAttachment) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "Attachment is inline, an ole image, or a reference attachment. Do not add to zip file. id is {0}", attachment.Id.ToString()); } else { AttachmentPolicyLevel policy = attachmentPolicyChecker.GetPolicy(attachment, this.webOperationContext.IsPublicLogon); if (this.IsBlocked(policy)) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug <string>((long)this.GetHashCode(), "Attachment is blocked. Do not add to zip file. id is {0}", attachment.Id.ToString()); } else { zipFileAttachments.AddAttachmentToZip(attachment, policy, this.configurationContext); } } } } if (zipFileAttachments.Count == 0) { ExTraceGlobals.AttachmentHandlingTracer.TraceDebug((long)this.GetHashCode(), "AttachmentHandler.GetAllAttachmentsAsZipStream: No attachments returned for item"); result = null; } else { IRecipientSession adrecipientSession = rootItem.Session.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid); OutboundConversionOptions outboundConversionOptions = new OutboundConversionOptions(this.callContext.DefaultDomain.DomainName.Domain); outboundConversionOptions.ClearCategories = false; outboundConversionOptions.UserADSession = adrecipientSession; outboundConversionOptions.LoadPerOrganizationCharsetDetectionOptions(adrecipientSession.SessionSettings.CurrentOrganizationId); stream = zipFileAttachments.WriteArchive(this.configurationContext, this.webOperationContext, outboundConversionOptions, attachmentCollection); stream.Seek(0L, SeekOrigin.Begin); result = stream; } } catch (Exception ex) { if (stream != null) { stream.Dispose(); } string formatString = string.Empty; if (ex is ExchangeDataException) { formatString = "Fail to sanitize HTML getting attachment. id is {0}, Exception: {1}"; } else if (ex is StoragePermanentException) { formatString = "StoragePermanentException when getting attachment. id is {0}, Exception: {1}"; } else { if (!(ex is StorageTransientException)) { throw; } formatString = "StorageTransientException when getting attachment. id is {0}, Exception: {1}"; } ExTraceGlobals.AttachmentHandlingTracer.TraceError <string, Exception>((long)this.GetHashCode(), formatString, this.id, ex); throw new CannotOpenFileAttachmentException(ex); } return(result); }