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); }