Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ DEFAULT_SETTING_SHOW_LIST_ICONS=true
DEFAULT_SETTING_START_PAGE=none
DEFAULT_SETTING_DISABLE_DELETE_PROMPT=false
DEFAULT_SETTING_FLAGGED_PER_SOURCE=20
DEFAULT_SETTING_FLAGGED_SEARCH_IN_ALL_FOLDER=false
DEFAULT_SETTING_NO_FOLDER_ICONS=false
DEFAULT_SETTING_ALL_EMAIL_PER_SOURCE=20
DEFAULT_SETTING_ALL_EMAIL_SINCE='-1 week'
Expand Down
6 changes: 6 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,12 @@
*/
'default_setting_flagged_per_source' => env('DEFAULT_SETTING_FLAGGED_PER_SOURCE', 20),

/*
| allow searching all in all folders
| Defaults to false
*/
'default_setting_flagged_search_in_all_folder' => env('DEFAULT_SETTING_FLAGGED_SEARCH_IN_ALL_FOLDER', false),

/*
|
| Per source time limit for the flagged combined view
Expand Down
1 change: 1 addition & 0 deletions lib/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function define_default_constants($config) {
define('DEFAULT_UNREAD_PER_SOURCE', $config->get('default_setting_unread_per_source', 20));
define('DEFAULT_FLAGGED_SINCE', $config->get('default_setting_flagged_since', '-1 week'));
define('DEFAULT_FLAGGED_PER_SOURCE', $config->get('default_setting_flagged_per_source', 20));
define('DEFAULT_FLAGGED_SEARCH_IN_ALL_FOLDERS', $config->get('default_setting_flagged_search_in_all_folder', false));
define('DEFAULT_ALL_SINCE', $config->get('default_setting_all_since', '-1 week'));
define('DEFAULT_ALL_PER_SOURCE', $config->get('default_setting_all_per_source', 20));
define('DEFAULT_ALL_EMAIL_SINCE', $config->get('default_setting_all_email_since', '-1 week'));
Expand Down
18 changes: 18 additions & 0 deletions modules/core/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,24 @@ function delete_disabled_callback($val) {
}
}

/**
* Process input from the allow searching flagged in all folders setting
* @subpackage core/handler
*/
class Hm_Handler_process_allow_search_all_flagged_folder_setting extends Hm_Handler_Module {
/**
* Allowed vals are bool true/false
*/
public function process() {
function allow_search_all_flagged_folder_callback($val) {
return $val;
}
// exit(var_dump($this->request->post['allow_search_all_flagged_folder']));
process_site_setting('allow_search_all_flagged_folder', $this, 'allow_search_all_flagged_folder_callback', DEFAULT_FLAGGED_SEARCH_IN_ALL_FOLDERS, true);
}
}


/**
* Process input from the disable delete attachment setting
* @subpackage core/handler
Expand Down
1 change: 1 addition & 0 deletions modules/core/js_modules/Hm_MessagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Hm_MessagesStore {
if (this.path != 'combined_inbox' && this.path != 'search') {
sources = sources.filter(s => s.type != 'feeds');
}
console.log('Sources:', sources);
sources.forEach((ds) => {
const cfg = config.slice();
if (ds.type == 'feeds') {
Expand Down
28 changes: 28 additions & 0 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,34 @@ protected function output() {
}
}

/**
* Option for the "allow search in all flagged folders" setting
* This setting allows searching flagged messages in all folders, not just the INBOX one.
* @subpackage core/output
*/
class Hm_Output_allow_search_all_flagged_folder_setting extends Hm_Output_Module {
/**
* Processed by Hm_Handler_process_allow_search_all_flagged_folder_setting
*/
protected function output() {
$settings = $this->get('user_settings', array());
if (array_key_exists('allow_search_all_flagged_folder', $settings) && $settings['allow_search_all_flagged_folder']) {
$checked = ' checked="checked"';
if($settings['allow_search_all_flagged_folder'] !== DEFAULT_FLAGGED_SEARCH_IN_ALL_FOLDERS) {
$reset = '<span class="tooltip_restore" restore_aria_label="Restore default value"><i class="bi bi-arrow-counterclockwise fs-6 cursor-pointer refresh_list reset_default_value_checkbox"></i></span>';
}
}
else {
$checked = '';
$reset='';
}
return '<tr class="flagged_setting"><td><label class="form-check-label" for="allow_search_all_flagged_folder">'.
$this->trans('Allow searching flagged in all folders').'</label></td>'.
'<td><input class="form-check-input" type="checkbox" '.$checked.
' value="1" id="allow_search_all_flagged_folder" name="allow_search_all_flagged_folder" data-default-value="'.(DEFAULT_FLAGGED_SEARCH_IN_ALL_FOLDERS ? 'true' : 'false') . '"/>'.$reset.'</td></tr>';
}
}

/**
* Option for the "received since" date range for the Flagged page
* @subpackage core/output
Expand Down
3 changes: 3 additions & 0 deletions modules/core/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
add_handler('settings', 'save_user_settings', true, 'core', 'save_user_data', 'before');
add_handler('settings', 'reload_folder_cookie', true, 'core', 'save_user_settings', 'after');
add_handler('settings', 'privacy_settings', true, 'core', 'date', 'after');
add_handler('settings', 'process_allow_search_all_flagged_folder_setting', true, 'core', 'save_user_settings', 'before');

add_output('settings', 'start_settings_form', true, 'core', 'content_section_start', 'after');
add_output('settings', 'start_general_settings', true, 'core', 'start_settings_form', 'after');
Expand Down Expand Up @@ -108,6 +109,7 @@
add_output('settings', 'all_email_source_max_setting', true, 'core', 'all_email_since_setting', 'after');
add_output('settings', 'end_settings_form', true, 'core', 'content_section_end', 'before');
add_output('settings', 'privacy_settings', 'true', 'core', 'start_unread_settings', 'before');
add_output('settings', 'allow_search_all_flagged_folder_setting', true, 'core', 'flagged_source_max_setting', 'after');

/* message list page */
setup_base_page('message_list');
Expand Down Expand Up @@ -300,6 +302,7 @@
'language' => FILTER_UNSAFE_RAW,
'flagged_per_source' => FILTER_VALIDATE_INT,
'flagged_since' => FILTER_UNSAFE_RAW,
'allow_search_all_flagged_folder' => FILTER_VALIDATE_INT,
'unread_per_source' => FILTER_VALIDATE_INT,
'unread_since' => FILTER_UNSAFE_RAW,
'all_email_per_source' => FILTER_VALIDATE_INT,
Expand Down
65 changes: 46 additions & 19 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,8 @@ public function process() {
$folders = array_map(function($ds) { return $ds['folder']; }, $data_sources);
}

$allow_all_folders = false;

list($sort, $reverse) = process_sort_arg($this->request->get['sort'], $this->user_config->get('default_sort_order_setting', 'arrival'));

switch ($this->get('list_path')) {
Expand All @@ -1294,6 +1296,10 @@ public function process() {
$date = process_since_argument($this->user_config->get('all_since_setting', DEFAULT_SINCE));
break;
case 'flagged':
$allow_all_folders = (bool)$this->user_config->get('allow_search_all_flagged_folder_setting', DEFAULT_FLAGGED_SEARCH_IN_ALL_FOLDERS);
$filter = 'FLAGGED';
$date = process_since_argument($this->user_config->get('flagged_since_setting', DEFAULT_FLAGGED_SINCE));
$limit = $this->user_config->get('flagged_per_source_setting', DEFAULT_FLAGGED_PER_SOURCE);
case 'unread':
$filter = $this->get('list_path') == 'unread' ? 'UNSEEN' : mb_strtoupper($this->get('list_path'));
default:
Expand All @@ -1317,33 +1323,54 @@ public function process() {

$messages = [];
$status = [];
$uids = [];
foreach ($ids as $key => $id) {
$details = Hm_IMAP_List::dump($id);
$mailbox = Hm_IMAP_List::get_connected_mailbox($id, $this->cache);
if($this->get('list_path') == 'snoozed' && !$mailbox->folder_exists('Snoozed')) {
continue;
}
$uids = $mailbox->search(hex2bin($folders[$key]), $filter, $terms, $sort, $reverse);

$total = count($uids);
$uids = array_slice($uids, 0, $limit);

$headers = $mailbox->get_message_list(hex2bin($folders[$key]), $uids);
foreach ($uids as $uid) {
if (isset($headers[$uid])) {
$msg = $headers[$uid];
} elseif (isset($headers[bin2hex($uid)])) {
$msg = $headers[bin2hex($uid)];
} else {
continue;
if($allow_all_folders) {
$all_folders = $mailbox->get_folders();
foreach (array_keys($all_folders) as $folder) {
$uids = $mailbox->search($folder, $filter, $terms, $sort, $reverse);
$headers = $mailbox->get_message_list($folder, $uids);
$uids = array_slice($uids, 0, $limit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you apply the limit across folders? Limit is flagged per source, so it should be decreased when a folder returns some results.

foreach ($uids as $uid) {
if (isset($headers[$uid])) {
$msg = $headers[$uid];
} elseif (isset($headers[bin2hex($uid)])) {
$msg = $headers[bin2hex($uid)];
} else {
continue;
}
$msg['server_id'] = $id;
$msg['server_name'] = $details['name'];
$msg['folder'] = $folders[$key];
$messages[] = $msg;
}
$status['imap_'.$id.'_'.bin2hex($folder)] = $mailbox->get_folder_status($folder);
}
$msg['server_id'] = $id;
$msg['server_name'] = $details['name'];
$msg['folder'] = $folders[$key];
$messages[] = $msg;
}else {
$uids = $mailbox->search(hex2bin($folders[$key]), $filter, $terms, $sort, $reverse);
$headers = $mailbox->get_message_list(hex2bin($folders[$key]), $uids);
$uids = array_slice($uids, 0, $limit);
// $total = count($uids);
foreach ($uids as $uid) {
if (isset($headers[$uid])) {
$msg = $headers[$uid];
} elseif (isset($headers[bin2hex($uid)])) {
$msg = $headers[bin2hex($uid)];
} else {
continue;
}
$msg['server_id'] = $id;
$msg['server_name'] = $details['name'];
$msg['folder'] = $folders[$key];
$messages[] = $msg;
}
$status['imap_'.$id.'_'.$folders[$key]] = $mailbox->get_folder_status(hex2bin($folders[$key]));
}

$status['imap_'.$id.'_'.$folders[$key]] = $mailbox->get_folder_status(hex2bin($folders[$key]));
}

$this->out('folder_status', $status);
Expand Down
4 changes: 2 additions & 2 deletions modules/imap/hm-imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,8 @@ public function get_message_content($uid, $message_part, $max=false, $struct=tru
* use IMAP SEARCH or ESEARCH
* @param string $target message types to search. can be ALL, UNSEEN, ANSWERED, etc
* @param mixed $uids an array of uids or a valid IMAP sequence set as a string (or false for ALL)
* @param string $fld optional field to search
* @param string $term optional search term
* @param array $terms optional search term
* @param array $esearch optional ESEARCH parameters
* @param bool $exclude_deleted extra argument to exclude messages with the deleted flag
* @param bool $exclude_auto_bcc don't include auto-bcc'ed messages
* @param bool $only_auto_bcc only include auto-bcc'ed messages
Expand Down
Loading