예제 #1
0
        internal ImapWebResponse(ImapCommandResult r)
            : base()
        {
            this.IsSessionClosedByResponseStream = false;

              this.MessageAttributes = new IImapMessageAttribute[] {};
              this.Mailboxes = new ImapMailbox[] {};
              this.ThreadTree = new ImapThreadTree(true, null, new ImapThreadTree[] {});
              this.SupportedCharsets = new Encoding[] {};

              this.Result = r;
        }
예제 #2
0
 protected internal virtual ImapCommandResult ProcessResult(ImapCommandResult result,
                                                        Func<ImapResponseCode, bool> throwIfError)
 {
     return ImapClient.ThrowIfError(result, throwIfError);
 }
예제 #3
0
 protected internal ImapCommandResult ProcessResult(ImapCommandResult result)
 {
     return ProcessResult(result, null);
 }
예제 #4
0
        protected internal override ImapCommandResult ProcessResult(ImapCommandResult result,
                                                                Func<ImapResponseCode, bool> throwIfError)
        {
            var prevExistMessageCount = Mailbox.ExistsMessage;
              var prevRecentMessageCount = Mailbox.RecentMessage;
              var deletedMessages = new List<ImapMessageInfo>();
              var statusChangedMessages = new List<ImapMessageInfo>();

              foreach (var response in result.ReceivedResponses) {
            var data = response as ImapDataResponse;

            if (data == null)
              continue;

            if (data.Type == ImapDataResponseType.Fetch) {
              var message = messages.Find(ImapDataResponseConverter.FromFetch(messages, data));

              if (message != null)
            statusChangedMessages.Add(message);
            }
            else if (data.Type == ImapDataResponseType.Expunge) {
              var expunged = ImapDataResponseConverter.FromExpunge(data);

              foreach (var message in messages) {
            if (message.Sequence == expunged) {
              message.Sequence = ImapMessageInfo.ExpungedMessageSequenceNumber;
              deletedMessages.Add(message);
            }
            else if (expunged < message.Sequence) {
              message.Sequence--;
            }
              }

              if (0L < Mailbox.ExistsMessage)
            Mailbox.ExistsMessage -= 1L;
            }
            else if (data.Type == ImapDataResponseType.Exists) {
              Mailbox.ExistsMessage = ImapDataResponseConverter.FromExists(data);
            }
            else if (data.Type == ImapDataResponseType.Recent) {
              Mailbox.RecentMessage = ImapDataResponseConverter.FromRecent(data);
            }
            else if (data.Type == ImapDataResponseType.Flags) {
              Mailbox.ApplicableFlags = ImapDataResponseConverter.FromFlags(data);
            }
              }

              var ret = base.ProcessResult(result, throwIfError);

              if (prevExistMessageCount != Mailbox.ExistsMessage)
            Client.RaiseExistMessageCountChanged(this, prevExistMessageCount);

              if (prevRecentMessageCount != Mailbox.RecentMessage)
            Client.RaiseRecentMessageCountChanged(this, prevRecentMessageCount);

              if (0 < statusChangedMessages.Count)
            Client.RaiseMessageStatusChanged(statusChangedMessages.ToArray());

              if (0 < deletedMessages.Count)
            Client.RaiseMessageDeleted(deletedMessages.ToArray());

              return ret;
        }
        private static ImapWebResponse CreateSearchErrorResponse(ImapCommandResult result)
        {
            var response = new ImapWebResponse(result);

              if (result.TaggedStatusResponse.ResponseText.Code == ImapResponseCode.BadCharset) {
            var supportedCharsets = new List<Encoding>();

            foreach (var charset in ImapResponseTextConverter.FromBadCharset(result.TaggedStatusResponse.ResponseText)) {
              try {
            supportedCharsets.Add(Encoding.GetEncoding(charset));
              }
              catch (ArgumentException) {
            // not supported by framework
              }
            }

            response.SupportedCharsets = supportedCharsets.ToArray();
              }

              return response;
        }
        private static ImapWebResponse CreateNotMatchedResponse(ImapCommandResult result)
        {
            var response = new ImapWebResponse(result);

              response.MessageAttributes = new IImapMessageAttribute[] {};

              return response;
        }
 public ImapAuthenticationException(ImapCommandResult result)
     : base(string.Format("authentication failed {0} (result code:{1})", result.ResultText, result.Code), result)
 {
 }
 protected override Exception GetFetchFailureException(ImapCommandResult result)
 {
     return new WebException(result.ResultText, WebExceptionStatus.ReceiveFailure);
 }
 protected override Exception GetNoSuchMessageException(ImapCommandResult result)
 {
     return new WebException("no such message or expunged", null, WebExceptionStatus.Success, new ImapWebResponse(result));
 }
 public ImapErrorResponseException(string message, Exception innerException)
     : base(message, innerException)
 {
     this.result = null;
 }
 public ImapErrorResponseException(string message, ImapCommandResult result)
     : base(message)
 {
     this.result = result;
 }
 public ImapErrorResponseException(ImapCommandResult result)
     : this(string.Format("{0}: {1}", result.Code, result.ResultText), result)
 {
 }
 public ImapErrorResponseException()
     : base()
 {
     this.result = null;
 }
예제 #14
0
        internal static ImapCommandResult ThrowIfError(ImapCommandResult result, Func<ImapResponseCode, bool> throwIfError)
        {
            if (result.Succeeded)
            return result;

              if (throwIfError != null && result.TaggedStatusResponse != null)
            if (!throwIfError(result.TaggedStatusResponse.ResponseText.Code))
              return result;

              throw new ImapErrorResponseException(result);
        }
예제 #15
0
 internal static ImapCommandResult ThrowIfError(ImapCommandResult result)
 {
     return ThrowIfError(result, null);
 }
예제 #16
0
        private ImapSession GetSession(out ImapCommandResult noopResult)
        {
            noopResult = null;

              var s = sessionManager.GetExistSession(requestUri);

              if (s != null) {
            if (s.IsDisposed) {
              s = null;
            }
            else if (s.IsTransactionProceeding) {
              throw new WebException("another transaction proceeding", WebExceptionStatus.Pending);
            }
            else {
              try {
            // check connected
            if (s.State != ImapSessionState.NotConnected)
              noopResult = s.NoOp();
              }
              catch {
            // ignore exception
              }

              // disconnected
              if (s.IsDisposed || s.State == ImapSessionState.NotConnected) {
            sessionManager.UnregisterSession(requestUri);
            s = null;
            noopResult = null;
              }
            }
              }

              if (s == null) {
            var session = ImapSessionManager.CreateSession(this);

            if (keepAlive)
              sessionManager.RegisterSession(requestUri, session);

            s = session;
              }

              this.session = s;

              return s;
        }