예제 #1
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);
        }
예제 #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));
                     }
                 }
             }
         }
     }
 }