public static void FetchAllMessages(string hostname, int port, bool useSsl, string username, string password) { // The client disconnects from the server when being disposed using (Pop3Client client = new Pop3Client()) { // Connect to the server client.Connect(hostname, port, useSsl); // Authenticate ourselves towards the server client.Authenticate(username, password, AuthenticationMethod.Auto); // Get the number of messages in the inbox int messageCount = client.GetMessageCount(); // We want to download all messages List <Message> allMessages = new List <Message>(messageCount); // Messages are numbered in the interval: [1, messageCount] // Ergo: message numbers are 1-based. // Most servers give the latest message the highest number for (int i = 1; i < messageCount + 1; i++) { allMessages.Add(client.GetMessage(i)); //client.DeleteMessage(i); CtlMsg tmp = new CtlMsg(); { tmp.from = client.GetMessageHeaders(i).From.Address; if (client.GetMessage(i).FindFirstPlainTextVersion() == null) { tmp.ctlmsg = client.GetMessage(i).FindFirstHtmlVersion().GetBodyAsText(); } else { tmp.ctlmsg = client.GetMessage(i).FindFirstPlainTextVersion().GetBodyAsText(); } foreach (IPAddress ipaddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { if (tmp.ctlmsg.Contains(ipaddress.ToString())) { client.DeleteMessage(i); QueueCommand.Enqueue(tmp); } } } //catch { } } client.Disconnect(); // Now return the fetched messages return; } }
public void QueueThread(ref Queue <CtlMsg> q) { while (true) { Thread.Sleep(2000); if (q.Count > 0) { CtlMsg command = q.Peek(); Console.WriteLine(command.from + " " + command.ctlmsg); foreach (IPAddress ipaddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList) { if (command.ctlmsg.Contains(ipaddress.ToString())) { //Если это тот компьютер if (command.ctlmsg.Contains("screenshot")) { GetPrintScreen(); Console.WriteLine("Отправляем: " + command.from); Messaging.SendMail(command.from, "*****@*****.**", "Скриншот", "", Path.GetTempPath() + "printscreen.jpg", "telemex", "teletele", "172.30.1.47"); } if (command.ctlmsg.Contains("process")) { Console.WriteLine("Отправляем список процессов: " + command.from); Messaging.SendMail(command.from, "*****@*****.**", "Список процессов", GetProcList(), "telemex", "teletele", "172.30.1.47"); } if (command.ctlmsg.Contains("netsrv")) { Console.WriteLine("Получена команда перезагрузки телемеханики, выполняю: " + command.from); //Messaging.SendMail(command.from, "*****@*****.**", "Список процессов", GetProcList(), "telemex", "teletele", "172.30.1.47"); Process.Start(@"C:\ntsrv.cmd"); } if (command.ctlmsg.Contains("om2000")) { Console.WriteLine("Получена команда перезагрузки телемеханики, выполняю: " + command.from); //Messaging.SendMail(command.from, "*****@*****.**", "Список процессов", GetProcList(), "telemex", "teletele", "172.30.1.47"); Process.Start(@"C:\om2000.cmd"); } if (command.ctlmsg.Contains("telemex")) { Console.WriteLine("Получена команда перезагрузки телемеханики, выполняю: " + command.from); //Messaging.SendMail(command.from, "*****@*****.**", "Список процессов", GetProcList(), "telemex", "teletele", "172.30.1.47"); Process.Start(@"C:\telemex.cmd"); } if (command.ctlmsg.Contains("reboot")) { reboot var = new reboot(); var.halt(true, false); } if (command.ctlmsg.Contains("freboot")) { reboot var = new reboot(); var.halt(true, true); } if (q.Count > 0) { q.Dequeue(); } } } } } }