예제 #1
0
        internal static CompositeProperty Parse(byte[] propertyBytes, bool useFileTime)
        {
            if (propertyBytes.Length != 12)
            {
                throw new ArgumentException("The length of the composite property must be 12. It is: " + propertyBytes.Length);
            }
            CompositeProperty compositeProperty = new CompositeProperty();

            compositeProperty.integer = BitConverter.ToInt32(propertyBytes, 0);
            if (useFileTime)
            {
                long num = BitConverter.ToInt64(propertyBytes, 4);
                if (num == 0L)
                {
                    compositeProperty.date = new DateTime?(DateTime.MinValue);
                }
                else
                {
                    compositeProperty.date = new DateTime?(DateTime.FromFileTimeUtc(num));
                }
            }
            else
            {
                compositeProperty.date = new DateTime?(DateTime.FromBinary(BitConverter.ToInt64(propertyBytes, 4)));
            }
            return(compositeProperty);
        }
예제 #2
0
        internal static void ApplyPolicy(MailboxSession mailboxSession, object policy, object flags, object period, object archivePolicy, object archivePeriod, object compactDefaultPolicy, MessageItem messageItem, bool keepRetentionTag)
        {
            if (policy == null && compactDefaultPolicy == null)
            {
                using (Folder folder = Folder.Bind(mailboxSession, messageItem.ParentId, new PropertyDefinition[]
                {
                    StoreObjectSchema.PolicyTag,
                    StoreObjectSchema.RetentionPeriod,
                    StoreObjectSchema.RetentionFlags,
                    StoreObjectSchema.ArchiveTag,
                    StoreObjectSchema.ArchivePeriod,
                    FolderSchema.RetentionTagEntryId
                }))
                {
                    RetentionTagHelper.ReadPolicyFromFolder(folder, out policy, out flags, out period, out archivePolicy, out archivePeriod, out compactDefaultPolicy);
                }
            }
            bool       flag  = false;
            bool       flag2 = false;
            ExDateTime d     = messageItem.ReceivedTime;

            if (d == ExDateTime.MinValue)
            {
                d = messageItem.SentTime;
                if (d == ExDateTime.MinValue)
                {
                    d = ExDateTime.Now;
                }
            }
            if (archivePolicy != null && archivePolicy is byte[] && archivePeriod != null && archivePeriod is int)
            {
                flag2 = true;
            }
            if (policy != null && policy is byte[] && period != null && period is int)
            {
                flag = true;
            }
            if (flag2)
            {
                try
                {
                    messageItem[ItemSchema.ArchiveDate] = d.AddDays((double)((int)archivePeriod));
                }
                catch (ArgumentOutOfRangeException)
                {
                    messageItem[ItemSchema.ArchiveDate] = DateTime.MaxValue;
                }
                messageItem[StoreObjectSchema.ArchiveTag] = (archivePolicy as byte[]);
            }
            else
            {
                messageItem.DeleteProperties(new PropertyDefinition[]
                {
                    StoreObjectSchema.ArchiveTag
                });
                messageItem.DeleteProperties(new PropertyDefinition[]
                {
                    ItemSchema.ArchiveDate
                });
            }
            Guid guid;
            int  num;

            RetentionTagHelper.GetDefaultPolicyInfo(mailboxSession, messageItem, compactDefaultPolicy, out guid, out num);
            if (!keepRetentionTag)
            {
                if (flag)
                {
                    try
                    {
                        messageItem[ItemSchema.RetentionDate] = d.AddDays((double)((int)period));
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        messageItem[ItemSchema.RetentionDate] = DateTime.MaxValue;
                    }
                    messageItem[StoreObjectSchema.PolicyTag] = (policy as byte[]);
                }
                else
                {
                    if (num > 0)
                    {
                        try
                        {
                            messageItem[ItemSchema.RetentionDate] = d.AddDays((double)num);
                            goto IL_223;
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            messageItem[ItemSchema.RetentionDate] = DateTime.MaxValue;
                            goto IL_223;
                        }
                    }
                    messageItem.DeleteProperties(new PropertyDefinition[]
                    {
                        ItemSchema.RetentionDate
                    });
IL_223:
                    if (!guid.Equals(Guid.Empty))
                    {
                        messageItem[StoreObjectSchema.PolicyTag] = guid.ToByteArray();
                    }
                    else
                    {
                        messageItem.DeleteProperties(new PropertyDefinition[]
                        {
                            StoreObjectSchema.PolicyTag
                        });
                        if (!flag2)
                        {
                            return;
                        }
                    }
                }
            }
            else if (!flag2)
            {
                return;
            }
            CompositeProperty compositeProperty = new CompositeProperty(num, d.UniversalTime);

            messageItem[ItemSchema.StartDateEtc]          = compositeProperty.GetBytes(true);
            messageItem[StoreObjectSchema.RetentionFlags] = 0;
        }
예제 #3
0
 internal static CompositeProperty Parse(byte[] propertyBytes)
 {
     return(CompositeProperty.Parse(propertyBytes, false));
 }