private long WriteAttachmentProperties(Attachment attachment) { long result = 0L; this.tnefWriter.StartAttribute(TnefAttributeTag.Attachment, TnefAttributeLevel.Attachment); foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in attachment.AllNativeProperties) { if (nativeStorePropertyDefinition.Equals(InternalSchema.AttachDataObj)) { result = this.WriteAttachDataObj(attachment); } else if (!nativeStorePropertyDefinition.Equals(InternalSchema.AttachDataBin) && this.propertyChecker.IsAttachmentPropertyWritable(nativeStorePropertyDefinition)) { object obj = attachment.TryGetProperty(nativeStorePropertyDefinition); PropertyError propertyError = obj as PropertyError; if (propertyError != null && PropertyError.IsPropertyValueTooBig(propertyError)) { this.WritePropertyStreamData(attachment.PropertyBag, nativeStorePropertyDefinition); } else if (propertyError == null) { obj = ExTimeZoneHelperForMigrationOnly.ToLegacyUtcIfDateTime(obj); this.tnefWriter.WriteProperty(nativeStorePropertyDefinition, obj); } } } ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { result = this.WriteAttachedItem(itemAttachment); } return(result); }
private long WriteAttachment(Item item, Attachment attachment) { this.limitsTracker.CountMessageAttachment(); this.WriteAttachmentAttributes(attachment); long result = 0L; StreamAttachment streamAttachment = attachment as StreamAttachment; if (streamAttachment != null) { using (Stream stream = this.tnefWriter.OpenAttributeStream(TnefAttributeTag.AttachData, TnefAttributeLevel.Attachment)) { object obj = attachment.TryGetProperty(InternalSchema.AttachDataBin); PropertyError propertyError = obj as PropertyError; if (propertyError != null) { using (Stream stream2 = streamAttachment.TryGetRawContentStream(PropertyOpenMode.ReadOnly)) { if (stream2 != null) { result = Util.StreamHandler.CopyStreamData(stream2, stream); } goto IL_88; } } byte[] array = (byte[])obj; result = (long)array.Length; stream.Write(array, 0, array.Length); IL_88 :; } } this.WriteAttachmentProperties(attachment); return(result); }
private void WriteAttachmentAttributes(Attachment attachment) { this.tnefWriter.StartAttribute(TnefAttributeTag.AttachRenderData, TnefAttributeLevel.Attachment); object obj = attachment.TryGetProperty(InternalSchema.AttachMethod); if (obj is PropertyError) { StorageGlobals.ContextTraceError <string>(ExTraceGlobals.CcOutboundTnefTracer, "ItemToTnefConverter::WriteAttachmentAttributes: unable to get attach method, {0}.", ((PropertyError)obj).PropertyErrorDescription); throw new ConversionFailedException(ConversionFailureReason.CorruptContent); } this.tnefWriter.WriteProperty(TnefPropertyTag.AttachMethod, (int)obj); obj = attachment.TryGetProperty(InternalSchema.RenderingPosition); if (obj is PropertyError) { obj = -1; } this.tnefWriter.WriteProperty(TnefPropertyTag.RenderingPosition, (int)obj); obj = attachment.TryGetProperty(InternalSchema.AttachEncoding); if (!(obj is PropertyError)) { this.tnefWriter.WriteProperty(TnefPropertyTag.AttachEncoding, (byte[])obj); } this.tnefWriter.StartAttribute(TnefAttributeTag.AttachTitle, TnefAttributeLevel.Attachment); this.tnefWriter.WriteProperty(TnefPropertyTag.AttachFilenameA, attachment.DisplayName ?? string.Empty); this.tnefWriter.StartAttribute(TnefAttributeTag.AttachCreateDate, TnefAttributeLevel.Attachment); this.tnefWriter.WriteProperty(TnefPropertyTag.CreationTime, attachment.CreationTime); this.tnefWriter.StartAttribute(TnefAttributeTag.AttachModifyDate, TnefAttributeLevel.Attachment); this.tnefWriter.WriteProperty(TnefPropertyTag.LastModificationTime, attachment.LastModifiedTime); object obj2 = attachment.TryGetProperty(InternalSchema.AttachRendering); if (!(obj2 is PropertyError)) { this.tnefWriter.StartAttribute(TnefAttributeTag.AttachMetaFile, TnefAttributeLevel.Attachment); this.tnefWriter.WriteProperty(TnefPropertyTag.AttachRendering, obj2); } }