private async void GetMessgesContainingMenuClick(Object sender, System.EventArgs e) { SearchRequestStringsWindow mySearchString = new SearchRequestStringsWindow(); if (mySearchString.ShowDialog() == true) { if (mySearchString.SortRequestTbx.Text != "") { query = SearchQuery.SubjectContains(mySearchString.SortRequestTbx.Text).Or(SearchQuery.BodyContains(mySearchString.SortRequestTbx.Text)); MessagesListTemp = await OperateData.Operating.CustomsDownloadBodyPartsAsync(OperateData.Operating.AccountsUpload()[IndexOfDynamicList], FolderName, query); messagesDetailsDataGrid.ItemsSource = MessagesListTemp; if (MessagesListTemp.Count > 0) { AddingMessagePartsToWindow(MessagesListTemp[0]); } else { MessageBox.Show("Selected folder is empty!"); } } else { MessageBox.Show("Enter a Request to Sort Messages!"); } } }
internal override SearchQuery Optimize(ISearchQueryOptimizer optimizer) { SearchQuery binary = null; SearchQuery right = null; SearchQuery left = null; if (optimizer.CanReduce(Left)) { left = optimizer.Reduce(Left); } if (optimizer.CanReduce(Right)) { right = optimizer.Reduce(Right); } if (left != null || right != null) { binary = new BinarySearchQuery(Term, left ?? Left, right ?? Right); } else { binary = this; } if (optimizer.CanReduce(binary)) { return(optimizer.Reduce(binary)); } return(binary); }
public IActionResult FindArrayBinarySearch([FromBody] BinarySearchQuery searchQuery) { var array = new DotnetArray <long>(MAX_ELEMENTS + 1); array.BinarySearch(searchQuery.Array, searchQuery.SearchKey); return(Ok(new SearchResult { VisitedIndex = array.visitedIndexOnBinarySearch, Found = array.found })); }
private static string CheckMail(long postId, IMailFolder inbox, UniqueIdRange range, BinarySearchQuery query) { string result = string.Empty; foreach (UniqueId uid in inbox.Search(range, query)) { var message = inbox.GetMessage(uid); result = message.TextBody.Split('\r', '\n').FirstOrDefault(); if (!string.IsNullOrEmpty(result)) { inbox.AddFlags(uid, MessageFlags.Seen, true); } if (result != null && result.ToLower().ToLower() == "cancel") { C.WriteLine("We won't be proceeding with this post..."); DbBlackList dbBlackList = new DbBlackList(); Blacklist item = new Blacklist { Subreddit = WorkingSub, PostId = postId, CreatedDate = DateTime.Now }; dbBlackList.AddToBlacklist(item); Environment.Exit(0); } else if (result != null && result.ToLower().ToLower() == "next") { C.WriteLine("We won't be proceeding with this post..."); DbBlackList dbBlackList = new DbBlackList(); Blacklist item = new Blacklist { Subreddit = WorkingSub, PostId = postId, CreatedDate = DateTime.Now }; dbBlackList.AddToBlacklist(item); Process.Start(Assembly.GetExecutingAssembly().Location, Args.FirstOrDefault()); Environment.Exit(0); } else { C.WriteLineNoTime("We got a title!"); } break; } return(result); }
internal override SearchQuery Optimize (ISearchQueryOptimizer optimizer) { var right = Right.Optimize (optimizer); var left = Left.Optimize (optimizer); SearchQuery binary; if (left != Left || right != Right) binary = new BinarySearchQuery (Term, left, right); else binary = this; return optimizer.Reduce (binary); }
internal override SearchQuery Optimize(ISearchQueryOptimizer optimizer) { var right = Right.Optimize(optimizer); var left = Left.Optimize(optimizer); SearchQuery binary; if (left != Left || right != Right) { binary = new BinarySearchQuery(Term, left, right); } else { binary = this; } return(optimizer.Reduce(binary)); }
private async void RefreshFoldersMenu_Click(Object sender, System.EventArgs e) { messagesDetailsDataGrid.ItemsSource = null; //MessagesListTemp = OperateData.Operating.DownloadBodyParts(); query = null; MessagesListTemp = await OperateData.Operating.CustomsDownloadBodyPartsAsync(OperateData.Operating.AccountsUpload()[IndexOfDynamicList], FolderName, query); messagesDetailsDataGrid.ItemsSource = MessagesListTemp; if (MessagesListTemp.Count > 0) { AddingMessagePartsToWindow(MessagesListTemp[0]); } else { MessageBox.Show("Selected folder is empty!"); } }
internal override SearchQuery Optimize (ISearchQueryOptimizer optimizer) { SearchQuery binary = null; SearchQuery right = null; SearchQuery left = null; if (optimizer.CanReduce (Left)) left = optimizer.Reduce (Left); if (optimizer.CanReduce (Right)) right = optimizer.Reduce (Right); if (left != null || right != null) binary = new BinarySearchQuery (Term, left ?? Left, right ?? Right); else binary = this; if (optimizer.CanReduce (binary)) return optimizer.Reduce (binary); return binary; }
private async void GetMessagesForperiodMenuClick(Object sender, System.EventArgs e) { SearchRequestDatesWindow mySearchDates = new SearchRequestDatesWindow(); if (mySearchDates.ShowDialog() == true) { if (mySearchDates.ToDatePicker.SelectedDate > mySearchDates.FromDatePicker.SelectedDate) { query = SearchQuery.DeliveredAfter(mySearchDates.FromDatePicker.SelectedDate.Value.Date).And(SearchQuery.DeliveredBefore(mySearchDates.ToDatePicker.SelectedDate.Value.Date)); MessagesListTemp = await OperateData.Operating.CustomsDownloadBodyPartsAsync(OperateData.Operating.AccountsUpload()[IndexOfDynamicList], FolderName, query); messagesDetailsDataGrid.ItemsSource = MessagesListTemp; if (MessagesListTemp.Count > 0) { AddingMessagePartsToWindow(MessagesListTemp[0]); } else { MessageBox.Show("Selected folder is empty!"); } } } }
public async Task GetDocFromStore(DateTime period) { // INFO PgModel.StopWatch.Start(); using (ImapClient client = new ImapClient()) { Cancellation = new CancellationTokenSource(); int c = 0; try { await client.ConnectAsync("outlook.office365.com", 993, true); await ReportProgress(0, $"Authenticating on mail server... Please wait."); await client.AuthenticateAsync(Properties.Settings.Default.User365, Properties.Settings.Default.Password365); IList <IMailFolder> folders = await client.GetFoldersAsync(client.PersonalNamespaces[0]); foreach (IMailFolder f in folders) { if (f == folders[1] || f == folders[8] || f == folders[13]) { await f.OpenAsync(FolderAccess.ReadOnly); UniqueIdRange range = new UniqueIdRange(new UniqueId(Convert.ToUInt32(Properties.Settings.Default.UIDRange)), UniqueId.MaxValue); BinarySearchQuery query = SearchQuery.DeliveredAfter(Properties.Settings.Default.DateTimeEmail).And(SearchQuery.ToContains(Properties.Settings.Default.User365)); IList <UniqueId> listM = await f.SearchAsync(range, query, Cancellation.Token); int total = listM.Count; foreach (UniqueId uid in await f.SearchAsync(range, query, Cancellation.Token)) { MimeMessage message = await f.GetMessageAsync(uid, Cancellation.Token); if (message.Attachments != null) { IEnumerable <MimeEntity> attachments = GetXmlAttachments(message.BodyParts); foreach (MimeEntity item in attachments) { using (MemoryStream memory = new MemoryStream()) { if (item is MessagePart rfc822) { await rfc822.Message.WriteToAsync(memory, Cancellation.Token); } else { MimePart part = (MimePart)item; await part.Content.DecodeToAsync(memory, Cancellation.Token); } memory.Position = 0; XDocument xDocument = null; try { xDocument = XDocument.Load(memory); } catch (XmlException) { //throw; } if (xDocument != null && xDocument.Root.Name.LocalName == "EnvioDTE") { int res = SaveFiles(xDocument); if (res == 0) { // ok } else if (res == 1) { //MessageBox.Show("Error", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); // ERROR SII. } } } } } if (f == folders[1]) { Properties.Settings.Default.DateTimeEmail = message.Date.DateTime; Properties.Settings.Default.UIDRange = uid.ToString(); c++; float porcent = (float)(100 * c) / total; PgModel.FchOutlook = Properties.Settings.Default.DateTimeEmail; SaveParam(); await ReportProgress(porcent, $"Dowloading messages... [{string.Format(CultureInfo.InvariantCulture, "{0:d-MM-yyyy HH:mm}", message.Date.DateTime)}] ({c}/{total}) Subject: {message.Subject} "); } } } } } catch (Exception) when(Cancellation.Token.IsCancellationRequested) { throw new TaskCanceledException(); } catch (Exception) { throw; } finally { await client.DisconnectAsync(true); } } }
//---------------------IMAP------MailKit------------------------------- public static async Task <List <MessageParts> > CustomsDownloadBodyPartsAsync(Account element, string FolderName, BinarySearchQuery queryCustom) { List <MessageParts> MessagesListRender = new List <MessageParts>(); List <IMailFolder> myListFolders = new List <IMailFolder>(); using (var client = new ImapClient()) { await client.ConnectAsync(element.IMAPServerDetails, element.IMAPPortDetails, SecureSocketOptions.SslOnConnect); await client.AuthenticateAsync(element.IMAPEmailAddress, element.IMAPEmailBoxPassword); await client.Inbox.OpenAsync(FolderAccess.ReadOnly); var personal = client.GetFolder(client.PersonalNamespaces[0]); IMailFolder CompleteFolder = personal.GetSubfolders()[1]; foreach (var folder in CompleteFolder.GetSubfolders()) { myListFolders.Add(folder); } int indexOfFolder = myListFolders.FindIndex(a => a.Name == FolderName); if (indexOfFolder > 0) { await myListFolders[indexOfFolder].OpenAsync(FolderAccess.ReadOnly); if (queryCustom == null) { DateTime DateNow = new DateTime(); DateNow = DateTime.Now; var query = SearchQuery.DeliveredAfter(new DateTime(2019, 05, 01)).And(SearchQuery.DeliveredBefore(DateNow)); var uids = await myListFolders[indexOfFolder].SearchAsync(query); const MessageSummaryItems SummaryItems = MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope | MessageSummaryItems.Flags | MessageSummaryItems.BodyStructure; var timeout = new CancellationToken(); MessagesList = await myListFolders[indexOfFolder].FetchAsync(uids, SummaryItems, timeout); } if (queryCustom != null) { var uids = myListFolders[indexOfFolder].Search(queryCustom); const MessageSummaryItems SummaryItems = MessageSummaryItems.UniqueId | MessageSummaryItems.Envelope | MessageSummaryItems.Flags | MessageSummaryItems.BodyStructure; var timeout = new CancellationToken(); MessagesList = await myListFolders[indexOfFolder].FetchAsync(uids, SummaryItems, timeout); } foreach (var message in MessagesList) { MessageParts temp = new MessageParts(); temp.Uid = message.UniqueId.ToString(); var bodyPart = message.TextBody; var body = (TextPart)myListFolders[indexOfFolder].GetBodyPart(message.UniqueId, bodyPart); temp.Body = body.Text; string str = message.Envelope.Date.ToString(); int index = str.IndexOf("+") > 0 ? str.IndexOf("+") : str.IndexOf("-"); temp.Date = str.Substring(0, index); temp.From = message.Envelope.From.ToString(); temp.Cc = message.Envelope.Cc.ToString(); temp.Subject = message.Envelope.Subject.ToString(); temp.To = message.Envelope.To.ToString(); MessagesListRender.Add(temp); } } client.Disconnect(true); } return(MessagesListRender); }