Example #1
0
 internal ItemToTnefConverter(Item itemIn, OutboundAddressCache addressCache, ItemToTnefConverter.TnefContentWriter writer, OutboundConversionOptions options, ConversionLimitsTracker limits, TnefType tnefType, bool parsingEmbeddedItem) : this(itemIn, addressCache, options, limits, tnefType, parsingEmbeddedItem)
 {
     this.tnefWriter         = writer;
     this.tnefCorrelationKey = null;
     this.propertyChecker    = new TnefPropertyChecker(tnefType, parsingEmbeddedItem, options);
     this.disposeTracker     = this.GetDisposeTracker();
 }
Example #2
0
        private long WriteAttachedItem(ItemAttachment attachment)
        {
            Item item   = ConvertUtils.OpenAttachedItem(attachment);
            long result = 0L;

            if (item != null)
            {
                try
                {
                    this.limitsTracker.StartEmbeddedMessage();
                    Charset itemWindowsCharset = ConvertUtils.GetItemWindowsCharset(item, this.options);
                    using (ItemToTnefConverter.TnefContentWriter embeddedMessageWriter = this.tnefWriter.GetEmbeddedMessageWriter(itemWindowsCharset))
                    {
                        OutboundAddressCache outboundAddressCache = new OutboundAddressCache(this.options, this.limitsTracker);
                        outboundAddressCache.CopyDataFromItem(item);
                        if (this.tnefType == TnefType.LegacyTnef && this.options.ResolveRecipientsInAttachedMessages)
                        {
                            outboundAddressCache.Resolve();
                        }
                        using (ItemToTnefConverter itemToTnefConverter = new ItemToTnefConverter(item, outboundAddressCache, embeddedMessageWriter, this.options, this.limitsTracker, this.tnefType, true))
                        {
                            ConversionResult conversionResult = itemToTnefConverter.Convert();
                            result = conversionResult.BodySize + conversionResult.AccumulatedAttachmentSize;
                        }
                    }
                    this.limitsTracker.EndEmbeddedMessage();
                }
                finally
                {
                    item.Dispose();
                }
            }
            return(result);
        }
Example #3
0
        internal ItemToTnefConverter(Item itemIn, OutboundAddressCache addressCache, Stream mimeOut, OutboundConversionOptions options, ConversionLimitsTracker limits, TnefType tnefType, string tnefCorrelationKey, bool parsingEmbeddedItem) : this(itemIn, addressCache, options, limits, tnefType, parsingEmbeddedItem)
        {
            this.tnefCorrelationKey = tnefCorrelationKey;
            Charset itemWindowsCharset = ConvertUtils.GetItemWindowsCharset(this.item, options);

            this.tnefWriter      = new ItemToTnefConverter.TnefContentWriter(mimeOut, itemWindowsCharset);
            this.propertyChecker = new TnefPropertyChecker(tnefType, parsingEmbeddedItem, options);
            this.disposeTracker  = this.GetDisposeTracker();
        }
Example #4
0
 private ItemToTnefConverter(Item itemIn, OutboundAddressCache addressCache, OutboundConversionOptions options, ConversionLimitsTracker limits, TnefType tnefType, bool parsingEmbeddedItem)
 {
     if (options.FilterAttachmentHandler != null)
     {
         throw new NotSupportedException("FilterAttachmentHandler is not supported in ItemToTnefConverter");
     }
     if (options.FilterBodyHandler != null)
     {
         throw new NotSupportedException("FilterBodyHandler is not supported in ItemToTnefConverter");
     }
     this.item           = itemIn;
     this.addressCache   = addressCache;
     this.options        = options;
     this.limitsTracker  = limits;
     this.isEmbeddedItem = parsingEmbeddedItem;
     this.tnefType       = tnefType;
 }
Example #5
0
        internal ADRawEntry GetCachedRecipient(Participant participant)
        {
            if (this.outboundOptions == null || this.outboundOptions.RecipientCache == null)
            {
                return(null);
            }
            if (participant == null)
            {
                return(null);
            }
            ProxyAddress proxyAddressForParticipant = OutboundAddressCache.GetProxyAddressForParticipant(participant);

            if (proxyAddressForParticipant == null)
            {
                return(null);
            }
            Result <ADRawEntry> result;

            if (this.outboundOptions.RecipientCache.TryGetValue(proxyAddressForParticipant, out result) && result.Error == null)
            {
                return(result.Data);
            }
            return(null);
        }
Example #6
0
        internal bool?IsDelegateOfPrincipal(Participant principal, Participant delegateParticipant)
        {
            if (this.outboundOptions == null || this.outboundOptions.RecipientCache == null)
            {
                return(null);
            }
            ProxyAddress proxyAddressForParticipant = OutboundAddressCache.GetProxyAddressForParticipant(principal);

            if (proxyAddressForParticipant == null)
            {
                return(null);
            }
            Result <ADRawEntry> result;

            if (this.outboundOptions.RecipientCache.TryGetValue(proxyAddressForParticipant, out result))
            {
                ADRawEntry data = result.Data;
                if (data == null)
                {
                    return(null);
                }
                MultiValuedProperty <ADObjectId> multiValuedProperty = data[ADRecipientSchema.GrantSendOnBehalfTo] as MultiValuedProperty <ADObjectId>;
                if (multiValuedProperty == null || multiValuedProperty.Count == 0)
                {
                    return(new bool?(false));
                }
                ProxyAddress proxyAddressForParticipant2 = OutboundAddressCache.GetProxyAddressForParticipant(delegateParticipant);
                if (proxyAddressForParticipant2 == null)
                {
                    return(null);
                }
                Result <ADRawEntry> result2;
                if (this.outboundOptions.RecipientCache.TryGetValue(proxyAddressForParticipant2, out result2))
                {
                    ADRawEntry data2 = result2.Data;
                    if (data2 == null)
                    {
                        return(null);
                    }
                    ADObjectId adobjectId = data2[ADObjectSchema.Id] as ADObjectId;
                    if (adobjectId == null)
                    {
                        goto IL_13A;
                    }
                    using (MultiValuedProperty <ADObjectId> .Enumerator enumerator = multiValuedProperty.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            ADObjectId x = enumerator.Current;
                            if (ADObjectId.Equals(x, adobjectId))
                            {
                                return(new bool?(true));
                            }
                        }
                        goto IL_13A;
                    }
                }
                return(null);
            }
IL_13A:
            return(new bool?(false));
        }
Example #7
0
        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();
                        }
                    }
                }
            }
        }
 internal ICalOutboundContext(Charset charset, IList <LocalizedString> errorStream, OutboundAddressCache addressCache, OutboundConversionOptions options, CalendarWriter calendarWriter, string calendarName, ReadOnlyCollection <AttachmentLink> attachmentLinks, bool suppressExceptionAndAttachmentDemotion) : base(charset, errorStream, addressCache)
 {
     Util.ThrowOnNullArgument(options, "options");
     Util.ThrowOnNullOrEmptyArgument(options.ImceaEncapsulationDomain, "options.ImceaEncapsulationDomain");
     Util.ThrowOnNullArgument(calendarWriter, "calendarWriter");
     this.Options         = options;
     this.Writer          = calendarWriter;
     this.CalendarName    = calendarName;
     this.AttachmentLinks = attachmentLinks;
     this.SuppressExceptionAndAttachmentDemotion = suppressExceptionAndAttachmentDemotion;
 }
        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 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));
        }