Example #1
0
            public async Task IdAsync(cMethodControl pMC, cId pClientId, cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cSession), nameof(IdAsync), pMC, pClientId);

                if (mDisposed)
                {
                    throw new ObjectDisposedException(nameof(cSession));
                }
                if (_ConnectionState < eConnectionState.notauthenticated || _ConnectionState > eConnectionState.selected)
                {
                    throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotConnected);
                }

                // install the permanent response data processor
                if (mIdResponseDataProcessor == null)
                {
                    mIdResponseDataProcessor = new cIdDataProcessor(mSynchroniser);
                    mPipeline.Install(mIdResponseDataProcessor);
                }

                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(kIdCommandPart);

                    if (pClientId == null || pClientId.Count == 0)
                    {
                        lBuilder.Add(cCommandPart.Nil);
                    }
                    else
                    {
                        lBuilder.BeginList(eListBracketing.bracketed);

                        foreach (var lPair in pClientId)
                        {
                            lBuilder.Add(mCommandPartFactory.AsString(lPair.Key));
                            lBuilder.Add(mCommandPartFactory.AsNString(lPair.Value));
                        }

                        lBuilder.EndList();
                    }

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

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

                    throw new cProtocolErrorException(lResult, fCapabilities.id, lContext);
                }
            }
Example #2
0
                private static bool ZGetId(cBytesCursor pCursor, out cId rServerId, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cIdDataProcessor), nameof(ZGetId));

                    if (pCursor.SkipBytes(cBytesCursor.Nil))
                    {
                        rServerId = null; return(true);
                    }

                    if (!pCursor.SkipByte(cASCII.LPAREN))
                    {
                        rServerId = null; return(false);
                    }

                    Dictionary <string, string> lDictionary = new Dictionary <string, string>();

                    try
                    {
                        bool lFirst = true;

                        while (true)
                        {
                            if (pCursor.SkipByte(cASCII.RPAREN))
                            {
                                break;
                            }

                            if (lFirst)
                            {
                                lFirst = false;
                            }
                            else if (!pCursor.SkipByte(cASCII.SPACE))
                            {
                                rServerId = null; return(false);
                            }

                            if (!pCursor.GetString(out string lField) || !pCursor.SkipByte(cASCII.SPACE))
                            {
                                rServerId = null; return(false);
                            }
                            if (!pCursor.GetNString(out string lValue))
                            {
                                rServerId = null; return(false);
                            }

                            lDictionary[lField] = lValue;
                        }

                        rServerId = new cId(lDictionary);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        lContext.TraceException("error when constructing the id dictionary", e);
                        rServerId = null;
                        return(false);
                    }
                }
Example #3
0
                public override eProcessDataResult ProcessData(cBytesCursor pCursor, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cIdDataProcessor), nameof(ProcessData));

                    if (pCursor.SkipBytes(kIdSpace))
                    {
                        if (ZGetId(pCursor, out var lServerId, lContext) && pCursor.Position.AtEnd)
                        {
                            lContext.TraceVerbose("got id: {0}", lServerId);
                            mServerId = lServerId;
                            mSynchroniser.InvokePropertyChanged(nameof(cIMAPClient.ServerId), lContext);
                            return(eProcessDataResult.processed);
                        }

                        lContext.TraceWarning("likely malformed id response");
                    }

                    return(eProcessDataResult.notprocessed);
                }