Пример #1
0
        internal static FolderSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, ISyncProviderFactory syncProviderFactory, string syncStateName, Func <SyncStateStorage, StoreObject, FolderSyncStateMetadata, SyncStateInfo, ISyncProviderFactory, bool, ISyncLogger, FolderSyncState> creator, ISyncLogger syncLogger = null)
        {
            ArgumentValidator.ThrowIfNullOrEmpty("syncStateName", syncStateName);
            SyncStateInfo syncStateInfo        = new FolderSyncStateInfo(syncStateName);
            StoreObject   syncStateStoreObject = SyncState.GetSyncStateStoreObject(syncStateStorage, syncStateParentFolder, syncStateInfo, syncLogger, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            });

            if (syncStateStoreObject == null)
            {
                return(null);
            }
            byte[] valueOrDefault = syncStateStoreObject.GetValueOrDefault <byte[]>(InternalSchema.SyncFolderSourceKey);
            if (syncProviderFactory != null)
            {
                try
                {
                    syncProviderFactory.SetCollectionIdFromBytes(valueOrDefault);
                }
                catch (ArgumentException innerException)
                {
                    syncStateStorage.DeleteFolderSyncState(syncStateName);
                    syncStateStorage.DeviceMetadata.TryRemove(syncStateName, null);
                    throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted(syncStateName), innerException);
                }
            }
            FolderSyncStateMetadata folderSyncStateMetadata = FolderSyncState.GetFolderSyncStateMetadata(syncStateStorage, syncStateStoreObject.Session as MailboxSession, syncStateName, syncLogger);

            if (creator == null)
            {
                return(new FolderSyncState(syncStateStorage, syncStateStoreObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
            }
            return(creator(syncStateStorage, syncStateStoreObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
        }
Пример #2
0
        public static Guid?GetPolicyTagForArchiveFromItem(StoreObject item, out bool isExplicit, out bool isKeptInPlace, out DateTime?moveToArchive)
        {
            isExplicit    = false;
            moveToArchive = null;
            Guid?result = null;

            byte[] array = (byte[])item.GetValueOrDefault <object>(InternalSchema.ArchiveTag);
            if (array != null && array.Length == PolicyTagHelper.SizeOfGuid)
            {
                result = new Guid?(new Guid(array));
            }
            object valueOrDefault = item.GetValueOrDefault <object>(StoreObjectSchema.RetentionFlags);

            if (valueOrDefault != null && valueOrDefault is int)
            {
                isKeptInPlace = (((int)valueOrDefault & 32) != 0);
            }
            else
            {
                isKeptInPlace = false;
            }
            isExplicit    = (item.GetValueOrDefault <object>(StoreObjectSchema.ArchivePeriod) != null);
            moveToArchive = (DateTime?)item.GetValueAsNullable <ExDateTime>(ItemSchema.ArchiveDate);
            return(result);
        }
Пример #3
0
        public static void ClearPolicyTagForArchiveOnItem(StoreObject item)
        {
            if (item.GetValueOrDefault <object>(StoreObjectSchema.ArchiveTag) != null)
            {
                item.DeleteProperties(new PropertyDefinition[]
                {
                    StoreObjectSchema.ArchiveTag
                });
            }
            if (item.GetValueOrDefault <object>(StoreObjectSchema.ArchivePeriod) != null)
            {
                item.DeleteProperties(new PropertyDefinition[]
                {
                    StoreObjectSchema.ArchivePeriod
                });
            }
            if (item.GetValueOrDefault <object>(InternalSchema.ArchiveDate) != null)
            {
                item.DeleteProperties(new PropertyDefinition[]
                {
                    InternalSchema.ArchiveDate
                });
            }
            object valueOrDefault = item.GetValueOrDefault <object>(StoreObjectSchema.RetentionFlags);

            if (valueOrDefault != null && valueOrDefault is int)
            {
                RetentionAndArchiveFlags retentionAndArchiveFlags = (RetentionAndArchiveFlags)((int)valueOrDefault & -33);
                item[StoreObjectSchema.RetentionFlags] = (int)retentionAndArchiveFlags;
            }
        }
Пример #4
0
        public static void SetPolicyTagForDeleteOnItem(PolicyTag policyTag, StoreObject item)
        {
            item[StoreObjectSchema.PolicyTag] = policyTag.PolicyGuid.ToByteArray();
            CompositeRetentionProperty compositeRetentionProperty = null;

            byte[] valueOrDefault = item.GetValueOrDefault <byte[]>(ItemSchema.StartDateEtc);
            if (valueOrDefault != null)
            {
                try
                {
                    compositeRetentionProperty = CompositeRetentionProperty.Parse(valueOrDefault, true);
                }
                catch (ArgumentException)
                {
                    compositeRetentionProperty = null;
                }
            }
            if (compositeRetentionProperty == null)
            {
                compositeRetentionProperty         = new CompositeRetentionProperty();
                compositeRetentionProperty.Integer = (int)policyTag.TimeSpanForRetention.TotalDays;
                object valueOrDefault2 = item.GetValueOrDefault <object>(InternalSchema.ReceivedTime);
                if (valueOrDefault2 == null)
                {
                    valueOrDefault2 = item.GetValueOrDefault <object>(StoreObjectSchema.CreationTime);
                }
                if (valueOrDefault2 == null)
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)ExDateTime.Now);
                }
                else
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)((ExDateTime)valueOrDefault2));
                }
                item[InternalSchema.StartDateEtc] = compositeRetentionProperty.GetBytes(true);
            }
            long fileTime = 0L;

            try
            {
                fileTime = compositeRetentionProperty.Date.Value.AddDays(policyTag.TimeSpanForRetention.TotalDays).ToFileTimeUtc();
            }
            catch (ArgumentOutOfRangeException)
            {
                fileTime = 0L;
            }
            item[InternalSchema.RetentionPeriod] = (int)policyTag.TimeSpanForRetention.TotalDays;
            DateTime dateTime = DateTime.FromFileTimeUtc(fileTime);

            item[InternalSchema.RetentionDate] = dateTime;
            if (item.GetValueOrDefault <object>(StoreObjectSchema.ExplicitPolicyTag) != null)
            {
                item.DeleteProperties(new PropertyDefinition[]
                {
                    StoreObjectSchema.ExplicitPolicyTag
                });
            }
        }
Пример #5
0
        internal static void Adjust(StoreObject storeObject)
        {
            Item item = storeObject as Item;

            if (item != null && item.Reminder != null)
            {
                item.LocationIdentifierHelperInstance.SetLocationIdentifier(43509U);
                item.Reminder.Adjust();
            }
        }
Пример #6
0
        public static void SetPolicyTagForDeleteOnNewItem(PolicyTag policyTag, StoreObject item)
        {
            item[StoreObjectSchema.PolicyTag]      = policyTag.PolicyGuid.ToByteArray();
            item[StoreObjectSchema.RetentionFlags] = 0;
            CompositeRetentionProperty setStartDateEtc = PolicyTagHelper.GetSetStartDateEtc(policyTag, item);

            if (policyTag.TimeSpanForRetention.TotalDays > 0.0)
            {
                item[InternalSchema.RetentionPeriod] = (int)policyTag.TimeSpanForRetention.TotalDays;
                item[InternalSchema.RetentionDate]   = PolicyTagHelper.CalculateExecutionDate(setStartDateEtc, policyTag.TimeSpanForRetention.TotalDays);
            }
        }
Пример #7
0
        internal static void SetCalendarTime(PropertyBag.BasicPropertyStore propertyBag, GuidIdPropertyDefinition utcTimeProperty, PropertyTagPropertyDefinition legacyUtcTimeProperty, GuidIdPropertyDefinition timeZoneDefinition, bool isEndTime, object value)
        {
            StoreObject      storeObject      = propertyBag.Context.StoreObject;
            CalendarItemBase calendarItemBase = storeObject as CalendarItemBase;

            if (calendarItemBase != null && calendarItemBase.PropertyBag.ExTimeZone != null && calendarItemBase.IsAllDayEventCache == null)
            {
                object obj = IsAllDayEventProperty.CalculateIsAllDayEvent(propertyBag);
                if (obj is bool)
                {
                    calendarItemBase.IsAllDayEventCache = new bool?((bool)obj);
                }
            }
            propertyBag.SetValueWithFixup(utcTimeProperty, value);
            propertyBag.SetValueWithFixup(legacyUtcTimeProperty, value);
            ExTimeZone timeZone = propertyBag.TimeZone;

            if (value is ExDateTime && ((ExDateTime)value).TimeZone != null && ((ExDateTime)value).TimeZone != ExTimeZone.UnspecifiedTimeZone)
            {
                timeZone = ((ExDateTime)value).TimeZone;
            }
            if (timeZone == ExTimeZone.UtcTimeZone)
            {
                if (!(storeObject is CalendarItemOccurrence))
                {
                    propertyBag.Delete(timeZoneDefinition);
                }
            }
            else if (value is ExDateTime && timeZone != ExTimeZone.UnspecifiedTimeZone)
            {
                if (timeZoneDefinition == InternalSchema.TimeZoneDefinitionStart)
                {
                    byte[] timeZoneBlob = O12TimeZoneFormatter.GetTimeZoneBlob(timeZone);
                    StartTimeZoneProperty.RecalculateNormalizedTimeProperty(propertyBag, InternalSchema.MapiEndTime, InternalSchema.MapiPREndDate, timeZone);
                    StartTimeZoneProperty.RecalculateNormalizedTimeProperty(propertyBag, InternalSchema.ReminderNextTime, null, timeZone);
                    StartTimeZoneProperty.SyncRecurringTimeZoneProperties(propertyBag, timeZone, timeZoneBlob);
                    propertyBag.SetValueWithFixup(timeZoneDefinition, timeZoneBlob);
                }
                else
                {
                    byte[] timeZoneBlob2 = O12TimeZoneFormatter.GetTimeZoneBlob(timeZone, (ExDateTime)value);
                    propertyBag.SetValueWithFixup(timeZoneDefinition, timeZoneBlob2);
                }
            }
            if (!isEndTime)
            {
                propertyBag.SetValueWithFixup(InternalSchema.ReminderDueByInternal, value);
            }
            if (storeObject != null)
            {
                Reminder.Adjust(storeObject);
            }
        }
Пример #8
0
 protected override void UpdateNewItemProperties()
 {
     base.UpdateNewItemProperties();
     this.newItem[InternalSchema.Importance] = (Importance)StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.Importance), typeof(Importance), Importance.Normal);
     this.newItem[InternalSchema.Codepage]   = (int)StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.Codepage), typeof(int), 0);
     if (this.originalItem is MeetingRequest || this.originalItem is MeetingCancellation || this.originalItem is CalendarItemBase || base.TreatAsMeetingMessage)
     {
         this.newItem.SetOrDeleteProperty(InternalSchema.From, this.originalItem.GetValueOrDefault <Participant>(InternalSchema.From));
         this.newItem.SetOrDeleteProperty(InternalSchema.AcceptLanguage, this.originalItem.GetValueOrDefault <string>(InternalSchema.AcceptLanguage));
     }
     this.newItem[InternalSchema.OriginalAuthorName] = string.Empty;
 }
        internal static FolderHierarchySyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, StoreObjectId storeObjectId, ISyncLogger syncLogger = null)
        {
            SyncStateInfo syncStateInfo        = new FolderHierarchySyncStateInfo();
            StoreObject   syncStateStoreObject = SyncState.GetSyncStateStoreObject(syncStateStorage, syncStateParentFolder, syncStateInfo, syncLogger, new PropertyDefinition[0]);

            if (syncStateStoreObject == null)
            {
                return(null);
            }
            SyncStateMetadata syncState = syncStateStorage.DeviceMetadata.GetSyncState(syncStateParentFolder.Session as MailboxSession, syncStateInfo.UniqueName, syncLogger);

            return(new FolderHierarchySyncState(syncStateStorage, syncStateStoreObject, syncState, syncStateInfo, false, syncLogger));
        }
Пример #10
0
        internal static CustomSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, SyncStateInfo syncStateInfo, ISyncLogger syncLogger, params PropertyDefinition[] propertiesToFetch)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateMetadata syncStateMetadata    = null;
            StoreObject       syncStateStoreObject = SyncState.GetSyncStateStoreObject(syncStateStorage, syncStateParentFolder, syncStateInfo, syncLogger, out syncStateMetadata, propertiesToFetch);

            if (syncStateStoreObject == null)
            {
                return(null);
            }
            return(new CustomSyncState(syncStateStorage, syncStateStoreObject, syncStateMetadata, syncStateInfo, false));
        }
Пример #11
0
 public static void SetRetentionProperties(StoreObject item, ExDateTime dateToExpireOn, int retentionPeriodInDays)
 {
     if (!(item is Item))
     {
         throw new ArgumentException("item must be of type Item. It cannot be null, a folder or anything else.");
     }
     if (retentionPeriodInDays <= 0)
     {
         throw new ArgumentException("retentionPeriodInDays must be greater than 0. The minimum value allowed is 1 day.");
     }
     item[StoreObjectSchema.PolicyTag]       = PolicyTagHelper.SystemCleanupTagGuid.ToByteArray();
     item[ItemSchema.RetentionDate]          = (DateTime)dateToExpireOn.ToUtc();
     item[StoreObjectSchema.RetentionPeriod] = retentionPeriodInDays;
     item[StoreObjectSchema.RetentionFlags]  = 64;
 }
Пример #12
0
        public static Guid?GetPolicyTagForDeleteFromItem(StoreObject item, out bool isExplicit, out DateTime?deleteTime)
        {
            isExplicit = false;
            deleteTime = null;
            Guid?result = null;

            byte[] array = (byte[])item.GetValueOrDefault <object>(InternalSchema.PolicyTag);
            if (array != null && array.Length == PolicyTagHelper.SizeOfGuid)
            {
                result = new Guid?(new Guid(array));
            }
            isExplicit = (item.GetValueOrDefault <object>(StoreObjectSchema.RetentionPeriod) != null);
            deleteTime = (DateTime?)item.GetValueAsNullable <ExDateTime>(ItemSchema.RetentionDate);
            return(result);
        }
Пример #13
0
        public static void SetKeepInPlaceForArchiveOnItem(StoreObject item)
        {
            PolicyTagHelper.ClearPolicyTagForArchiveOnItem(item);
            object valueOrDefault = item.GetValueOrDefault <object>(StoreObjectSchema.RetentionFlags);
            RetentionAndArchiveFlags retentionAndArchiveFlags;

            if (valueOrDefault != null && valueOrDefault is int)
            {
                retentionAndArchiveFlags = (RetentionAndArchiveFlags)((int)valueOrDefault | 32);
            }
            else
            {
                retentionAndArchiveFlags = RetentionAndArchiveFlags.KeepInPlace;
            }
            item[StoreObjectSchema.RetentionFlags] = (int)retentionAndArchiveFlags;
        }
Пример #14
0
        internal static CustomSyncState CreateSyncState(SyncStateStorage syncStateStorage, SyncStateInfo syncStateInfo, Folder syncStateParentFolder, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            StoreObject storeObject = SyncState.CreateSyncStateStoreObject(syncStateStorage, syncStateInfo, syncStateParentFolder, null, null, syncLogger);

            if (syncStateStorage.DeviceMetadata.TryRemove(syncStateInfo.UniqueName, syncLogger) != null)
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[CustomSyncState.CreateSyncState] Removed stale cached sync state metadata for device {0}, sync state {1}", syncStateStorage.DeviceMetadata.Id, syncStateInfo.UniqueName);
            }
            SyncStateMetadata syncStateMetadata = (storeObject is Item) ? new SyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, syncStateStorage.SaveOnDirectItems ? null : storeObject.ParentId, storeObject.Id.ObjectId) : new SyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, storeObject.Id.ObjectId, null);

            return(new CustomSyncState(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, true));
        }
Пример #15
0
        public static MessageItem CreateNotReadNotification(MessageItem originalItem)
        {
            ExDateTime  utcNow      = ExDateTime.UtcNow;
            MessageItem messageItem = MessageItem.CreateInMemory(StoreObjectSchema.ContentConversionProperties);

            messageItem.ClassName = ObjectClass.MakeReportClassName(originalItem.ClassName, "IPNNRN");
            messageItem.SafeSetProperty(InternalSchema.ReportTime, utcNow);
            Participant participant = originalItem.ReadReceiptAddressee;

            if (null == participant)
            {
                if (null != originalItem.Sender)
                {
                    participant = originalItem.Sender;
                }
                else
                {
                    participant = originalItem.From;
                }
            }
            messageItem.Recipients.Add(participant, RecipientItemType.To);
            foreach (KeyValuePair <PropertyDefinition, PropertyDefinition> keyValuePair in RuleMessageUtils.NrnPropertyMap)
            {
                messageItem.SafeSetProperty(keyValuePair.Key, originalItem.TryGetProperty(keyValuePair.Value));
            }
            BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextHtml, originalItem.Body.RawCharset.Name);
            CultureInfo            formatProvider;

            using (Stream stream = messageItem.Body.OpenWriteStream(configuration))
            {
                Charset charset;
                ReportMessage.GenerateReportBody(messageItem, stream, out formatProvider, out charset);
            }
            messageItem.SafeSetProperty(InternalSchema.Subject, ServerStrings.NotRead.ToString(formatProvider) + originalItem.TryGetProperty(InternalSchema.Subject));
            byte[] parentBytes = originalItem.TryGetProperty(InternalSchema.ConversationIndex) as byte[];
            messageItem.SafeSetProperty(InternalSchema.ConversationIndex, ConversationIndex.CreateFromParent(parentBytes).ToByteArray());
            messageItem.SafeSetProperty(InternalSchema.ConversationTopic, StoreObject.SafePropertyValue(originalItem.TryGetProperty(InternalSchema.ConversationTopic), typeof(string), StoreObject.SafePropertyValue(originalItem.TryGetProperty(InternalSchema.NormalizedSubjectInternal), typeof(string), null)));
            messageItem.SafeSetProperty(InternalSchema.IsReadReceiptRequested, false);
            messageItem.SafeSetProperty(InternalSchema.IsDeliveryReceiptRequested, false);
            messageItem.SafeSetProperty(InternalSchema.IsNonDeliveryReceiptRequested, false);
            messageItem.SafeSetProperty(InternalSchema.NonReceiptReason, 0);
            messageItem.SafeSetProperty(InternalSchema.DiscardReason, 1);
            messageItem.SafeSetProperty(InternalSchema.OriginalDeliveryTime, utcNow);
            return(messageItem);
        }
Пример #16
0
        internal static FolderSyncState CreateSyncState(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, ISyncProviderFactory syncProviderFactory, string syncFolderId, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            SyncStateInfo syncStateInfo = new FolderSyncStateInfo(syncFolderId);
            StoreObject   storeObject   = SyncState.CreateSyncStateStoreObject(syncStateStorage, syncStateInfo, syncStateParentFolder, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            }, new object[]
            {
                syncProviderFactory.GetCollectionIdBytes()
            }, syncLogger);

            if (syncStateStorage.DeviceMetadata.TryRemove(syncStateInfo.UniqueName, syncLogger) != null)
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.CreateSyncState] Removed stale cached sync state metadata for device {0}, sync state {1}", syncStateStorage.DeviceMetadata.Id, syncStateInfo.UniqueName);
            }
            FolderSyncStateMetadata syncStateMetadata = (storeObject is Item) ? new FolderSyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, syncStateStorage.SaveOnDirectItems ? null : storeObject.ParentId, storeObject.Id.ObjectId, StoreObjectId.Deserialize(syncProviderFactory.GetCollectionIdBytes())) : new FolderSyncStateMetadata(syncStateStorage.DeviceMetadata, syncStateInfo.UniqueName, storeObject.Id.ObjectId, null, StoreObjectId.Deserialize(syncProviderFactory.GetCollectionIdBytes()));

            return(new FolderSyncState(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, syncProviderFactory, true, syncLogger));
        }
Пример #17
0
        protected static StoreObject GetSyncStateStoreObject(SyncStateStorage syncStateStorage, Folder syncStateParentFolder, SyncStateInfo syncStateInfo, byte[] identBytes, ISyncLogger syncLogger, params PropertyDefinition[] propsToReturn)
        {
            FolderSyncStateMetadata folderSyncStateMetadata = FolderSyncState.GetFolderSyncStateMetadata(syncStateStorage, syncStateParentFolder.Session as MailboxSession, syncStateInfo.UniqueName, syncLogger);

            if (folderSyncStateMetadata == null)
            {
                return(null);
            }
            StoreObject storeObject = null;

            if (folderSyncStateMetadata.StorageType != StorageType.Folder)
            {
                if (folderSyncStateMetadata.StorageType != StorageType.Item)
                {
                    if (folderSyncStateMetadata.StorageType != StorageType.DirectItem)
                    {
                        goto IL_85;
                    }
                }
                try
                {
                    storeObject = Microsoft.Exchange.Data.Storage.Item.Bind(syncStateParentFolder.Session, folderSyncStateMetadata.ItemSyncStateId, SyncState.AppendAdditionalProperties(propsToReturn));
                    ((Item)storeObject).OpenAsReadWrite();
                    return(storeObject);
                }
                catch
                {
                    storeObject.Dispose();
                    throw;
                }
IL_85:
                throw new InvalidOperationException("Unsupported storage type for sync state");
            }
            storeObject = Folder.Bind(syncStateParentFolder.Session, folderSyncStateMetadata.FolderSyncStateId, SyncState.AppendAdditionalProperties(propsToReturn));
            return(storeObject);
        }
Пример #18
0
 protected override void UpdateNewItemProperties()
 {
     base.UpdateNewItemProperties();
     if ((this.parameters.ForwardCreationFlags & ForwardCreationFlags.PreserveSender) == ForwardCreationFlags.PreserveSender)
     {
         PostItem postItem = this.newItem as PostItem;
         if (postItem != null)
         {
             postItem.Sender = ((PostItem)this.originalItem).Sender;
         }
         else
         {
             ((MessageItem)this.newItem).Sender = ((MessageItem)this.originalItem).Sender;
         }
     }
     this.newItem[InternalSchema.Importance]         = (Importance)StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.Importance), typeof(Importance), Importance.Normal);
     this.newItem[InternalSchema.OriginalAuthorName] = string.Empty;
     if (this.originalItem is MeetingRequest || this.originalItem is MeetingCancellation || this.originalItem is CalendarItemBase || base.TreatAsMeetingMessage)
     {
         this.newItem.SetOrDeleteProperty(InternalSchema.From, this.originalItem.GetValueOrDefault <Participant>(InternalSchema.From));
         this.newItem.SetOrDeleteProperty(InternalSchema.AcceptLanguage, this.originalItem.GetValueOrDefault <string>(InternalSchema.AcceptLanguage));
         this.UpdateCalendarProperties();
     }
 }
Пример #19
0
 public static void ClearPolicyTagForDeleteOnItem(StoreObject item)
 {
     if (item.GetValueOrDefault <object>(StoreObjectSchema.PolicyTag) != null)
     {
         item.DeleteProperties(new PropertyDefinition[]
         {
             StoreObjectSchema.PolicyTag
         });
     }
     if (item.GetValueOrDefault <object>(StoreObjectSchema.RetentionPeriod) != null)
     {
         item.DeleteProperties(new PropertyDefinition[]
         {
             StoreObjectSchema.RetentionPeriod
         });
     }
     if (item.GetValueOrDefault <object>(InternalSchema.RetentionDate) != null)
     {
         item.DeleteProperties(new PropertyDefinition[]
         {
             InternalSchema.RetentionDate
         });
     }
 }
 protected FolderHierarchySyncState(SyncStateStorage syncStateStorage, StoreObject storeObject, SyncStateMetadata syncStateMetadata, SyncStateInfo syncStateInfo, bool newSyncState, ISyncLogger syncLogger = null) : base(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, newSyncState, syncLogger)
 {
 }
Пример #21
0
 protected CustomSyncState(SyncStateStorage syncStateStorage, StoreObject storeObject, SyncStateMetadata syncStateMetadata, SyncStateInfo syncStateInfo, bool syncStateIsNew) : base(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, syncStateIsNew, null)
 {
 }
Пример #22
0
        private static CompositeRetentionProperty GetSetStartDateEtc(PolicyTag policyTag, StoreObject item)
        {
            CompositeRetentionProperty compositeRetentionProperty = null;

            byte[] array = null;
            try
            {
                array = item.GetValueOrDefault <byte[]>(InternalSchema.StartDateEtc);
            }
            catch (NotInBagPropertyErrorException)
            {
                array = null;
            }
            if (array != null)
            {
                try
                {
                    compositeRetentionProperty = CompositeRetentionProperty.Parse(array, true);
                }
                catch (ArgumentException)
                {
                    compositeRetentionProperty = null;
                }
            }
            if (compositeRetentionProperty == null)
            {
                compositeRetentionProperty         = new CompositeRetentionProperty();
                compositeRetentionProperty.Integer = (int)policyTag.TimeSpanForRetention.TotalDays;
                object valueOrDefault = item.GetValueOrDefault <object>(InternalSchema.ReceivedTime);
                if (valueOrDefault == null)
                {
                    valueOrDefault = item.GetValueOrDefault <object>(StoreObjectSchema.CreationTime);
                }
                if (valueOrDefault == null)
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)ExDateTime.Now);
                }
                else
                {
                    compositeRetentionProperty.Date = new DateTime?((DateTime)((ExDateTime)valueOrDefault));
                }
                item[InternalSchema.StartDateEtc] = compositeRetentionProperty.GetBytes(true);
            }
            return(compositeRetentionProperty);
        }
Пример #23
0
 public static Schema GetSchema(StoreObject storeObject)
 {
     return(ObjectClass.GetSchema(storeObject.ClassName));
 }
Пример #24
0
 protected FolderSyncState(SyncStateStorage syncStateStorage, StoreObject storeObject, FolderSyncStateMetadata syncStateMetadata, SyncStateInfo syncStateInfo, ISyncProviderFactory syncProviderFactory, bool newSyncState, ISyncLogger syncLogger = null) : base(syncStateStorage, storeObject, syncStateMetadata, syncStateInfo, newSyncState, syncLogger)
 {
     this.syncProviderFactory = syncProviderFactory;
 }
Пример #25
0
        internal static FolderSyncState GetSyncState(SyncStateStorage syncStateStorage, Folder deviceFolder, ISyncProviderFactory syncProviderFactory, Func <SyncStateStorage, StoreObject, FolderSyncStateMetadata, SyncStateInfo, ISyncProviderFactory, bool, ISyncLogger, FolderSyncState> creator, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            ArgumentValidator.ThrowIfNull("syncStateStorage", syncStateStorage);
            ArgumentValidator.ThrowIfNull("deviceFolder", deviceFolder);
            ArgumentValidator.ThrowIfNull("syncProviderFactory", syncProviderFactory);
            byte[] collectionIdBytes = syncProviderFactory.GetCollectionIdBytes();
            if (collectionIdBytes == null || collectionIdBytes.Length == 0)
            {
                throw new ArgumentException("SyncProviderFactory CollectionId bytes cannot be null or empty.");
            }
            StoreObjectId storeObjectId = null;

            try
            {
                storeObjectId = StoreObjectId.Deserialize(collectionIdBytes);
            }
            catch (ArgumentException innerException)
            {
                syncLogger.TraceError <string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.GetSyncState(syncProviderFactory)] The IPMFolderBytes that the provider gave us are invalid for folder {0}", deviceFolder.DisplayName);
                throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted(deviceFolder.DisplayName), innerException);
            }
            FolderSyncStateMetadata folderSyncStateMetadata = null;

            if (!syncStateStorage.DeviceMetadata.SyncStatesByIPMFolderId.TryGetValue(storeObjectId, out folderSyncStateMetadata))
            {
                syncLogger.TraceDebug <DeviceIdentity, string>(ExTraceGlobals.SyncTracer, 0L, "[FolderSyncState.GetSyncState(syncProviderFactory)] Cache miss for device {0}, IPM folder Id {1}", syncStateStorage.DeviceMetadata.Id, storeObjectId.ToBase64String());
                return(null);
            }
            SyncStateMetadata syncStateMetadata = folderSyncStateMetadata;
            StoreObject       storeObject       = SyncState.GetSyncStateStoreObject(deviceFolder, ref syncStateMetadata, syncLogger, new PropertyDefinition[]
            {
                InternalSchema.SyncFolderSourceKey
            });

            if (!object.ReferenceEquals(folderSyncStateMetadata, syncStateMetadata))
            {
                FolderSyncStateMetadata folderSyncStateMetadata2 = syncStateMetadata as FolderSyncStateMetadata;
                if (folderSyncStateMetadata2 == null)
                {
                    syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetSyncState] Device {0} has non-folder sync state for {1}.  Returning null.", deviceFolder.DisplayName, folderSyncStateMetadata.Name);
                    if (storeObject != null)
                    {
                        storeObject.Dispose();
                        storeObject = null;
                    }
                }
                else
                {
                    syncLogger.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, 0L, "[FolderSyncState.GetSyncState] Device {0} had  state folder sync state metadata for {1}.  Replacing.", deviceFolder.DisplayName, folderSyncStateMetadata.Name);
                    folderSyncStateMetadata = folderSyncStateMetadata2;
                }
            }
            if (storeObject == null)
            {
                return(null);
            }
            SyncStateInfo syncStateInfo = new FolderSyncStateInfo(folderSyncStateMetadata.Name);

            if (creator == null)
            {
                return(new FolderSyncState(syncStateStorage, storeObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
            }
            return(creator(syncStateStorage, storeObject, folderSyncStateMetadata, syncStateInfo, syncProviderFactory, false, syncLogger));
        }
Пример #26
0
        protected virtual void UpdateNewItemProperties()
        {
            IExchangePrincipal exchangePrincipal = (this.newItem.Session == null) ? null : this.newItem.Session.MailboxOwner;
            MailboxSession     mailboxSession    = this.newItem.Session as MailboxSession;

            if (mailboxSession != null && exchangePrincipal != null)
            {
                PostItem postItem = this.newItem as PostItem;
                if (postItem != null)
                {
                    postItem.Sender = new Participant(exchangePrincipal);
                }
                else
                {
                    ((MessageItem)this.newItem).Sender = new Participant(exchangePrincipal);
                }
            }
            string text           = null;
            string valueOrDefault = this.originalItem.GetValueOrDefault <string>(InternalSchema.InternetMessageId);

            if (!string.IsNullOrEmpty(valueOrDefault))
            {
                text = valueOrDefault;
            }
            string text2 = null;

            valueOrDefault = this.originalItem.GetValueOrDefault <string>(InternalSchema.InReplyTo);
            if (!string.IsNullOrEmpty(valueOrDefault))
            {
                text2 = valueOrDefault;
            }
            this.newItem.SafeSetProperty(InternalSchema.InReplyTo, text);
            StringBuilder stringBuilder = new StringBuilder(128);

            valueOrDefault = this.originalItem.GetValueOrDefault <string>(InternalSchema.InternetReferences);
            if (!string.IsNullOrEmpty(valueOrDefault))
            {
                stringBuilder.Append(valueOrDefault);
            }
            else if (text2 != null)
            {
                stringBuilder.Append(text2);
            }
            if (text != null)
            {
                if (stringBuilder.Length + 1 + text.Length > 32768 || stringBuilder.Length == 0)
                {
                    stringBuilder.Clear();
                    stringBuilder.Append(text);
                }
                else
                {
                    stringBuilder.Append(',');
                    stringBuilder.Append(text);
                }
            }
            this.newItem.SafeSetProperty(InternalSchema.InternetReferences, stringBuilder.ToString());
            this.newItem.SafeSetProperty(InternalSchema.Categories, StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.Categories), typeof(string[]), null));
            byte[]            parentBytes       = this.originalItem.TryGetProperty(InternalSchema.ConversationIndex) as byte[];
            ConversationIndex conversationIndex = ConversationIndex.CreateFromParent(parentBytes);

            this.newItem.SafeSetProperty(InternalSchema.ConversationIndex, conversationIndex.ToByteArray());
            ConversationId valueOrDefault2 = this.originalItem.GetValueOrDefault <ConversationId>(InternalSchema.ConversationFamilyId);

            this.newItem.SafeSetProperty(InternalSchema.ConversationFamilyId, valueOrDefault2);
            object propValue = this.originalItem.TryGetProperty(InternalSchema.SupportsSideConversation);

            this.newItem.SafeSetProperty(InternalSchema.SupportsSideConversation, propValue);
            ConversationCreatorSidCalculatorFactory conversationCreatorSidCalculatorFactory = new ConversationCreatorSidCalculatorFactory(XSOFactory.Default);
            IConversationCreatorSidCalculator       conversationCreatorSidCalculator;

            byte[] propValue2;
            if (conversationCreatorSidCalculatorFactory.TryCreate(mailboxSession, exchangePrincipal, out conversationCreatorSidCalculator) && conversationCreatorSidCalculator.TryCalculateOnReply(conversationIndex, out propValue2))
            {
                this.newItem.SafeSetProperty(ItemSchema.ConversationCreatorSID, propValue2);
            }
            bool?valueAsNullable = this.originalItem.GetValueAsNullable <bool>(InternalSchema.ConversationIndexTracking);

            if (valueAsNullable != null && valueAsNullable.Value)
            {
                this.newItem.SafeSetProperty(InternalSchema.ConversationIndexTracking, true);
            }
            this.newItem.SafeSetProperty(InternalSchema.ConversationTopic, StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.ConversationTopic), typeof(string), StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.NormalizedSubjectInternal), typeof(string), null)));
            this.newItem.SafeSetProperty(InternalSchema.Sensitivity, StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.Sensitivity), typeof(Sensitivity), Sensitivity.Normal));
            this.newItem.SafeSetProperty(InternalSchema.OriginalSensitivity, StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.OriginalSensitivity), typeof(Sensitivity), Sensitivity.Normal));
            this.newItem.SafeSetProperty(InternalSchema.IsReadReceiptRequested, false);
            this.newItem.SafeSetProperty(InternalSchema.IsDeliveryReceiptRequested, false);
            this.newItem.SafeSetProperty(InternalSchema.IsReplyRequested, StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.IsReplyRequested), typeof(bool), null));
            this.newItem.SafeSetProperty(InternalSchema.IsResponseRequested, StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.IsResponseRequested), typeof(bool), null));
            this.newItem.SafeSetProperty(InternalSchema.NativeBlockStatus, StoreObject.SafePropertyValue(this.originalItem.TryGetProperty(InternalSchema.NativeBlockStatus), typeof(int), null));
            object obj = this.originalItem.TryGetProperty(InternalSchema.IconIndex);

            if (!PropertyError.IsPropertyError(obj))
            {
                IconIndex iconIndex = (IconIndex)obj;
                if (iconIndex != IconIndex.Default)
                {
                    iconIndex = ReplyForwardCommon.GetIconIndexForNewItem(iconIndex);
                    this.newItem.SafeSetProperty(InternalSchema.IconIndex, iconIndex);
                }
            }
            ReplyForwardCommon.UpdateXLoop(this.originalItem, this.newItem, this.parameters.XLoop);
        }