private async Task <List <cMessage> > ZZMessagesAsync(cMethodControl pMC, iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZZMessagesAsync), pMC, pMailboxHandle, pFilter, pSort, pItems); if (mDisposed) { throw new ObjectDisposedException(nameof(cIMAPClient)); } var lSession = mSession; if (lSession == null || lSession.ConnectionState != eConnectionState.selected) { throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotSelected); } if (pMailboxHandle == null) { throw new ArgumentNullException(nameof(pMailboxHandle)); } if (pFilter == null) { throw new ArgumentNullException(nameof(pFilter)); } if (pSort == null) { throw new ArgumentNullException(nameof(pSort)); } if (pItems == null) { throw new ArgumentNullException(nameof(pItems)); } cMessageCacheItems lItems; if (ReferenceEquals(pSort, cSort.None)) { lItems = pItems; } /* de-implemented pending a requirement to complete it * else if (ReferenceEquals(pSort, cSort.ThreadOrderedSubject)) * { * if (lSession.Capabilities.ThreadOrderedSubject) return await ZMessagesThreadAsync(pMC, lSession, pHandle, eMessageThreadAlgorithm.orderedsubject, pFilter, pItems, pConfiguration, lContext).ConfigureAwait(false); * lItems = new cCacheItems(pItems.Attributes | fCacheAttributes.envelope | fCacheAttributes.received, pItems.Names); * } * else if (ReferenceEquals(pSort, cSort.ThreadReferences)) * { * if (lSession.Capabilities.ThreadReferences) return await ZMessagesThreadAsync(pMC, lSession, pHandle, eMessageThreadAlgorithm.references, pFilter, pItems, pConfiguration, lContext).ConfigureAwait(false); * lItems = new cCacheItems(pItems.Attributes | fCacheAttributes.envelope | fCacheAttributes.received, pItems.Names.Union(cHeaderFieldNames.References)); * } */ else { var lSortAttributes = pSort.Attributes(out var lSortDisplay); if (!lSortDisplay && lSession.Capabilities.Sort || lSortDisplay && lSession.Capabilities.SortDisplay) { return(await ZMessagesSortAsync(pMC, lSession, pMailboxHandle, pSort, pFilter, pItems, pConfiguration, lContext).ConfigureAwait(false)); } lItems = new cMessageCacheItems(pItems.Attributes | lSortAttributes, pItems.Names); } cMessageHandleList lMessageHandles; if (lSession.Capabilities.ESearch) { lMessageHandles = await lSession.SearchExtendedAsync(pMC, pMailboxHandle, pFilter, lContext).ConfigureAwait(false); } else { lMessageHandles = await lSession.SearchAsync(pMC, pMailboxHandle, pFilter, lContext).ConfigureAwait(false); } // get the properties await ZMessagesFetchAsync(pMC, lSession, lMessageHandles, lItems, pConfiguration, lContext).ConfigureAwait(false); if (ReferenceEquals(pSort, cSort.None)) { return(ZMessagesFlatMessageList(lMessageHandles, lContext)); } // client side sorting // de-implemented pending a requirement to complete it // if (ReferenceEquals(pSort, cSort.ThreadOrderedSubject)) return ZMessagesThreadOrderedSubject(lHandles, lContext); // if (ReferenceEquals(pSort, cSort.ThreadReferences)) return ZMessagesThreadReferences(lHandles, lContext); lMessageHandles.Sort(pSort); return(ZMessagesFlatMessageList(lMessageHandles, lContext)); }
private async Task <List <cMessage> > ZMessagesAsync(iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZMessagesAsync), pMailboxHandle, pFilter, pSort, pItems); if (pConfiguration == null) { using (var lToken = mCancellationManager.GetToken(lContext)) { var lMC = new cMethodControl(mTimeout, lToken.CancellationToken); return(await ZZMessagesAsync(lMC, pMailboxHandle, pFilter, pSort, pItems, null, lContext).ConfigureAwait(false)); } } else { var lMC = new cMethodControl(pConfiguration.Timeout, pConfiguration.CancellationToken); return(await ZZMessagesAsync(lMC, pMailboxHandle, pFilter, pSort, pItems, pConfiguration, lContext).ConfigureAwait(false)); } }
internal Task <List <cMessage> > MessagesAsync(iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration) { var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(MessagesAsync)); return(ZMessagesAsync(pMailboxHandle, pFilter, pSort, pItems, pConfiguration, lContext)); }
internal List <cMessage> Messages(iMailboxHandle pMailboxHandle, cFilter pFilter, cSort pSort, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration) { var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(Messages)); var lTask = ZMessagesAsync(pMailboxHandle, pFilter, pSort, pItems, pConfiguration, lContext); mSynchroniser.Wait(lTask, lContext); return(lTask.Result); }
private async Task ZMessagesFetchAsync(cMethodControl pMC, cSession pSession, cMessageHandleList pMessageHandles, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZMessagesFetchAsync), pMC, pMessageHandles, pItems); if (pMessageHandles.Count == 0) { return; } if (pItems.IsEmpty) { return; } if (pMessageHandles.TrueForAll(h => h.Contains(pItems))) { return; } cProgress lProgress; if (pConfiguration == null) { lProgress = new cProgress(); } else { mSynchroniser.InvokeActionInt(pConfiguration.SetCount, pMessageHandles.Count, lContext); lProgress = new cProgress(mSynchroniser, pConfiguration.Increment); } await pSession.FetchCacheItemsAsync(pMC, pMessageHandles, pItems, lProgress, lContext).ConfigureAwait(false); }
private async Task <List <cMessage> > ZMessagesSortAsync(cMethodControl pMC, cSession pSession, iMailboxHandle pMailboxHandle, cSort pSort, cFilter pFilter, cMessageCacheItems pItems, cMessageFetchConfiguration pConfiguration, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZMessagesSortAsync), pMC, pMailboxHandle, pSort, pFilter, pItems); cMessageHandleList lMessageHandles; if (pSession.Capabilities.ESort) { lMessageHandles = await pSession.SortExtendedAsync(pMC, pMailboxHandle, pFilter, pSort, lContext).ConfigureAwait(false); } else { lMessageHandles = await pSession.SortAsync(pMC, pMailboxHandle, pFilter, pSort, lContext).ConfigureAwait(false); } await ZMessagesFetchAsync(pMC, pSession, lMessageHandles, pItems, pConfiguration, lContext).ConfigureAwait(false); return(ZMessagesFlatMessageList(lMessageHandles, lContext)); }