Beispiel #1
0
 public void Delete( Pop3Message message )
 {
     try
     {
         SendCommand("DELE", message);
     }
     catch (Pop3Exception e)
     {
         ConsoleLog.WriteLine("Error deleteing message: " + e.Message);
     }
 }
Beispiel #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 );
        }
Beispiel #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 );
        }
Beispiel #4
0
 public void Delete( Pop3Message message )
 {
     SendCommand( "DELE", message );
 }
Beispiel #5
0
 public void CloseConnection()
 {
     Send("quit");
     m_socket = null;
     m_pop3Message = null;
 }
Beispiel #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 );
        }
Beispiel #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;
            }
        }
Beispiel #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 );
                }
            }
        }
Beispiel #9
0
 public IAsyncAction RetrieveAsync(Pop3Message message)
 {
     return(_client.RetrieveAsync(message).AsAsyncAction( ));
 }
Beispiel #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);
            }
        }
Beispiel #11
0
 private async Task SendCommandAsync(string command, Pop3Message message)
 {
     await SendCommandAsync(command, null, message).ConfigureAwait(false);
 }
Beispiel #12
0
 private void SendCommand(string command, Pop3Message message)
 {
     SendCommand(command, null, message);
 }
Beispiel #13
0
 public IAsyncAction DeleteAsync( Pop3Message message )
 {
     return _client.DeleteAsync( message ).AsAsyncAction( );
 }
Beispiel #14
0
 public IAsyncAction RetrieveHeaderAsync( Pop3Message message )
 {
     return _client.RetrieveHeaderAsync( message ).AsAsyncAction( );
 }
Beispiel #15
0
 private async Task SendCommandAsync( string command, Pop3Message message )
 {
     await SendCommandAsync( command, null, message ).ConfigureAwait( false );
 }
Beispiel #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 );
        }
Beispiel #17
0
 public IAsyncAction DeleteAsync(Pop3Message message)
 {
     return(_client.DeleteAsync(message).AsAsyncAction( ));
 }
Beispiel #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;
            }
        }
Beispiel #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;
        }
Beispiel #20
0
 private void SendCommand( string command, Pop3Message message )
 {
     SendCommand( command, null, message );
 }
Beispiel #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 );
        }
Beispiel #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 );
            }
        }
Beispiel #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;
        }
Beispiel #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;
        }
Beispiel #25
0
 public void CloseConnection()
 {
     Send("quit");
     if (m_socket != null)
     {
         m_socket.Close();
         m_socket = null;
     }
     m_pop3Message = null;
 }