예제 #1
0
        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));
        }
예제 #2
0
                public bool Process(cByteList pCode, cByteList pArguments, out cResponseData rResponseData, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cResponseTextCodeParserSelect), nameof(Process));

                    if (pCode.Equals(kPermanentFlags))
                    {
                        if (pArguments != null)
                        {
                            cBytesCursor lCursor = new cBytesCursor(pArguments);

                            if (lCursor.GetFlags(out var lRawFlags) && lCursor.Position.AtEnd && cPermanentFlags.TryConstruct(lRawFlags, out var lFlags))
                            {
                                rResponseData = new cResponseDataPermanentFlags(lFlags);
                                return(true);
                            }
                        }

                        lContext.TraceWarning("likely malformed permanentflags");

                        rResponseData = null;
                        return(false);
                    }

                    if (pCode.Equals(kUIDNext))
                    {
                        if (pArguments != null)
                        {
                            cBytesCursor lCursor = new cBytesCursor(pArguments);

                            if (lCursor.GetNZNumber(out _, out var lNumber) && lCursor.Position.AtEnd)
                            {
                                rResponseData = new cResponseDataUIDNext(lNumber);
                                return(true);
                            }
                        }

                        lContext.TraceWarning("likely malformed uidnext");

                        rResponseData = null;
                        return(false);
                    }

                    if (pCode.Equals(kUIDValidity))
                    {
                        if (pArguments != null)
                        {
                            cBytesCursor lCursor = new cBytesCursor(pArguments);

                            if (lCursor.GetNZNumber(out _, out var lNumber) && lCursor.Position.AtEnd)
                            {
                                rResponseData = new cResponseDataUIDValidity(lNumber);
                                return(true);
                            }
                        }

                        lContext.TraceWarning("likely malformed uidvalidity");

                        rResponseData = null;
                        return(false);
                    }

                    if (mCapabilities.CondStore)
                    {
                        if (pCode.Equals(kHighestModSeq))
                        {
                            if (pArguments != null)
                            {
                                cBytesCursor lCursor = new cBytesCursor(pArguments);

                                if (lCursor.GetNZNumber(out _, out var lNumber) && lCursor.Position.AtEnd)
                                {
                                    rResponseData = new cResponseDataHighestModSeq(lNumber);
                                    return(true);
                                }
                            }

                            lContext.TraceWarning("likely malformed highestmodseq");

                            rResponseData = null;
                            return(false);
                        }
                    }

                    if (pCode.Equals(kReadWrite) && pArguments == null)
                    {
                        rResponseData = new cResponseDataAccess(false);
                        return(true);
                    }

                    if (pCode.Equals(kReadOnly) && pArguments == null)
                    {
                        rResponseData = new cResponseDataAccess(true);
                        return(true);
                    }

                    rResponseData = null;
                    return(false);
                }
예제 #3
0
파일: create.cs 프로젝트: bacome/imapclient
            public async Task <iMailboxHandle> CreateAsync(cMethodControl pMC, cMailboxName pMailboxName, bool pAsFutureParent, cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cSession), nameof(CreateAsync), pMC, pMailboxName, pAsFutureParent);

                if (mDisposed)
                {
                    throw new ObjectDisposedException(nameof(cSession));
                }
                if (_ConnectionState != eConnectionState.notselected && _ConnectionState != eConnectionState.selected)
                {
                    throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotConnected);
                }
                if (pMailboxName == null)
                {
                    throw new ArgumentNullException(nameof(pMailboxName));
                }
                if (pAsFutureParent && pMailboxName.Delimiter == null)
                {
                    throw new ArgumentOutOfRangeException(nameof(pAsFutureParent));
                }

                string lMailboxPath;

                if (pAsFutureParent)
                {
                    lMailboxPath = pMailboxName.Path + pMailboxName.Delimiter.Value;
                }
                else
                {
                    lMailboxPath = pMailboxName.Path;
                }

                if (!mCommandPartFactory.TryAsMailbox(lMailboxPath, pMailboxName.Delimiter, out var lMailboxCommandPart, out _))
                {
                    throw new ArgumentOutOfRangeException(nameof(pMailboxName));
                }

                using (var lBuilder = new cCommandDetailsBuilder())
                {
                    if (!_Capabilities.QResync)
                    {
                        lBuilder.Add(await mSelectExclusiveAccess.GetBlockAsync(pMC, lContext).ConfigureAwait(false)); // block select if mailbox-data delivered during the command would be ambiguous
                    }
                    lBuilder.Add(await mMSNUnsafeBlock.GetBlockAsync(pMC, lContext).ConfigureAwait(false));            // this command is msnunsafe

                    lBuilder.Add(kCreateCommandPart, lMailboxCommandPart);

                    var lHook = new cCreateCommandHook(mMailboxCache, pMailboxName);
                    lBuilder.Add(lHook);

                    var lResult = await mPipeline.ExecuteAsync(pMC, lBuilder.EmitCommandDetails(), lContext).ConfigureAwait(false);

                    if (lResult.ResultType == eCommandResultType.ok)
                    {
                        lContext.TraceInformation("create success");
                        return(lHook.MailboxHandle);
                    }

                    if (lResult.ResultType == eCommandResultType.no)
                    {
                        throw new cUnsuccessfulCompletionException(lResult.ResponseText, 0, lContext);
                    }
                    throw new cProtocolErrorException(lResult, 0, lContext);
                }
            }
예제 #4
0
파일: lsub.cs 프로젝트: bacome/imapclient
                public bool Process(cBytesCursor pCursor, out cResponseData rResponseData, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cResponseDataParserLSub), nameof(Process));

                    if (!pCursor.SkipBytes(kLSubSpace))
                    {
                        rResponseData = null; return(false);
                    }

                    if (!pCursor.GetFlags(out var lFlags) ||
                        !pCursor.SkipByte(cASCII.SPACE) ||
                        !pCursor.GetMailboxDelimiter(out var lDelimiter) ||
                        !pCursor.SkipByte(cASCII.SPACE) ||
                        !pCursor.GetAString(out IList <byte> lEncodedMailboxPath) ||
                        !pCursor.Position.AtEnd ||
                        !cMailboxName.TryConstruct(lEncodedMailboxPath, lDelimiter, mUTF8Enabled, out var lMailboxName))
                    {
                        lContext.TraceWarning("likely malformed lsub response");
                        rResponseData = null;
                        return(true);
                    }

                    rResponseData = new cResponseDataLSub(lMailboxName, !lFlags.Contains(@"\Noselect", StringComparer.InvariantCultureIgnoreCase));
                    return(true);
                }