Skip to content

Commit

Permalink
add actions from plugins and (undocumented) config
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoh committed Jul 16, 2023
1 parent 7c469c4 commit ff6f90f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
4 changes: 4 additions & 0 deletions plugins/archive/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ if (window.rcmail) {
}
});
}

rcmail.addEventListener('list-actions-show', function(p) {
p.menu.find('a.archive')[!p.message.deleted ? 'show' : 'hide']();
});
});
}
23 changes: 22 additions & 1 deletion plugins/archive/archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function init()
rcube_storage::$folder_types[] = 'archive';

$this->archive_folder = $rcmail->config->get('archive_mbox');
$this->add_texts('localization', true);

if ($rcmail->task == 'mail' && ($rcmail->action == '' || $rcmail->action == 'show') && $this->archive_folder) {
$this->include_stylesheet($this->local_skin_path() . '/archive.css');
$this->include_script('archive.js');
$this->add_texts('localization', true);
$this->add_button(
[
'type' => 'link',
Expand All @@ -56,10 +56,16 @@ function init()
// set env variables for client
$rcmail->output->set_env('archive_folder', $this->archive_folder);
$rcmail->output->set_env('archive_type', $rcmail->config->get('archive_type',''));

// add icon to message list actions menu
$this->add_hook('message_list_actions', [$this, 'message_list_actions']);
}
else if ($rcmail->task == 'mail') {
// handler for ajax request
$this->register_action('plugin.move2archive', [$this, 'move_messages']);

// add icon to message list actions menu
$this->add_hook('message_list_actions', [$this, 'message_list_actions']);
}
else if ($rcmail->task == 'settings') {
$this->add_hook('preferences_list', [$this, 'prefs_table']);
Expand Down Expand Up @@ -530,4 +536,19 @@ protected function sender_subfolder($from)
// replace reserved characters in folder name
return strtr($folder_name, $replacements);
}

function message_list_actions($p)
{
$config = rcmail::get_instance()->config->get('message_actions', []);
if ($this->archive_folder && in_array('archive', $config)) {
$onclick = sprintf(
"return %s.command('list_action_callback', '%s', this, event)",
rcmail_output::JS_OBJECT_NAME,
'plugin.archive'
);
$p['actions']['archive'] = html::a(['class' => 'archive', 'title' => $this->gettext('buttontext'), 'href' => '#', 'onclick' => $onclick, 'data-action-link' => 1], '');

return $p;
}
}
}
5 changes: 5 additions & 0 deletions plugins/markasjunk/markasjunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,9 @@ if (window.rcmail) {
return false;
}
});

rcmail.addEventListener('list-actions-show', function(p) {
p.menu.find('a.junk')[!rcmail.markasjunk_is_spam_mbox() && !p.message.deleted ? 'show' : 'hide']();
p.menu.find('a.notjunk')[rcmail.markasjunk_is_spam_mbox() && !p.message.deleted ? 'show' : 'hide']();
});
}
50 changes: 48 additions & 2 deletions plugins/markasjunk/markasjunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class markasjunk extends rcube_plugin
private $rcube;
private $spam_mbox;
private $ham_mbox;
private $spam_only;
private $driver;
private $flags = [
'JUNK' => 'Junk',
Expand Down Expand Up @@ -65,12 +66,13 @@ public function init()

$this->ham_mbox = $this->rcube->config->get('markasjunk_ham_mbox', 'INBOX');
$this->spam_mbox = $this->rcube->config->get('markasjunk_spam_mbox', $this->rcube->config->get('junk_mbox'));
$this->spam_only = $this->rcube->config->get('markasjunk_spam_only', false);
$toolbar = $this->rcube->config->get('markasjunk_toolbar', true);
$this->_init_flags();
$this->add_texts('localization', true);

if ($this->rcube->action == '' || $this->rcube->action == 'show') {
$this->include_script('markasjunk.js');
$this->add_texts('localization', true);
$this->include_stylesheet($this->local_skin_path() . '/markasjunk.css');

if ($toolbar) {
Expand Down Expand Up @@ -126,11 +128,14 @@ public function init()
$this->rcube->output->set_env('markasjunk_move_spam', $this->rcube->config->get('markasjunk_move_spam', false));
$this->rcube->output->set_env('markasjunk_move_ham', $this->rcube->config->get('markasjunk_move_ham', false));
$this->rcube->output->set_env('markasjunk_permanently_remove', $this->rcube->config->get('markasjunk_permanently_remove', false));
$this->rcube->output->set_env('markasjunk_spam_only', $this->rcube->config->get('markasjunk_spam_only', false));
$this->rcube->output->set_env('markasjunk_spam_only', $this->spam_only);
}

// init learning driver
$this->_init_driver();

// add icon to message list actions menu
$this->add_hook('message_list_actions', [$this, 'message_list_actions']);
}

public function mark_message()
Expand Down Expand Up @@ -178,6 +183,47 @@ public function set_flags($p)
return $p;
}

public function message_list_actions($p)
{
$config = $this->rcube->config->get('message_actions', []);
if (!in_array('junk', $config)) {
return;
}

$disp_ham = true;
$disp_spam = true;
$search_set = $this->rcube->storage->get_search_set();
$multifolder = $search_set && !empty($search_set[1]->multi);

if ($this->spam_only) {
$disp_ham = false;
}
elseif (!$multifolder && $this->spam_mbox) {
if ($this->rcube->storage->get_folder() == $this->spam_mbox) {
$disp_ham = false;
}
else {
$disp_spam = false;
}
}

$onclick = sprintf(
"return %s.command('list_action_callback', '%s', this, event)",
rcmail_output::JS_OBJECT_NAME,
'plugin.markasjunk.junk'
);
$p['actions']['junk'] = html::a(['class' => 'junk', 'style' => $disp_spam ? null : 'display: none;', 'title' => $this->rcube->gettext('junk'), 'href' => '#', 'onclick' => $onclick, 'data-action-link' => 1], '');

$onclick = sprintf(
"return %s.command('list_action_callback', '%s', this, event)",
rcmail_output::JS_OBJECT_NAME,
'plugin.markasjunk.not_junk'
);
$p['actions']['notjunk'] = html::a(['class' => 'notjunk', 'style' => $disp_ham ? null : 'display: none;', 'title' => $this->rcube->gettext('markasjunk.notjunk'), 'href' => '#', 'onclick' => $onclick, 'data-action-link' => 1], '');

return $p;
}

private function _spam(&$messageset, $dest_mbox = null)
{
$storage = $this->rcube->get_storage();
Expand Down
18 changes: 18 additions & 0 deletions program/actions/mail/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ public static function message_list_head($attrib, $a_show_cols)
public static function message_list_actions($attrib)
{
$rcmail = rcmail::get_instance();
$config = $rcmail->config->get('message_actions', ['size', 'date', 'flag', 'delete']);

$actions = [
'size' => null,
Expand All @@ -729,6 +730,23 @@ public static function message_list_actions($attrib)
'forward' => ['label' => 'forward', 'action' => 'compose/forward']
];

$actions = array_filter($actions, function($action) use ($config) {
// map paired values to config
switch ($action) {
case 'unread':
$action = 'read';
break;
case 'unflag':
$action = 'flag';
break;
case 'undelete':
$action = 'delete';
break;
}

return in_array($action, $config);
}, ARRAY_FILTER_USE_KEY);

if (isset($attrib['actions'])) {
$enabled_actions = $attrib['actions'];
$enabled_actions = is_array($enabled_actions) ? $enabled_actions : preg_split('/[\s,;]+/', $attrib['actions']);
Expand Down

0 comments on commit ff6f90f

Please sign in to comment.