public static bool ProcessEmail(string headerPath, string bodyPath, string filename) { try { var headerString = FileManager.FileToString(headerPath, filename); var bodyString = FileManager.FileToString(bodyPath, filename); List <string> OverallEmailList = GetAllEmails(headerString, bodyString); List <string> OverallDomainList = GetAllDomains(headerString, bodyString); //Find EmailID or creat new elements List <int> EmailIDList = UpdateEmailTable(OverallEmailList); //Find DomainID or creat new elements List <int> DomainIDList = UpdateDomainTable(OverallDomainList); EmailHeader emailHeader = GetHeader(headerPath, filename); long HeaderID = SaveEmailHeader(emailHeader); SaveEmailDomains(HeaderID, DomainIDList); SaveEmailRecipients(HeaderID, EmailIDList); return(true); } catch (Exception Ex) { Console.WriteLine("Something wrong with the email: " + filename); return(false); } }
private static long SaveEmailHeader(EmailHeader emailHeader) { using (QuarksoftDBEmailsEntities database = new QuarksoftDBEmailsEntities()) { emailHeader.SenderEmailID = GetEmailID(ExtractEmails(emailHeader.Sender).First()); //adding the timestamp emailHeader.DateAdded = DateTime.Now; database.EmailHeader.Add(emailHeader); database.SaveChanges(); return(emailHeader.EmailHeaderID); } }
private static EmailHeader GetHeader(string headerPath, string filename) { //Read Header string header = "{\"" + FileManager.FileToString(headerPath, filename) + "\"}"; //Format string to JSON string[] jsonHeaderArray = header.Replace("#EQUAL#", "\":\"").Replace("\t", "\"\t\"").Split('\t'); //JoingArray to JSON string jsonEmailHeader = String.Join(",", jsonHeaderArray); //Conver to EmailHeaderObject EmailHeader emailHeader = (EmailHeader)(new JavaScriptSerializer()) .Deserialize(jsonEmailHeader, (new EmailHeader()).GetType()); //Adding the filename emailHeader.SupplementalTextFilename = filename; return(emailHeader); }