' Collection of code snippets by Arne Vajhøj ' posted to eksperten.dk, usenet and other places (2002-now) Imports System Imports System.IO Imports System.Net.Sockets Namespace E Class MainClass Public Shared Function GetPopMails(ByVal server As String, ByVal username As String, ByVal password As String) As Integer Dim cli As TcpClient = New TcpClient(server, 110) Dim sw As StreamWriter = New StreamWriter(cli.GetStream) Dim sr As StreamReader = New StreamReader(cli.GetStream) sw.AutoFlush = True sr.ReadLine sw.WriteLine("user " + username) sr.ReadLine sw.WriteLine("pass " + password) sr.ReadLine sw.WriteLine("list") Dim line As String = sr.ReadLine Dim ix1 As Integer = line.IndexOf(" ") Dim ix2 As Integer = line.IndexOf(" ", ix1 + 1) Dim res As Integer = Integer.Parse(line.Substring(ix1 + 1, ix2 - ix1 - 1)) While Not (sr.ReadLine = ".") End While sw.WriteLine("quit") sr.ReadLine sw.Close sr.Close cli.Close Return res End Function Public Shared Sub Main(ByVal args As String()) Console.WriteLine(GetPopMails("pop.vajhoej.dk", "xxxx", "xxxx")) Console.WriteLine(GetPopMails("pop.vajhoej.dk", "xxxx", "xxxx")) End Sub End Class End Namespace