internal Attachment Open(AttachmentHandle handle, AttachmentType?type, ICollection <PropertyDefinition> propertyDefinitions) { Util.ThrowOnNullArgument(handle, "handle"); if (type != null) { EnumValidator.ThrowIfInvalid <AttachmentType>(type.Value, "type"); } Attachment attachment = null; CoreAttachment coreAttachment = null; try { coreAttachment = this.CoreAttachmentCollection.Open(handle, propertyDefinitions); attachment = AttachmentCollection.CreateTypedAttachment(coreAttachment, type); } finally { if (attachment == null && coreAttachment != null) { coreAttachment.Dispose(); } } return(attachment); }
public void SetProtectedData(Body body, AttachmentCollection attachments) { this.CheckDisposed("SetProtectedData"); this.EnsureIsDecoded(); RightsManagedMessageItem.CopyProtectableData(body, attachments, this.decodedItem); }
public Attachment Open(AttachmentId id, ICollection <PropertyDefinition> propertyDefinitions) { Util.ThrowOnNullArgument(id, "id"); return(AttachmentCollection.CreateTypedAttachment(this.CoreAttachmentCollection.Open(id, propertyDefinitions), null)); }
protected static IAttachment CreateCopy(Attachment attachment, AttachmentCollection collection, AttachmentType?newAttachmentType) { return(collection.Create(newAttachmentType, attachment)); }
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); }
internal virtual Attachment CreateCopy(AttachmentCollection collection, BodyFormat?targetBodyFormat) { return((Attachment)Attachment.CreateCopy(this, collection, new AttachmentType?(this.AttachmentType))); }
internal static Item OpenEmbeddedMessageAndAttachment(AttachmentCollection attachments, ExTimeZone organizerTimeZone, ExDateTime userStartTime, ExDateTime userEndTime, out ItemAttachment itemAttachment, ICollection <PropertyDefinition> properties) { AttachmentId[] array; return(RecurrenceManager.InternalOpenEmbeddedMessageAndAttachment(attachments, organizerTimeZone, userStartTime, userEndTime, out itemAttachment, false, out array, properties)); }
private void PopulateExceptionOccurrence(object[] occurrence, PropertyDefinition[] columns, ExceptionInfo exception, ref AttachmentCollection attachments, ref Item master, VersionedId versionedId) { object[] array = null; for (int i = 0; i < columns.Length; i++) { if (!columns[i].Equals(InternalSchema.ItemId) && !columns[i].Equals(InternalSchema.IsRecurring) && !columns[i].Equals(InternalSchema.IsException) && !columns[i].Equals(InternalSchema.AppointmentRecurring) && !columns[i].Equals(InternalSchema.MapiStartTime) && !columns[i].Equals(InternalSchema.MapiPRStartDate) && !columns[i].Equals(InternalSchema.MapiEndTime) && !columns[i].Equals(InternalSchema.MapiPREndDate) && !columns[i].Equals(InternalSchema.CalendarItemType) && !columns[i].Equals(InternalSchema.GlobalObjectId) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionStart) && !columns[i].Equals(InternalSchema.TimeZoneDefinitionEnd) && !columns[i].Equals(InternalSchema.Codepage) && !RecurrenceManager.MasterOnlyProperties.Contains(columns[i])) { if (RecurrenceManager.CanPropertyBeInExceptionData(columns[i])) { object obj = exception.PropertyBag.TryGetProperty(columns[i]); PropertyError propertyError = obj as PropertyError; if (propertyError != null) { if (propertyError.PropertyErrorCode != PropertyErrorCode.NotFound) { throw PropertyError.ToException(new PropertyError[] { propertyError }); } } else { occurrence[i] = obj; } } else { ExTraceGlobals.RecurrenceTracer.Information <PropertyDefinition>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Opening embedded message for {0} property", columns[i]); if (array == null) { if (attachments == null) { if (master == null) { ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand. Fetching master message when constructing view"); StoreObjectId masterId = versionedId.ObjectId; bool flag = false; try { master = ItemBuilder.ConstructItem <Item>(this.storeSession, masterId, null, CalendarItemBaseSchema.Instance.AutoloadProperties, () => new StoreObjectPropertyBag(this.storeSession, this.storeSession.GetMapiProp(masterId), CalendarItemBaseSchema.Instance.AutoloadProperties), ItemCreateInfo.GenericItemInfo.Creator, Origin.Existing, ItemLevel.TopLevel); flag = true; } finally { if (!flag && master != null) { master.Dispose(); master = null; } } } attachments = master.AttachmentCollection; ExTraceGlobals.RecurrenceTracer.Information((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching attachments"); } ItemAttachment itemAttachment = null; using (Item item = RecurrenceManager.OpenEmbeddedMessageAndAttachment(attachments, TimeZoneHelper.GetRecurringTimeZoneFromPropertyBag(attachments.ContainerItem.PropertyBag), exception.StartTime, exception.EndTime, out itemAttachment, columns)) { ExTraceGlobals.RecurrenceTracer.Information <ExDateTime>((long)this.recurrence.GetHashCode(), "RecurrenceManager::Expand, Fetching Embedded Message for exception occurence dateId: {0}", exception.OccurrenceDateId); if (item != null) { array = item.GetProperties(columns); itemAttachment.Dispose(); } else { array = new object[columns.Length]; } } } if (array[i] != null && !(array[i] is PropertyError)) { occurrence[i] = array[i]; } } } } }
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); }
internal List <object[]> Expand(object[] masterValues, ExDateTime start, ExDateTime end, int codePage, PropertyDefinition[] columns, RecurrenceExpansionOption options) { List <object[]> list = new List <object[]>(); if (masterValues.Length != columns.Length) { throw new ArgumentException(ServerStrings.ExInvalidMasterValueAndColumnLength); } object[] array = null; if ((options & RecurrenceExpansionOption.TruncateMaster) == RecurrenceExpansionOption.TruncateMaster) { array = this.GetTruncatedRecurringMaster(masterValues, start, end, columns); if (array == null) { return(list); } } else { array = masterValues; } int num = Array.IndexOf <PropertyDefinition>(columns, InternalSchema.ItemId); VersionedId versionedId = (VersionedId)array[num]; Item item = null; AttachmentCollection attachmentCollection = null; bool flag; try { byte[] timeZoneBlob = O12TimeZoneFormatter.GetTimeZoneBlob(this.recurrence.CreatedExTimeZone); IList <OccurrenceInfo> occurrenceInfoList = this.recurrence.GetOccurrenceInfoList(start, end); flag = (occurrenceInfoList.Count != 0); foreach (OccurrenceInfo occurrenceInfo in occurrenceInfoList) { bool flag2 = occurrenceInfo is ExceptionInfo; if (flag2 || (options & RecurrenceExpansionOption.IncludeRegularOccurrences) == RecurrenceExpansionOption.IncludeRegularOccurrences) { object[] array2 = new object[array.Length]; array.CopyTo(array2, 0); if (flag2) { this.PopulateExceptionOccurrence(array2, columns, (ExceptionInfo)occurrenceInfo, ref attachmentCollection, ref item, occurrenceInfo.VersionedId); } this.AdjustOccurrenceColumnsForExpansion(array2, columns, occurrenceInfo, codePage, timeZoneBlob, flag2); list.Add(array2); } } } finally { if (item != null) { item.Dispose(); item = null; } } if (flag && (options & RecurrenceExpansionOption.IncludeMaster) == RecurrenceExpansionOption.IncludeMaster) { list.Insert(0, array); } return(list); }
protected HtmlCallbackBase(AttachmentCollection collection, Body itemBody) : this(collection.CoreAttachmentCollection, itemBody) { }