3 class junk_keyword
extends rcube_plugin
{
7 #write_log($this->name, "init: task=" . print_r($rcmail->task, true) . " action=" . print_r($rcmail->action, true));
8 $rcmail = rcmail
::get_instance();
9 $this->name
= get_class($this);
10 if (($rcmail->task
== 'mail') && ($rcmail->action
== '')) {
11 $this->add_hook('render_page', array($this, 'render_page'));
12 $this->include_script('junk_keyword.js');
14 $this->add_junk_flags
= array
16 , 'NONJUNK' => 'NonJunk'
18 $this->register_action('plugin.junk_keyword.set_keywords', array($this, 'set_keywords'));
19 $this->add_hook('messages_list', array($this, 'message_list'));
20 $this->add_texts('localization');
22 public function render_page($args) {
23 #write_log($this->name, "render_page: args=" . print_r($args, true));
24 $rcmail = rcmail
::get_instance();
25 $icon = 'plugins/junk_keyword/' .$this->local_skin_path(). '/junk.png';
26 $junk_keywordicon = html
::img(array
27 ( 'alt' => $this->gettext('junk_keyword')
28 , 'id' => 'junk_keyword_menulink'
30 , 'title' => $this->gettext('junk_keyword')));
31 $rcmail->output
->add_label('junk_keyword.junk_keyword');
32 $rcmail->output
->set_env('junk_keywordicon', $junk_keywordicon);
33 $this->include_stylesheet($this->local_skin_path(). '/junk.css');
37 public function message_list($args) {
38 #write_log($this->name, "message_list: args=" . print_r($args, true));
39 if (!isset($args['messages']) or !is_array($args['messages']))
41 foreach($args['messages'] as $message) {
42 #write_log($this->name, "message_list: foreach: begin: message=" . print_r($message, true));
43 $message->list_flags
['extra_flags']['junk_keywords'] = array(); # always set extra_flags, needed for javascript later!
44 if (is_array($message->flags
)) {
47 foreach ($message->flags
as $flagname => $flagvalue) {
48 $flag = is_numeric("$flagvalue") ?
$flagname : $flagvalue; // for compatibility with < 0.5.4
49 $flag = strtolower($flag);
50 #write_log($this->name, "message_list: foreach: flag=" . print_r($flag, true));
51 $message->list_flags
['extra_flags']['junk'] = false;
52 if (preg_match('/^junk$/', $flag)) {
54 $message->list_flags
['extra_flags']['junk'] = true;
56 if (preg_match('/^nonjunk$/', $flag)) {
58 $message->list_flags
['extra_flags']['junk'] = false;
62 $message->list_cols
['junk_keyword'] = '<div id="rcmjunk_keyword'.$uid.'" name="rcmjunk_keyword'.$uid.'" class="'.$class.'"> </div>';
67 public function set_keywords() {
68 #write_log($this->name, "set_keywords: _GET=" . print_r($_GET, true));
70 $rcmail = rcmail
::get_instance();
71 $imap = $rcmail->imap
;
72 //$cbox = get_input_value('_cur', RCUBE_INPUT_GET);
73 $mbox = get_input_value('_mbox', RCUBE_INPUT_GET
);
74 $junk_uids = get_input_value('_junk_uids', RCUBE_INPUT_GET
);
75 $junk_uids = array_filter(explode(',', $junk_uids));
76 $nonjunk_uids = get_input_value('_nonjunk_uids', RCUBE_INPUT_GET
);
77 $nonjunk_uids = array_filter(explode(',', $nonjunk_uids));
79 $imap->conn
->flags
= array_merge($imap->conn
->flags
, $this->add_junk_flags
);
81 if (!is_array($junk_uids) ||
!is_array($nonjunk_uids))
83 //write_log($this->name, "set_keywords: junk_uids=" . print_r($junk_uids, true));
84 //write_log($this->name, "set_keywords: nonjunk_uids=" . print_r($nonjunk_uids, true));
87 $imap->conn
->error
= "";
88 if (!empty($junk_uids)) {
89 if (!$imap->set_flag($junk_uids, 'SEEN', $mbox))
90 $error = "set SEEN: " . $imap->conn
->error
;
91 if (!$imap->unset_flag($junk_uids, 'NONJUNK', $mbox))
92 $error = "unset NONJUNK: " . $imap->conn
->error
;
93 if (!$imap->set_flag($junk_uids, 'JUNK', $mbox))
94 $error = "set JUNK: " . $imap->conn
->error
;
96 if (!empty($nonjunk_uids)) {
97 if (!$imap->unset_flag($nonjunk_uids, 'JUNK', $mbox))
98 $error = "unset JUNK: " . $imap->conn
->error
;
99 if (!$imap->set_flag($nonjunk_uids, 'NONJUNK', $mbox))
100 $error = "set NONJUNK: " . $imap->conn
->error
;
103 $rcmail->output
->command('display_message', $this->gettext('classification_done'), 'confirmation');
105 $rcmail->output
->command('display_message', $this->gettext('classification_failed'). ': ' . $error, 'error');
106 $this->api
->output
->send();
107 return empty($error);