public void Delete( Pop3Message message ) { try { SendCommand("DELE", message); } catch (Pop3Exception e) { ConsoleLog.WriteLine("Error deleteing message: " + e.Message); } }
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 ); }
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 ); }
public void Delete( Pop3Message message ) { SendCommand( "DELE", message ); }
public void CloseConnection() { Send("quit"); m_socket = null; m_pop3Message = null; }
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 ); }
public void RetrieveHeader( Pop3Message message ) { string response; SendCommand( "TOP", "0", message ); while ( true ) { response = Response( ); if ( response == ".\r\n" ) break; else message.Header += response; } }
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 ); } } }
public IAsyncAction RetrieveAsync(Pop3Message message) { return(_client.RetrieveAsync(message).AsAsyncAction( )); }
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); } }
private async Task SendCommandAsync(string command, Pop3Message message) { await SendCommandAsync(command, null, message).ConfigureAwait(false); }
private void SendCommand(string command, Pop3Message message) { SendCommand(command, null, message); }
public IAsyncAction DeleteAsync( Pop3Message message ) { return _client.DeleteAsync( message ).AsAsyncAction( ); }
public IAsyncAction RetrieveHeaderAsync( Pop3Message message ) { return _client.RetrieveHeaderAsync( message ).AsAsyncAction( ); }
private async Task SendCommandAsync( string command, Pop3Message message ) { await SendCommandAsync( command, null, message ).ConfigureAwait( false ); }
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 ); }
public IAsyncAction DeleteAsync(Pop3Message message) { return(_client.DeleteAsync(message).AsAsyncAction( )); }
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; } }
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; }
private void SendCommand( string command, Pop3Message message ) { SendCommand( command, null, message ); }
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 ); }
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 ); } }
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; }
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; }
public void CloseConnection() { Send("quit"); if (m_socket != null) { m_socket.Close(); m_socket = null; } m_pop3Message = null; }