Esempio n. 1
0
        // Token: 0x0600014F RID: 335 RVA: 0x00008054 File Offset: 0x00006254
        private void HandleCancellation(AsyncResult <ImapConnectionContext, ImapResultData> curOp)
        {
            ImapNetworkFacade.CountCommand(curOp, false);
            this.Log.Error("networkFacade operation cancelled.  Dropped connection.", new object[0]);
            Exception canceledException = AsyncOperationResult <ImapResultData> .CanceledException;

            curOp.ProcessCompleted(new ImapConnectionException(string.Empty, RetryPolicy.Backoff, canceledException));
        }
Esempio n. 2
0
 // Token: 0x0600014A RID: 330 RVA: 0x00007AA4 File Offset: 0x00005CA4
 private void OnReadMoreResponse(IAsyncResult asyncResult)
 {
     lock (this.syncRoot)
     {
         if (this.ShouldCancelCallback())
         {
             NetworkConnection networkConnection = this.ExtractNetworkConnectionFrom(asyncResult);
             byte[]            data;
             int    offset;
             int    num;
             object obj2;
             networkConnection.EndRead(asyncResult, out data, out offset, out num, out obj2);
         }
         else
         {
             base.CheckDisposed();
             AsyncResult <ImapConnectionContext, ImapResultData> asyncResult2 = (AsyncResult <ImapConnectionContext, ImapResultData>)asyncResult.AsyncState;
             ImapResponse imapResponse = this.currentResponse;
             byte[]       data;
             int          offset;
             int          num;
             object       obj2;
             this.networkConnection.EndRead(asyncResult, out data, out offset, out num, out obj2);
             if (obj2 != null)
             {
                 ImapNetworkFacade.HandleError(obj2, asyncResult2);
             }
             else if (this.cancellationRequested)
             {
                 this.HandleCancellation(asyncResult2);
             }
             else
             {
                 ExTraceGlobals.FaultInjectionTracer.TraceTest(2674273597U);
                 this.totalBytesReceived += (long)num;
                 DownloadCompleteEventArgs eventArgs = new DownloadCompleteEventArgs((long)num, 0L);
                 asyncResult2.State.ActivatePerfDownloadEvent(asyncResult2.State, eventArgs);
                 if (this.totalBytesReceived > this.connectionParameters.MaxBytesToTransfer)
                 {
                     ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesReceivedExceeded(), asyncResult2);
                 }
                 else
                 {
                     int num2 = imapResponse.AddData(data, offset, num);
                     int num3 = num - num2;
                     this.Log.Assert(num3 >= 0, "The unconsumed bytes must be non-negative.", new object[0]);
                     if (num3 > 0)
                     {
                         this.networkConnection.PutBackReceivedBytes(num3);
                     }
                     if (imapResponse.IsComplete)
                     {
                         ImapNetworkFacade.CountCommand(asyncResult2, true);
                         asyncResult2.State.Log.Debug("Command complete: [{0}].  Status = {1}", new object[]
                         {
                             this.currentCommand.ToPiiCleanString(),
                             imapResponse.Status
                         });
                         this.currentResultData.Status = imapResponse.Status;
                         if (asyncResult.CompletedSynchronously)
                         {
                             asyncResult2.SetCompletedSynchronously();
                         }
                         if (imapResponse.Status == ImapStatus.No || imapResponse.Status == ImapStatus.Bad || imapResponse.Status == ImapStatus.Bye)
                         {
                             this.LogFailureDetails(this.currentCommand, imapResponse);
                             asyncResult2.ProcessCompleted(this.currentResultData);
                         }
                         else if (imapResponse.Status != ImapStatus.Ok)
                         {
                             this.LogFailureDetails(this.currentCommand, imapResponse);
                             asyncResult2.ProcessCompleted(this.BuildAndLogUnknownCommandFailureException(asyncResult2.State));
                         }
                         else
                         {
                             if (!imapResponse.TryParseIntoResult(this.currentCommand, ref this.currentResultData))
                             {
                                 if (this.currentResultData.FailureException == null)
                                 {
                                     if (this.currentResultData.MessageStream != null)
                                     {
                                         this.totalMessagesReceived += 1UL;
                                     }
                                     asyncResult2.ProcessCompleted(this.currentResultData, this.BuildAndLogUnknownParseFailureException(asyncResult2.State));
                                     return;
                                 }
                                 ImapUtilities.LogExceptionDetails(asyncResult2.State.Log, this.currentCommand, this.currentResultData.FailureException);
                                 this.LogFailureDetails(this.currentCommand, this.currentResponse);
                             }
                             else
                             {
                                 asyncResult2.State.Log.Debug("Parsed server response succesfully.", new object[0]);
                             }
                             asyncResult2.ProcessCompleted(this.currentResultData);
                         }
                     }
                     else if (imapResponse.IsWaitingForLiteral)
                     {
                         Exception ex = null;
                         Stream    commandParameterStream = this.currentCommand.GetCommandParameterStream(this.serverParameters.Server, imapResponse.GetLastResponseLine(), out ex);
                         if (ex != null)
                         {
                             if (commandParameterStream != null)
                             {
                                 commandParameterStream.Close();
                             }
                             ImapNetworkFacade.CountCommand(asyncResult2, false);
                             asyncResult2.ProcessCompleted(ex);
                         }
                         else if (commandParameterStream == null)
                         {
                             ImapNetworkFacade.CountCommand(asyncResult2, false);
                             asyncResult2.ProcessCompleted(this.BuildAndLogUnexpectedLiteralRequestException(asyncResult2.State));
                         }
                         else
                         {
                             this.totalBytesSent += commandParameterStream.Length;
                             if (this.totalBytesSent > this.connectionParameters.MaxBytesToTransfer)
                             {
                                 ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesSentExceeded(), asyncResult2);
                             }
                             else
                             {
                                 eventArgs = new DownloadCompleteEventArgs(0L, commandParameterStream.Length);
                                 asyncResult2.State.ActivatePerfDownloadEvent(asyncResult2.State, eventArgs);
                                 asyncResult2.State.Log.Debug("Begin writing literal stream.", new object[0]);
                                 asyncResult2.PendingAsyncResult = this.networkConnection.BeginWrite(commandParameterStream, new AsyncCallback(this.OnEndWriteLiteral), asyncResult2);
                             }
                         }
                     }
                     else if (imapResponse.TotalLiteralBytesExpected > 0 && this.totalBytesReceived + (long)imapResponse.LiteralBytesRemaining > this.connectionParameters.MaxBytesToTransfer)
                     {
                         this.totalBytesReceived += (long)imapResponse.LiteralBytesRemaining;
                         ImapNetworkFacade.HandleError(ImapNetworkFacade.MaxBytesReceivedExceeded(), asyncResult2);
                     }
                     else
                     {
                         asyncResult2.PendingAsyncResult = this.BeginNetworkRead(asyncResult2, new AsyncCallback(this.OnReadMoreResponse));
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
        // Token: 0x06000141 RID: 321 RVA: 0x00006FEC File Offset: 0x000051EC
        private static void HandleError(object errorCode, AsyncResult <ImapConnectionContext, ImapResultData> curOp)
        {
            ImapNetworkFacade.CountCommand(curOp, false);
            if (errorCode is ConnectionsPermanentException || errorCode is ConnectionsTransientException)
            {
                curOp.State.Log.Error("Exception while communicating: {0}.", new object[]
                {
                    errorCode
                });
                curOp.ProcessCompleted((Exception)errorCode);
                return;
            }
            ImapNetworkFacade imapNetworkFacade = (ImapNetworkFacade)curOp.State.NetworkFacade;

            if (imapNetworkFacade.networkConnection != null)
            {
                imapNetworkFacade.networkConnection.Shutdown();
                imapNetworkFacade.isNetworkConnectionShutdown = true;
            }
            if (errorCode is SocketError)
            {
                switch ((SocketError)errorCode)
                {
                case SocketError.Shutdown:
                    curOp.State.Log.Error("Network connection shut down: {0}.", new object[]
                    {
                        errorCode
                    });
                    curOp.ProcessCompleted(ImapNetworkFacade.BuildConnectionShutdownException());
                    return;

                case SocketError.TimedOut:
                    curOp.State.Log.Error("Operation timed out, shutting down network connection: {0}.", new object[]
                    {
                        errorCode
                    });
                    curOp.ProcessCompleted(ImapNetworkFacade.BuildTimeoutException());
                    return;
                }
                curOp.State.Log.Error("HandleError unhandled SocketError={0}, shutting down network connection.", new object[]
                {
                    ((SocketError)errorCode).ToString()
                });
                curOp.ProcessCompleted(ImapNetworkFacade.BuildUnknownNetworkException());
                return;
            }
            if (errorCode is SecurityStatus)
            {
                curOp.State.Log.Error("ImapNetworkFacade.HandleError (SecurityStatus={0}), shutting down network connection.", new object[]
                {
                    errorCode
                });
                LocalizedString     value          = CXStrings.TlsFailureOccurredError(((SecurityStatus)errorCode).ToString());
                TlsFailureException innerException = new TlsFailureException(value);
                curOp.ProcessCompleted(new ImapConnectionException(CXStrings.ImapSecurityStatusError, RetryPolicy.Backoff, innerException));
                return;
            }
            curOp.State.Log.Error("HandleError unknown error type (error={0}), shutting down network connection.", new object[]
            {
                errorCode
            });
            curOp.ProcessCompleted(ImapNetworkFacade.BuildUnknownNetworkException());
        }