/// <summary> /// <see cref="ExchangeSyncProvider.FillItemsFilterCollection"/> /// </summary> protected override void FillItemsFilterCollection() { _itemsFilterCollection = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And); var draftFilter = new Exchange.SearchFilter.IsNotEqualTo(Exchange.ItemSchema.IsDraft, true); _itemsFilterCollection.Add(draftFilter); if (_userConnection.GetIsFeatureEnabled("SetEmailSynchronizedInExchange")) { var customPropSetFilter = new Exchange.SearchFilter.Exists(ExchangeUtilityImpl.LocalIdProperty); var notCustomPropSetFilter = new Exchange.SearchFilter.Not(customPropSetFilter); _itemsFilterCollection.Add(notCustomPropSetFilter); } DateTime loadEmailsFromDate = LoadEmailsFromDate != DateTime.MinValue ? LoadEmailsFromDate : UserSettings.LastSyncDate; LogError($"LoadEmailsFromDate = '{LoadEmailsFromDate}', LastSyncDate = '{UserSettings.LastSyncDate}', result = '{loadEmailsFromDate}'"); if (loadEmailsFromDate != DateTime.MinValue) { var localLastSyncDate = GetLastSyncDate(loadEmailsFromDate); var itemsFilter = new Exchange.SearchFilter.IsGreaterThan(Exchange.ItemSchema.LastModifiedTime, localLastSyncDate); _itemsFilterCollection.Add(itemsFilter); LogError($"LoadEmailsFromDate filter adedd, filter date '{localLastSyncDate}'"); } }
/// <summary> /// Gets filters for Exchange data query. /// </summary> /// <returns>Filter instance.</returns> private Exchange.SearchFilter.SearchFilterCollection GetItemsSearchFilters() { var itemsFilter = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And) { new Exchange.SearchFilter.IsEqualTo(Exchange.ItemSchema.ItemClass, ExchangeConsts.TaskItemClassName) }; DateTime lastSyncDateUtc = TimeZoneInfo.ConvertTimeToUtc(UserSettings.LastSyncDate, TimeZone); DateTime importActivitiesFromDate = UserSettings.ImportActivitiesFrom; if (UserSettings.ImportActivitiesFrom != DateTime.MinValue) { itemsFilter.Add(new Exchange.SearchFilter.IsGreaterThanOrEqualTo( Exchange.TaskSchema.LastModifiedTime, importActivitiesFromDate)); } if (UserSettings.LastSyncDate != DateTime.MinValue) { var lastSyncDateUtcFilter = new Exchange.SearchFilter.IsGreaterThan( Exchange.ItemSchema.LastModifiedTime, lastSyncDateUtc.ToLocalTime()); var filterCollection = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.Or); var customPropSetFilter = new Exchange.SearchFilter.Exists(ExchangeUtilityImpl.LocalIdProperty); var notCustomPropSetFilter = new Exchange.SearchFilter.Not(customPropSetFilter); filterCollection.AddRange(new List <Exchange.SearchFilter> { lastSyncDateUtcFilter, notCustomPropSetFilter }); itemsFilter.Add(filterCollection); } return(itemsFilter); }
public List <ExchangeMailFolder> GetMailboxFolders(string mailServerId, string mailboxName, string mailboxPassword, string senderEmailAddress, string folderClassName) { if (string.IsNullOrEmpty(mailboxPassword)) { mailboxPassword = GetExistingMailboxPassword(senderEmailAddress, UserConnection); } var credentials = new Mail.Credentials { UserName = mailboxName, UserPassword = mailboxPassword, ServerId = Guid.Parse(mailServerId), UseOAuth = GetSettingsHasOauth(senderEmailAddress, UserConnection) }; SetServerCertificateValidation(); var exchangeUtility = new ExchangeUtilityImpl(); Exchange.ExchangeService service = exchangeUtility.CreateExchangeService(UserConnection, credentials, senderEmailAddress, true); var filterCollection = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.Or); var filter = new Exchange.SearchFilter.IsEqualTo(Exchange.FolderSchema.FolderClass, folderClassName); var nullfilter = new Exchange.SearchFilter.Exists(Exchange.FolderSchema.FolderClass); filterCollection.Add(filter); filterCollection.Add(new Exchange.SearchFilter.Not(nullfilter)); string[] selectedFolders = null; var idPropertySet = new Exchange.PropertySet(Exchange.BasePropertySet.IdOnly); Exchange.Folder draftFolder = null; if (folderClassName == ExchangeConsts.NoteFolderClassName) { Exchange.Folder inboxFolder = Exchange.Folder.Bind(service, Exchange.WellKnownFolderName.Inbox, idPropertySet); if (inboxFolder != null) { selectedFolders = new[] { inboxFolder.Id.UniqueId }; } draftFolder = Exchange.Folder.Bind(service, Exchange.WellKnownFolderName.Drafts, idPropertySet); } List <ExchangeMailFolder> folders = exchangeUtility.GetHierarhicalFolderList(service, Exchange.WellKnownFolderName.MsgFolderRoot, filterCollection, selectedFolders); if (folders != null && folders.Any()) { folders[0] = new ExchangeMailFolder { Id = folders[0].Id, Name = mailboxName, ParentId = string.Empty, Path = string.Empty, Selected = false }; if (draftFolder != null) { folders.Remove(folders.FirstOrDefault(e => e.Path == draftFolder.Id.UniqueId)); } } return(folders); }
/// <summary> /// Get folder filters. /// </summary> /// <returns>Folder filters.</returns> private Exchange.SearchFilter getFolderFilters() { var filterCollection = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.Or); var filter = new Exchange.SearchFilter.IsEqualTo(Exchange.FolderSchema.FolderClass, ExchangeConsts.NoteFolderClassName); var nullfilter = new Exchange.SearchFilter.Exists(Exchange.FolderSchema.FolderClass); filterCollection.Add(filter); filterCollection.Add(new Exchange.SearchFilter.Not(nullfilter)); return(filterCollection); }
/// <summary> /// Add less than SyncDate filter to <seealso cref="_itemsFilterCollection"/> /// </summary> /// <param name="localLastSyncDate">Sync date.</param> private void AddLessThanSyncDateFilter(DateTime localLastSyncDate) { if (!_userConnection.GetIsFeatureEnabled("IsLessThanSyncDateInterval")) { return; } var lessThanSyncDateInterval = SysSettings.GetValue(_userConnection, "LessThanSyncDateInterval", 1); var lessThanSyncDate = localLastSyncDate.AddDays(lessThanSyncDateInterval); var ffilter = new Exchange.SearchFilter.IsLessThan(Exchange.ItemSchema.LastModifiedTime, lessThanSyncDate); LogError($"LessThanSyncDate filter adedd, filter date '{lessThanSyncDate}', interval {lessThanSyncDateInterval}"); _itemsFilterCollection.Add(ffilter); }
/// <summary> /// Loads exchange appointment from exchange, filtered by related <paramref name="activityMetadata"/> to /// activity unique identifier. /// </summary> /// <param name="activityMetadata">Activity instance synchronization metadata.</param> /// <returns>If appointment with activity id found, returns <see cref="Exchange.Appointment"/> instance. /// Otherwise returns null.</returns> private Exchange.Appointment GetAppointmentByLocalIdProperty(SysSyncMetaData activityMetadata) { var localId = activityMetadata.LocalId; var filters = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And); var customPropSetFilter = new Exchange.SearchFilter.IsEqualTo(ExchangeUtilityImpl.LocalIdProperty, localId.ToString()); filters.Add(customPropSetFilter); foreach (var noteFolder in Folders) { Exchange.PropertySet idOnlyPropertySet = new Exchange.PropertySet(Exchange.BasePropertySet.IdOnly); var itemView = new Exchange.ItemView(1) { PropertySet = idOnlyPropertySet }; IEnumerable <Exchange.Item> itemCollection = GetCalendarItemsByFilter(noteFolder, filters, itemView); if (itemCollection == null) { continue; } foreach (Exchange.Item item in itemCollection) { Exchange.Appointment appointment = SafeBindItem <Exchange.Appointment>(Service, item.Id); if (appointment != null) { return(appointment); } } } return(null); }
public IEnumerable <IRemoteItem> EnumerateChangesOld(SyncContext context) { base.EnumerateChanges(context); var result = new List <IRemoteItem>(); var folders = new List <Exchange.Folder>(); if (UserSettings.LoadAll) { Exchange.Folder rootFolder = Exchange.Folder.Bind(Service, Exchange.WellKnownFolderName.MsgFolderRoot); var filter = new Exchange.SearchFilter.IsEqualTo( Exchange.FolderSchema.FolderClass, ExchangeConsts.NoteFolderClassName); folders.GetAllFoldersByFilter(rootFolder, filter); } else { folders = SafeBindFolders(Service, UserSettings.RemoteFolderUIds.Keys, context); } var itemsFilterCollection = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And); var draftFilter = new Exchange.SearchFilter.IsNotEqualTo(Exchange.ItemSchema.IsDraft, true); itemsFilterCollection.Add(draftFilter); DateTime loadEmailsFromDate = LoadEmailsFromDate != DateTime.MinValue ? LoadEmailsFromDate : UserSettings.LastSyncDate; if (loadEmailsFromDate != DateTime.MinValue) { var localLastSyncDate = GetLastSyncDate(loadEmailsFromDate); var itemsFilter = new Exchange.SearchFilter.IsGreaterThan(Exchange.ItemSchema.LastModifiedTime, localLastSyncDate); _itemsFilterCollection.Add(itemsFilter); } FilterDeprecatedFolders(ref folders); foreach (var noteFolder in folders) { var activityFolderIds = new List <Guid>(); if (UserSettings.RootFolderId != Guid.Empty) { activityFolderIds.Add(UserSettings.RootFolderId); } var folderId = GetFolderId(noteFolder); if (UserSettings.RemoteFolderUIds.ContainsKey(folderId)) { activityFolderIds.Add(UserSettings.RemoteFolderUIds[folderId]); } Exchange.PropertySet idOnlyPropertySet = new Exchange.PropertySet(Exchange.BasePropertySet.IdOnly); var itemView = new Exchange.ItemView(PageItemCount) { PropertySet = idOnlyPropertySet }; Exchange.FindItemsResults <Exchange.Item> itemCollection; do { itemCollection = GetFolderItemsByFilter(noteFolder, itemsFilterCollection, itemView); if (itemCollection == null) { break; } result.AddRange(GetEmailsFromCollection(itemCollection, activityFolderIds)); } while (itemCollection.MoreAvailable); } return(result); }