/usr/share/roundcube/plugins/markasjunk2/markasjunk2.php is in roundcube-plugins-extra 0.7-20120110.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | <?php
/**
* MarkAsJunk2
*
* Sample plugin that adds a new button to the mailbox toolbar
* to mark the selected messages as Junk and move them to the Junk folder
* or to move messages in the Junk folder to the inbox - moving only the
* attachment if it is a Spamassassin spam report email
*
* @version @package_version@
* @author Philip Weir
* Based on the Markasjunk plugin by Thomas Bruederli
*/
class markasjunk2 extends rcube_plugin
{
public $task = 'mail';
private $spam_mbox = null;
private $ham_mbox = 'INBOX';
private $spam_flag = 'JUNK';
private $ham_flag = 'NOTJUNK';
private $toolbar = true;
function init()
{
$this->register_action('plugin.markasjunk2.junk', array($this, 'mark_junk'));
$this->register_action('plugin.markasjunk2.not_junk', array($this, 'mark_notjunk'));
$rcmail = rcmail::get_instance();
$this->load_config();
$this->spam_mbox = $rcmail->config->get('junk_mbox', null);
$this->toolbar = $rcmail->config->get('markasjunk2_mb_toolbar', true);
if ($rcmail->action == '' || $rcmail->action == 'show') {
$this->include_script('markasjunk2.js');
$this->add_texts('localization', true);
$this->include_stylesheet($this->local_skin_path() .'/markasjunk2.css');
if ($rcmail->output->browser->ie && $rcmail->output->browser->ver == 6)
$this->include_stylesheet($this->local_skin_path() . '/ie6hacks.css');
$mb_override = ($this->spam_mbox) ? false : true;
$display_junk = $display_not_junk = '';
if ($_SESSION['mbox'] == $this->spam_mbox)
$display_junk = 'display: none;';
elseif (!$mb_override)
$display_not_junk = 'display: none;';
if ($rcmail->action == 'show') {
$this->add_button(array('command' => 'plugin.markasjunk2.junk', 'type' => 'link', 'class' => 'buttonPas markasjunk2', 'classact' => 'button markasjunk2', 'classsel' => 'button markasjunk2Sel', 'title' => 'markasjunk2.buttonjunk', 'content' => ' ', 'style' => $display_junk), 'toolbar');
$this->add_button(array('command' => 'plugin.markasjunk2.not_junk', 'type' => 'link', 'class' => 'buttonPas markasnotjunk2', 'classact' => 'button markasnotjunk2', 'classsel' => 'button markasnotjunk2Sel', 'title' => 'markasjunk2.buttonnotjunk', 'content' => ' ', 'style' => $display_not_junk), 'toolbar');
}
elseif ($this->toolbar) {
$this->add_button(array('command' => 'plugin.markasjunk2.junk', 'type' => 'link', 'class' => 'buttonPas markasjunk2', 'classact' => 'button markasjunk2', 'classsel' => 'button markasjunk2Sel', 'title' => 'markasjunk2.buttonjunk', 'content' => ' ', 'style' => $display_junk), 'toolbar');
$this->add_button(array('command' => 'plugin.markasjunk2.not_junk', 'type' => 'link', 'class' => 'buttonPas markasnotjunk2', 'classact' => 'button markasnotjunk2', 'classsel' => 'button markasnotjunk2Sel', 'title' => 'markasjunk2.buttonnotjunk', 'content' => ' ', 'style' => $display_not_junk), 'toolbar');
}
else {
$markjunk = $this->api->output->button(array('command' => 'plugin.markasjunk2.junk', 'label' => 'markasjunk2.markasjunk', 'id' => 'markasjunk2', 'class' => 'markasjunk2', 'classact' => 'markasjunk2 active'));
$marknotjunk = $this->api->output->button(array('command' => 'plugin.markasjunk2.not_junk', 'label' => 'markasjunk2.markasnotjunk', 'id' => 'markasnotjunk2', 'class' => 'markasnotjunk2', 'classact' => 'markasnotjunk2 active'));
$this->api->add_content(html::tag('li', array('style' => $display_junk), $markjunk), 'markmenu');
$this->api->add_content(html::tag('li', array('style' => $display_not_junk), $marknotjunk), 'markmenu');
}
$this->api->output->set_env('markasjunk2_override', $mb_override);
}
}
function mark_junk()
{
$this->add_texts('localization');
$this->_set_flags();
$uids = get_input_value('_uid', RCUBE_INPUT_POST);
$mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
$this->_spam($uids, $mbox, $this->spam_mbox);
$this->api->output->command('display_message', $this->gettext('reportedasjunk'), 'confirmation');
$this->api->output->send();
}
function mark_notjunk()
{
$this->add_texts('localization');
$this->_set_flags();
$rcmail = rcmail::get_instance();
$imap = $rcmail->imap;
$uids = get_input_value('_uid', RCUBE_INPUT_POST);
$mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
$this->_ham($uids, $mbox, $this->ham_mbox);
$this->api->output->command('display_message', $this->gettext('reportedasnotjunk'), 'confirmation');
$this->api->output->send();
}
private function _spam($uids, $mbox_name = NULL, $dest_mbox = NULL)
{
$rcmail = rcmail::get_instance();
$imap = $rcmail->imap;
if ($rcmail->config->get('markasjunk2_learning_driver', false))
$this->_call_driver($uids, true);
if ($rcmail->config->get('markasjunk2_read_spam', false))
$imap->set_flag($uids, 'SEEN', $mbox_name);
if ($rcmail->config->get('markasjunk2_spam_flag', false))
$imap->set_flag($uids, $this->spam_flag, $mbox_name);
if ($rcmail->config->get('markasjunk2_ham_flag', false))
$imap->unset_flag($uids, $this->ham_flag, $mbox_name);
if ($rcmail->config->get('markasjunk2_move_spam', true) && $dest_mbox && $mbox_name != $dest_mbox)
$this->api->output->command('rcmail_markasjunk2_move', $dest_mbox, $uids);
else
$this->api->output->command('command', 'list', $mbox_name);
}
private function _ham($uids, $mbox_name = NULL, $dest_mbox = NULL)
{
$rcmail = rcmail::get_instance();
$imap = $rcmail->imap;
if ($rcmail->config->get('markasjunk2_learning_driver', false))
$this->_call_driver($uids, false);
if ($rcmail->config->get('markasjunk2_unread_ham', false))
$imap->unset_flag($uids, 'SEEN', $mbox_name);
if ($rcmail->config->get('markasjunk2_spam_flag', false))
$imap->unset_flag($uids, $this->spam_flag, $mbox_name);
if ($rcmail->config->get('markasjunk2_ham_flag', false))
$imap->set_flag($uids, $this->ham_flag, $mbox_name);
if ($rcmail->config->get('markasjunk2_move_ham', true) && $dest_mbox && $mbox_name != $dest_mbox)
$this->api->output->command('rcmail_markasjunk2_move', $dest_mbox, $uids);
else
$this->api->output->command('command', 'list', $mbox_name);
}
private function _call_driver(&$uids, $spam)
{
$driver = $this->home.'/drivers/'.rcmail::get_instance()->config->get('markasjunk2_learning_driver', 'cmd_learn').'.php';
if (!is_readable($driver)) {
raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__,
'line' => __LINE__,
'message' => "MarkasJunk2 plugin: Unable to open driver file $driver"
), true, false);
return $this->gettext('internalerror');
}
include_once($driver);
if (!function_exists('learn_spam') || !function_exists('learn_ham')) {
raise_error(array(
'code' => 600,
'type' => 'php',
'file' => __FILE__,
'line' => __LINE__,
'message' => "MarkasJunk2 plugin: Broken driver: $driver"
), true, false);
return $this->gettext('internalerror');
}
if ($spam)
learn_spam($uids);
else
learn_ham($uids);
}
private function _set_flags()
{
$rcmail = rcmail::get_instance();
if ($rcmail->config->get('markasjunk2_spam_flag', false)) {
if ($flag = array_search($rcmail->config->get('markasjunk2_spam_flag'), $rcmail->imap->conn->flags))
$this->spam_flag = $flag;
else
$rcmail->imap->conn->flags[$this->spam_flag] = $rcmail->config->get('markasjunk2_spam_flag');
}
if ($rcmail->config->get('markasjunk2_ham_flag', false)) {
if ($flag = array_search($rcmail->config->get('markasjunk2_ham_flag'), $rcmail->imap->conn->flags))
$this->ham_flag = $flag;
else
$rcmail->imap->conn->flags[$this->ham_flag] = $rcmail->config->get('markasjunk2_ham_flag');
}
}
}
?>
|