// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Net.Sockets; namespace E { class MainClass { public static int GetPopMails(string server, string username, string password) { TcpClient cli = new TcpClient(server, 110); StreamWriter sw = new StreamWriter(cli.GetStream()); StreamReader sr = new StreamReader(cli.GetStream()); sw.AutoFlush = true; sr.ReadLine(); sw.WriteLine("user " + username); sr.ReadLine(); sw.WriteLine("pass " + password); sr.ReadLine(); sw.WriteLine("list"); string line = sr.ReadLine(); int ix1 = line.IndexOf(" "); int ix2 = line.IndexOf(" ", ix1 + 1); int res = int.Parse(line.Substring(ix1 + 1, ix2 - ix1 - 1)); while(sr.ReadLine() != "."); sw.WriteLine("quit"); sr.ReadLine(); sw.Close(); sr.Close(); cli.Close(); return res; } public static void Main(string[] args) { Console.WriteLine(GetPopMails("pop.vajhoej.dk", "xxxx", "xxxx")); Console.WriteLine(GetPopMails("pop.vajhoej.dk", "xxxx", "xxxx")); } } }