コード例 #1
0
            public void InvokeResponseText(eResponseTextContext pTextContext, cResponseText pResponseText, cTrace.cContext pParentContext)
            {
                if (ResponseText == null)
                {
                    return;                       // pre-check for efficiency only
                }
                var lContext = pParentContext.NewMethod(nameof(cCallbackSynchroniser), nameof(InvokeResponseText), pTextContext, pResponseText);

                if (mDisposed)
                {
                    throw new ObjectDisposedException(nameof(cCallbackSynchroniser));
                }
                ZInvokeAndForget(new cResponseTextEventArgs(pTextContext, pResponseText), lContext);
                // NOTE the event is fired by parallel code in the ZInvokeEvents routine: when adding an event you must put code there also
            }
コード例 #2
0
ファイル: base.cs プロジェクト: bacome/imapclient
            private bool ZSetHomeServerReferral(cResponseText pResponseText, cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cSession), nameof(ZSetHomeServerReferral), pResponseText);

                if (pResponseText.Code != eResponseTextCode.referral || pResponseText.Arguments == null || pResponseText.Arguments.Count != 1)
                {
                    return(false);
                }

                if (cURL.TryParse(pResponseText.Arguments[0], out var lReferral) && lReferral.IsHomeServerReferral)
                {
                    _HomeServerReferral = lReferral;
                    mSynchroniser.InvokePropertyChanged(nameof(cIMAPClient.HomeServerReferral), lContext);
                    return(true);
                }

                return(false);
            }
コード例 #3
0
ファイル: initialisation.cs プロジェクト: bacome/imapclient
                public async Task <sGreeting> ConnectAsync(cMethodControl pMC, cServer pServer, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ConnectAsync), pMC, pServer);

                    if (mDisposed)
                    {
                        throw new ObjectDisposedException(nameof(cCommandPipeline));
                    }

                    if (mState != eState.notconnected)
                    {
                        throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotUnconnected);
                    }
                    mState = eState.connecting;

                    try
                    {
                        await mConnection.ConnectAsync(pMC, pServer, lContext).ConfigureAwait(false);

                        using (var lAwaiter = new cAwaiter(pMC))
                        {
                            while (true)
                            {
                                lContext.TraceVerbose("waiting");
                                await lAwaiter.AwaitAny(mConnection.GetBuildResponseTask(lContext)).ConfigureAwait(false);

                                var lResponse = mConnection.GetResponse(lContext);
                                mSynchroniser.InvokeNetworkReceive(lResponse, lContext);
                                var lCursor = new cBytesCursor(lResponse);

                                if (lCursor.SkipBytes(kGreetingAsteriskSpaceOKSpace))
                                {
                                    var lHook = new cCommandHookInitial();

                                    cResponseText lResponseText = mResponseTextProcessor.Process(eResponseTextContext.greetingok, lCursor, lHook, lContext);
                                    lContext.TraceVerbose("got ok: {0}", lResponseText);

                                    mState          = eState.connected;
                                    mBackgroundTask = ZBackgroundTaskAsync(lContext);

                                    mCapabilities             = lHook.Capabilities;
                                    mAuthenticationMechanisms = lHook.AuthenticationMechanisms;

                                    return(new sGreeting(eGreetingType.ok, null));
                                }

                                if (lCursor.SkipBytes(kGreetingAsteriskSpacePreAuthSpace))
                                {
                                    var lHook = new cCommandHookInitial();

                                    cResponseText lResponseText = mResponseTextProcessor.Process(eResponseTextContext.greetingpreauth, lCursor, lHook, lContext);
                                    lContext.TraceVerbose("got preauth: {0}", lResponseText);

                                    mState          = eState.connected;
                                    mBackgroundTask = ZBackgroundTaskAsync(lContext);

                                    mCapabilities             = lHook.Capabilities;
                                    mAuthenticationMechanisms = lHook.AuthenticationMechanisms;

                                    return(new sGreeting(eGreetingType.preauth, lResponseText));
                                }

                                if (lCursor.SkipBytes(kGreetingAsteriskSpaceBYESpace))
                                {
                                    cResponseText lResponseText = mResponseTextProcessor.Process(eResponseTextContext.greetingbye, lCursor, null, lContext);
                                    lContext.TraceError("got bye: {0}", lResponseText);

                                    mConnection.Disconnect(lContext);

                                    mState = eState.stopped;
                                    return(new sGreeting(eGreetingType.bye, lResponseText));
                                }

                                lContext.TraceError("unrecognised response: {0}", lResponse);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        mConnection.Disconnect(lContext);
                        mState = eState.stopped;
                        throw;
                    }
                }
コード例 #4
0
            private void ZAuthenticated(cStrings pOldPipelineCapabilities, cCommandHookInitial pHook, cResponseText pResponseText, cAccountId pAccountId, cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cSession), nameof(ZAuthenticated));

                if (pHook.Capabilities != null)
                {
                    ZSetCapabilities(pHook.Capabilities, pHook.AuthenticationMechanisms, lContext);
                }
                else if (!ReferenceEquals(pOldPipelineCapabilities, mPipeline.Capabilities))
                {
                    ZSetCapabilities(mPipeline.Capabilities, mPipeline.AuthenticationMechanisms, lContext);
                }

                ZSetHomeServerReferral(pResponseText, lContext);
                ZSetConnectedAccountId(pAccountId, lContext);
            }
コード例 #5
0
                    public cResponseText Process(eResponseTextContext pTextContext, cBytesCursor pCursor, iTextCodeProcessor pTextCodeProcessor, cTrace.cContext pParentContext)
                    {
                        var lContext = pParentContext.NewMethod(nameof(cResponseTextProcessor), nameof(Process), pTextContext);

                        cResponseText lResponseText;

                        var lBookmarkBeforeLBRACET = pCursor.Position;

                        if (pCursor.SkipByte(cASCII.LBRACKET))
                        {
                            if (ZTryGetCodeAndArguments(pCursor, out var lCodeBytes, out var lArgumentsBytes))
                            {
                                string lText = pCursor.GetRestAsString();

                                if (lArgumentsBytes == null)
                                {
                                    eResponseTextCode lCode;

                                    if (lCodeBytes.Equals(kAlert))
                                    {
                                        lCode = eResponseTextCode.alert;
                                    }
                                    else if (lCodeBytes.Equals(kParse))
                                    {
                                        lCode = eResponseTextCode.parse;
                                    }
                                    else if (lCodeBytes.Equals(kTryCreate))
                                    {
                                        lCode = eResponseTextCode.trycreate;
                                    }
                                    else if (lCodeBytes.Equals(kUnavailable))
                                    {
                                        lCode = eResponseTextCode.unavailable;
                                    }
                                    else if (lCodeBytes.Equals(kAuthenticationFailed))
                                    {
                                        lCode = eResponseTextCode.authenticationfailed;
                                    }
                                    else if (lCodeBytes.Equals(kAuthorizationFailed))
                                    {
                                        lCode = eResponseTextCode.authorizationfailed;
                                    }
                                    else if (lCodeBytes.Equals(kExpired))
                                    {
                                        lCode = eResponseTextCode.expired;
                                    }
                                    else if (lCodeBytes.Equals(kPrivacyRequired))
                                    {
                                        lCode = eResponseTextCode.privacyrequired;
                                    }
                                    else if (lCodeBytes.Equals(kContactAdmin))
                                    {
                                        lCode = eResponseTextCode.contactadmin;
                                    }
                                    else if (lCodeBytes.Equals(kNoPerm))
                                    {
                                        lCode = eResponseTextCode.noperm;
                                    }
                                    else if (lCodeBytes.Equals(kInUse))
                                    {
                                        lCode = eResponseTextCode.inuse;
                                    }
                                    else if (lCodeBytes.Equals(kExpungeIssued))
                                    {
                                        lCode = eResponseTextCode.expungeissued;
                                    }
                                    else if (lCodeBytes.Equals(kCorruption))
                                    {
                                        lCode = eResponseTextCode.corruption;
                                    }
                                    else if (lCodeBytes.Equals(kServerBug))
                                    {
                                        lCode = eResponseTextCode.serverbug;
                                    }
                                    else if (lCodeBytes.Equals(kClientBug))
                                    {
                                        lCode = eResponseTextCode.clientbug;
                                    }
                                    else if (lCodeBytes.Equals(kCannot))
                                    {
                                        lCode = eResponseTextCode.cannot;
                                    }
                                    else if (lCodeBytes.Equals(kLimit))
                                    {
                                        lCode = eResponseTextCode.limit;
                                    }
                                    else if (lCodeBytes.Equals(kOverQuota))
                                    {
                                        lCode = eResponseTextCode.overquota;
                                    }
                                    else if (lCodeBytes.Equals(kAlreadyExists))
                                    {
                                        lCode = eResponseTextCode.alreadyexists;
                                    }
                                    else if (lCodeBytes.Equals(kNonExistent))
                                    {
                                        lCode = eResponseTextCode.nonexistent;
                                    }
                                    else if (lCodeBytes.Equals(kBadCharset))
                                    {
                                        lCode = eResponseTextCode.badcharset;
                                    }
                                    else if (lCodeBytes.Equals(kUseAttr))
                                    {
                                        lCode = eResponseTextCode.useattr;
                                    }
                                    else if (lCodeBytes.Equals(kUnknownCTE))
                                    {
                                        lCode = eResponseTextCode.unknowncte;
                                    }
                                    else
                                    {
                                        lCode = eResponseTextCode.other;
                                        ZProcess(pTextContext, lCodeBytes, null, pTextCodeProcessor, lContext);
                                    }

                                    lResponseText = new cResponseText(lCodeBytes, lCode, lText);
                                }
                                else
                                {
                                    eResponseTextCode lCode;
                                    cStrings          lArguments;

                                    if (lCodeBytes.Equals(kBadCharset))
                                    {
                                        lCode      = eResponseTextCode.badcharset;
                                        lArguments = ZProcessCharsets(lArgumentsBytes);
                                    }
                                    else if (lCodeBytes.Equals(kReferral))
                                    {
                                        lCode      = eResponseTextCode.referral;
                                        lArguments = ZProcessReferrals(lArgumentsBytes, lContext);
                                    }
                                    else
                                    {
                                        lCode      = eResponseTextCode.other;
                                        lArguments = null;
                                        ZProcess(pTextContext, lCodeBytes, lArgumentsBytes, pTextCodeProcessor, lContext);
                                    }

                                    lResponseText = new cResponseText(lCodeBytes, lArgumentsBytes, lCode, lArguments, lText);
                                }
                            }
                            else
                            {
                                lContext.TraceWarning("likely badly formed response text code");
                                pCursor.Position = lBookmarkBeforeLBRACET;
                                lResponseText    = new cResponseText(pCursor.GetRestAsString());
                            }
                        }
コード例 #6
0
ファイル: responsetext.cs プロジェクト: bacome/imapclient
 internal cResponseTextEventArgs(eResponseTextContext pContext, cResponseText pText)
 {
     Context = pContext;
     Text    = pText;
 }
コード例 #7
0
 internal cUnsuccessfulCompletionException(cResponseText pResponseText, fCapabilities pTryIgnoring, cTrace.cContext pContext)
 {
     ResponseText = pResponseText;
     TryIgnoring  = pTryIgnoring;
     pContext.TraceError("{0}: {1}", nameof(cUnsuccessfulCompletionException), pResponseText);
 }
コード例 #8
0
ファイル: greeting.cs プロジェクト: bacome/imapclient
 public sGreeting(eGreetingType pType, cResponseText pResponseText)
 {
     Type         = pType;
     ResponseText = pResponseText;
 }
コード例 #9
0
 public cResponseDataBye(cResponseText pResponseText)
 {
     ResponseText = pResponseText;
 }
コード例 #10
0
ファイル: commandresult.cs プロジェクト: bacome/imapclient
 internal cCommandResult(eCommandResultType pResultType, cResponseText pResponseText)
 {
     ResultType   = pResultType;
     ResponseText = pResponseText;
 }