private IEnumerable <Item> GetIcalEnumerator() { string calendarName; IEnumerable <Item> result = CalendarDocument.InternalICalToItems(this.inputStream, this.charset, this.addressCache, CalendarImporter.maxICalBodyLength, true, delegate { Util.DisposeIfPresent(this.itemCache); this.itemCache = MessageItem.CreateInMemory(InternalSchema.ContentConversionProperties); this.itemCache.PropertyBag.ExTimeZone = this.session.ExTimeZone; this.itemCache.Sensitivity = Sensitivity.Normal; return(this.itemCache); }, this.results.RawErrors, out calendarName); this.results.CalendarName = calendarName; return(result); }
internal static ReadOnlyCollection <AttachmentLink> ItemToICal(Item item, ReadOnlyCollection <AttachmentLink> existingAttachmentLinks, OutboundAddressCache addressCache, Stream stream, string charsetName, OutboundConversionOptions outboundConversionOptions) { ReadOnlyCollection <AttachmentLink> readOnlyCollection = AttachmentLink.MergeAttachmentLinks(existingAttachmentLinks, item.AttachmentCollection.CoreAttachmentCollection); foreach (AttachmentLink attachmentLink in readOnlyCollection) { if (string.IsNullOrEmpty(attachmentLink.ContentId)) { attachmentLink.ContentId = AttachmentLink.CreateContentId(item.CoreItem, attachmentLink.AttachmentId, outboundConversionOptions.ImceaEncapsulationDomain); } } return(CalendarDocument.InternalItemsToICal(null, new Item[] { item }, readOnlyCollection, addressCache, false, stream, new List <LocalizedString>(), charsetName, outboundConversionOptions)); }
internal static ReadOnlyCollection <AttachmentLink> InternalItemsToICal(string calendarName, IList <Item> items, ReadOnlyCollection <AttachmentLink> existingAttachmentLinks, OutboundAddressCache addressCache, bool suppressExceptionAndAttachmentDemotion, Stream stream, List <LocalizedString> errorStream, string charsetName, OutboundConversionOptions outboundConversionOptions) { Util.ThrowOnNullArgument(items, "items"); if (!suppressExceptionAndAttachmentDemotion && items.Count != 1) { throw new ArgumentException("Non suppressExceptionAndAttachmentDemotion mode should have one and only one item to demote"); } Charset charset = Charset.GetCharset(charsetName); CalendarDocument calendarDocument = new CalendarDocument(); using (CalendarWriter calendarWriter = new CalendarWriter(new StreamWrapper(stream, false), charset.Name)) { ICalOutboundContext outboundContext = new ICalOutboundContext(charset, errorStream, addressCache, outboundConversionOptions, calendarWriter, calendarName, existingAttachmentLinks, suppressExceptionAndAttachmentDemotion); calendarDocument.Demote(outboundContext, items); } return(existingAttachmentLinks); }
internal static IEnumerable <Item> InternalICalToItems(Stream iCalStream, string charsetName, InboundAddressCache addressCache, uint?maxBodyLength, bool hasExceptionPromotion, Func <Item> getItem, IList <LocalizedString> errorStream, out string calendarName) { Util.ThrowOnNullArgument(iCalStream, "iCalStream"); Util.ThrowOnNullArgument(addressCache, "addressCache"); Util.ThrowOnNullArgument(errorStream, "errorStream"); bool flag = false; LocalizedException ex = null; Charset charset = Charset.GetCharset(charsetName ?? "utf-8"); CalendarDocument calendarDocument = new CalendarDocument(); IEnumerable <Item> result; using (CalendarReader calendarReader = new CalendarReader(new StreamWrapper(iCalStream, false), charset.Name, CalendarComplianceMode.Loose)) { ICalInboundContext calInboundContext = new ICalInboundContext(charset, errorStream, addressCache, addressCache.Options, calendarReader, maxBodyLength, hasExceptionPromotion); try { flag = (calendarDocument.Parse(calInboundContext) && calendarDocument.vCalendar.Validate()); } catch (InvalidCalendarDataException ex2) { ex = ex2; } calendarName = calInboundContext.CalendarName; if (!flag) { if (ex != null) { ExTraceGlobals.ICalTracer.TraceError <string>((long)calendarDocument.GetHashCode(), "CalendarDocument::InternalICalToItems. Found exception: '{0}'.", ex.Message); errorStream.Add(ex.LocalizedString); } else if (errorStream.Count != 0) { ExTraceGlobals.ICalTracer.TraceError <int>((long)calendarDocument.GetHashCode(), "CalendarDocument::InternalICalToItems. {0} error found.", errorStream.Count); errorStream.Add(ServerStrings.InvalidICalElement("VCALENDAR")); } result = Array <CalendarItemBase> .Empty; } else { result = calendarDocument.vCalendar.Promote(getItem); } } return(result); }
internal static bool ICalToItem(Stream iCalStream, Item item, InboundAddressCache addressCache, bool suppressBodyPromotion, string charsetName, out LocalizedString errorMessage) { IList <LocalizedString> list = new List <LocalizedString>(); string text; IEnumerable <Item> enumerable = CalendarDocument.InternalICalToItems(iCalStream, charsetName, addressCache, suppressBodyPromotion ? new uint?(0U) : null, false, () => item, list, out text); bool flag = false; using (IEnumerator <Item> enumerator = enumerable.GetEnumerator()) { if (enumerator.MoveNext()) { Item item2 = enumerator.Current; if (item2.Validate().Length != 0) { ExTraceGlobals.ICalTracer.TraceDebug(0L, "CalendarDocument::ICalToItem. Validation error for promoted item."); list.Add(ServerStrings.ValidationFailureAfterPromotion(string.Empty)); } flag = (list.Count == 0); } } if (!flag) { CalendarDocument.AttachICalToItem(iCalStream, item); } if (list.Count == 0) { errorMessage = LocalizedString.Empty; } else if (list.Count == 1) { errorMessage = list[0]; } else { errorMessage = LocalizedString.Join(Environment.NewLine, list.Cast <object>().ToArray <object>()); } return(flag); }
public static void ExportCalendar(Stream outputStream, string charset, OutboundConversionOptions options, MailboxSession session, StoreObjectId folderId, ExDateTime windowStart, ExDateTime windowEnd, DetailLevelEnumType detailType) { EnumValidator.ThrowIfInvalid <DetailLevelEnumType>(detailType, "detailType"); PropertyDefinition[] array = InternetCalendarSchema.FromDetailLevel(detailType); Array.IndexOf <PropertyDefinition>(array, CalendarItemBaseSchema.FreeBusyStatus); int num = Array.IndexOf <PropertyDefinition>(array, InternalSchema.ItemId); using (CalendarFolder calendarFolder = CalendarFolder.Bind(session, folderId)) { object[][] array2 = calendarFolder.InternalGetCalendarView(windowStart, windowEnd, detailType == DetailLevelEnumType.AvailabilityOnly, true, true, RecurrenceExpansionOption.IncludeMaster | RecurrenceExpansionOption.TruncateMaster, array); Item[] items = new Item[array2.Length]; try { for (int i = 0; i < array2.Length; i++) { items[i] = MessageItem.CreateInMemory(StoreObjectSchema.ContentConversionProperties); for (int j = 0; j < array.Length; j++) { StorePropertyDefinition storePropertyDefinition = array[j] as StorePropertyDefinition; if (storePropertyDefinition != null && (storePropertyDefinition.PropertyFlags & PropertyFlags.ReadOnly) != PropertyFlags.ReadOnly) { object obj = array2[i][j]; if (!PropertyError.IsPropertyError(obj)) { items[i][storePropertyDefinition] = obj; } } } if (detailType == DetailLevelEnumType.FullDetails && array2[i][num] is VersionedId) { using (CoreItem coreItem = CoreItem.Bind(session, (VersionedId)array2[i][num], new PropertyDefinition[] { ItemSchema.TextBody, ItemSchema.HtmlBody, ItemSchema.RtfBody })) { using (TextReader textReader = coreItem.Body.OpenTextReader(BodyFormat.TextPlain)) { items[i][ItemSchema.TextBody] = textReader.ReadToEnd(); } } } } OutboundAddressCache addressCache = new OutboundAddressCache(options, new ConversionLimitsTracker(options.Limits)); List <LocalizedString> errorStream = new List <LocalizedString>(); ConvertUtils.CallCts(ExTraceGlobals.ICalTracer, "ICalSharingHelper::ExportCalendar", ServerStrings.ConversionCorruptContent, delegate { CalendarDocument.InternalItemsToICal(calendarFolder.DisplayName, items, null, addressCache, true, outputStream, errorStream, charset, options); }); if (errorStream.Count > 0) { ExTraceGlobals.ICalTracer.TraceError <int>(0L, "{0} errors found during outbound iCal content conversion.", errorStream.Count); AnonymousSharingLog.LogEntries(session, errorStream); } } finally { foreach (Item item in items) { if (item != null) { item.Dispose(); } } } } }