예제 #1
0
 public void Delete( Pop3Message message )
 {
     try
     {
         SendCommand("DELE", message);
     }
     catch (Pop3Exception e)
     {
         ConsoleLog.WriteLine("Error deleteing message: " + e.Message);
     }
 }
예제 #2
0
        private void SendCommand( string command, string aditionalParameters = null, Pop3Message message = null )
        {
            var request = new StringBuilder( );

            if ( message == null )
                request.AppendFormat( CultureInfo.InvariantCulture, "{0}", command );
            else
                request.AppendFormat( CultureInfo.InvariantCulture, "{0} {1}", command, message.Number );

            if ( !String.IsNullOrEmpty( aditionalParameters ) )
                request.AppendFormat( CultureInfo.InvariantCulture, " {0}", aditionalParameters );

            request.Append( "\r\n" );

            _networkOperations.Write( request.ToString( ) );

            var response = _networkOperations.Read( );

            if ( String.IsNullOrEmpty( response ) || response.Substring( 0, 3 ) != "+OK" )
                throw new InvalidOperationException( response );
        }
예제 #3
0
        public async Task DeleteAsync( Pop3Message message )
        {
            if ( !this.IsConnected )
                throw new InvalidOperationException( "Pop3 client is not connected to host" );

            if ( message == null )
                throw new ArgumentNullException( "message" );

            await SendCommandAsync( "DELE", message ).ConfigureAwait( false );
        }
예제 #4
0
 public void Delete( Pop3Message message )
 {
     SendCommand( "DELE", message );
 }
예제 #5
0
 public void CloseConnection()
 {
     Send("quit");
     m_socket = null;
     m_pop3Message = null;
 }
예제 #6
0
        private void SendCommand( string command, string aditionalParameters, Pop3Message message )
        {
            StringBuilder request = new StringBuilder();
            string response;

            if ( message == null )
                request.AppendFormat( CultureInfo.InvariantCulture, "{0}", command );
            else
                request.AppendFormat( CultureInfo.InvariantCulture, "{0} {1}", command, message.Number );

            if ( !String.IsNullOrEmpty( aditionalParameters ))
                request.AppendFormat( " {0}", aditionalParameters );

            request.Append( "\r\n" );

            Write( request.ToString( ) );

            response = Response( );
            if ( response.Substring( 0, 3 ) != "+OK" )
                throw new Pop3Exception( response );
        }
예제 #7
0
        public void RetrieveHeader( Pop3Message message )
        {
            string response;

            SendCommand( "TOP", "0", message );

            while ( true )
            {
                response = Response( );
                if ( response == ".\r\n" )
                    break;
                else
                    message.Header += response;
            }
        }
예제 #8
0
        public List<Pop3Message> List( )
        {
            string response;

            List<Pop3Message> result = new List<Pop3Message>( );

            SendCommand( "LIST" );

            while ( true )
            {
                response = Response( );
                if ( response == ".\r\n" )
                {
                    return result;
                }
                else
                {
                    Pop3Message message = new Pop3Message( );

                    char[ ] seps = { ' ' };
                    string[ ] values = response.Split( seps );

                    message.Number = Int32.Parse( values[ 0 ] );
                    message.Bytes = Int32.Parse( values[ 1 ] );
                    message.Retrieved = false;

                    result.Add( message );
                }
            }
        }
예제 #9
0
 public IAsyncAction RetrieveAsync(Pop3Message message)
 {
     return(_client.RetrieveAsync(message).AsAsyncAction( ));
 }
예제 #10
0
        private async Task SendCommandAsync(string command, string aditionalParameters = null, Pop3Message message = null)
        {
            var request = new StringBuilder( );

            if (message == null)
            {
                request.AppendFormat(CultureInfo.InvariantCulture, "{0}", command);
            }
            else
            {
                request.AppendFormat(CultureInfo.InvariantCulture, "{0} {1}", command, message.Number);
            }

            if (!String.IsNullOrEmpty(aditionalParameters))
            {
                request.AppendFormat(" {0}", aditionalParameters);
            }

            request.Append(Environment.NewLine);

            await _networkOperations.WriteAsync(request.ToString( )).ConfigureAwait(false);

            var response = await _networkOperations.ReadAsync( ).ConfigureAwait(false);

            if (String.IsNullOrEmpty(response) || response.Substring(0, 3) != "+OK")
            {
                throw new InvalidOperationException(response);
            }
        }
예제 #11
0
 private async Task SendCommandAsync(string command, Pop3Message message)
 {
     await SendCommandAsync(command, null, message).ConfigureAwait(false);
 }
예제 #12
0
 private void SendCommand(string command, Pop3Message message)
 {
     SendCommand(command, null, message);
 }
예제 #13
0
 public IAsyncAction DeleteAsync( Pop3Message message )
 {
     return _client.DeleteAsync( message ).AsAsyncAction( );
 }
예제 #14
0
 public IAsyncAction RetrieveHeaderAsync( Pop3Message message )
 {
     return _client.RetrieveHeaderAsync( message ).AsAsyncAction( );
 }
예제 #15
0
 private async Task SendCommandAsync( string command, Pop3Message message )
 {
     await SendCommandAsync( command, null, message ).ConfigureAwait( false );
 }
예제 #16
0
        private async Task SendCommandAsync( string command, string aditionalParameters = null, Pop3Message message = null )
        {
            var request = new StringBuilder( );

            if ( message == null )
                request.AppendFormat( CultureInfo.InvariantCulture, "{0}", command );
            else
                request.AppendFormat( CultureInfo.InvariantCulture, "{0} {1}", command, message.Number );

            if ( !String.IsNullOrEmpty( aditionalParameters ) )
                request.AppendFormat( " {0}", aditionalParameters );

            request.Append( Environment.NewLine );

            await _networkOperations.WriteAsync( request.ToString( ) ).ConfigureAwait( false );

            var response = await _networkOperations.ReadAsync( ).ConfigureAwait( false );

            if ( String.IsNullOrEmpty( response ) || response.Substring( 0, 3 ) != "+OK" )
                throw new InvalidOperationException( response );
        }
예제 #17
0
 public IAsyncAction DeleteAsync(Pop3Message message)
 {
     return(_client.DeleteAsync(message).AsAsyncAction( ));
 }
예제 #18
0
        public void Retrieve( Pop3Message message )
        {
            string response;

            SendCommand( "RETR", message );

            message.Retrieved = true;
            while ( true )
            {
                response = Response( );
                if ( response == ".\r\n" )
                    break;
                else
                    message.Message += response;
            }
        }
예제 #19
0
        public void Retrieve( Pop3Message message )
        {
            if ( !this.IsConnected )
                throw new InvalidOperationException( "Pop3 client is not connected to host" );
            if ( message == null )
                throw new ArgumentNullException( "message" );

            SendCommand( "RETR", message );

            while ( true )
            {
                string response = _networkOperations.Read( );
                if ( response == ".\r\n" )
                    break;

                message.RawMessage += response;
            }
            message.ParseRawMessage( );

            message.Retrieved = true;
        }
예제 #20
0
 private void SendCommand( string command, Pop3Message message )
 {
     SendCommand( command, null, message );
 }
예제 #21
0
        public void Delete( Pop3Message message )
        {
            if ( !this.IsConnected )
                throw new InvalidOperationException( "Pop3 client is not connected to host" );
            if ( message == null )
                throw new ArgumentNullException( "message" );

            SendCommand( "DELE", message );
        }
예제 #22
0
        public async Task<IEnumerable<Pop3Message>> ListAsync( )
        {
            if ( !this.IsConnected )
                throw new InvalidOperationException( "Pop3 client is not connected to host" );

            List<Pop3Message> result = new List<Pop3Message>( );

            await SendCommandAsync( "LIST" ).ConfigureAwait( false );

            while ( true )
            {
                string response = await _networkOperations.ReadAsync( ).ConfigureAwait( false );
                if ( response == ".\r\n" )
                    return result.AsEnumerable( );

                Pop3Message message = new Pop3Message( );

                char[] seps = { ' ' };
                string[] values = response.Split( seps );

                message.Number = Int32.Parse( values[ 0 ], CultureInfo.InvariantCulture );
                message.Bytes = Int32.Parse( values[ 1 ], CultureInfo.InvariantCulture );
                message.Retrieved = false;

                result.Add( message );
            }
        }
예제 #23
0
        public async Task RetrieveAsync( Pop3Message message )
        {
            if ( !this.IsConnected )
                throw new InvalidOperationException( "Pop3 client is not connected to host" );

            if ( message == null )
                throw new ArgumentNullException( "message" );

            await SendCommandAsync( "RETR", message ).ConfigureAwait( false );

            while ( true )
            {
                string response = await _networkOperations.ReadAsync( ).ConfigureAwait( false );
                if ( response == ".\r\n" )
                    break;

                message.RawMessage += response;
            }

            message.ParseRawMessage( );

            message.Retrieved = true;
        }
예제 #24
0
        public bool NextEmail()
        {
            string returned;

            long pos;

            if (m_directPosition == -1)
            {
                if (m_inboxPosition == 0)
                {
                    pos = 1;
                }
                else
                {
                    pos = m_inboxPosition + 1;
                }
            }
            else
            {
                pos = m_directPosition + 1;
                m_directPosition = -1;
            }

            //send username
            Send("list " + pos.ToString());

            //get response
            returned = GetPop3String();

            //if email does not exist then return false
            if (returned.Substring(0, 4).Equals("-ERR"))
            {
                return false;
            }

            m_inboxPosition = pos;

            //strip clrf
            string[] nocr = returned.Split(new char[] { '\r' });

            //get size
            string[] elements = nocr[0].Split(new char[] { ' ' });

            long size = long.Parse(elements[2]);

            //else read data
            m_pop3Message = new Pop3Message(m_inboxPosition, size, m_socket);

            return true;
        }
예제 #25
0
 public void CloseConnection()
 {
     Send("quit");
     if (m_socket != null)
     {
         m_socket.Close();
         m_socket = null;
     }
     m_pop3Message = null;
 }