Пример #1
0
        // Token: 0x06000144 RID: 324 RVA: 0x00007280 File Offset: 0x00005480
        private void OnEndConnectInternalReadResponse(IAsyncResult asyncResult)
        {
            AsyncResult <ImapConnectionContext, ImapResultData> asyncResult2 = null;
            ImapConnectionContext imapConnectionContext = null;

            lock (this.syncRoot)
            {
                if (!this.ShouldCancelCallback())
                {
                    base.CheckDisposed();
                    asyncResult2          = (AsyncResult <ImapConnectionContext, ImapResultData>)asyncResult.AsyncState;
                    imapConnectionContext = asyncResult2.State;
                    try
                    {
                        Socket socket = this.socket;
                        socket.EndConnect(asyncResult);
                        if (this.cancellationRequested)
                        {
                            this.HandleCancellation(asyncResult2);
                            this.socket = null;
                            return;
                        }
                        this.networkConnection         = new NetworkConnection(this.socket, 4096);
                        this.socket                    = null;
                        this.networkConnection.Timeout = (this.connectionParameters.Timeout + 999) / 1000;
                        this.Log.Debug("Connection Completed. Connection ID : {0}, Remote End Point {1}", new object[]
                        {
                            this.networkConnection.ConnectionId,
                            this.networkConnection.RemoteEndPoint
                        });
                    }
                    catch (SocketException ex)
                    {
                        ImapUtilities.LogExceptionDetails(this.Log, "Failed to connect, SocketException", ex);
                        this.socket = null;
                        asyncResult2.ProcessCompleted(new ImapConnectionException(CXStrings.ImapSocketException, RetryPolicy.Backoff, ex));
                        return;
                    }
                    this.Log.Info(string.Format(CultureInfo.InvariantCulture, "Connect, from:{0} to:{1}", new object[]
                    {
                        this.serverParameters.Server,
                        this.networkConnection.RemoteEndPoint
                    }), new object[0]);
                    switch (imapConnectionContext.ImapSecurityMechanism)
                    {
                    case ImapSecurityMechanism.None:
                    case ImapSecurityMechanism.Tls:
                        asyncResult2.PendingAsyncResult = this.BeginNetworkRead(asyncResult2, new AsyncCallback(this.OnReadAndDiscardLine));
                        break;

                    case ImapSecurityMechanism.Ssl:
                        asyncResult2.PendingAsyncResult = this.networkConnection.BeginNegotiateTlsAsClient(null, this.networkConnection.RemoteEndPoint.Address.ToString(), new AsyncCallback(this.OnEndConnectNegotiateTlsAsClientInternalReadResponse), asyncResult2);
                        break;

                    default:
                        throw new InvalidOperationException("Unexpected security mechanism " + imapConnectionContext.ImapSecurityMechanism);
                    }
                }
            }
        }
Пример #2
0
        // Token: 0x0600004E RID: 78 RVA: 0x0000356C File Offset: 0x0000176C
        public bool IsConnected()
        {
            base.CheckDisposed();
            ImapConnectionContext imapConnectionContext = this.ConnectionContext;

            return(imapConnectionContext != null && imapConnectionContext.NetworkFacade != null && imapConnectionContext.NetworkFacade.IsConnected);
        }
Пример #3
0
        // Token: 0x06000131 RID: 305 RVA: 0x00006BA0 File Offset: 0x00004DA0
        public IAsyncResult BeginNegotiateTlsAsClient(ImapConnectionContext imapConnectionContext, AsyncCallback callback, object callbackState)
        {
            base.CheckDisposed();
            AsyncResult <ImapConnectionContext, ImapResultData> asyncResult = new AsyncResult <ImapConnectionContext, ImapResultData>(this, imapConnectionContext, callback, callbackState);

            asyncResult.PendingAsyncResult = this.networkConnection.BeginNegotiateTlsAsClient(null, this.networkConnection.RemoteEndPoint.Address.ToString(), new AsyncCallback(this.OnEndConnectNegotiateTlsAsClientInternalReadResponse), asyncResult);
            return(asyncResult);
        }
Пример #4
0
        // Token: 0x06000134 RID: 308 RVA: 0x00006C24 File Offset: 0x00004E24
        public IAsyncResult BeginCommand(ImapCommand command, bool processResponse, ImapConnectionContext imapConnectionContext, AsyncCallback callback, object callbackState)
        {
            base.CheckDisposed();
            byte[] array = command.ToBytes();
            this.currentResponse.Reset(command);
            this.currentCommand = command;
            AsyncResult <ImapConnectionContext, ImapResultData> asyncResult = new AsyncResult <ImapConnectionContext, ImapResultData>(this, imapConnectionContext, callback, callbackState);

            asyncResult.State.TimeSent = ExDateTime.MinValue;
            if (this.cancellationRequested)
            {
                asyncResult.SetCompletedSynchronously();
                this.HandleCancellation(asyncResult);
                return(asyncResult);
            }
            if (this.isNetworkConnectionShutdown)
            {
                asyncResult.SetCompletedSynchronously();
                ImapNetworkFacade.HandleError(ImapNetworkFacade.GetConnectionClosedException(), asyncResult);
                return(asyncResult);
            }
            this.totalBytesSent += (long)array.Length;
            if (this.totalBytesSent > this.connectionParameters.MaxBytesToTransfer)
            {
                asyncResult.SetCompletedSynchronously();
                ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesSentExceeded(), asyncResult);
                return(asyncResult);
            }
            if (processResponse && this.totalBytesReceived > this.connectionParameters.MaxBytesToTransfer)
            {
                asyncResult.State.Log.Debug("Not sending {0}, since we've exceeded our received-bytes threshold.", new object[]
                {
                    this.currentCommand.ToPiiCleanString()
                });
                asyncResult.SetCompletedSynchronously();
                ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesReceivedExceeded(), asyncResult);
                return(asyncResult);
            }
            asyncResult.State.Log.Info("IMAP Send command: [{0}]", new object[]
            {
                this.currentCommand.ToPiiCleanString()
            });
            DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs(0L, (long)array.Length);

            imapConnectionContext.ActivatePerfDownloadEvent(imapConnectionContext, eventArgs);
            if (processResponse)
            {
                asyncResult.PendingAsyncResult = this.networkConnection.BeginWrite(array, 0, array.Length, new AsyncCallback(this.OnEndWriteCommandOrLiteralBeginReadResponse), asyncResult);
            }
            else
            {
                asyncResult.PendingAsyncResult = this.networkConnection.BeginWrite(array, 0, array.Length, new AsyncCallback(this.OnEndSendCommandIgnoreResponse), asyncResult);
                asyncResult.SetCompletedSynchronously();
                this.currentResultData.Clear();
                asyncResult.ProcessCompleted(this.currentResultData);
            }
            return(asyncResult);
        }
Пример #5
0
        // Token: 0x0600014E RID: 334 RVA: 0x00007FF4 File Offset: 0x000061F4
        private Exception BuildAndLogUnexpectedLiteralRequestException(ImapConnectionContext context)
        {
            string text = string.Format(CultureInfo.InvariantCulture, "Server waiting for literal, but none given with command. Command = {0}.", new object[]
            {
                this.currentCommand.ToPiiCleanString()
            });

            context.Log.Error(text, new object[0]);
            this.LogFailureDetails(this.currentCommand, this.currentResponse);
            return(new ImapCommunicationException(text, RetryPolicy.Backoff));
        }
Пример #6
0
        // Token: 0x0600014D RID: 333 RVA: 0x00007FA4 File Offset: 0x000061A4
        private Exception BuildAndLogUnknownCommandFailureException(ImapConnectionContext context, string commandCleanString)
        {
            string text = string.Format(CultureInfo.InvariantCulture, "Unknown command failure, retry.  Command = {0}.", new object[]
            {
                commandCleanString
            });

            context.Log.Error(text, new object[0]);
            this.LogFailureDetails(commandCleanString, this.currentResponse);
            return(new ImapCommunicationException(text, RetryPolicy.Immediate));
        }
Пример #7
0
        // Token: 0x0600014B RID: 331 RVA: 0x00007F30 File Offset: 0x00006130
        private Exception BuildAndLogUnknownParseFailureException(ImapConnectionContext context)
        {
            string text = string.Format(CultureInfo.InvariantCulture, "Unknown parse error in response.  Command = {0}", new object[]
            {
                this.currentCommand.ToPiiCleanString()
            });

            context.Log.Error(text, new object[0]);
            this.LogFailureDetails(this.currentCommand, this.currentResponse);
            return(new ImapCommunicationException(text, RetryPolicy.Backoff));
        }
Пример #8
0
        // Token: 0x0600003F RID: 63 RVA: 0x0000317C File Offset: 0x0000137C
        public void ConnectAndAuthenticate(ImapServerParameters serverParameters, ImapAuthenticationParameters authenticationParameters, IServerCapabilities capabilities = null)
        {
            base.CheckDisposed();
            this.ThrowIfConnected();
            ImapConnectionContext imapConnectionContext = this.ConnectionContext;

            imapConnectionContext.AuthenticationParameters = authenticationParameters;
            imapConnectionContext.ServerParameters         = serverParameters;
            imapConnectionContext.NetworkFacade            = this.CreateNetworkFacade.Value(this.ConnectionContext, serverParameters);
            AsyncOperationResult <DBNull> asyncOperationResult = ImapConnectionCore.ConnectAndAuthenticate(this.ConnectionContext, capabilities, null, null);

            this.ThrowIfExceptionNotNull(asyncOperationResult.Exception);
        }
Пример #9
0
        // Token: 0x06000146 RID: 326 RVA: 0x000074DC File Offset: 0x000056DC
        private void OnEndConnectNegotiateTlsAsClientInternalReadResponse(IAsyncResult asyncResult)
        {
            lock (this.syncRoot)
            {
                if (this.ShouldCancelCallback())
                {
                    NetworkConnection networkConnection = this.ExtractNetworkConnectionFrom(asyncResult);
                    object            obj2;
                    networkConnection.EndNegotiateTlsAsClient(asyncResult, out obj2);
                }
                else
                {
                    base.CheckDisposed();
                    AsyncResult <ImapConnectionContext, ImapResultData> asyncResult2 = (AsyncResult <ImapConnectionContext, ImapResultData>)asyncResult.AsyncState;
                    ImapConnectionContext state = asyncResult2.State;
                    object obj2;
                    this.networkConnection.EndNegotiateTlsAsClient(asyncResult, out obj2);
                    if (obj2 != null)
                    {
                        ImapNetworkFacade.HandleError(obj2, asyncResult2);
                    }
                    else if (this.cancellationRequested)
                    {
                        this.HandleCancellation(asyncResult2);
                    }
                    else
                    {
                        ExTraceGlobals.FaultInjectionTracer.TraceTest(3211144509U);
                        switch (state.ImapSecurityMechanism)
                        {
                        case ImapSecurityMechanism.Ssl:
                            this.currentResponse.Reset(null);
                            asyncResult2.PendingAsyncResult = this.BeginNetworkRead(asyncResult2, new AsyncCallback(this.OnReadAndDiscardLine));
                            break;

                        case ImapSecurityMechanism.Tls:
                            asyncResult2.ProcessCompleted();
                            break;

                        default:
                            throw new InvalidOperationException("Invalid security mechanism");
                        }
                    }
                }
            }
        }
Пример #10
0
        // Token: 0x0600012F RID: 303 RVA: 0x00006AF8 File Offset: 0x00004CF8
        public IAsyncResult BeginConnect(ImapConnectionContext imapConnectionContext, AsyncCallback callback, object callbackState)
        {
            base.CheckDisposed();
            this.ResetStateForConnectIfNecessary();
            this.socket = SocketFactory.CreateTcpStreamSocket();
            AsyncResult <ImapConnectionContext, ImapResultData> asyncResult = new AsyncResult <ImapConnectionContext, ImapResultData>(this, imapConnectionContext, callback, callbackState);

            try
            {
                asyncResult.PendingAsyncResult = this.socket.BeginConnect(this.serverParameters.Server, this.serverParameters.Port, new AsyncCallback(this.OnEndConnectInternalReadResponse), asyncResult);
            }
            catch (SocketException errorCode)
            {
                this.socket = null;
                ImapNetworkFacade.HandleError(errorCode, asyncResult);
            }
            return(asyncResult);
        }
Пример #11
0
 // Token: 0x0600014C RID: 332 RVA: 0x00007F8E File Offset: 0x0000618E
 private Exception BuildAndLogUnknownCommandFailureException(ImapConnectionContext context)
 {
     return(this.BuildAndLogUnknownCommandFailureException(context, this.currentCommand.ToPiiCleanString()));
 }
Пример #12
0
 // Token: 0x06000133 RID: 307 RVA: 0x00006C14 File Offset: 0x00004E14
 public IAsyncResult BeginCommand(ImapCommand command, ImapConnectionContext imapConnectionContext, AsyncCallback callback, object callbackState)
 {
     return(this.BeginCommand(command, true, imapConnectionContext, callback, callbackState));
 }