From 747501d679e01ac254f28fc8ccad59c06c0dfa25 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 23 Jan 2022 11:45:43 -0800 Subject: [PATCH] UI improvements for long-running searches --- mailbox/index.cgi | 16 ++++++++++++++++ mailbox/mail_search.cgi | 14 +++++++++++++- mailbox/ulang/en | 5 ++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/mailbox/index.cgi b/mailbox/index.cgi index 9c0998fe..4bd4bee3 100755 --- a/mailbox/index.cgi +++ b/mailbox/index.cgi @@ -8,6 +8,7 @@ our ($remote_user, $remote_pass); our $special_folder_id; our $plen; our ($cb); # XXX +our $search_folder_id; require './mailbox-lib.pl'; &ReadParse(); @@ -102,6 +103,21 @@ my $sel = &folder_select(\@folders, $folder, "id", undef, 1, 1); # Show page flipping arrows &show_arrows(); +# If this is the search results folder, check if a search is in progress +if ($folder->{'id'} eq $search_folder_id) { + my ($pid, $action) = &test_lock_folder($folder); + if ($pid) { + if ($action && $action->{'search'}) { + print "",&text('index_searching', + "".&html_escape($action->{'search'}).""), + "

\n"; + } + else { + print "",&text('index_searching2'),"

\n"; + } + } + } + # Work out displayed range my $start = int($in{'start'}); my $end = $in{'start'}+$perpage-1; diff --git a/mailbox/mail_search.cgi b/mailbox/mail_search.cgi index 135c6b38..eeee2a86 100755 --- a/mailbox/mail_search.cgi +++ b/mailbox/mail_search.cgi @@ -77,10 +77,14 @@ if ($folder && $folder->{'id'} eq $search_folder_id) { # Create a virtual folder for the search results my $virt; +my $virt_exists = 0; if ($in{'dest_def'} || !defined($in{'dest'})) { # Use the default search results folder ($virt) = grep { $_->{'type'} == 6 && $_->{'id'} == 1 } @folders; - if (!$virt) { + if ($virt) { + $virt_exists = 1; + } + else { $virt = { 'id' => $search_folder_id, 'type' => 6, }; @@ -94,6 +98,13 @@ else { 'name' => $in{'dest'} }; } +# Lock the output folder +if ($virt_exists) { + my %act; + $act{'search'} = $in{'search'} if ($in{'simple'}); + &lock_folder($virt, \%act); + } + # Show some progress if it's a big folder my $large_search = 0; if ($in{'returned_format'} ne "json" && @@ -239,6 +250,7 @@ else { } &delete_new_sort_index($virt); &save_folder($virt, $virt); +&unlock_folder($virt) if ($virt_exists); if ($in{'returned_format'} eq "json") { #Return in JSON format if needed diff --git a/mailbox/ulang/en b/mailbox/ulang/en index 3b96b2cd..4f754e32 100644 --- a/mailbox/ulang/en +++ b/mailbox/ulang/en @@ -1,5 +1,8 @@ index_title=Mail In $1 index_return=mail list +index_searching=A search for $1 is in progress. Results will be shown here when it completes. +index_searching2=A complex search is in progress. Results will be shown here when it completes. + mail_title=Read Mail mail_none=There are no messages in folder $1 mail_pos=Messages $1 to $2 of $3 in folder $4 @@ -223,7 +226,7 @@ search_edest=Missing virtual folder name for results search_eself=The search results folder cannot be searched search_doing=Searching for $1 in folder $2. search_doing2=Searching messages in the selected folder. -search_results=Match messages will be shown in the search results folder when the search completes ... +search_results=Matching messages will be shown in the search results folder when the search completes ... virtualize_ename=Missing virtual folder name