Пример #1
0
        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);
        }
Пример #2
0
 protected ConversionCallbackBase(CoreAttachmentCollection attachmentCollection, Body itemBody)
 {
     this.AttachmentCollection            = attachmentCollection;
     this.itemBody                        = itemBody;
     this.attachmentLinks                 = null;
     this.attachmentsByPositionEnumerator = null;
 }
Пример #3
0
        internal MessageAttachmentWriter(InboundMessageWriter messageWriter, int attachMethod)
        {
            StorageGlobals.TraceConstructIDisposable(this);
            this.messageWriter = messageWriter;
            AttachmentType attachmentType = CoreAttachmentCollection.GetAttachmentType(new int?(attachMethod));

            this.coreAttachment = this.CoreItem.AttachmentCollection.Create(attachmentType);
        }
Пример #4
0
 internal CoreAttachment(CoreAttachmentCollection parentCollection, AttachmentPropertyBag propertyBag, Origin origin)
 {
     this.parentCollection = parentCollection;
     this.propertyBag      = propertyBag;
     this.attachmentNumber = propertyBag.AttachmentNumber;
     this.Origin           = origin;
     this.propertyBag.Context.CoreState = this;
     this.propertyBag.Context.Session   = this.parentCollection.ContainerItem.Session;
 }
 public bool MoveNext()
 {
     while (this.list.MoveNext())
     {
         AttachmentHandle handle = this.list.Current;
         if (!CoreAttachmentCollection.IsCalendarException(handle))
         {
             return(true);
         }
     }
     return(false);
 }
 internal void Load(ICollection <PropertyDefinition> propertyList)
 {
     this.CheckDisposed(null);
     if (propertyList == InternalSchema.ContentConversionProperties)
     {
         throw new InvalidOperationException("Cannot load ContentConversionProperties on the attachment collection. Call Load() on individual attachments instead");
     }
     if (propertyList != null && propertyList.Count != 0)
     {
         this.fetchProperties = CoreAttachmentCollection.CreatePrefetchPropertySet <PropertyDefinition>(this.fetchProperties, propertyList);
     }
 }
 public IList <AttachmentHandle> GetHandles()
 {
     if (this.hideCalendarExceptions)
     {
         List <AttachmentHandle> list = new List <AttachmentHandle>(this.CoreAttachmentCollection.Count);
         foreach (AttachmentHandle attachmentHandle in this.CoreAttachmentCollection)
         {
             if (!CoreAttachmentCollection.IsCalendarException(attachmentHandle))
             {
                 list.Add(attachmentHandle);
             }
         }
         return(list);
     }
     return(this.GetAllHandles());
 }
Пример #8
0
        private AttachmentPropertyBag.SavedData ComputeSavedData()
        {
            AttachmentPropertyBag.SavedData savedData = new AttachmentPropertyBag.SavedData();
            savedData.AttachmentId = this.AttachmentId;
            savedData.AttachMethod = this.AttachMethod;
            StringBuilder stringBuilder = new StringBuilder();

            this.ComputeCharsetDetectionData(stringBuilder);
            savedData.CharsetDetectionString = stringBuilder.ToString();
            int?num = ((IDirectPropertyBag)this.CurrentPropertyBag).GetValue(InternalSchema.AttachCalendarFlags) as int?;

            savedData.IsCalendarException = CoreAttachmentCollection.IsCalendarException((num != null) ? num.Value : 0);
            bool?flag = base.TryGetProperty(InternalSchema.AttachmentIsInline) as bool?;

            savedData.IsInline = (flag != null && flag.Value);
            return(savedData);
        }
Пример #9
0
        public StreamAttachment ConvertToImageAttachment(CoreAttachmentCollection collection, ImageFormat format)
        {
            base.CheckDisposed("ConvertToImageAttachment");
            Util.ThrowOnNullArgument(collection, "collection");
            EnumValidator.ThrowIfInvalid <ImageFormat>(format);
            StreamAttachment result;

            using (DisposeGuard disposeGuard = default(DisposeGuard))
            {
                CoreAttachment coreAttachment = collection.InternalCreateCopy(new AttachmentType?(AttachmentType.Stream), base.CoreAttachment);
                disposeGuard.Add <CoreAttachment>(coreAttachment);
                StreamAttachment streamAttachment = (StreamAttachment)AttachmentCollection.CreateTypedAttachment(coreAttachment, new AttachmentType?(AttachmentType.Stream));
                disposeGuard.Add <StreamAttachment>(streamAttachment);
                string text = streamAttachment.FileName;
                if (string.IsNullOrEmpty(text))
                {
                    text = Attachment.GenerateFilename();
                }
                string str = null;
                switch (format)
                {
                case ImageFormat.Jpeg:
                    str = ".jpg";
                    break;

                case ImageFormat.Png:
                    str = ".png";
                    break;
                }
                streamAttachment.FileName    = text + str;
                streamAttachment.ContentType = "image/jpeg";
                streamAttachment.IsInline    = true;
                using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create))
                {
                    if (!this.TryConvertToImage(contentStream, ImageFormat.Jpeg))
                    {
                        ConvertUtils.SaveDefaultImage(contentStream);
                    }
                }
                disposeGuard.Success();
                result = streamAttachment;
            }
            return(result);
        }
        private AttachmentPropertyBag InternalCreateAttachmentPropertyBag(AttachmentType?type, CoreAttachment attachmentToClone, IItem itemToAttach)
        {
            this.InitCollection("InternalCreateAttachmentPropertyBag", true);
            bool flag             = false;
            int  attachmentNumber = -1;
            PersistablePropertyBag persistablePropertyBag = null;
            AttachmentPropertyBag  attachmentPropertyBag  = null;

            try
            {
                Schema attachmentSchema = CoreAttachmentCollection.GetAttachmentSchema(type);
                ICollection <PropertyDefinition> prefetchProperties = InternalSchema.Combine <PropertyDefinition>(attachmentSchema.AutoloadProperties, (ICollection <PropertyDefinition>) this.fetchProperties);
                persistablePropertyBag           = this.attachmentProvider.CreateAttachment(prefetchProperties, attachmentToClone, itemToAttach, out attachmentNumber);
                attachmentPropertyBag            = new AttachmentPropertyBag(this.attachmentProvider, attachmentNumber, persistablePropertyBag, true);
                attachmentPropertyBag.ExTimeZone = this.ExTimeZone;
                if (type != null)
                {
                    int num = CoreAttachment.AttachmentTypeToAttachMethod(type.Value);
                    ((IDirectPropertyBag)attachmentPropertyBag).SetValue(InternalSchema.AttachMethod, num);
                }
                this.isDirty = true;
                this.IsClonedFromAnExistingAttachmentCollection = false;
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (attachmentPropertyBag != null)
                    {
                        attachmentPropertyBag.Dispose();
                        attachmentPropertyBag = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                }
            }
            return(attachmentPropertyBag);
        }
Пример #11
0
 protected RtfCallbackBase(CoreAttachmentCollection collection, Body itemBody) : base(collection, itemBody)
 {
 }
Пример #12
0
        internal static ReadOnlyCollection <AttachmentLink> MergeAttachmentLinks(IList <AttachmentLink> existingLinks, CoreAttachmentCollection attachments)
        {
            IList <AttachmentLink> list;

            if (attachments != null)
            {
                list = ((existingLinks == null) ? new List <AttachmentLink>(attachments.Count) : new List <AttachmentLink>(existingLinks));
                ICollection <PropertyDefinition> preloadProperties = new PropertyDefinition[]
                {
                    AttachmentSchema.AttachContentId
                };
                using (IEnumerator <AttachmentHandle> enumerator = attachments.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        AttachmentHandle handle = enumerator.Current;
                        using (CoreAttachment coreAttachment = attachments.Open(handle, preloadProperties))
                        {
                            using (Attachment attachment = AttachmentCollection.CreateTypedAttachment(coreAttachment, null))
                            {
                                if (AttachmentLink.Find(attachment.Id, list) == null)
                                {
                                    AttachmentLink item = new AttachmentLink(attachment);
                                    list.Add(item);
                                }
                            }
                        }
                    }
                    goto IL_C5;
                }
            }
            list = ((existingLinks == null) ? new List <AttachmentLink>(0) : new List <AttachmentLink>(existingLinks));
IL_C5:
            return(new ReadOnlyCollection <AttachmentLink>(list));
        }
Пример #13
0
        public static bool IsItemLegallyDirty(StoreSession session, CoreItem item, bool verifyLegallyDirty, out List <string> dirtyProperties)
        {
            dirtyProperties = null;
            if (COWSettings.IsCalendarRepairAssistantAction(session))
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the action was generated by Calendar Repair Assistant.", item);
                return(false);
            }
            if (item.PropertyBag.GetValueOrDefault <bool>(InternalSchema.IsDraft))
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it is a draft.", item);
                return(false);
            }
            if (item.Id == null)
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it does not have an id.", item);
                return(false);
            }
            if (item.PropertyBag.GetValueOrDefault <bool>(InternalSchema.IsAssociated))
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it is an associated item.", item);
                return(false);
            }
            if (item.Id == null)
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the id was null.", item);
                return(false);
            }
            string valueOrDefault = item.PropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);

            if (ObjectClass.IsOfClass(valueOrDefault, "IPM.Post.RSS"))
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because it is a RSS item.", item);
                return(false);
            }
            Schema schema = ObjectClass.GetSchema(valueOrDefault);

            if (!(schema is ItemSchema))
            {
                schema = ItemSchema.Instance;
            }
            bool isLegallyDirty = item.IsLegallyDirty;
            CoreRecipientCollection  recipients           = ((ICoreItem)item).Recipients;
            CoreAttachmentCollection attachmentCollection = ((ICoreItem)item).AttachmentCollection;
            bool flag  = (recipients != null && recipients.IsDirty) || item.IsLegallyDirtyProperty("RecipientCollection");
            bool flag2 = (attachmentCollection != null && attachmentCollection.IsDirty) || item.IsLegallyDirtyProperty("AttachmentCollection");

            if (!isLegallyDirty && !item.PropertyBag.IsDirty && !flag && !flag2)
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the property bag is not dirty.", item);
                return(false);
            }
            StorePropertyDefinition[] array = (from x in schema.LegalTrackingProperties
                                               where item.PropertyBag.IsPropertyDirty(x) || item.IsLegallyDirtyProperty(x.Name)
                                               select x).ToArray <StorePropertyDefinition>();
            if (array.Length == 0 && !flag && !flag2)
            {
                ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} skipped because the property bag is not legally dirty.", item);
                return(false);
            }
            dirtyProperties = new List <string>();
            if (!verifyLegallyDirty)
            {
                dirtyProperties = (from x in array
                                   select x.Name).ToList <string>();
                if (flag)
                {
                    dirtyProperties.Add("RecipientCollection");
                }
                if (flag2)
                {
                    dirtyProperties.Add("AttachmentCollection");
                }
            }
            else
            {
                using (CoreItem coreItem = CoreItem.Bind(session, item.Id, array))
                {
                    CoreRecipientCollection recipients2 = coreItem.Recipients;
                    if (flag)
                    {
                        flag = false;
                        int num  = (recipients == null) ? 0 : recipients.Count;
                        int num2 = (recipients2 == null) ? 0 : recipients2.Count;
                        if (num == num2)
                        {
                            if (recipients == null || recipients2 == null)
                            {
                                goto IL_36E;
                            }
                            using (IEnumerator <CoreRecipient> enumerator = recipients.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    CoreRecipient value = enumerator.Current;
                                    if (!recipients2.Contains(value, COWDumpster.CoreRecipientParticipantEqualityComparer.Default))
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                                goto IL_36E;
                            }
                        }
                        flag = true;
                    }
                    else
                    {
                        int num3 = (recipients == null) ? 0 : recipients.Count;
                        int num4 = (recipients2 == null) ? 0 : recipients2.Count;
                        flag = (num3 != num4);
                    }
IL_36E:
                    if (flag)
                    {
                        ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} is dirty because the recipient collection is dirty.", item);
                        dirtyProperties.Add("RecipientCollection");
                    }
                    if (!flag2)
                    {
                        CoreAttachmentCollection attachmentCollection2 = coreItem.AttachmentCollection;
                        int num5 = (attachmentCollection == null) ? 0 : attachmentCollection.Count;
                        int num6 = (attachmentCollection2 == null) ? 0 : attachmentCollection2.Count;
                        flag2 = (num5 != num6);
                    }
                    if (flag2)
                    {
                        ExTraceGlobals.SessionTracer.TraceWarning <CoreItem>((long)session.GetHashCode(), "Update Item {0} is dirty because the attachment collection is dirty.", item);
                        dirtyProperties.Add("AttachmentCollection");
                    }
                    foreach (StorePropertyDefinition propertyDefinition in array)
                    {
                        object x2 = item.PropertyBag.TryGetProperty(propertyDefinition);
                        object y  = coreItem.PropertyBag.TryGetProperty(propertyDefinition);
                        if (!COWDumpster.PropertyValuesAreEqual(propertyDefinition, x2, y))
                        {
                            ExTraceGlobals.SessionTracer.TraceWarning <CoreItem, string, PropertyDefinition>((long)session.GetHashCode(), "Update Item {0}, class {1} is dirty because the {2} property is dirty.", item, valueOrDefault, propertyDefinition);
                            dirtyProperties.Add(propertyDefinition.Name);
                        }
                    }
                }
            }
            if (dirtyProperties.Count > 0)
            {
                ExTraceGlobals.SessionTracer.TraceWarning((long)session.GetHashCode(), "Update Item {0}, class {1} is {2} dirty with {3} properties changed", new object[]
                {
                    item,
                    valueOrDefault,
                    verifyLegallyDirty ? "verified" : "not verified",
                    dirtyProperties.Count
                });
                return(true);
            }
            ExTraceGlobals.SessionTracer.TraceWarning <CoreItem, string, int>((long)session.GetHashCode(), "Update Item {0}, class {1} skipped because no legal tracking property was found dirty out of {2} modified legal tracking properties.", item, valueOrDefault, array.Length);
            dirtyProperties = null;
            return(false);
        }
Пример #14
0
 internal DefaultRtfCallbacks(CoreAttachmentCollection collection, Body itemBody, bool itemReadOnly) : base(collection, itemBody)
 {
     this.readOnly = itemReadOnly;
 }
Пример #15
0
 internal DefaultHtmlCallbacks(CoreAttachmentCollection collection, Body itemBody, bool itemReadOnly) : base(collection, itemBody)
 {
     this.readOnly        = itemReadOnly;
     this.clearEmptyLinks = false;
     this.removeLinksToNonImageAttachments = false;
 }
Пример #16
0
        protected override void OnBeforeSave()
        {
            if (this.decodedItem == null && !base.AttachmentCollection.IsDirty && base.IsRestricted && (base.Recipients.IsDirty || base.IsPropertyDirty(ItemSchema.Sender)))
            {
                this.EnsureIsDecoded();
            }
            if (this.decodedItem != null)
            {
                string contentClass = base.TryGetProperty(InternalSchema.ContentClass) as string;
                if (this.rmsTemplate == null)
                {
                    this.UnprotectAllAttachments();
                    RightsManagedMessageItem.CopyProtectableData(this.decodedItem, this);
                    if (ObjectClass.IsRightsManagedContentClass(contentClass))
                    {
                        base.Delete(StoreObjectSchema.ContentClass);
                    }
                }
                else
                {
                    this.charsetDetectionStringForProtectedData = new StringBuilder((int)Math.Min(this.ProtectedBody.Size, 2147483647L));
                    this.GetCharsetDetectionStringFromProtectedData(this.charsetDetectionStringForProtectedData);
                    if (!ObjectClass.IsRightsManagedContentClass(contentClass))
                    {
                        this[StoreObjectSchema.ContentClass] = "rpmsg.message";
                    }
                    if (this.isSending)
                    {
                        byte[][] valueOrDefault = base.GetValueOrDefault <byte[][]>(InternalSchema.DRMLicense);
                        if (valueOrDefault != null && valueOrDefault.Length == RightsManagedMessageItem.EmptyDrmLicense.Length && valueOrDefault[0].Length == RightsManagedMessageItem.EmptyDrmLicense[0].Length)
                        {
                            base.DeleteProperties(new PropertyDefinition[]
                            {
                                InternalSchema.DRMLicense
                            });
                        }
                    }
                    else if (base.IsDraft && base.GetValueOrDefault <byte[][]>(InternalSchema.DRMLicense) == null)
                    {
                        this[InternalSchema.DRMLicense] = RightsManagedMessageItem.EmptyDrmLicense;
                    }
                    base.AttachmentCollection.RemoveAll();
                    using (StreamAttachment streamAttachment = base.AttachmentCollection.Create(AttachmentType.Stream) as StreamAttachment)
                    {
                        streamAttachment.FileName    = "message.rpmsg";
                        streamAttachment.ContentType = "application/x-microsoft-rpmsg-message";
                        using (Stream stream = new PooledMemoryStream(131072))
                        {
                            if (this.serverUseLicense == null || ((this.UsageRights & ContentRight.Owner) == ContentRight.Owner && this.rmsTemplate.RequiresRepublishingWhenRecipientsChange && this.CanRepublish && (base.Recipients.IsDirty || (base.IsPropertyDirty(ItemSchema.Sender) && this.conversationOwner == null))))
                            {
                                if (this.ConversationOwner == null)
                                {
                                    throw new InvalidOperationException("Conversation owner must be set before protecting the message.");
                                }
                                this.UnprotectAllAttachments();
                                using (MsgToRpMsgConverter msgToRpMsgConverter = new MsgToRpMsgConverter(this, this.ConversationOwner, this.orgId, this.rmsTemplate, this.options))
                                {
                                    msgToRpMsgConverter.Convert(this.decodedItem, stream);
                                    using (Stream stream2 = base.OpenPropertyStream(MessageItemSchema.DRMServerLicenseCompressed, PropertyOpenMode.Create))
                                    {
                                        DrmEmailCompression.CompressUseLicense(msgToRpMsgConverter.ServerUseLicense, stream2);
                                    }
                                    if (this.InternalSession != null && this.InternalSession.MailboxOwner.Sid != null)
                                    {
                                        ExDateTime useLicenseExpiryTime = RmsClientManagerUtils.GetUseLicenseExpiryTime(msgToRpMsgConverter.ServerUseLicense, this.UsageRights);
                                        this[MessageItemSchema.DRMRights]     = (int)this.UsageRights;
                                        this[MessageItemSchema.DRMExpiryTime] = useLicenseExpiryTime;
                                        using (RightsSignatureBuilder rightsSignatureBuilder = new RightsSignatureBuilder(msgToRpMsgConverter.ServerUseLicense, msgToRpMsgConverter.PublishLicense, RmsClientManager.EnvironmentHandle, msgToRpMsgConverter.LicensePair))
                                        {
                                            this[MessageItemSchema.DRMPropsSignature] = rightsSignatureBuilder.Sign(this.UsageRights, useLicenseExpiryTime, this.InternalSession.MailboxOwner.Sid);
                                        }
                                    }
                                    goto IL_362;
                                }
                            }
                            using (MsgToRpMsgConverter msgToRpMsgConverter2 = new MsgToRpMsgConverter(this, this.orgId, this.publishLicense, this.serverUseLicense, this.options))
                            {
                                msgToRpMsgConverter2.Convert(this.decodedItem, stream);
                            }
IL_362:
                            using (Stream contentStream = streamAttachment.GetContentStream(PropertyOpenMode.Create))
                            {
                                stream.Seek(0L, SeekOrigin.Begin);
                                Util.StreamHandler.CopyStreamData(stream, contentStream);
                            }
                        }
                        bool flag = false;
                        foreach (AttachmentHandle handle in this.decodedItem.AttachmentCollection)
                        {
                            if (!CoreAttachmentCollection.IsInlineAttachment(handle))
                            {
                                flag = true;
                                break;
                            }
                        }
                        this[InternalSchema.AllAttachmentsHidden] = !flag;
                        streamAttachment.Save();
                    }
                }
                this.decodedItem.Dispose();
                this.decodedItem       = null;
                this.effectiveRights   = ContentRight.Owner;
                this.publishLicense    = null;
                this.restrictionInfo   = null;
                this.rmsTemplate       = null;
                this.serverUseLicense  = null;
                this.conversationOwner = null;
            }
            base.OnBeforeSave();
        }
Пример #17
0
 public void SetCollection(CoreAttachmentCollection attachmentCollection)
 {
     this.attachmentCollection = attachmentCollection;
 }