Skip to content

Commit

Permalink
Added a way to check sieve server capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
josaphatim committed Aug 8, 2023
1 parent 2ccca8c commit 52ea601
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
16 changes: 0 additions & 16 deletions modules/imap/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,6 @@ public function process() {
list($success, $form) = $this->process_form(array('imap_server_ids'));
if ($success) {
$ids = explode(',', $form['imap_server_ids']);
$capabilities = [];
foreach ($ids as $id) {
$cache = Hm_IMAP_List::get_cache($this->cache, $id);
$start_time = microtime(true);
Expand All @@ -1221,21 +1220,6 @@ public function process() {
if (imap_authed($imap)) {
$this->out('imap_connect_status', $imap->get_state());
$this->out('imap_status_server_id', $id);
$imap_account = Hm_IMAP_List::get($id, true);
if (isset($imap_account['sieve_config_host'])) {
if (isset($capabilities[$imap_account['sieve_config_host']])) {
$this->out('sieve_server_capabilities', $capabilities[$imap_account['sieve_config_host']]);
continue;
}
require_once APP_PATH.'modules/sievefilters/modules.php';
$clientFactory = new Hm_Sieve_Client_Factory();
$client = $clientFactory->init(null, $imap_account);
if ($client) {
$this->out('sieve_server_capabilities', $client->getCapabilities());
$capabilities[$imap_account['sieve_config_host']] = $client->getCapabilities();
}
}

}
else {
$this->out('imap_connect_status', 'disconnected');
Expand Down
3 changes: 1 addition & 2 deletions modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,12 @@ protected function output() {
$res .= '<span class="down">'.$this->trans('Down').'</span>';
}
$this->out('imap_status_display', $res);

$res = '';
$capabilities = $this->get('sieve_server_capabilities', array());
if ($capabilities) {
$res .= '<span class="sieve_extensions">'.implode(', ', $capabilities).'</span>';
}
$this->out('imap_detail_display', $res);
$this->out('sieve_detail_display', $res);
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var imap_status_update = function() {
var process_result = function(res) {
var id = res.imap_status_server_id;
$('.imap_status_'+id).html(res.imap_status_display);
$('.imap_detail_'+id).html(res.imap_detail_display);
$('.imap_detail_'+id).html(res.sieve_detail_display);
};
for (i=0;i<ids.length;i++) {
id=ids[i];
Expand Down
33 changes: 33 additions & 0 deletions modules/sievefilters/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,39 @@ protected function output() {
}
}

/**
* Check the status of an SIEVE server
* @subpackage sieve/handler
*/
class Hm_Handler_sieve_status extends Hm_Handler_Module {
protected static $capabilities = [];

/**
* Output used on the info page to display the server status
*/
public function process() {
list($success, $form) = $this->process_form(array('imap_server_ids'));
if ($success) {
$ids = explode(',', $form['imap_server_ids']);
foreach ($ids as $id) {
$imap_account = Hm_IMAP_List::get($id, true);
if (isset($imap_account['sieve_config_host'])) {
if (isset(self::$capabilities[$imap_account['sieve_config_host']])) {
$this->out('sieve_server_capabilities', self::$capabilities[$imap_account['sieve_config_host']]);
continue;
}
$clientFactory = new Hm_Sieve_Client_Factory();
$client = $clientFactory->init(null, $imap_account);
if ($client) {
$this->out('sieve_server_capabilities', $client->getCapabilities());
self::$capabilities[$imap_account['sieve_config_host']] = $client->getCapabilities();
}
}
}
}
}
}

if (!hm_exists('get_script_modal_content')) {
function get_script_modal_content()
{
Expand Down
7 changes: 5 additions & 2 deletions modules/sievefilters/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
add_handler('ajax_imap_message_content', 'sieve_filters_enabled_message_content', true, 'sievefilters', 'imap_message_content', 'after');
add_handler('ajax_hm_folders', 'sieve_filters_enabled', true, 'core', 'load_user_data', 'after');

add_handler('ajax_imap_status', 'sieve_status', true, 'sievefilters', 'imap_status', 'before');

setup_base_page('sieve_filters', 'core');
setup_base_page('block_list', 'core');

Expand Down Expand Up @@ -113,7 +115,7 @@
'ajax_sieve_unblock_sender',
'ajax_sieve_get_mailboxes',
'ajax_sieve_block_domain',
'ajax_sieve_block_change_behaviour'
'ajax_sieve_block_change_behaviour',
),
'allowed_output' => array(
'imap_server_ids' => array(FILTER_UNSAFE_RAW, false),
Expand All @@ -122,7 +124,8 @@
'conditions' => array(FILTER_UNSAFE_RAW, false),
'actions' => array(FILTER_UNSAFE_RAW, false),
'test_type' => array(FILTER_UNSAFE_RAW, false),
'mailboxes' => array(FILTER_UNSAFE_RAW, false)
'mailboxes' => array(FILTER_UNSAFE_RAW, false),
'sieve_detail_display' => array(FILTER_UNSAFE_RAW, false),
),
'allowed_get' => array(),
'allowed_post' => array(
Expand Down

0 comments on commit 52ea601

Please sign in to comment.