Example #1
0
 /// <summary>
 /// Ensures the state of the POP3.
 /// </summary>
 /// <param name="currentState">State of the current.</param>
 protected void EnsurePop3State(Pop3State currentState)
 {
     if (!((currentState & ValidExecuteState) == currentState))
     {
         throw new Pop3Exception(string.Format("This command is being executed" +
                                               "in an invalid execution state.  Current:{0}, Valid:{1}",
                                               currentState, ValidExecuteState));
     }
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Pop3CommandBase"/> class.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="isMultiline">if set to <c>true</c> [is multiline].</param>
        /// <param name="validExecuteState">State of the valid execute.</param>
        public Pop3Command(Stream stream, bool isMultiline, Pop3State validExecuteState)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            _manualResetEvent  = new ManualResetEvent(false);
            _buffer            = new byte[BufferSize];
            _responseContents  = new MemoryStream();
            _networkStream     = stream;
            _isMultiline       = isMultiline;
            _validExecuteState = validExecuteState;
        }
Example #3
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <returns></returns>
        internal override ConnectResponse Execute(Pop3State currentState)
        {
            EnsurePop3State(currentState);

            try
            {
                _client.Connect(_hostname, _port);

                SetClientStream();
            }
            catch (SocketException e)
            {
                throw new Pop3Exception(string.Format("Unable to connect to {0}:{1}.", _hostname, _port), e);
            }

            return(base.Execute(currentState));
        }
Example #4
0
        /// <summary>
        /// Authenticates this instance.
        /// </summary>
        /// <remarks>A successful execution of this method will result in a Current State of Transaction.
        /// Unsuccessful USER or PASS commands can be reattempted by resetting the Username or Password
        /// properties and re-execution of the methods.</remarks>
        /// <exception cref="Pop3Exception">
        /// If the Pop3Server is unable to be connected.
        /// If the User command is unable to be successfully executed.
        /// If the Pass command is unable to be successfully executed.
        /// </exception>
        public void Authenticate()
        {
            Connect();

            //execute the user command.
            using (UserCommand userCommand = new UserCommand(_clientStream, _username))
            {
                ExecuteCommand <Pop3Response, UserCommand>(userCommand);
            }

            //execute the pass command.
            using (PassCommand passCommand = new PassCommand(_clientStream, _password))
            {
                ExecuteCommand <Pop3Response, PassCommand>(passCommand);
            }

            _currentState = Pop3State.Transaction;
        }
Example #5
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <returns></returns>
        internal virtual T Execute(Pop3State currentState)
        {
            EnsurePop3State(currentState);

            var message = CreateRequestMessage();

            if (message != null)
            {
                Send(message);
            }

            var response = CreateResponse(GetResponse());

            if (response == null)
            {
                return(null);
            }

            OnTrace(response.HostMessage);
            return(response);
        }
Example #6
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <returns></returns>
        internal virtual T Execute(Pop3State currentState)
        {
            EnsurePop3State(currentState);

            byte[] message = CreateRequestMessage();

            if (message != null)
            {
                Send(message);
            }

            T response = CreateResponse(GetResponse());

            if (response == null)
            {
                return(null);
            }
            Log.bound_to(this).log_a_debug_event_containing(response.HostMessage);
            //OnTrace(response.HostMessage);
            return(response);
        }
Example #7
0
 /// <summary>
 /// Resets the state.
 /// </summary>
 /// <param name="state">The state.</param>
 private void SetState(Pop3State state)
 {
     _currentState = state;
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pop3Client"/> class.
 /// </summary>
 private Pop3Client()
 {
     _client       = new TcpClient();
     _currentState = Pop3State.Unknown;
 }