private static void CopyProtectableData(Body sourceBody, AttachmentCollection sourceAttachmentCollection, MessageItem targetItem) { if (sourceBody.IsBodyDefined) { using (Stream stream = sourceBody.OpenReadStream(new BodyReadConfiguration(sourceBody.Format, sourceBody.RawCharset.Name))) { using (Stream stream2 = targetItem.Body.OpenWriteStream(new BodyWriteConfiguration(sourceBody.Format, sourceBody.RawCharset))) { Util.StreamHandler.CopyStreamData(stream, stream2); } goto IL_6D; } } targetItem.DeleteProperties(Body.BodyProps); IL_6D: targetItem.AttachmentCollection.RemoveAll(); foreach (AttachmentHandle handle in sourceAttachmentCollection) { using (Attachment attachment = sourceAttachmentCollection.Open(handle)) { using (Attachment attachment2 = attachment.CreateCopy(targetItem.AttachmentCollection, new BodyFormat?(targetItem.Body.Format))) { attachment2.Save(); } } } }
private static List <RecurrenceManager.ExceptionSummary> GetExceptionSumaryList(AttachmentCollection attachments) { List <RecurrenceManager.ExceptionSummary> list = new List <RecurrenceManager.ExceptionSummary>(attachments.Count); foreach (AttachmentHandle handle in attachments.GetAllHandles()) { if (CoreAttachmentCollection.IsCalendarException(handle)) { using (Attachment attachment = attachments.Open(handle, null)) { ExDateTime?valueAsNullable = attachment.GetValueAsNullable <ExDateTime>(InternalSchema.AppointmentExceptionStartTime); if (valueAsNullable != null) { ExDateTime?valueAsNullable2 = attachment.GetValueAsNullable <ExDateTime>(InternalSchema.AppointmentExceptionEndTime); if (valueAsNullable2 != null) { ExDateTime utcStart = ExTimeZone.UtcTimeZone.ConvertDateTime(valueAsNullable.Value); ExDateTime utcEnd = ExTimeZone.UtcTimeZone.ConvertDateTime(valueAsNullable2.Value); list.Add(new RecurrenceManager.ExceptionSummary(handle, utcStart, utcEnd)); } } } } } return(list); }
protected void CopyAttachments(BodyConversionCallbacks callbacks, AttachmentCollection sourceCollection, AttachmentCollection targetCollection, bool copyInlinesOnly, bool targetIsPlainText, InboundConversionOptions optionsForSmime) { ReadOnlyCollection <AttachmentLink> readOnlyCollection = null; bool flag = true; if (callbacks.HtmlCallback != null && callbacks.HtmlCallback.AttachmentListInitialized) { readOnlyCollection = callbacks.HtmlCallback.AttachmentLinks; flag = (flag && callbacks.HtmlCallback.ClearInlineOnUnmarkedAttachments); } if (callbacks.RtfCallback != null && callbacks.RtfCallback.AttachmentListInitialized) { readOnlyCollection = callbacks.RtfCallback.AttachmentLinks; flag = (flag && callbacks.RtfCallback.ClearInlineOnUnmarkedAttachments); } if (readOnlyCollection == null) { if (copyInlinesOnly) { return; } using (IEnumerator <AttachmentHandle> enumerator = sourceCollection.GetEnumerator()) { while (enumerator.MoveNext()) { AttachmentHandle handle = enumerator.Current; using (Attachment attachment = sourceCollection.Open(handle, null)) { if (!attachment.IsCalendarException) { using (Attachment attachment2 = attachment.CreateCopy(targetCollection, new BodyFormat?(this.parameters.TargetFormat))) { attachment2.IsInline = false; attachment2.Save(); } } } } return; } } foreach (AttachmentLink attachmentLink in readOnlyCollection) { if (!copyInlinesOnly || attachmentLink.IsInline(flag)) { using (Attachment attachment3 = sourceCollection.Open(attachmentLink.AttachmentId, null)) { if (!copyInlinesOnly || !(attachment3 is ReferenceAttachment)) { using (Attachment attachment4 = attachment3.CreateCopy(targetCollection, new BodyFormat?(this.parameters.TargetFormat))) { attachmentLink.MakeAttachmentChanges(attachment4, flag); if (targetIsPlainText) { attachment4.IsInline = false; } attachment4.Save(); } } } } } }
private static Item InternalOpenEmbeddedMessageAndAttachment(AttachmentCollection attachments, ExTimeZone organizerTimeZone, ExDateTime userStartTime, ExDateTime userEndTime, out ItemAttachment itemAttachment, bool detectDuplicatedAttachment, out AttachmentId[] duplicatedAttachmentIds, ICollection <PropertyDefinition> properties) { itemAttachment = null; duplicatedAttachmentIds = null; Item item = null; ItemAttachment itemAttachment2 = null; List <KeyValuePair <long, AttachmentHandle> > list = new List <KeyValuePair <long, AttachmentHandle> >(); List <AttachmentId> list2 = null; ExDateTime exDateTime = ExTimeZone.UtcTimeZone.ConvertDateTime(userStartTime); ExDateTime exDateTime2 = ExTimeZone.UtcTimeZone.ConvertDateTime(userEndTime); ExDateTime exDateTime3 = organizerTimeZone.ConvertDateTime(exDateTime); ExDateTime exDateTime4 = organizerTimeZone.ConvertDateTime(exDateTime2); exDateTime3 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime3); exDateTime4 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime4); if (properties == null) { properties = new PropertyDefinition[] { InternalSchema.StartTime, InternalSchema.EndTime }; } else { properties = InternalSchema.Combine <PropertyDefinition>(properties, new PropertyDefinition[] { InternalSchema.StartTime, InternalSchema.EndTime }); } CalendarItem calendarItem = attachments.ContainerItem as CalendarItem; List <RecurrenceManager.ExceptionSummary> list3; if (calendarItem != null) { if (calendarItem.ExceptionSummaryList == null) { ExTraceGlobals.RecurrenceTracer.TraceDebug((long)calendarItem.GetHashCode(), "For calendar item, retrieve exception summary information by walking through all hidden attachements"); calendarItem.ExceptionSummaryList = RecurrenceManager.GetExceptionSumaryList(attachments); } list3 = calendarItem.ExceptionSummaryList; } else { ExTraceGlobals.RecurrenceTracer.TraceDebug((long)attachments.GetHashCode(), "No calendar item exists, retrieve exception summary information by walking through all hidden attachements"); list3 = RecurrenceManager.GetExceptionSumaryList(attachments); } foreach (RecurrenceManager.ExceptionSummary exceptionSummary in list3) { ExDateTime utcStartTime = exceptionSummary.UtcStartTime; ExDateTime utcEndTime = exceptionSummary.UtcEndTime; TimeSpan timeSpan = utcStartTime - exDateTime; utcEndTime - exDateTime2; if (Math.Abs((exDateTime3 - exDateTime4 - (utcStartTime - utcEndTime)).Ticks) < 1200000000L && Math.Abs(timeSpan.Ticks) <= 504000000000L) { list.Add(new KeyValuePair <long, AttachmentHandle>(Math.Abs((utcStartTime - exDateTime3).Ticks), exceptionSummary.Handle)); } } list.Sort(delegate(KeyValuePair <long, AttachmentHandle> left, KeyValuePair <long, AttachmentHandle> right) { if (left.Key == right.Key) { return(0); } if (left.Key <= right.Key) { return(-1); } return(1); }); bool flag = false; try { foreach (KeyValuePair <long, AttachmentHandle> keyValuePair in list) { ItemAttachment itemAttachment3 = (ItemAttachment)attachments.Open(keyValuePair.Value, new AttachmentType?(AttachmentType.EmbeddedMessage), null); ExTraceGlobals.RecurrenceTracer.TraceDebug <ExDateTime, int>((long)keyValuePair.Value.GetHashCode(), "Open embedded message for StartTime: {0}, Probables queue length: {1}", userStartTime, list.Count); if (itemAttachment3 != null) { Item item2 = null; bool flag2 = true; try { if (itemAttachment3.IsItemOpen) { ExTraceGlobals.RecurrenceTracer.TraceError((long)keyValuePair.Value.GetHashCode(), "Embedded message is in erroneous open state, which should be guaranteed by master"); } else { item2 = itemAttachment3.GetItem(InternalSchema.Combine <PropertyDefinition>(MessageItemSchema.Instance.AutoloadProperties, properties)); TimeSpan timeSpan2 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiStartTime, ExDateTime.MinValue) - userStartTime; TimeSpan timeSpan3 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiEndTime, ExDateTime.MinValue) - userEndTime; if (timeSpan2.TotalMinutes < 1.0 && timeSpan2.TotalMinutes > -1.0 && timeSpan3.TotalMinutes < 1.0 && timeSpan3.TotalMinutes > -1.0) { if (item == null) { flag2 = false; itemAttachment2 = itemAttachment3; item = item2; if (!detectDuplicatedAttachment) { break; } list2 = new List <AttachmentId>(); } else { ExTraceGlobals.RecurrenceTracer.TraceDebug <AttachmentId, ExDateTime>((long)keyValuePair.Value.GetHashCode(), "Detected duplicated attachment {0} for StartTime: {1}", itemAttachment3.Id, userStartTime); list2.Add(itemAttachment3.Id); } } } } finally { if (flag2) { Util.DisposeIfPresent(item2); Util.DisposeIfPresent(itemAttachment3); } } } } flag = true; } finally { if (!flag) { Util.DisposeIfPresent(item); Util.DisposeIfPresent(itemAttachment2); } } itemAttachment = itemAttachment2; duplicatedAttachmentIds = ((list2 == null) ? null : list2.ToArray()); return(item); }