Ejemplo n.º 1
0
 public static void Log(IImapTransaction transaction, string format, params object[] args)
 {
     Verbose("CID:{0} {1}: {2}",
       transaction.Connection.Id,
       transaction.GetType().Name.Replace("Transaction", string.Empty),
       args == null ? format : string.Format(format, args));
 }
        private ImapCommandResult PostProcessTransaction(IImapTransaction t)
        {
            lastTransactionResult = t.Result;

              switch (t.Result.Code) {
            /*
             * disconnect without processing responses
             */
            case ImapCommandResultCode.InternalError:
              CloseConnection();
              throw new ImapException(t.Result.Description, t.Result.Exception);

            case ImapCommandResultCode.SocketTimeout:
              CloseConnection();
              throw new TimeoutException(string.Format("socket timeout in {0}", t.GetType().FullName), t.Result.Exception);

            case ImapCommandResultCode.ConnectionError:
            case ImapCommandResultCode.UpgradeError:
              CloseConnection();
              throw t.Result.Exception;
               }

              ProcessUpdatedSizeAndStatusResponse(t.Result);

              if (t.Result.Code == ImapCommandResultCode.Bye) {
            TransitStateTo(ImapSessionState.NotAuthenticated);
            CloseConnection();
              }

              return t.Result;
        }
        private ImapCommandResult ProcessTransaction(IImapTransaction t)
        {
            if (transactionTimeout == Timeout.Infinite) {
            // no timeout
            PreProcessTransaction(t, handlesIncapableAsException);

            ProcessTransactionInternal(t);

            return PostProcessTransaction(t);
              }
              else {
            var async = BeginProcessTransaction(t, handlesIncapableAsException);

            if (async.AsyncWaitHandle.WaitOne(transactionTimeout, false)) {
              return EndProcessTransaction(async);
            }
            else {
              CloseConnection();
              throw new TimeoutException(string.Format("transaction timeout ({0})", t.GetType().FullName));
            }
              }
        }