annotate plugins/managesieve/managesieve.php @ 58:082a19037887 default tip

More cleaning up php8 Warnings/deprecations
author Charlie Root
date Wed, 15 Oct 2025 14:06:01 -0400
parents 1e000243b222
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1 <?php
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
3 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
4 * Managesieve (Sieve Filters)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
5 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
6 * Plugin that adds a possibility to manage Sieve filters in Thunderbird's style.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 * It's clickable interface which operates on text scripts and communicates
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 * with server using managesieve protocol. Adds Filters tab in Settings.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 * @author Aleksander Machniak <alec@alec.pl>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
12 * Configuration (see config.inc.php.dist)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
13 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 * Copyright (C) 2008-2013, The Roundcube Dev Team
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 * Copyright (C) 2011-2013, Kolab Systems AG
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
17 * This program is free software: you can redistribute it and/or modify
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 * it under the terms of the GNU General Public License as published by
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 * the Free Software Foundation, either version 3 of the License, or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 * (at your option) any later version.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
22 * This program is distributed in the hope that it will be useful,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 * GNU General Public License for more details.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
26 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
27 * You should have received a copy of the GNU General Public License
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 * along with this program. If not, see http://www.gnu.org/licenses/.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 class managesieve extends rcube_plugin
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 public $task = 'mail|settings';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 private $rc;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 private $engine;
58
082a19037887 More cleaning up php8 Warnings/deprecations
Charlie Root
parents: 0
diff changeset
36 private $ui_initialized;
0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 function init()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 $this->rc = rcube::get_instance();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 // register actions
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 $this->register_action('plugin.managesieve', array($this, 'managesieve_actions'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 $this->register_action('plugin.managesieve-action', array($this, 'managesieve_actions'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 $this->register_action('plugin.managesieve-vacation', array($this, 'managesieve_actions'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 $this->register_action('plugin.managesieve-save', array($this, 'managesieve_save'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 $this->register_action('plugin.managesieve-saveraw', array($this, 'managesieve_saveraw'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 if ($this->rc->task == 'settings') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 $this->add_hook('settings_actions', array($this, 'settings_actions'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 $this->init_ui();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 else if ($this->rc->task == 'mail') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 // register message hook
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 if ($this->rc->action == 'show') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 $this->add_hook('message_headers_output', array($this, 'mail_headers'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 // inject Create Filter popup stuff
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 if (empty($this->rc->action) || $this->rc->action == 'show'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 || strpos($this->rc->action, 'plugin.managesieve') === 0
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 $this->mail_task_handler();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
64 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
65 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
66 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69 * Initializes plugin's UI (localization, js script)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
70 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
71 function init_ui()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 if ($this->ui_initialized) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
75 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
76
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 // load localization
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 $this->add_texts('localization/');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
79
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
80 $sieve_action = strpos($this->rc->action, 'plugin.managesieve') === 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 if ($this->rc->task == 'mail' || $sieve_action) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 $this->include_script('managesieve.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
84 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
85
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 // include styles
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 $skin_path = $this->local_skin_path();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 if ($sieve_action || ($this->rc->task == 'settings' && empty($_REQUEST['_framed']))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 $this->include_stylesheet("$skin_path/managesieve.css");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 else if ($this->rc->task == 'mail') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 $this->include_stylesheet("$skin_path/managesieve_mail.css");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
93 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
94
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
95 $this->ui_initialized = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
97
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
98 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 * Adds Filters section in Settings
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 function settings_actions($args)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
102 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
103 $this->load_config();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 $vacation_mode = (int) $this->rc->config->get('managesieve_vacation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
106
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
107 // register Filters action
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 if ($vacation_mode != 2) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 $args['actions'][] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 'action' => 'plugin.managesieve',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 'class' => 'filter',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 'label' => 'filters',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 'domain' => 'managesieve',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 'title' => 'filterstitle',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
115 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
116 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
117
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 // register Vacation action
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119 if ($vacation_mode > 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 $args['actions'][] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 'action' => 'plugin.managesieve-vacation',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 'class' => 'vacation',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 'label' => 'vacation',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 'domain' => 'managesieve',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 'title' => 'vacationtitle',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
127 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
128
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 return $args;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
131
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
132 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
133 * Add UI elements to the 'mailbox view' and 'show message' UI.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 function mail_task_handler()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
136 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
137 // make sure we're not in ajax request
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 if ($this->rc->output->type != 'html') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
141
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
142 // use jQuery for popup window
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 $this->require_plugin('jqueryui');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 // include js script and localization
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 $this->init_ui();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
147
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
148 // add 'Create filter' item to message menu
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 $this->api->add_content(html::tag('li', null,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150 $this->api->output->button(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 'command' => 'managesieve-create',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 'label' => 'managesieve.filtercreate',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153 'type' => 'link',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 'classact' => 'icon filterlink active',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 'class' => 'icon filterlink',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 'innerclass' => 'icon filterlink',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 ))), 'messagemenu');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 // register some labels/messages
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 $this->rc->output->add_label('managesieve.newfilter', 'managesieve.usedata',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 'managesieve.nodata', 'managesieve.nextstep', 'save');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 $this->rc->session->remove('managesieve_current');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 * Get message headers for popup window
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
168 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
169 function mail_headers($args)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171 // this hook can be executed many times
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 if ($this->mail_headers_done) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 return $args;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
175
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
176 $this->mail_headers_done = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 $headers = $this->parse_headers($args['headers']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 if ($this->rc->action == 'preview')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 $this->rc->output->command('parent.set_env', array('sieve_headers' => $headers));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183 $this->rc->output->set_env('sieve_headers', $headers);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 return $args;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 * Plugin action handler
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 function managesieve_actions()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 // handle fetching email headers for the new filter form
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 if ($uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 $uids = rcmail::get_uids();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 $mailbox = key($uids);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197 $message = new rcube_message($uids[$mailbox][0], $mailbox);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 $headers = $this->parse_headers($message->headers);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200 $this->rc->output->set_env('sieve_headers', $headers);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 $this->rc->output->command('managesieve_create', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 $this->rc->output->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 // handle other actions
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 $engine_type = $this->rc->action == 'plugin.managesieve-vacation' ? 'vacation' : '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 $engine = $this->get_engine($engine_type);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 $this->init_ui();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 $engine->actions();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 * Forms save action handler
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
215 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
216 function managesieve_save()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
217 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
218 // load localization
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 $this->add_texts('localization/', array('filters','managefilters'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 // include main js script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 if ($this->api->output->type == 'html') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 $this->include_script('managesieve.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
225
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
226 $engine = $this->get_engine();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 $engine->save();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
228 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
229
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
230 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
231 * Raw form save action handler
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
232 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
233 function managesieve_saveraw()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
234 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
235 $engine = $this->get_engine();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
236
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
237 if (!$this->rc->config->get('managesieve_raw_editor', true)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241 // load localization
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 $this->add_texts('localization/', array('filters','managefilters'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 $engine->saveraw();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
246
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
247 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 * Initializes engine object
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
249 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
250 public function get_engine($type = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 if (!$this->engine) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 $this->load_config();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255 // Add include path for internal classes
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 $include_path = $this->home . '/lib' . PATH_SEPARATOR;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 $include_path .= ini_get('include_path');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 set_include_path($include_path);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
259
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
260 $class_name = 'rcube_sieve_' . ($type ?: 'engine');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 $this->engine = new $class_name($this);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
262 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
263
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
264 return $this->engine;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268 * Extract mail headers for new filter form
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
269 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
270 private function parse_headers($headers)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
271 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
272 $result = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274 if ($headers->subject)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275 $result[] = array('Subject', rcube_mime::decode_header($headers->subject));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 // @TODO: List-Id, others?
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278 foreach (array('From', 'To') as $h) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 $hl = strtolower($h);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 if ($headers->$hl) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 $list = rcube_mime::decode_address_list($headers->$hl);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 foreach ($list as $item) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 if ($item['mailto']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 $result[] = array($h, $item['mailto']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
285 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
286 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
289
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
290 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 }