public static string GetYandexHttp(string userEmail, string Password, string Subject)
{
using (
Pop3Client client = new Pop3Client())
{
client.Connect("pop.yandex.ru", 995, true);
client.Authenticate(userEmail.Substring(0, userEmail.IndexOf("@")), Password);
string readyHTTP = "";
int messageCount = client.GetMessageCount();
List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);
for (int i = 1; i <= messageCount; i++)
{
//проверяем тему письма, если та что нам надо, добавляем письмо в список писем
if (client.GetMessage(i).Headers.Subject.IndexOf(Subject) >= 0)
allMessages.Add(client.GetMessage(i));
}
if (allMessages.Count != 0)
{
//если письмо типа текст, то парсим текст
MessagePart plainText = allMessages[0].FindFirstPlainTextVersion();
if (plainText != null)
{
string input = plainText.GetBodyAsText();
Regex httpRx = new Regex(@"(https|http)://.*\r", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant);
Match matchHttp = httpRx.Match(input);
if (matchHttp.Success)
{
readyHTTP = matchHttp.Value;
}
}
//если письмо типа HTML
MessagePart plainHTML = allMessages[0].FindFirstHtmlVersion();
if (plainHTML != null)
{
string input = plainHTML.GetBodyAsText();
string HRefPattern = @"(?i)<\s*?a\s+[\S\s\x22\x27\x3d]*?href=[\x22\x27]?([^\s\x22\x27<>]+)[\x22\x27]?.*?>";
Match m;
m = Regex.Match(input, HRefPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
string workString = m.Groups[1].Value;
while (m.Success)
{
if (workString.IndexOf("/register/reg.php?code=") > 0)
{
readyHTTP = workString;
break;
}
}
}
}
return readyHTTP;
}
}