public void ReadImap() { string appURL = mySql.ApplicantURL().url; string profURl = mySql.ProfessionURL().url; mySql.dbClose(); try { List <MimeMessage> emailList = GetUnreadMails(); Console.WriteLine("Email-ek száma: " + emailList.Count.ToString()); int otherType = 0; int savedDocs = 0; int savedApplicants = 0; foreach (MimeMessage email in emailList) { string from = ""; try { from = (email.From.ToString().Split('<')[1]).Split('>')[0]; } catch (Exception) { } if (from.Equals("*****@*****.**")) { bool hasMessage = false; foreach (MimeKit.MimePart mimePart in email.Attachments) { hasMessage = true; } if (hasMessage == true) { string seged = email.HtmlBody.ToString(); try { Profession prof = new Profession(seged); string profId = prof.Insert(); savedApplicants++; if (profId != null) { string path = appURL + profId + "\\"; foreach (MimeKit.MimePart mimePart in email.Attachments) { using (var memory = new MemoryStream()) { mimePart.Content.DecodeTo(memory); var bytes = memory.ToArray(); prof.SaveDocuments(path, mimePart.FileName, bytes); savedDocs++; } } } } catch (Exception) { otherType++; Console.WriteLine(otherType); } } } //if (email.From.Equals("*****@*****.**")) //{ // string seged = Regex.Split(email.HtmlBody, "\r\n")[1].Split('-')[0]; // //Applicant applicant = new Applicant(); // string path = appURL + seged + "\\"; // foreach (MimeKit.MimePart mimePart in email.Attachments) // { // using (var memory = new MemoryStream()) // { // if (seged == "") // { // path = appURL + "Without ID\\"; // } // mimePart.Content.DecodeTo(memory); // var bytes = memory.ToArray(); // Applicant.SaveDocument(path, mimePart.FileName, bytes); // } // } //} } Console.WriteLine("Mentett jelöltek száma:" + savedApplicants); Console.WriteLine("Mentett dokumentumok száma:" + savedDocs); } catch (Exception e) { Console.WriteLine(e.ToString()); } }