annotate plugins/managesieve/lib/Roundcube/rcube_sieve_engine.php @ 27:e097905863b9

turn off logging
author Charlie Root
date Sun, 28 Jan 2018 11:37:00 -0500
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) Engine
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 * Engine part of Managesieve plugin implementing UI and backend access.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
7 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
8 * Copyright (C) 2008-2014, The Roundcube Dev Team
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
9 * Copyright (C) 2011-2014, Kolab Systems AG
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
10 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
11 * 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
12 * 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
13 * the Free Software Foundation, either version 3 of the License, or
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
14 * (at your option) any later version.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
15 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
16 * 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
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
19 * GNU General Public License for more details.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
20 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
21 * 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
22 * 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
23 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
24
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
25 class rcube_sieve_engine
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 protected $rc;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
28 protected $sieve;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
29 protected $errors;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
30 protected $form;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
31 protected $list;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
32 protected $tips = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
33 protected $script = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
34 protected $exts = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
35 protected $active = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
36 protected $headers = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
37 'subject' => 'Subject',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
38 'from' => 'From',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
39 'to' => 'To',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
40 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
41 protected $addr_headers = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
42 // Required
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
43 "from", "to", "cc", "bcc", "sender", "resent-from", "resent-to",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
44 // Additional (RFC 822 / RFC 2822)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
45 "reply-to", "resent-reply-to", "resent-sender", "resent-cc", "resent-bcc",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
46 // Non-standard (RFC 2076, draft-palme-mailext-headers-08.txt)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
47 "for-approval", "for-handling", "for-comment", "apparently-to", "errors-to",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
48 "delivered-to", "return-receipt-to", "x-admin", "read-receipt-to",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
49 "x-confirm-reading-to", "return-receipt-requested",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
50 "registered-mail-reply-requested-by", "mail-followup-to", "mail-reply-to",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
51 "abuse-reports-to", "x-complaints-to", "x-report-abuse-to",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
52 // Undocumented
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
53 "x-beenthere",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
54 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
55 protected $notify_methods = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
56 'mailto',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
57 // 'sms',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
58 // 'tel',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
59 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
60 protected $notify_importance_options = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
61 3 => 'notifyimportancelow',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
62 2 => 'notifyimportancenormal',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
63 1 => 'notifyimportancehigh'
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 const VERSION = '8.9';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
67 const PROGNAME = 'Roundcube (Managesieve)';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
68 const PORT = 4190;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
69
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 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
72 * Class constructor
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
73 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
74 function __construct($plugin)
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 $this->rc = rcube::get_instance();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
77 $this->plugin = $plugin;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
78 }
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 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
81 * Loads configuration, initializes plugin (including sieve connection)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
82 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
83 function start($mode = null)
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 // register UI objects
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
86 $this->rc->output->add_handlers(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
87 'filterslist' => array($this, 'filters_list'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
88 'filtersetslist' => array($this, 'filtersets_list'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
89 'filterframe' => array($this, 'filter_frame'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
90 'filterform' => array($this, 'filter_form'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
91 'filtersetform' => array($this, 'filterset_form'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
92 'filterseteditraw' => array($this, 'filterset_editraw'),
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 // connect to managesieve server
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
96 $error = $this->connect($_SESSION['username'], $this->rc->decrypt($_SESSION['password']));
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 // load current/active script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
99 if (!$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
100 // Get list of scripts
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
101 $list = $this->list_scripts();
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 // reset current script when entering filters UI (#1489412)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
104 if ($this->rc->action == 'plugin.managesieve') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
105 $this->rc->session->remove('managesieve_current');
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
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
108 if ($mode != 'vacation') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
109 if (!empty($_GET['_set']) || !empty($_POST['_set'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
110 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
111 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
112 else if (!empty($_SESSION['managesieve_current'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
113 $script_name = $_SESSION['managesieve_current'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
114 }
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 $error = $this->load_script($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
118 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
119
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
120 // finally set script objects
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
121 if ($error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
122 switch ($error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
123 case rcube_sieve::ERROR_CONNECTION:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
124 case rcube_sieve::ERROR_LOGIN:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
125 $this->rc->output->show_message('managesieve.filterconnerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
126 break;
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 default:
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
129 $this->rc->output->show_message('managesieve.filterunknownerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
130 break;
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 // reload interface in case of possible error when specified script wasn't found (#1489412)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
134 if ($script_name !== null && !empty($list) && !in_array($script_name, $list)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
135 $this->rc->output->command('reload', 500);
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
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
138 // to disable 'Add filter' button set env variable
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
139 $this->rc->output->set_env('filterconnerror', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
140 $this->script = array();
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 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
143 $this->exts = $this->sieve->get_extensions();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
144 $this->init_script();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
145 $this->rc->output->set_env('currentset', $this->sieve->current);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
146 $_SESSION['managesieve_current'] = $this->sieve->current;
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
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
149 $this->rc->output->set_env('raw_sieve_editor', $this->rc->config->get('managesieve_raw_editor', true));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
150
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
151 return $error;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
152 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
153
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
154 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
155 * Connect to configured managesieve server
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
156 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
157 * @param string $username User login
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
158 * @param string $password User password
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
159 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
160 * @return int Connection status: 0 on success, >0 on failure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
161 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
162 public function connect($username, $password)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
163 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
164 // Get connection parameters
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
165 $host = $this->rc->config->get('managesieve_host', 'localhost');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
166 $port = $this->rc->config->get('managesieve_port');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
167 $tls = $this->rc->config->get('managesieve_usetls', false);
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 $host = rcube_utils::parse_host($host);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
170 $host = rcube_utils::idn_to_ascii($host);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
171
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
172 // remove tls:// prefix, set TLS flag
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
173 if (($host = preg_replace('|^tls://|i', '', $host, 1, $cnt)) && $cnt) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
174 $tls = true;
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
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
177 if (empty($port)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
178 $port = getservbyname('sieve', 'tcp');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
179 if (empty($port)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
180 $port = self::PORT;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
181 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
182 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
183
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
184 $plugin = $this->rc->plugins->exec_hook('managesieve_connect', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
185 'user' => $username,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
186 'password' => $password,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
187 'host' => $host,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
188 'port' => $port,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
189 'usetls' => $tls,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
190 'auth_type' => $this->rc->config->get('managesieve_auth_type'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
191 'disabled' => $this->rc->config->get('managesieve_disabled_extensions'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
192 'debug' => $this->rc->config->get('managesieve_debug', false),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
193 'auth_cid' => $this->rc->config->get('managesieve_auth_cid'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
194 'auth_pw' => $this->rc->config->get('managesieve_auth_pw'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
195 'socket_options' => $this->rc->config->get('managesieve_conn_options'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
196 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
197
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
198 // Handle per-host socket options
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
199 rcube_utils::parse_socket_options($plugin['socket_options'], $plugin['host']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
200
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
201 // try to connect to managesieve server and to fetch the script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
202 $this->sieve = new rcube_sieve(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
203 $plugin['user'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
204 $plugin['password'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
205 $plugin['host'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
206 $plugin['port'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
207 $plugin['auth_type'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
208 $plugin['usetls'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
209 $plugin['disabled'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
210 $plugin['debug'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
211 $plugin['auth_cid'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
212 $plugin['auth_pw'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
213 $plugin['socket_options']
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
214 );
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 $error = $this->sieve->error();
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 if ($error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
219 rcube::raise_error(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
220 'code' => 403,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
221 'file' => __FILE__,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
222 'line' => __LINE__,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
223 'message' => "Unable to connect to managesieve on $host:$port"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
224 ), true, false);
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
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
227 return $error;
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 * Load specified (or active) script
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 * @param string $script_name Optional script name
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 * @return int Connection status: 0 on success, >0 on failure
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 protected function load_script($script_name = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
238 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
239 // Get list of scripts
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
240 $list = $this->list_scripts();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
241
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
242 if ($script_name === null || $script_name === '') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
243 // get (first) active script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
244 if (!empty($this->active)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
245 $script_name = $this->active[0];
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 else if ($list) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
248 $script_name = $list[0];
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 // create a new (initial) script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
251 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
252 // if script not exists build default script contents
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
253 $script_file = $this->rc->config->get('managesieve_default');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
254 $script_name = $this->rc->config->get('managesieve_script_name');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
255
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
256 if (empty($script_name)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
257 $script_name = 'roundcube';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
258 }
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 if ($script_file && is_readable($script_file)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
261 $content = file_get_contents($script_file);
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 // add script and set it active
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
265 if ($this->sieve->save_script($script_name, $content)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
266 $this->activate_script($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
267 $this->list[] = $script_name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
268 }
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 }
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 if ($script_name) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
273 $this->sieve->load($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
274 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
275
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
276 return $this->sieve->error();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
277 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
278
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
279 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
280 * User interface actions handler
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
281 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
282 function actions()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
283 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
284 $error = $this->start();
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 // Handle user requests
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
287 if ($action = rcube_utils::get_input_value('_act', rcube_utils::INPUT_GPC)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
288 $fid = (int) rcube_utils::get_input_value('_fid', rcube_utils::INPUT_POST);
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 if ($action == 'delete' && !$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
291 if (isset($this->script[$fid])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
292 if ($this->sieve->script->delete_rule($fid))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
293 $result = $this->save_script();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
294
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
295 if ($result === true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
296 $this->rc->output->show_message('managesieve.filterdeleted', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
297 $this->rc->output->command('managesieve_updatelist', 'del', array('id' => $fid));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
298 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
299 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
300 $this->rc->output->show_message('managesieve.filterdeleteerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
301 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
302 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
303 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
304 else if ($action == 'move' && !$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
305 if (isset($this->script[$fid])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
306 $to = (int) rcube_utils::get_input_value('_to', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
307 $rule = $this->script[$fid];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
308
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
309 // remove rule
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
310 unset($this->script[$fid]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
311 $this->script = array_values($this->script);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
312
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
313 // add at target position
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
314 if ($to >= count($this->script)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
315 $this->script[] = $rule;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
316 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
317 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
318 $script = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
319 foreach ($this->script as $idx => $r) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
320 if ($idx == $to)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
321 $script[] = $rule;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
322 $script[] = $r;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
323 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
324 $this->script = $script;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
325 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
326
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
327 $this->sieve->script->content = $this->script;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
328 $result = $this->save_script();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
329
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
330 if ($result === true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
331 $result = $this->list_rules();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
332
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
333 $this->rc->output->show_message('managesieve.moved', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
334 $this->rc->output->command('managesieve_updatelist', 'list',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
335 array('list' => $result, 'clear' => true, 'set' => $to));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
336 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
337 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
338 $this->rc->output->show_message('managesieve.moveerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
339 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
340 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
341 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
342 else if ($action == 'act' && !$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
343 if (isset($this->script[$fid])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
344 $rule = $this->script[$fid];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
345 $disabled = !empty($rule['disabled']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
346 $rule['disabled'] = !$disabled;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
347 $result = $this->sieve->script->update_rule($fid, $rule);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
348
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
349 if ($result !== false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
350 $result = $this->save_script();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
351
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
352 if ($result === true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
353 if ($rule['disabled'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
354 $this->rc->output->show_message('managesieve.deactivated', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
355 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
356 $this->rc->output->show_message('managesieve.activated', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
357 $this->rc->output->command('managesieve_updatelist', 'update',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
358 array('id' => $fid, 'disabled' => $rule['disabled']));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
359 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
360 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
361 if ($rule['disabled'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
362 $this->rc->output->show_message('managesieve.deactivateerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
363 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
364 $this->rc->output->show_message('managesieve.activateerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
365 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
366 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
367 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
368 else if ($action == 'setact' && !$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
369 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
370 $result = $this->activate_script($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
371 $kep14 = $this->rc->config->get('managesieve_kolab_master');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
372
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
373 if ($result === true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
374 $this->rc->output->set_env('active_sets', $this->active);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
375 $this->rc->output->show_message('managesieve.setactivated', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
376 $this->rc->output->command('managesieve_updatelist', 'setact',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
377 array('name' => $script_name, 'active' => true, 'all' => !$kep14));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
378 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
379 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
380 $this->rc->output->show_message('managesieve.setactivateerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
381 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
382 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
383 else if ($action == 'deact' && !$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
384 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
385 $result = $this->deactivate_script($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
386
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
387 if ($result === true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
388 $this->rc->output->set_env('active_sets', $this->active);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
389 $this->rc->output->show_message('managesieve.setdeactivated', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
390 $this->rc->output->command('managesieve_updatelist', 'setact',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
391 array('name' => $script_name, 'active' => false));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
392 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
393 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
394 $this->rc->output->show_message('managesieve.setdeactivateerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
395 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
396 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
397 else if ($action == 'setdel' && !$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
398 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
399 $result = $this->remove_script($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
400
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
401 if ($result === true) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
402 $this->rc->output->show_message('managesieve.setdeleted', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
403 $this->rc->output->command('managesieve_updatelist', 'setdel',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
404 array('name' => $script_name));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
405 $this->rc->session->remove('managesieve_current');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
406 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
407 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
408 $this->rc->output->show_message('managesieve.setdeleteerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
409 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
410 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
411 else if ($action == 'setget') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
412 $this->rc->request_security_check(rcube_utils::INPUT_GET);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
413
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
414 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_GPC, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
415 $script = $this->sieve->get_script($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
416
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
417 if ($script === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
418 exit;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
419 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
420
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
421 $browser = new rcube_browser;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
422
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
423 // send download headers
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
424 header("Content-Type: application/octet-stream");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
425 header("Content-Length: ".strlen($script));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
426
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
427 if ($browser->ie) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
428 header("Content-Type: application/force-download");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
429 $filename = rawurlencode($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
430 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
431 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
432 $filename = addcslashes($script_name, '\\"');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
433 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
434
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
435 header("Content-Disposition: attachment; filename=\"$filename.txt\"");
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
436 echo $script;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
437 exit;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
438 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
439 else if ($action == 'list') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
440 $result = $this->list_rules();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
441
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
442 $this->rc->output->command('managesieve_updatelist', 'list', array('list' => $result));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
443 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
444 else if ($action == 'ruleadd') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
445 $rid = rcube_utils::get_input_value('_rid', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
446 $id = $this->genid();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
447 $content = $this->rule_div($fid, $id, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
448
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
449 $this->rc->output->command('managesieve_rulefill', $content, $id, $rid);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
450 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
451 else if ($action == 'actionadd') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
452 $aid = rcube_utils::get_input_value('_aid', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
453 $id = $this->genid();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
454 $content = $this->action_div($fid, $id, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
455
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
456 $this->rc->output->command('managesieve_actionfill', $content, $id, $aid);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
457 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
458 else if ($action == 'addresses') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
459 $aid = rcube_utils::get_input_value('_aid', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
460
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
461 $this->rc->output->command('managesieve_vacation_addresses_update', $aid, $this->user_emails());
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
462 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
463
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
464 $this->rc->output->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
465 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
466 else if ($this->rc->task == 'mail') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
467 // Initialize the form
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
468 $rules = rcube_utils::get_input_value('r', rcube_utils::INPUT_GET);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
469 if (!empty($rules)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
470 $i = 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
471 foreach ($rules as $rule) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
472 list($header, $value) = explode(':', $rule, 2);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
473 $tests[$i] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
474 'type' => 'contains',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
475 'test' => 'header',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
476 'arg1' => $header,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
477 'arg2' => $value,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
478 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
479 $i++;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
480 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
481
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
482 $this->form = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
483 'join' => count($tests) > 1 ? 'allof' : 'anyof',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
484 'name' => '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
485 'tests' => $tests,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
486 'actions' => array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
487 0 => array('type' => 'fileinto'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
488 1 => array('type' => 'stop'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
489 ),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
490 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
491 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
492 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
493
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
494 $this->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
495 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
496
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
497 function saveraw()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
498 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
499 // Init plugin and handle managesieve connection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
500 $error = $this->start();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
501
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
502 $script_name = rcube_utils::get_input_value('_set', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
503
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
504 $result = $this->sieve->save_script($script_name, $_POST['rawsetcontent']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
505
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
506 if ($result === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
507 $this->rc->output->show_message('managesieve.filtersaveerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
508 $errorLines = $this->sieve->get_error_lines();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
509 if (count($errorLines) > 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
510 $this->rc->output->set_env("sieve_errors", $errorLines);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
511 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
512 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
513 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
514 $this->rc->output->show_message('managesieve.setupdated', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
515 $this->rc->output->command('parent.managesieve_updatelist', 'refresh');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
516 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
517
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
518 $this->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
519 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
520
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
521 function save()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
522 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
523 // Init plugin and handle managesieve connection
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
524 $error = $this->start();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
525
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
526 // get request size limits (#1488648)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
527 $max_post = max(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
528 ini_get('max_input_vars'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
529 ini_get('suhosin.request.max_vars'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
530 ini_get('suhosin.post.max_vars'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
531 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
532 $max_depth = max(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
533 ini_get('suhosin.request.max_array_depth'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
534 ini_get('suhosin.post.max_array_depth'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
535 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
536
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
537 // check request size limit
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
538 if ($max_post && count($_POST, COUNT_RECURSIVE) >= $max_post) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
539 rcube::raise_error(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
540 'code' => 500, 'type' => 'php',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
541 'file' => __FILE__, 'line' => __LINE__,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
542 'message' => "Request size limit exceeded (one of max_input_vars/suhosin.request.max_vars/suhosin.post.max_vars)"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
543 ), true, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
544 $this->rc->output->show_message('managesieve.filtersaveerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
545 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
546 // check request depth limits
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
547 else if ($max_depth && count($_POST['_header']) > $max_depth) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
548 rcube::raise_error(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
549 'code' => 500, 'type' => 'php',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
550 'file' => __FILE__, 'line' => __LINE__,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
551 'message' => "Request size limit exceeded (one of suhosin.request.max_array_depth/suhosin.post.max_array_depth)"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
552 ), true, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
553 $this->rc->output->show_message('managesieve.filtersaveerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
554 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
555 // filters set add action
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
556 else if (!empty($_POST['_newset'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
557 $name = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
558 $copy = rcube_utils::get_input_value('_copy', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
559 $from = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
560 $exceptions = $this->rc->config->get('managesieve_filename_exceptions');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
561 $kolab = $this->rc->config->get('managesieve_kolab_master');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
562 $name_uc = mb_strtolower($name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
563 $list = $this->list_scripts();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
564
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
565 if (!$name) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
566 $this->errors['name'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
567 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
568 else if (mb_strlen($name) > 128) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
569 $this->errors['name'] = $this->plugin->gettext('nametoolong');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
570 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
571 else if (!empty($exceptions) && in_array($name, (array)$exceptions)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
572 $this->errors['name'] = $this->plugin->gettext('namereserved');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
573 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
574 else if (!empty($kolab) && in_array($name_uc, array('MASTER', 'USER', 'MANAGEMENT'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
575 $this->errors['name'] = $this->plugin->gettext('namereserved');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
576 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
577 else if (in_array($name, $list)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
578 $this->errors['name'] = $this->plugin->gettext('setexist');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
579 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
580 else if ($from == 'file') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
581 // from file
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
582 if (is_uploaded_file($_FILES['_file']['tmp_name'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
583 $file = file_get_contents($_FILES['_file']['tmp_name']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
584 $file = preg_replace('/\r/', '', $file);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
585 // for security don't save script directly
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
586 // check syntax before, like this...
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
587 $this->sieve->load_script($file);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
588 if (!$this->save_script($name)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
589 $this->errors['file'] = $this->plugin->gettext('setcreateerror');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
590 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
591 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
592 else { // upload failed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
593 $err = $_FILES['_file']['error'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
594
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
595 if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
596 $msg = $this->rc->gettext(array('name' => 'filesizeerror',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
597 'vars' => array('size' =>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
598 $this->rc->show_bytes(rcube_utils::max_upload_size()))));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
599 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
600 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
601 $this->errors['file'] = $this->plugin->gettext('fileuploaderror');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
602 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
603 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
604 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
605 else if (!$this->sieve->copy($name, $from == 'set' ? $copy : '')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
606 $error = 'managesieve.setcreateerror';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
607 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
608
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
609 if (!$error && empty($this->errors)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
610 // Find position of the new script on the list
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
611 $list[] = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
612 asort($list, SORT_LOCALE_STRING);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
613 $list = array_values($list);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
614 $index = array_search($name, $list);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
615
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
616 $this->rc->output->show_message('managesieve.setcreated', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
617 $this->rc->output->command('parent.managesieve_updatelist', 'setadd',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
618 array('name' => $name, 'index' => $index));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
619 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
620 else if ($msg) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
621 $this->rc->output->command('display_message', $msg, 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
622 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
623 else if ($error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
624 $this->rc->output->show_message($error, 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
625 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
626 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
627 // filter add/edit action
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
628 else if (isset($_POST['_name'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
629 $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
630 $fid = trim(rcube_utils::get_input_value('_fid', rcube_utils::INPUT_POST));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
631 $join = trim(rcube_utils::get_input_value('_join', rcube_utils::INPUT_POST));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
632
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
633 // and arrays
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
634 $headers = rcube_utils::get_input_value('_header', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
635 $cust_headers = rcube_utils::get_input_value('_custom_header', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
636 $cust_vars = rcube_utils::get_input_value('_custom_var', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
637 $ops = rcube_utils::get_input_value('_rule_op', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
638 $sizeops = rcube_utils::get_input_value('_rule_size_op', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
639 $sizeitems = rcube_utils::get_input_value('_rule_size_item', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
640 $sizetargets = rcube_utils::get_input_value('_rule_size_target', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
641 $targets = rcube_utils::get_input_value('_rule_target', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
642 $mods = rcube_utils::get_input_value('_rule_mod', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
643 $mod_types = rcube_utils::get_input_value('_rule_mod_type', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
644 $body_trans = rcube_utils::get_input_value('_rule_trans', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
645 $body_types = rcube_utils::get_input_value('_rule_trans_type', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
646 $comparators = rcube_utils::get_input_value('_rule_comp', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
647 $indexes = rcube_utils::get_input_value('_rule_index', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
648 $lastindexes = rcube_utils::get_input_value('_rule_index_last', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
649 $dateheaders = rcube_utils::get_input_value('_rule_date_header', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
650 $dateparts = rcube_utils::get_input_value('_rule_date_part', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
651 $message = rcube_utils::get_input_value('_rule_message', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
652 $dup_handles = rcube_utils::get_input_value('_rule_duplicate_handle', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
653 $dup_headers = rcube_utils::get_input_value('_rule_duplicate_header', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
654 $dup_uniqueids = rcube_utils::get_input_value('_rule_duplicate_uniqueid', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
655 $dup_seconds = rcube_utils::get_input_value('_rule_duplicate_seconds', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
656 $dup_lasts = rcube_utils::get_input_value('_rule_duplicate_last', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
657 $act_types = rcube_utils::get_input_value('_action_type', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
658 $mailboxes = rcube_utils::get_input_value('_action_mailbox', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
659 $act_targets = rcube_utils::get_input_value('_action_target', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
660 $domain_targets = rcube_utils::get_input_value('_action_target_domain', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
661 $area_targets = rcube_utils::get_input_value('_action_target_area', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
662 $reasons = rcube_utils::get_input_value('_action_reason', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
663 $addresses = rcube_utils::get_input_value('_action_addresses', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
664 $intervals = rcube_utils::get_input_value('_action_interval', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
665 $interval_types = rcube_utils::get_input_value('_action_interval_type', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
666 $from = rcube_utils::get_input_value('_action_from', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
667 $subject = rcube_utils::get_input_value('_action_subject', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
668 $flags = rcube_utils::get_input_value('_action_flags', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
669 $varnames = rcube_utils::get_input_value('_action_varname', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
670 $varvalues = rcube_utils::get_input_value('_action_varvalue', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
671 $varmods = rcube_utils::get_input_value('_action_varmods', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
672 $notifymethods = rcube_utils::get_input_value('_action_notifymethod', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
673 $notifytargets = rcube_utils::get_input_value('_action_notifytarget', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
674 $notifyoptions = rcube_utils::get_input_value('_action_notifyoption', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
675 $notifymessages = rcube_utils::get_input_value('_action_notifymessage', rcube_utils::INPUT_POST, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
676 $notifyfrom = rcube_utils::get_input_value('_action_notifyfrom', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
677 $notifyimp = rcube_utils::get_input_value('_action_notifyimportance', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
678
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
679 // we need a "hack" for radiobuttons
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
680 foreach ($sizeitems as $item)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
681 $items[] = $item;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
682
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
683 $this->form['disabled'] = !empty($_POST['_disabled']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
684 $this->form['join'] = $join == 'allof';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
685 $this->form['name'] = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
686 $this->form['tests'] = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
687 $this->form['actions'] = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
688
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
689 if ($name == '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
690 $this->errors['name'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
691 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
692 foreach ($this->script as $idx => $rule)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
693 if($rule['name'] == $name && $idx != $fid) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
694 $this->errors['name'] = $this->plugin->gettext('ruleexist');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
695 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
696 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
697 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
698
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
699 $i = 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
700 // rules
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
701 if ($join == 'any') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
702 $this->form['tests'][0]['test'] = 'true';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
703 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
704 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
705 foreach ($headers as $idx => $header) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
706 // targets are indexed differently (assume form order)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
707 $target = $this->strip_value(array_shift($targets), true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
708 $header = $this->strip_value($header);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
709 $operator = $this->strip_value($ops[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
710 $comparator = $this->strip_value($comparators[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
711
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
712 if ($header == 'size') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
713 $sizeop = $this->strip_value($sizeops[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
714 $sizeitem = $this->strip_value($items[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
715 $sizetarget = $this->strip_value($sizetargets[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
716
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
717 $this->form['tests'][$i]['test'] = 'size';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
718 $this->form['tests'][$i]['type'] = $sizeop;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
719 $this->form['tests'][$i]['arg'] = $sizetarget;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
720
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
721 if ($sizetarget == '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
722 $this->errors['tests'][$i]['sizetarget'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
723 else if (!preg_match('/^[0-9]+(K|M|G)?$/i', $sizetarget.$sizeitem, $m)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
724 $this->errors['tests'][$i]['sizetarget'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
725 $this->form['tests'][$i]['item'] = $sizeitem;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
726 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
727 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
728 $this->form['tests'][$i]['arg'] .= $m[1];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
729 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
730 else if ($header == 'currentdate') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
731 $datepart = $this->strip_value($dateparts[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
732
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
733 if (preg_match('/^not/', $operator))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
734 $this->form['tests'][$i]['not'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
735 $type = preg_replace('/^not/', '', $operator);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
736
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
737 if ($type == 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
738 $this->errors['tests'][$i]['op'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
739 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
740
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
741 $this->form['tests'][$i]['test'] = 'currentdate';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
742 $this->form['tests'][$i]['type'] = $type;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
743 $this->form['tests'][$i]['part'] = $datepart;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
744 $this->form['tests'][$i]['arg'] = $target;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
745
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
746 if ($type != 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
747 if (!count($target)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
748 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
749 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
750 else if (strpos($type, 'count-') === 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
751 foreach ($target as $arg) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
752 if (preg_match('/[^0-9]/', $arg)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
753 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
754 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
755 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
756 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
757 else if (strpos($type, 'value-') === 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
758 // Some date/time formats do not support i;ascii-numeric comparator
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
759 if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
760 $comparator = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
761 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
762 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
763
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
764 if (!preg_match('/^(regex|matches|count-)/', $type) && count($target)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
765 foreach ($target as $arg) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
766 if (!$this->validate_date_part($datepart, $arg)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
767 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
768 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
769 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
770 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
771 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
772 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
773 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
774 else if ($header == 'date') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
775 $datepart = $this->strip_value($dateparts[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
776 $dateheader = $this->strip_value($dateheaders[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
777 $index = $this->strip_value($indexes[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
778 $indexlast = $this->strip_value($lastindexes[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
779
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
780 if (preg_match('/^not/', $operator))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
781 $this->form['tests'][$i]['not'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
782 $type = preg_replace('/^not/', '', $operator);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
783
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
784 if ($type == 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
785 $this->errors['tests'][$i]['op'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
786 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
787
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
788 if (!empty($index) && $mod != 'envelope') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
789 $this->form['tests'][$i]['index'] = intval($index);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
790 $this->form['tests'][$i]['last'] = !empty($indexlast);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
791 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
792
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
793 if (empty($dateheader)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
794 $dateheader = 'Date';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
795 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
796 else if (!preg_match('/^[\x21-\x39\x41-\x7E]+$/i', $dateheader)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
797 $this->errors['tests'][$i]['dateheader'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
798 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
799
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
800 $this->form['tests'][$i]['test'] = 'date';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
801 $this->form['tests'][$i]['type'] = $type;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
802 $this->form['tests'][$i]['part'] = $datepart;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
803 $this->form['tests'][$i]['arg'] = $target;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
804 $this->form['tests'][$i]['header'] = $dateheader;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
805
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
806 if ($type != 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
807 if (!count($target)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
808 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
809 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
810 else if (strpos($type, 'count-') === 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
811 foreach ($target as $arg) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
812 if (preg_match('/[^0-9]/', $arg)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
813 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
814 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
815 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
816 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
817 else if (strpos($type, 'value-') === 0) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
818 // Some date/time formats do not support i;ascii-numeric comparator
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
819 if ($comparator == 'i;ascii-numeric' && in_array($datepart, array('date', 'time', 'iso8601', 'std11'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
820 $comparator = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
821 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
822 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
823
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
824 if (count($target) && !preg_match('/^(regex|matches|count-)/', $type)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
825 foreach ($target as $arg) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
826 if (!$this->validate_date_part($datepart, $arg)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
827 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('invaliddateformat');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
828 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
829 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
830 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
831 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
832 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
833 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
834 else if ($header == 'body') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
835 $trans = $this->strip_value($body_trans[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
836 $trans_type = $this->strip_value($body_types[$idx], true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
837
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
838 if (preg_match('/^not/', $operator))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
839 $this->form['tests'][$i]['not'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
840 $type = preg_replace('/^not/', '', $operator);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
841
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
842 if ($type == 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
843 $this->errors['tests'][$i]['op'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
844 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
845
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
846 $this->form['tests'][$i]['test'] = 'body';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
847 $this->form['tests'][$i]['type'] = $type;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
848 $this->form['tests'][$i]['arg'] = $target;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
849
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
850 if (empty($target) && $type != 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
851 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
852 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
853 else if (preg_match('/^(value|count)-/', $type)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
854 foreach ($target as $target_value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
855 if (preg_match('/[^0-9]/', $target_value)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
856 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
857 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
858 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
859 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
860
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
861 $this->form['tests'][$i]['part'] = $trans;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
862 if ($trans == 'content') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
863 $this->form['tests'][$i]['content'] = $trans_type;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
864 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
865 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
866 else if ($header == 'message') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
867 $test = $this->strip_value($message[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
868
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
869 if (preg_match('/^not/', $test)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
870 $this->form['tests'][$i]['not'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
871 $test = substr($test, 3);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
872 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
873
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
874 $this->form['tests'][$i]['test'] = $test;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
875
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
876 if ($test == 'duplicate') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
877 $this->form['tests'][$i]['last'] = !empty($dup_lasts[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
878 $this->form['tests'][$i]['handle'] = trim($dup_handles[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
879 $this->form['tests'][$i]['header'] = trim($dup_headers[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
880 $this->form['tests'][$i]['uniqueid'] = trim($dup_uniqueids[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
881 $this->form['tests'][$i]['seconds'] = trim($dup_seconds[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
882
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
883 if ($this->form['tests'][$i]['seconds']
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
884 && preg_match('/[^0-9]/', $this->form['tests'][$i]['seconds'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
885 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
886 $this->errors['tests'][$i]['duplicate_seconds'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
887 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
888
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
889 if ($this->form['tests'][$i]['header'] && $this->form['tests'][$i]['uniqueid']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
890 $this->errors['tests'][$i]['duplicate_uniqueid'] = $this->plugin->gettext('duplicate.conflict.err');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
891 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
892 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
893 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
894 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
895 $cust_header = $headers = $this->strip_value(array_shift($cust_headers));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
896 $mod = $this->strip_value($mods[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
897 $mod_type = $this->strip_value($mod_types[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
898 $index = $this->strip_value($indexes[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
899 $indexlast = $this->strip_value($lastindexes[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
900
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
901 if ($header == 'string') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
902 $cust_var = $headers = $this->strip_value(array_shift($cust_vars));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
903 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
904
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
905 if (preg_match('/^not/', $operator))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
906 $this->form['tests'][$i]['not'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
907 $type = preg_replace('/^not/', '', $operator);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
908
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
909 if (!empty($index) && $mod != 'envelope') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
910 $this->form['tests'][$i]['index'] = intval($index);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
911 $this->form['tests'][$i]['last'] = !empty($indexlast);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
912 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
913
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
914 if ($header == '...' || $header == 'string') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
915 if (!count($headers))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
916 $this->errors['tests'][$i]['header'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
917 else if ($header == '...') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
918 foreach ($headers as $hr) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
919 // RFC2822: printable ASCII except colon
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
920 if (!preg_match('/^[\x21-\x39\x41-\x7E]+$/i', $hr)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
921 $this->errors['tests'][$i]['header'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
922 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
923 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
924 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
925
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
926 if (empty($this->errors['tests'][$i]['header']))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
927 $cust_header = $cust_var = (is_array($headers) && count($headers) == 1) ? $headers[0] : $headers;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
928 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
929
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
930 $test = $header == 'string' ? 'string' : 'header';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
931 $header = $header == 'string' ? $cust_var : $header;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
932 $header = $header == '...' ? $cust_header : $header;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
933
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
934 if (is_array($header)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
935 foreach ($header as $h_index => $val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
936 if (isset($this->headers[$val])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
937 $header[$h_index] = $this->headers[$val];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
938 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
939 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
940 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
941
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
942 if ($type == 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
943 $this->form['tests'][$i]['test'] = 'exists';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
944 $this->form['tests'][$i]['arg'] = $header;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
945 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
946 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
947 if ($mod == 'address' || $mod == 'envelope') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
948 $found = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
949 if (empty($this->errors['tests'][$i]['header'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
950 foreach ((array)$header as $hdr) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
951 if (!in_array(strtolower(trim($hdr)), $this->addr_headers))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
952 $found = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
953 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
954 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
955 if (!$found)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
956 $test = $mod;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
957 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
958
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
959 $this->form['tests'][$i]['type'] = $type;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
960 $this->form['tests'][$i]['test'] = $test;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
961 $this->form['tests'][$i]['arg1'] = $header;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
962 $this->form['tests'][$i]['arg2'] = $target;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
963
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
964 if (empty($target)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
965 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
966 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
967 else if (preg_match('/^(value|count)-/', $type)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
968 foreach ($target as $target_value) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
969 if (preg_match('/[^0-9]/', $target_value)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
970 $this->errors['tests'][$i]['target'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
971 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
972 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
973 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
974
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
975 if ($mod) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
976 $this->form['tests'][$i]['part'] = $mod_type;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
977 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
978 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
979 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
980
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
981 if ($header != 'size' && $comparator) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
982 $this->form['tests'][$i]['comparator'] = $comparator;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
983 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
984
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
985 $i++;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
986 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
987 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
988
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
989 $i = 0;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
990 // actions
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
991 foreach ($act_types as $idx => $type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
992 $type = $this->strip_value($type);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
993
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
994 switch ($type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
995 case 'fileinto':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
996 case 'fileinto_copy':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
997 $mailbox = $this->strip_value($mailboxes[$idx], false, false);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
998 $this->form['actions'][$i]['target'] = $this->mod_mailbox($mailbox, 'in');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
999
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1000 if ($type == 'fileinto_copy') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1001 $type = 'fileinto';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1002 $this->form['actions'][$i]['copy'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1003 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1004 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1005
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1006 case 'reject':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1007 case 'ereject':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1008 $target = $this->strip_value($area_targets[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1009 $this->form['actions'][$i]['target'] = str_replace("\r\n", "\n", $target);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1010
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1011 // if ($target == '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1012 // $this->errors['actions'][$i]['targetarea'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1013 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1014
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1015 case 'redirect':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1016 case 'redirect_copy':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1017 $target = $this->strip_value($act_targets[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1018 $domain = $this->strip_value($domain_targets[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1019
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1020 // force one of the configured domains
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1021 $domains = (array) $this->rc->config->get('managesieve_domains');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1022 if (!empty($domains) && !empty($target)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1023 if (!$domain || !in_array($domain, $domains)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1024 $domain = $domains[0];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1025 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1026
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1027 $target .= '@' . $domain;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1028 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1029
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1030 $this->form['actions'][$i]['target'] = $target;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1031
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1032 if ($target == '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1033 $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1034 else if (!rcube_utils::check_email($target))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1035 $this->errors['actions'][$i]['target'] = $this->plugin->gettext(!empty($domains) ? 'forbiddenchars' : 'noemailwarning');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1036
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1037 if ($type == 'redirect_copy') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1038 $type = 'redirect';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1039 $this->form['actions'][$i]['copy'] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1040 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1041
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1042 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1043
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1044 case 'addflag':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1045 case 'setflag':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1046 case 'removeflag':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1047 $_target = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1048 if (empty($flags[$idx])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1049 $this->errors['actions'][$i]['target'] = $this->plugin->gettext('noflagset');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1050 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1051 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1052 foreach ($flags[$idx] as $flag) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1053 $_target[] = $this->strip_value($flag);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1054 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1055 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1056 $this->form['actions'][$i]['target'] = $_target;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1057 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1058
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1059 case 'vacation':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1060 $reason = $this->strip_value($reasons[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1061 $interval_type = $interval_types[$idx] == 'seconds' ? 'seconds' : 'days';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1062
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1063 $this->form['actions'][$i]['reason'] = str_replace("\r\n", "\n", $reason);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1064 $this->form['actions'][$i]['from'] = $from[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1065 $this->form['actions'][$i]['subject'] = $subject[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1066 $this->form['actions'][$i]['addresses'] = array_shift($addresses);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1067 $this->form['actions'][$i][$interval_type] = $intervals[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1068 // @TODO: vacation :mime, :handle
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1069
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1070 foreach ((array)$this->form['actions'][$i]['addresses'] as $aidx => $address) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1071 $this->form['actions'][$i]['addresses'][$aidx] = $address = trim($address);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1072
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1073 if (empty($address)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1074 unset($this->form['actions'][$i]['addresses'][$aidx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1075 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1076 else if (!rcube_utils::check_email($address)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1077 $this->errors['actions'][$i]['addresses'] = $this->plugin->gettext('noemailwarning');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1078 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1079 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1080 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1081
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1082 if (!empty($this->form['actions'][$i]['from']) && !rcube_utils::check_email($this->form['actions'][$i]['from'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1083 $this->errors['actions'][$i]['from'] = $this->plugin->gettext('noemailwarning');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1084 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1085
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1086 if ($this->form['actions'][$i]['reason'] == '')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1087 $this->errors['actions'][$i]['reason'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1088 if ($this->form['actions'][$i][$interval_type] && !preg_match('/^[0-9]+$/', $this->form['actions'][$i][$interval_type]))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1089 $this->errors['actions'][$i]['interval'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1090 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1091
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1092 case 'set':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1093 $this->form['actions'][$i]['name'] = $varnames[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1094 $this->form['actions'][$i]['value'] = $varvalues[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1095 foreach ((array)$varmods[$idx] as $v_m) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1096 $this->form['actions'][$i][$v_m] = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1097 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1098
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1099 if (empty($varnames[$idx])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1100 $this->errors['actions'][$i]['name'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1101 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1102 else if (!preg_match('/^[0-9a-z_]+$/i', $varnames[$idx])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1103 $this->errors['actions'][$i]['name'] = $this->plugin->gettext('forbiddenchars');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1104 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1105
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1106 if (!isset($varvalues[$idx]) || $varvalues[$idx] === '') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1107 $this->errors['actions'][$i]['value'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1108 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1109 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1110
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1111 case 'notify':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1112 if (empty($notifymethods[$idx])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1113 $this->errors['actions'][$i]['method'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1114 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1115 if (empty($notifytargets[$idx])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1116 $this->errors['actions'][$i]['target'] = $this->plugin->gettext('cannotbeempty');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1117 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1118 if (!empty($notifyfrom[$idx]) && !rcube_utils::check_email($notifyfrom[$idx])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1119 $this->errors['actions'][$i]['from'] = $this->plugin->gettext('noemailwarning');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1120 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1121
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1122 // skip empty options
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1123 foreach ((array)$notifyoptions[$idx] as $opt_idx => $opt) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1124 if (!strlen(trim($opt))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1125 unset($notifyoptions[$idx][$opt_idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1126 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1127 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1128
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1129 $this->form['actions'][$i]['method'] = $notifymethods[$idx] . ':' . $notifytargets[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1130 $this->form['actions'][$i]['options'] = $notifyoptions[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1131 $this->form['actions'][$i]['message'] = $notifymessages[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1132 $this->form['actions'][$i]['from'] = $notifyfrom[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1133 $this->form['actions'][$i]['importance'] = $notifyimp[$idx];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1134 break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1135 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1136
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1137 $this->form['actions'][$i]['type'] = $type;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1138 $i++;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1139 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1140
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1141 if (!$this->errors && !$error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1142 // save the script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1143 if (!isset($this->script[$fid])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1144 $fid = $this->sieve->script->add_rule($this->form);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1145 $new = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1146 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1147 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1148 $fid = $this->sieve->script->update_rule($fid, $this->form);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1149 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1150
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1151 if ($fid !== false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1152 $save = $this->save_script();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1153 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1154
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1155 if ($save && $fid !== false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1156 $this->rc->output->show_message('managesieve.filtersaved', 'confirmation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1157 if ($this->rc->task != 'mail') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1158 $this->rc->output->command('parent.managesieve_updatelist',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1159 isset($new) ? 'add' : 'update',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1160 array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1161 'name' => $this->form['name'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1162 'id' => $fid,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1163 'disabled' => $this->form['disabled']
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1164 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1165 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1166 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1167 $this->rc->output->command('managesieve_dialog_close');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1168 $this->rc->output->send('iframe');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1169 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1170 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1171 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1172 $this->rc->output->show_message('managesieve.filtersaveerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1173 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1174 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1175 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1176 $this->rc->output->show_message('managesieve.filterformerror', 'warning');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1177 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1178 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1179
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1180 $this->send();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1181 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1182
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1183 protected function send()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1184 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1185 // Handle form action
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1186 if (isset($_GET['_framed']) || isset($_POST['_framed'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1187 if (isset($_GET['_newset']) || isset($_POST['_newset'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1188 $this->rc->output->send('managesieve.setedit');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1189 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1190 else if (isset($_GET['_seteditraw']) || isset($_POST['_seteditraw'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1191 $this->rc->output->send('managesieve.seteditraw');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1192 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1193 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1194 $this->rc->output->send('managesieve.filteredit');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1195 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1196 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1197 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1198 $this->rc->output->set_pagetitle($this->plugin->gettext('filters'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1199 $this->rc->output->send('managesieve.managesieve');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1200 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1201 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1202
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1203 // return the filters list as HTML table
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1204 function filters_list($attrib)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1205 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1206 // add id to message list table if not specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1207 if (!strlen($attrib['id']))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1208 $attrib['id'] = 'rcmfilterslist';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1209
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1210 // define list of cols to be displayed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1211 $a_show_cols = array('name');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1212
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1213 $result = $this->list_rules();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1214
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1215 // create XHTML table
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1216 $out = $this->rc->table_output($attrib, $result, $a_show_cols, 'id');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1217
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1218 // set client env
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1219 $this->rc->output->add_gui_object('filterslist', $attrib['id']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1220 $this->rc->output->include_script('list.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1221
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1222 // add some labels to client
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1223 $this->rc->output->add_label('managesieve.filterdeleteconfirm');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1224
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1225 return $out;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1226 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1227
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1228 // return the filters list as <SELECT>
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1229 function filtersets_list($attrib, $no_env = false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1230 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1231 // add id to message list table if not specified
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1232 if (!strlen($attrib['id'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1233 $attrib['id'] = 'rcmfiltersetslist';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1234 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1235
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1236 $list = $this->list_scripts();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1237
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1238 if ($list) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1239 asort($list, SORT_LOCALE_STRING);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1240 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1241
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1242 if (!empty($attrib['type']) && $attrib['type'] == 'list') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1243 // define list of cols to be displayed
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1244 $a_show_cols = array('name');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1245
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1246 if ($list) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1247 foreach ($list as $idx => $set) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1248 $scripts['S'.$idx] = $set;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1249 $result[] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1250 'name' => $set,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1251 'id' => 'S'.$idx,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1252 'class' => !in_array($set, $this->active) ? 'disabled' : '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1253 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1254 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1255 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1256
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1257 // create XHTML table
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1258 $out = $this->rc->table_output($attrib, $result, $a_show_cols, 'id');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1259
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1260 $this->rc->output->set_env('filtersets', $scripts);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1261 $this->rc->output->include_script('list.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1262 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1263 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1264 $select = new html_select(array('name' => '_set', 'id' => $attrib['id'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1265 'onchange' => $this->rc->task != 'mail' ? 'rcmail.managesieve_set()' : ''));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1266
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1267 if ($list) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1268 foreach ($list as $set)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1269 $select->add($set, $set);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1270 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1271
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1272 $out = $select->show($this->sieve->current);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1273 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1274
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1275 // set client env
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1276 if (!$no_env) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1277 $this->rc->output->add_gui_object('filtersetslist', $attrib['id']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1278 $this->rc->output->add_label('managesieve.setdeleteconfirm');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1279 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1280
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1281 return $out;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1282 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1283
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1284 function filter_frame($attrib)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1285 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1286 return $this->rc->output->frame($attrib, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1287 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1288
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1289 function filterset_editraw($attrib)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1290 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1291 $script_name = isset($_GET['_set']) ? $_GET['_set'] : $_POST['_set'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1292 $script = $this->sieve->get_script($script_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1293 $script_post = $_POST['rawsetcontent'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1294
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1295 $out = '<form name="filtersetrawform" action="./" method="post" enctype="multipart/form-data">'."\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1296
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1297 $hiddenfields = new html_hiddenfield();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1298 $hiddenfields->add(array('name' => '_task', 'value' => $this->rc->task));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1299 $hiddenfields->add(array('name' => '_action', 'value' => 'plugin.managesieve-saveraw'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1300 $hiddenfields->add(array('name' => '_set', 'value' => $script_name));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1301 $hiddenfields->add(array('name' => '_seteditraw', 'value' => 1));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1302 $hiddenfields->add(array('name' => '_framed', 'value' => ($_POST['_framed'] || $_GET['_framed'] ? 1 : 0)));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1303
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1304 $out .= $hiddenfields->show();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1305
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1306 $txtarea = new html_textarea(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1307 'id' => 'rawfiltersettxt',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1308 'name' => 'rawsetcontent',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1309 'rows' => '15'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1310 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1311
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1312 $out .= $txtarea->show($script_post !== null ? $script_post : ($script !== false ? rtrim($script) : ''));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1313
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1314 $this->rc->output->add_gui_object('sievesetrawform', 'filtersetrawform');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1315 $this->plugin->include_stylesheet('codemirror/lib/codemirror.css');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1316 $this->plugin->include_script('codemirror/lib/codemirror.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1317 $this->plugin->include_script('codemirror/addon/selection/active-line.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1318 $this->plugin->include_script('codemirror/mode/sieve/sieve.js');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1319
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1320 if ($script === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1321 $this->rc->output->show_message('managesieve.filterunknownerror', 'error');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1322 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1323
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1324 return $out;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1325 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1326
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1327 function filterset_form($attrib)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1328 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1329 if (!$attrib['id'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1330 $attrib['id'] = 'rcmfiltersetform';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1331
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1332 $out = '<form name="filtersetform" action="./" method="post" enctype="multipart/form-data">'."\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1333
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1334 $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $this->rc->task));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1335 $hiddenfields->add(array('name' => '_action', 'value' => 'plugin.managesieve-save'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1336 $hiddenfields->add(array('name' => '_framed', 'value' => ($_POST['_framed'] || $_GET['_framed'] ? 1 : 0)));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1337 $hiddenfields->add(array('name' => '_newset', 'value' => 1));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1338
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1339 $out .= $hiddenfields->show();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1340
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1341 $name = rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1342 $copy = rcube_utils::get_input_value('_copy', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1343 $selected = rcube_utils::get_input_value('_from', rcube_utils::INPUT_POST);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1344
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1345 // filter set name input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1346 $input_name = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1347 'class' => ($this->errors['name'] ? 'error' : '')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1348
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1349 $out .= sprintf('<label for="%s"><b>%s:</b></label> %s<br><br>',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1350 '_name', rcube::Q($this->plugin->gettext('filtersetname')), $input_name->show($name));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1351
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1352 $out .="\n<fieldset class=\"itemlist\"><legend>" . $this->plugin->gettext('filters') . ":</legend>\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1353 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1354 'type' => 'radio',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1355 'id' => 'from_none',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1356 'name' => '_from',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1357 'value' => 'none',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1358 'checked' => !$selected || $selected == 'none'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1359 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1360 $out .= html::label('from_none', rcube::Q($this->plugin->gettext('none')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1361
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1362 // filters set list
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1363 $list = $this->list_scripts();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1364 $select = new html_select(array('name' => '_copy', 'id' => '_copy'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1365
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1366 if (is_array($list)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1367 asort($list, SORT_LOCALE_STRING);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1368
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1369 if (!$copy)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1370 $copy = $_SESSION['managesieve_current'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1371
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1372 foreach ($list as $set) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1373 $select->add($set, $set);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1374 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1375
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1376 $out .= '<br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1377 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1378 'type' => 'radio',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1379 'id' => 'from_set',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1380 'name' => '_from',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1381 'value' => 'set',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1382 'checked' => $selected == 'set',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1383 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1384 $out .= html::label('from_set', rcube::Q($this->plugin->gettext('fromset')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1385 $out .= $select->show($copy);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1386 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1387
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1388 // script upload box
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1389 $upload = new html_inputfield(array('name' => '_file', 'id' => '_file', 'size' => 30,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1390 'type' => 'file', 'class' => ($this->errors['file'] ? 'error' : '')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1391
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1392 $out .= '<br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1393 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1394 'type' => 'radio',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1395 'id' => 'from_file',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1396 'name' => '_from',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1397 'value' => 'file',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1398 'checked' => $selected == 'file',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1399 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1400 $out .= html::label('from_file', rcube::Q($this->plugin->gettext('fromfile')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1401 $out .= $upload->show();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1402 $out .= '</fieldset>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1403
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1404 $this->rc->output->add_gui_object('sieveform', 'filtersetform');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1405
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1406 if ($this->errors['name'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1407 $this->add_tip('_name', $this->errors['name'], true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1408 if ($this->errors['file'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1409 $this->add_tip('_file', $this->errors['file'], true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1410
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1411 $this->print_tips();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1412
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1413 return $out;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1414 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1415
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1416
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1417 function filter_form($attrib)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1418 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1419 if (!$attrib['id'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1420 $attrib['id'] = 'rcmfilterform';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1421
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1422 $fid = rcube_utils::get_input_value('_fid', rcube_utils::INPUT_GPC);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1423 $scr = isset($this->form) ? $this->form : $this->script[$fid];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1424
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1425 $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $this->rc->task));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1426 $hiddenfields->add(array('name' => '_action', 'value' => 'plugin.managesieve-save'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1427 $hiddenfields->add(array('name' => '_framed', 'value' => ($_POST['_framed'] || $_GET['_framed'] ? 1 : 0)));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1428 $hiddenfields->add(array('name' => '_fid', 'value' => $fid));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1429
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1430 $out = '<form name="filterform" action="./" method="post">'."\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1431 $out .= $hiddenfields->show();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1432
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1433 // 'any' flag
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1434 if ((!isset($this->form) && empty($scr['tests']) && !empty($scr))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1435 || (count($scr['tests']) == 1 && $scr['tests'][0]['test'] == 'true' && !$scr['tests'][0]['not'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1436 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1437 $any = true;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1438 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1439
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1440 // filter name input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1441 $field_id = '_name';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1442 $input_name = new html_inputfield(array('name' => '_name', 'id' => $field_id, 'size' => 30,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1443 'class' => ($this->errors['name'] ? 'error' : '')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1444
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1445 if ($this->errors['name'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1446 $this->add_tip($field_id, $this->errors['name'], true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1447
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1448 if (isset($scr))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1449 $input_name = $input_name->show($scr['name']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1450 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1451 $input_name = $input_name->show();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1452
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1453 $out .= sprintf("\n<label for=\"%s\"><b>%s:</b></label> %s\n",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1454 $field_id, rcube::Q($this->plugin->gettext('filtername')), $input_name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1455
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1456 // filter set selector
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1457 if ($this->rc->task == 'mail') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1458 $out .= sprintf("\n&nbsp;<label for=\"%s\"><b>%s:</b></label> %s\n",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1459 $field_id, rcube::Q($this->plugin->gettext('filterset')),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1460 $this->filtersets_list(array('id' => 'sievescriptname'), true));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1461 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1462
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1463 $out .= '<br><br><fieldset><legend>' . rcube::Q($this->plugin->gettext('messagesrules')) . "</legend>\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1464
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1465 // any, allof, anyof radio buttons
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1466 $field_id = '_allof';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1467 $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'allof',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1468 'onclick' => 'rule_join_radio(\'allof\')', 'class' => 'radio'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1469
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1470 if (isset($scr) && !$any)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1471 $input_join = $input_join->show($scr['join'] ? 'allof' : '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1472 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1473 $input_join = $input_join->show();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1474
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1475 $out .= $input_join . html::label($field_id, rcube::Q($this->plugin->gettext('filterallof')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1476
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1477 $field_id = '_anyof';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1478 $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'anyof',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1479 'onclick' => 'rule_join_radio(\'anyof\')', 'class' => 'radio'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1480
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1481 if (isset($scr) && !$any)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1482 $input_join = $input_join->show($scr['join'] ? '' : 'anyof');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1483 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1484 $input_join = $input_join->show('anyof'); // default
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1485
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1486 $out .= $input_join . html::label($field_id, rcube::Q($this->plugin->gettext('filteranyof')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1487
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1488 $field_id = '_any';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1489 $input_join = new html_radiobutton(array('name' => '_join', 'id' => $field_id, 'value' => 'any',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1490 'onclick' => 'rule_join_radio(\'any\')', 'class' => 'radio'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1491
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1492 $input_join = $input_join->show($any ? 'any' : '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1493
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1494 $out .= $input_join . html::label($field_id, rcube::Q($this->plugin->gettext('filterany')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1495
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1496 $rows_num = !empty($scr['tests']) ? count($scr['tests']) : 1;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1497
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1498 $out .= '<div id="rules"'.($any ? ' style="display: none"' : '').'>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1499 for ($x=0; $x<$rows_num; $x++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1500 $out .= $this->rule_div($fid, $x);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1501 $out .= "</div>\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1502
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1503 $out .= "</fieldset>\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1504
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1505 // actions
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1506 $out .= '<fieldset><legend>' . rcube::Q($this->plugin->gettext('messagesactions')) . "</legend>\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1507
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1508 $rows_num = isset($scr) ? count($scr['actions']) : 1;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1509
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1510 $out .= '<div id="actions">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1511 for ($x=0; $x<$rows_num; $x++)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1512 $out .= $this->action_div($fid, $x);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1513 $out .= "</div>\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1514
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1515 $out .= "</fieldset>\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1516
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1517 $this->print_tips();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1518
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1519 if ($scr['disabled']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1520 $this->rc->output->set_env('rule_disabled', true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1521 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1522 $this->rc->output->add_label(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1523 'managesieve.ruledeleteconfirm',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1524 'managesieve.actiondeleteconfirm'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1525 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1526 $this->rc->output->add_gui_object('sieveform', 'filterform');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1527
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1528 return $out;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1529 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1530
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1531 function rule_div($fid, $id, $div=true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1532 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1533 $rule = isset($this->form) ? $this->form['tests'][$id] : $this->script[$fid]['tests'][$id];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1534 $rows_num = isset($this->form) ? count($this->form['tests']) : count($this->script[$fid]['tests']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1535
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1536 // headers select
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1537 $select_header = new html_select(array('name' => "_header[]", 'id' => 'header'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1538 'onchange' => 'rule_header_select(' .$id .')'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1539
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1540 foreach ($this->headers as $index => $header) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1541 $header = $this->rc->text_exists($index) ? $this->plugin->gettext($index) : $header;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1542 $select_header->add($header, $index);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1543 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1544 $select_header->add($this->plugin->gettext('...'), '...');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1545 if (in_array('body', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1546 $select_header->add($this->plugin->gettext('body'), 'body');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1547 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1548 $select_header->add($this->plugin->gettext('size'), 'size');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1549 if (in_array('date', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1550 $select_header->add($this->plugin->gettext('datetest'), 'date');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1551 $select_header->add($this->plugin->gettext('currdate'), 'currentdate');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1552 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1553 if (in_array('variables', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1554 $select_header->add($this->plugin->gettext('string'), 'string');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1555 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1556 if (in_array('duplicate', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1557 $select_header->add($this->plugin->gettext('message'), 'message');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1558 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1559
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1560 if (isset($rule['test'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1561 if (in_array($rule['test'], array('header', 'address', 'envelope'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1562 if (is_array($rule['arg1']) && count($rule['arg1']) == 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1563 $rule['arg1'] = $rule['arg1'][0];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1564 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1565
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1566 $matches = ($header = strtolower($rule['arg1'])) && isset($this->headers[$header]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1567 $test = $matches ? $header : '...';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1568 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1569 else if ($rule['test'] == 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1570 if (is_array($rule['arg']) && count($rule['arg']) == 1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1571 $rule['arg'] = $rule['arg'][0];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1572 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1573
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1574 $matches = ($header = strtolower($rule['arg'])) && isset($this->headers[$header]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1575 $test = $matches ? $header : '...';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1576 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1577 else if (in_array($rule['test'], array('size', 'body', 'date', 'currentdate', 'string'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1578 $test = $rule['test'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1579 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1580 else if (in_array($rule['test'], array('duplicate'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1581 $test = 'message';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1582 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1583 else if ($rule['test'] != 'true') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1584 $test = '...';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1585 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1586 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1587
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1588 $aout = $select_header->show($test);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1589
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1590 // custom headers input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1591 if (isset($rule['test']) && in_array($rule['test'], array('header', 'address', 'envelope'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1592 $custom = (array) $rule['arg1'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1593 if (count($custom) == 1 && isset($this->headers[strtolower($custom[0])])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1594 unset($custom);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1595 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1596 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1597 else if (isset($rule['test']) && $rule['test'] == 'string') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1598 $customv = (array) $rule['arg1'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1599 if (count($customv) == 1 && isset($this->headers[strtolower($customv[0])])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1600 unset($customv);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1601 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1602 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1603 else if (isset($rule['test']) && $rule['test'] == 'exists') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1604 $custom = (array) $rule['arg'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1605 if (count($custom) == 1 && isset($this->headers[strtolower($custom[0])])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1606 unset($custom);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1607 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1608 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1609
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1610 // custom variable input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1611 $tout = $this->list_input($id, 'custom_header', $custom, isset($custom),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1612 $this->error_class($id, 'test', 'header', 'custom_header'), 15) . "\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1613
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1614 $tout .= $this->list_input($id, 'custom_var', $customv, isset($customv),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1615 $this->error_class($id, 'test', 'header', 'custom_var'), 15) . "\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1616
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1617 // matching type select (operator)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1618 $select_op = new html_select(array('name' => "_rule_op[]", 'id' => 'rule_op'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1619 'style' => 'display:' .(!in_array($rule['test'], array('size', 'duplicate')) ? 'inline' : 'none'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1620 'class' => 'operator_selector',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1621 'onchange' => 'rule_op_select(this, '.$id.')'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1622 $select_op->add(rcube::Q($this->plugin->gettext('filtercontains')), 'contains');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1623 $select_op->add(rcube::Q($this->plugin->gettext('filternotcontains')), 'notcontains');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1624 $select_op->add(rcube::Q($this->plugin->gettext('filteris')), 'is');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1625 $select_op->add(rcube::Q($this->plugin->gettext('filterisnot')), 'notis');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1626 $select_op->add(rcube::Q($this->plugin->gettext('filterexists')), 'exists');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1627 $select_op->add(rcube::Q($this->plugin->gettext('filternotexists')), 'notexists');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1628 $select_op->add(rcube::Q($this->plugin->gettext('filtermatches')), 'matches');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1629 $select_op->add(rcube::Q($this->plugin->gettext('filternotmatches')), 'notmatches');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1630 if (in_array('regex', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1631 $select_op->add(rcube::Q($this->plugin->gettext('filterregex')), 'regex');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1632 $select_op->add(rcube::Q($this->plugin->gettext('filternotregex')), 'notregex');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1633 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1634 if (in_array('relational', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1635 $select_op->add(rcube::Q($this->plugin->gettext('countisgreaterthan')), 'count-gt');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1636 $select_op->add(rcube::Q($this->plugin->gettext('countisgreaterthanequal')), 'count-ge');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1637 $select_op->add(rcube::Q($this->plugin->gettext('countislessthan')), 'count-lt');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1638 $select_op->add(rcube::Q($this->plugin->gettext('countislessthanequal')), 'count-le');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1639 $select_op->add(rcube::Q($this->plugin->gettext('countequals')), 'count-eq');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1640 $select_op->add(rcube::Q($this->plugin->gettext('countnotequals')), 'count-ne');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1641 $select_op->add(rcube::Q($this->plugin->gettext('valueisgreaterthan')), 'value-gt');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1642 $select_op->add(rcube::Q($this->plugin->gettext('valueisgreaterthanequal')), 'value-ge');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1643 $select_op->add(rcube::Q($this->plugin->gettext('valueislessthan')), 'value-lt');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1644 $select_op->add(rcube::Q($this->plugin->gettext('valueislessthanequal')), 'value-le');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1645 $select_op->add(rcube::Q($this->plugin->gettext('valueequals')), 'value-eq');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1646 $select_op->add(rcube::Q($this->plugin->gettext('valuenotequals')), 'value-ne');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1647 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1648
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1649 $test = self::rule_test($rule);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1650 $target = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1651
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1652 // target(s) input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1653 if (in_array($rule['test'], array('header', 'address', 'envelope','string'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1654 $target = $rule['arg2'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1655 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1656 else if (in_array($rule['test'], array('body', 'date', 'currentdate'))) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1657 $target = $rule['arg'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1658 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1659 else if ($rule['test'] == 'size') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1660 if (preg_match('/^([0-9]+)(K|M|G)?$/', $rule['arg'], $matches)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1661 $sizetarget = $matches[1];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1662 $sizeitem = $matches[2];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1663 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1664 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1665 $sizetarget = $rule['arg'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1666 $sizeitem = $rule['item'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1667 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1668 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1669
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1670 // (current)date part select
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1671 if (in_array('date', $this->exts) || in_array('currentdate', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1672 $date_parts = array('date', 'iso8601', 'std11', 'julian', 'time',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1673 'year', 'month', 'day', 'hour', 'minute', 'second', 'weekday', 'zone');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1674 $select_dp = new html_select(array('name' => "_rule_date_part[]", 'id' => 'rule_date_part'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1675 'style' => in_array($rule['test'], array('currentdate', 'date')) && !preg_match('/^(notcount|count)-/', $test) ? '' : 'display:none',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1676 'class' => 'datepart_selector',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1677 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1678
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1679 foreach ($date_parts as $part) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1680 $select_dp->add(rcube::Q($this->plugin->gettext($part)), $part);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1681 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1682
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1683 $tout .= $select_dp->show($rule['test'] == 'currentdate' || $rule['test'] == 'date' ? $rule['part'] : '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1684 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1685
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1686 // message test select (e.g. duplicate)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1687 if (in_array('duplicate', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1688 $select_msg = new html_select(array('name' => "_rule_message[]", 'id' => 'rule_message'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1689 'style' => in_array($rule['test'], array('duplicate')) ? '' : 'display:none',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1690 'class' => 'message_selector',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1691 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1692
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1693 $select_msg->add(rcube::Q($this->plugin->gettext('duplicate')), 'duplicate');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1694 $select_msg->add(rcube::Q($this->plugin->gettext('notduplicate')), 'notduplicate');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1695
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1696 $tout .= $select_msg->show($test);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1697 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1698
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1699 $tout .= $select_op->show($test);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1700 $tout .= $this->list_input($id, 'rule_target', $target,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1701 $rule['test'] != 'size' && $rule['test'] != 'exists' && $rule['test'] != 'duplicate',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1702 $this->error_class($id, 'test', 'target', 'rule_target')) . "\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1703
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1704 $select_size_op = new html_select(array('name' => "_rule_size_op[]", 'id' => 'rule_size_op'.$id));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1705 $select_size_op->add(rcube::Q($this->plugin->gettext('filterover')), 'over');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1706 $select_size_op->add(rcube::Q($this->plugin->gettext('filterunder')), 'under');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1707
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1708 $tout .= '<div id="rule_size' .$id. '" style="display:' . ($rule['test']=='size' ? 'inline' : 'none') .'">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1709 $tout .= $select_size_op->show($rule['test']=='size' ? $rule['type'] : '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1710 $tout .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1711 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1712 'name' => '_rule_size_target[]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1713 'id' => 'rule_size_i'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1714 'value' => $sizetarget,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1715 'size' => 10,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1716 'class' => $this->error_class($id, 'test', 'sizetarget', 'rule_size_i'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1717 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1718 foreach (array('', 'K', 'M', 'G') as $unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1719 $tout .= html::label(null, html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1720 'type' => 'radio',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1721 'name' => '_rule_size_item['.$id.']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1722 'value' => $unit,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1723 'checked' => $sizeitem == $unit,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1724 'class' => 'radio',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1725 )) . $this->rc->gettext($unit . 'B'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1726 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1727 $tout .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1728
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1729 // Advanced modifiers (address, envelope)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1730 $select_mod = new html_select(array('name' => "_rule_mod[]", 'id' => 'rule_mod_op'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1731 'onchange' => 'rule_mod_select(' .$id .')'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1732 $select_mod->add(rcube::Q($this->plugin->gettext('none')), '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1733 $select_mod->add(rcube::Q($this->plugin->gettext('address')), 'address');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1734 if (in_array('envelope', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1735 $select_mod->add(rcube::Q($this->plugin->gettext('envelope')), 'envelope');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1736 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1737
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1738 $select_type = new html_select(array('name' => "_rule_mod_type[]", 'id' => 'rule_mod_type'.$id));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1739 $select_type->add(rcube::Q($this->plugin->gettext('allparts')), 'all');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1740 $select_type->add(rcube::Q($this->plugin->gettext('domain')), 'domain');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1741 $select_type->add(rcube::Q($this->plugin->gettext('localpart')), 'localpart');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1742 if (in_array('subaddress', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1743 $select_type->add(rcube::Q($this->plugin->gettext('user')), 'user');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1744 $select_type->add(rcube::Q($this->plugin->gettext('detail')), 'detail');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1745 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1746
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1747 $need_mod = !in_array($rule['test'], array('size', 'body', 'date', 'currentdate', 'duplicate', 'string'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1748 $mout = '<div id="rule_mod' .$id. '" class="adv"' . (!$need_mod ? ' style="display:none"' : '') . '>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1749 $mout .= ' <span class="label">' . rcube::Q($this->plugin->gettext('modifier')) . ' </span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1750 $mout .= $select_mod->show($rule['test']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1751 $mout .= ' <span id="rule_mod_type' . $id . '"';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1752 $mout .= ' style="display:' . (in_array($rule['test'], array('address', 'envelope')) ? 'inline' : 'none') .'">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1753 $mout .= rcube::Q($this->plugin->gettext('modtype')) . ' ';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1754 $mout .= $select_type->show($rule['part']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1755 $mout .= '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1756 $mout .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1757
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1758 // Advanced modifiers (body transformations)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1759 $select_mod = new html_select(array('name' => "_rule_trans[]", 'id' => 'rule_trans_op'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1760 'onchange' => 'rule_trans_select(' .$id .')'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1761 $select_mod->add(rcube::Q($this->plugin->gettext('text')), 'text');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1762 $select_mod->add(rcube::Q($this->plugin->gettext('undecoded')), 'raw');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1763 $select_mod->add(rcube::Q($this->plugin->gettext('contenttype')), 'content');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1764
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1765 $mout .= '<div id="rule_trans' .$id. '" class="adv"' . ($rule['test'] != 'body' ? ' style="display:none"' : '') . '>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1766 $mout .= '<span class="label">' . rcube::Q($this->plugin->gettext('modifier')) . '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1767 $mout .= $select_mod->show($rule['part']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1768 $mout .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1769 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1770 'name' => '_rule_trans_type[]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1771 'id' => 'rule_trans_type'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1772 'value' => is_array($rule['content']) ? implode(',', $rule['content']) : $rule['content'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1773 'size' => 20,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1774 'style' => $rule['part'] != 'content' ? 'display:none' : '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1775 'class' => $this->error_class($id, 'test', 'part', 'rule_trans_type'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1776 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1777 $mout .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1778
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1779 // Advanced modifiers (body transformations)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1780 $select_comp = new html_select(array('name' => "_rule_comp[]", 'id' => 'rule_comp_op'.$id));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1781 $select_comp->add(rcube::Q($this->plugin->gettext('default')), '');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1782 $select_comp->add(rcube::Q($this->plugin->gettext('octet')), 'i;octet');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1783 $select_comp->add(rcube::Q($this->plugin->gettext('asciicasemap')), 'i;ascii-casemap');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1784 if (in_array('comparator-i;ascii-numeric', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1785 $select_comp->add(rcube::Q($this->plugin->gettext('asciinumeric')), 'i;ascii-numeric');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1786 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1787
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1788 // Comparators
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1789 $need_comp = $rule['test'] != 'size' && $rule['test'] != 'duplicate';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1790 $mout .= '<div id="rule_comp' .$id. '" class="adv"' . (!$need_comp ? ' style="display:none"' : '') . '>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1791 $mout .= '<span class="label">' . rcube::Q($this->plugin->gettext('comparator')) . '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1792 $mout .= $select_comp->show($rule['comparator']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1793 $mout .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1794
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1795 // Date header
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1796 if (in_array('date', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1797 $mout .= '<div id="rule_date_header_div' .$id. '" class="adv"'. ($rule['test'] != 'date' ? ' style="display:none"' : '') .'>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1798 $mout .= '<span class="label">' . rcube::Q($this->plugin->gettext('dateheader')) . '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1799 $mout .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1800 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1801 'name' => '_rule_date_header[]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1802 'id' => 'rule_date_header' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1803 'value' => $rule['test'] == 'date' ? $rule['header'] : '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1804 'size' => 15,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1805 'class' => $this->error_class($id, 'test', 'dateheader', 'rule_date_header'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1806 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1807 $mout .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1808 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1809
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1810 // Index
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1811 if (in_array('index', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1812 $need_index = in_array($rule['test'], array('header', ', address', 'date'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1813 $mout .= '<div id="rule_index_div' .$id. '" class="adv"'. (!$need_index ? ' style="display:none"' : '') .'>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1814 $mout .= '<span class="label">' . rcube::Q($this->plugin->gettext('index')) . '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1815 $mout .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1816 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1817 'name' => '_rule_index[]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1818 'id' => 'rule_index' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1819 'value' => $rule['index'] ? intval($rule['index']) : '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1820 'size' => 3,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1821 'class' => $this->error_class($id, 'test', 'index', 'rule_index'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1822 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1823 $mout .= '&nbsp;' . html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1824 'type' => 'checkbox',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1825 'name' => '_rule_index_last[]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1826 'id' => 'rule_index_last' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1827 'value' => 1,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1828 'checked' => !empty($rule['last']),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1829 ))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1830 . html::label('rule_index_last' . $id, rcube::Q($this->plugin->gettext('indexlast')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1831 $mout .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1832 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1833
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1834 // Duplicate
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1835 if (in_array('duplicate', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1836 $need_duplicate = $rule['test'] == 'duplicate';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1837 $mout .= '<div id="rule_duplicate_div' .$id. '" class="adv"'. (!$need_duplicate ? ' style="display:none"' : '') .'>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1838
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1839 foreach (array('handle', 'header', 'uniqueid') as $unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1840 $mout .= '<span class="label">' . rcube::Q($this->plugin->gettext('duplicate.handle')) . '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1841 $mout .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1842 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1843 'name' => '_rule_duplicate_' . $unit . '[]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1844 'id' => 'rule_duplicate_' . $unit . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1845 'value' => $rule[$unit],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1846 'size' => 30,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1847 'class' => $this->error_class($id, 'test', 'duplicate_' . $unit, 'rule_duplicate_' . $unit),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1848 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1849 $mout .= '<br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1850 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1851
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1852 $mout .= '<span class="label">' . rcube::Q($this->plugin->gettext('duplicate.seconds')) . '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1853 $mout .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1854 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1855 'name' => '_rule_duplicate_seconds[]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1856 'id' => 'rule_duplicate_seconds' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1857 'value' => $rule['seconds'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1858 'size' => 6,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1859 'class' => $this->error_class($id, 'test', 'duplicate_seconds', 'rule_duplicate_seconds'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1860 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1861 $mout .= '&nbsp;' . html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1862 'type' => 'checkbox',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1863 'name' => '_rule_duplicate_last[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1864 'id' => 'rule_duplicate_last' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1865 'value' => 1,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1866 'checked' => !empty($rule['last']),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1867 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1868 $mout .= html::label('rule_duplicate_last' . $id, rcube::Q($this->plugin->gettext('duplicate.last')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1869 $mout .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1870 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1871
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1872 // Build output table
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1873 $out = $div ? '<div class="rulerow" id="rulerow' .$id .'">'."\n" : '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1874 $out .= '<table><tr>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1875 $out .= '<td class="advbutton">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1876 $out .= '<a href="#" id="ruleadv' . $id .'" title="'. rcube::Q($this->plugin->gettext('advancedopts')). '"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1877 onclick="rule_adv_switch(' . $id .', this)" class="show">&nbsp;&nbsp;</a>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1878 $out .= '</td>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1879 $out .= '<td class="rowactions">' . $aout . '</td>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1880 $out .= '<td class="rowtargets">' . $tout . "\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1881 $out .= '<div id="rule_advanced' .$id. '" style="display:none">' . $mout . '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1882 $out .= '</td>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1883
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1884 // add/del buttons
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1885 $out .= '<td class="rowbuttons">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1886 $out .= '<a href="#" id="ruleadd' . $id .'" title="'. rcube::Q($this->plugin->gettext('add')). '"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1887 onclick="rcmail.managesieve_ruleadd(' . $id .')" class="button add"></a>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1888 $out .= '<a href="#" id="ruledel' . $id .'" title="'. rcube::Q($this->plugin->gettext('del')). '"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1889 onclick="rcmail.managesieve_ruledel(' . $id .')" class="button del' . ($rows_num<2 ? ' disabled' : '') .'"></a>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1890 $out .= '</td>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1891 $out .= '</tr></table>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1892
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1893 $out .= $div ? "</div>\n" : '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1894
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1895 return $out;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1896 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1897
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1898 private static function rule_test(&$rule)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1899 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1900 // first modify value/count tests with 'not' keyword
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1901 // we'll revert the meaning of operators
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1902 if ($rule['not'] && preg_match('/^(count|value)-([gteqnl]{2})/', $rule['type'], $m)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1903 $rule['not'] = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1904
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1905 switch ($m[2]) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1906 case 'gt': $rule['type'] = $m[1] . '-le'; break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1907 case 'ge': $rule['type'] = $m[1] . '-lt'; break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1908 case 'lt': $rule['type'] = $m[1] . '-ge'; break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1909 case 'le': $rule['type'] = $m[1] . '-gt'; break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1910 case 'eq': $rule['type'] = $m[1] . '-ne'; break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1911 case 'ne': $rule['type'] = $m[1] . '-eq'; break;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1912 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1913 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1914 else if ($rule['not'] && $rule['test'] == 'size') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1915 $rule['not'] = false;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1916 $rule['type'] = $rule['type'] == 'over' ? 'under' : 'over';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1917 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1918
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1919 $set = array('header', 'address', 'envelope', 'body', 'date', 'currentdate', 'string');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1920
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1921 // build test string supported by select element
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1922 if ($rule['size']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1923 $test = $rule['type'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1924 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1925 else if (in_array($rule['test'], $set)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1926 $test = ($rule['not'] ? 'not' : '') . ($rule['type'] ?: 'is');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1927 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1928 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1929 $test = ($rule['not'] ? 'not' : '') . $rule['test'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1930 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1931
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1932 return $test;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1933 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1934
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1935 function action_div($fid, $id, $div=true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1936 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1937 $action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1938 $rows_num = isset($this->form) ? count($this->form['actions']) : count($this->script[$fid]['actions']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1939
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1940 $out = $div ? '<div class="actionrow" id="actionrow' .$id .'">'."\n" : '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1941
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1942 $out .= '<table><tr><td class="rowactions">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1943
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1944 // action select
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1945 $select_action = new html_select(array('name' => "_action_type[$id]", 'id' => 'action_type'.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1946 'onchange' => 'action_type_select(' .$id .')'));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1947 if (in_array('fileinto', $this->exts))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1948 $select_action->add(rcube::Q($this->plugin->gettext('messagemoveto')), 'fileinto');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1949 if (in_array('fileinto', $this->exts) && in_array('copy', $this->exts))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1950 $select_action->add(rcube::Q($this->plugin->gettext('messagecopyto')), 'fileinto_copy');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1951 $select_action->add(rcube::Q($this->plugin->gettext('messageredirect')), 'redirect');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1952 if (in_array('copy', $this->exts))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1953 $select_action->add(rcube::Q($this->plugin->gettext('messagesendcopy')), 'redirect_copy');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1954 if (in_array('reject', $this->exts))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1955 $select_action->add(rcube::Q($this->plugin->gettext('messagediscard')), 'reject');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1956 else if (in_array('ereject', $this->exts))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1957 $select_action->add(rcube::Q($this->plugin->gettext('messagediscard')), 'ereject');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1958 if (in_array('vacation', $this->exts))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1959 $select_action->add(rcube::Q($this->plugin->gettext('messagereply')), 'vacation');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1960 $select_action->add(rcube::Q($this->plugin->gettext('messagedelete')), 'discard');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1961 if (in_array('imapflags', $this->exts) || in_array('imap4flags', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1962 $select_action->add(rcube::Q($this->plugin->gettext('setflags')), 'setflag');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1963 $select_action->add(rcube::Q($this->plugin->gettext('addflags')), 'addflag');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1964 $select_action->add(rcube::Q($this->plugin->gettext('removeflags')), 'removeflag');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1965 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1966 if (in_array('variables', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1967 $select_action->add(rcube::Q($this->plugin->gettext('setvariable')), 'set');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1968 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1969 if (in_array('enotify', $this->exts) || in_array('notify', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1970 $select_action->add(rcube::Q($this->plugin->gettext('notify')), 'notify');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1971 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1972 $select_action->add(rcube::Q($this->plugin->gettext('messagekeep')), 'keep');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1973 $select_action->add(rcube::Q($this->plugin->gettext('rulestop')), 'stop');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1974
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1975 $select_type = $action['type'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1976 if (in_array($action['type'], array('fileinto', 'redirect')) && $action['copy']) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1977 $select_type .= '_copy';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1978 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1979
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1980 $out .= $select_action->show($select_type);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1981 $out .= '</td>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1982
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1983 // actions target inputs
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1984 $out .= '<td class="rowtargets">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1985
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1986 // force domain selection in redirect email input
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1987 $domains = (array) $this->rc->config->get('managesieve_domains');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1988 if (!empty($domains)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1989 sort($domains);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1990
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1991 $domain_select = new html_select(array('name' => "_action_target_domain[$id]", 'id' => 'action_target_domain'.$id));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1992 $domain_select->add(array_combine($domains, $domains));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1993
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1994 if ($action['type'] == 'redirect') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1995 $parts = explode('@', $action['target']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1996 if (!empty($parts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1997 $action['domain'] = array_pop($parts);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1998 $action['target'] = implode('@', $parts);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
1999 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2000 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2001 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2002
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2003 // redirect target
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2004 $out .= '<span id="redirect_target' . $id . '" style="white-space:nowrap;'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2005 . ' display:' . ($action['type'] == 'redirect' ? 'inline' : 'none') . '">'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2006 . html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2007 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2008 'name' => '_action_target[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2009 'id' => 'action_target' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2010 'value' => $action['type'] == 'redirect' ? $action['target'] : '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2011 'size' => !empty($domains) ? 20 : 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2012 'class' => $this->error_class($id, 'action', 'target', 'action_target'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2013 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2014 $out .= !empty($domains) ? ' @ ' . $domain_select->show($action['domain']) : '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2015 $out .= '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2016
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2017 // (e)reject target
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2018 $out .= html::tag('textarea', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2019 'name' => '_action_target_area[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2020 'id' => 'action_target_area' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2021 'rows' => 3,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2022 'cols' => 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2023 'class' => $this->error_class($id, 'action', 'targetarea', 'action_target_area'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2024 'style' => 'display:' . (in_array($action['type'], array('reject', 'ereject')) ? 'inline' : 'none'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2025 ), (in_array($action['type'], array('reject', 'ereject')) ? rcube::Q($action['target'], 'strict', false) : ''));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2026
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2027 // vacation
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2028 $vsec = in_array('vacation-seconds', $this->exts);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2029 $auto_addr = $this->rc->config->get('managesieve_vacation_addresses_init');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2030 $from_addr = $this->rc->config->get('managesieve_vacation_from_init');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2031
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2032 if (empty($action)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2033 if ($auto_addr) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2034 $action['addresses'] = $this->user_emails();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2035 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2036 if ($from_addr) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2037 $default_identity = $this->rc->user->list_emails(true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2038 $action['from'] = $default_identity['email'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2039 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2040 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2041
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2042 $out .= '<div id="action_vacation' .$id.'" style="display:' .($action['type']=='vacation' ? 'inline' : 'none') .'">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2043 $out .= '<span class="label">'. rcube::Q($this->plugin->gettext('vacationreason')) .'</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2044 $out .= html::tag('textarea', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2045 'name' => '_action_reason[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2046 'id' => 'action_reason' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2047 'rows' => 3,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2048 'cols' => 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2049 'class' => $this->error_class($id, 'action', 'reason', 'action_reason'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2050 ), rcube::Q($action['reason'], 'strict', false));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2051 $out .= '<br><span class="label">' .rcube::Q($this->plugin->gettext('vacationsubject')) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2052 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2053 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2054 'name' => '_action_subject[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2055 'id' => 'action_subject' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2056 'value' => is_array($action['subject']) ? implode(', ', $action['subject']) : $action['subject'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2057 'size' => 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2058 'class' => $this->error_class($id, 'action', 'subject', 'action_subject'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2059 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2060 $out .= '<br><span class="label">' .rcube::Q($this->plugin->gettext('vacationfrom')) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2061 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2062 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2063 'name' => '_action_from[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2064 'id' => 'action_from' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2065 'value' => $action['from'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2066 'size' => 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2067 'class' => $this->error_class($id, 'action', 'from', 'action_from'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2068 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2069 $out .= '<br><span class="label">' .rcube::Q($this->plugin->gettext('vacationaddr')) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2070 $out .= $this->list_input($id, 'action_addresses', $action['addresses'], true,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2071 $this->error_class($id, 'action', 'addresses', 'action_addresses'), 30)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2072 . html::a(array('href' => '#', 'onclick' => rcmail_output::JS_OBJECT_NAME . ".managesieve_vacation_addresses($id)"),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2073 rcube::Q($this->plugin->gettext('filladdresses')));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2074 $out .= '<br><span class="label">' . rcube::Q($this->plugin->gettext($vsec ? 'vacationinterval' : 'vacationdays')) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2075 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2076 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2077 'name' => '_action_interval[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2078 'id' => 'action_interval' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2079 'value' => rcube_sieve_vacation::vacation_interval($action),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2080 'size' => 2,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2081 'class' => $this->error_class($id, 'action', 'interval', 'action_interval'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2082 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2083 if ($vsec) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2084 foreach (array('days', 'seconds') as $unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2085 $out .= '&nbsp;' . html::label(null, html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2086 'type' => 'radio',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2087 'name' => '_action_interval_type[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2088 'value' => $unit,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2089 'checked' => ($unit == 'seconds' && isset($action['seconds'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2090 || $unit == 'deys' && !isset($action['seconds'])),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2091 'class' => 'radio',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2092 )) . $this->plugin->gettext($unit));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2093 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2094 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2095 $out .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2096
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2097 // flags
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2098 $flags = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2099 'read' => '\\Seen',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2100 'answered' => '\\Answered',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2101 'flagged' => '\\Flagged',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2102 'deleted' => '\\Deleted',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2103 'draft' => '\\Draft',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2104 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2105 $flags_target = (array)$action['target'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2106
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2107 $flout = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2108 foreach ($flags as $fidx => $flag) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2109 $flout .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2110 'type' => 'checkbox',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2111 'name' => '_action_flags[' .$id .'][]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2112 'value' => $flag,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2113 'checked' => in_array_nocase($flag, $flags_target),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2114 ))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2115 . rcube::Q($this->plugin->gettext('flag'.$fidx)) .'<br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2116 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2117 $out .= html::div(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2118 'id' => 'action_flags' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2119 'style' => 'display:' . (preg_match('/^(set|add|remove)flag$/', $action['type']) ? 'inline' : 'none'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2120 'class' => $this->error_class($id, 'action', 'flags', 'action_flags'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2121 ), $flout);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2122
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2123 // set variable
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2124 $set_modifiers = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2125 'lower',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2126 'upper',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2127 'lowerfirst',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2128 'upperfirst',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2129 'quotewildcard',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2130 'length'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2131 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2132
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2133 $out .= '<div id="action_set' .$id.'" style="display:' .($action['type']=='set' ? 'inline' : 'none') .'">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2134 foreach (array('name', 'value') as $unit) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2135 $out .= '<span class="label">' .rcube::Q($this->plugin->gettext('setvar' . $unit)) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2136 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2137 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2138 'name' => '_action_var' . $unit . '[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2139 'id' => 'action_var' . $unit . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2140 'value' => $action[$unit],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2141 'size' => 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2142 'class' => $this->error_class($id, 'action', $unit, 'action_var' . $unit),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2143 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2144 $out .= '<br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2145 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2146 $out .= '<span class="label">' .rcube::Q($this->plugin->gettext('setvarmodifiers')) . '</span>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2147 foreach ($set_modifiers as $s_m) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2148 $s_m_id = 'action_varmods' . $id . $s_m;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2149 $out .= '<br>' . html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2150 'type' => 'checkbox',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2151 'name' => '_action_varmods[' . $id . '][]',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2152 'value' => $s_m,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2153 'id' => $s_m_id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2154 'checked' => array_key_exists($s_m, (array)$action) && $action[$s_m],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2155 ))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2156 .rcube::Q($this->plugin->gettext('var' . $s_m));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2157 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2158 $out .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2159
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2160 // notify
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2161 $notify_methods = (array) $this->rc->config->get('managesieve_notify_methods');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2162 $importance_options = $this->notify_importance_options;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2163
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2164 if (empty($notify_methods)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2165 $notify_methods = $this->notify_methods;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2166 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2167
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2168 list($method, $target) = explode(':', $action['method'], 2);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2169 $method = strtolower($method);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2170
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2171 if ($method && !in_array($method, $notify_methods)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2172 $notify_methods[] = $method;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2173 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2174
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2175 $select_method = new html_select(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2176 'name' => "_action_notifymethod[$id]",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2177 'id' => "_action_notifymethod$id",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2178 'class' => $this->error_class($id, 'action', 'method', 'action_notifymethod'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2179 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2180 foreach ($notify_methods as $m_n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2181 $select_method->add(rcube::Q($this->rc->text_exists('managesieve.notifymethod'.$m_n) ? $this->plugin->gettext('managesieve.notifymethod'.$m_n) : $m_n), $m_n);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2182 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2183
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2184 $select_importance = new html_select(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2185 'name' => "_action_notifyimportance[$id]",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2186 'id' => "_action_notifyimportance$id",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2187 'class' => $this->error_class($id, 'action', 'importance', 'action_notifyimportance')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2188 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2189 foreach ($importance_options as $io_v => $io_n) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2190 $select_importance->add(rcube::Q($this->plugin->gettext($io_n)), $io_v);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2191 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2192
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2193 // @TODO: nice UI for mailto: (other methods too) URI parameters
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2194 $out .= '<div id="action_notify' .$id.'" style="display:' .($action['type'] == 'notify' ? 'inline' : 'none') .'">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2195 $out .= '<span class="label">' .rcube::Q($this->plugin->gettext('notifytarget')) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2196 $out .= $select_method->show($method);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2197 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2198 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2199 'name' => '_action_notifytarget[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2200 'id' => 'action_notifytarget' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2201 'value' => $target,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2202 'size' => 25,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2203 'class' => $this->error_class($id, 'action', 'target', 'action_notifytarget'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2204 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2205 $out .= '<br><span class="label">'. rcube::Q($this->plugin->gettext('notifymessage')) .'</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2206 $out .= html::tag('textarea', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2207 'name' => '_action_notifymessage[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2208 'id' => 'action_notifymessage' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2209 'rows' => 3,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2210 'cols' => 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2211 'class' => $this->error_class($id, 'action', 'message', 'action_notifymessage'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2212 ), rcube::Q($action['message'], 'strict', false));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2213 if (in_array('enotify', $this->exts)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2214 $out .= '<br><span class="label">' .rcube::Q($this->plugin->gettext('notifyfrom')) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2215 $out .= html::tag('input', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2216 'type' => 'text',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2217 'name' => '_action_notifyfrom[' . $id . ']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2218 'id' => 'action_notifyfrom' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2219 'value' => $action['from'],
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2220 'size' => 35,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2221 'class' => $this->error_class($id, 'action', 'from', 'action_notifyfrom'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2222 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2223 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2224 $out .= '<br><span class="label">' . rcube::Q($this->plugin->gettext('notifyimportance')) . '</span><br>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2225 $out .= $select_importance->show($action['importance'] ? (int) $action['importance'] : 2);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2226 $out .= '<div id="action_notifyoption_div' . $id . '">'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2227 .'<span class="label">' . rcube::Q($this->plugin->gettext('notifyoptions')) . '</span><br>'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2228 .$this->list_input($id, 'action_notifyoption', (array)$action['options'], true,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2229 $this->error_class($id, 'action', 'options', 'action_notifyoption'), 30) . '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2230 $out .= '</div>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2231
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2232 // mailbox select
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2233 if ($action['type'] == 'fileinto') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2234 $mailbox = $this->mod_mailbox($action['target'], 'out');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2235 // make sure non-existing (or unsubscribed) mailbox is listed (#1489956)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2236 $additional = array($mailbox);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2237 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2238 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2239 $mailbox = '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2240 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2241
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2242 $select = $this->rc->folder_selector(array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2243 'realnames' => false,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2244 'maxlength' => 100,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2245 'id' => 'action_mailbox' . $id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2246 'name' => "_action_mailbox[$id]",
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2247 'style' => 'display:'.(empty($action['type']) || $action['type'] == 'fileinto' ? 'inline' : 'none'),
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2248 'additional' => $additional,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2249 ));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2250 $out .= $select->show($mailbox);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2251 $out .= '</td>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2252
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2253 // add/del buttons
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2254 $out .= '<td class="rowbuttons">';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2255 $out .= '<a href="#" id="actionadd' . $id .'" title="'. rcube::Q($this->plugin->gettext('add')). '"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2256 onclick="rcmail.managesieve_actionadd(' . $id .')" class="button add"></a>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2257 $out .= '<a href="#" id="actiondel' . $id .'" title="'. rcube::Q($this->plugin->gettext('del')). '"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2258 onclick="rcmail.managesieve_actiondel(' . $id .')" class="button del' . ($rows_num<2 ? ' disabled' : '') .'"></a>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2259 $out .= '</td>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2260
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2261 $out .= '</tr></table>';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2262
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2263 $out .= $div ? "</div>\n" : '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2264
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2265 return $out;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2266 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2267
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2268 protected function genid()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2269 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2270 return preg_replace('/[^0-9]/', '', microtime(true));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2271 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2272
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2273 protected function strip_value($str, $allow_html = false, $trim = true)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2274 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2275 if (is_array($str)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2276 foreach ($str as $idx => $val) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2277 $val = $this->strip_value($val, $allow_html, $trim);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2278
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2279 if ($val === '') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2280 unset($str[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2281 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2282 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2283
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2284 return $str;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2285 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2286
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2287 if (!$allow_html) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2288 $str = strip_tags($str);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2289 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2290
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2291 return $trim ? trim($str) : $str;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2292 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2293
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2294 protected function error_class($id, $type, $target, $elem_prefix='')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2295 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2296 // TODO: tooltips
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2297 if (($type == 'test' && ($str = $this->errors['tests'][$id][$target])) ||
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2298 ($type == 'action' && ($str = $this->errors['actions'][$id][$target]))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2299 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2300 $this->add_tip($elem_prefix.$id, $str, true);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2301 return 'error';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2302 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2303
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2304 return '';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2305 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2306
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2307 protected function add_tip($id, $str, $error=false)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2308 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2309 if ($error) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2310 $str = html::span('sieve error', $str);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2311 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2312
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2313 $this->tips[] = array($id, $str);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2314 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2315
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2316 protected function print_tips()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2317 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2318 if (empty($this->tips)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2319 return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2320 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2321
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2322 $script = rcmail_output::JS_OBJECT_NAME.'.managesieve_tip_register('.json_encode($this->tips).');';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2323 $this->rc->output->add_script($script, 'foot');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2324 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2325
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2326 protected function list_input($id, $name, $value, $enabled, $class, $size=null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2327 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2328 $value = (array) $value;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2329 $value = array_map(array('rcube', 'Q'), $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2330 $value = implode("\n", $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2331
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2332 return html::tag('textarea', array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2333 'data-type' => 'list',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2334 'data-size' => $size,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2335 'name' => '_' . $name . '['. $id .']',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2336 'id' => $name.$id,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2337 'disabled' => !$enabled,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2338 'class' => $class,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2339 'style' => 'display:none',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2340 ), $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2341 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2342
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2343 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2344 * Validate input for date part elements
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2345 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2346 protected function validate_date_part($type, $value)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2347 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2348 // we do simple validation of date/part format
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2349 switch ($type) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2350 case 'date': // yyyy-mm-dd
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2351 return preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2352 case 'iso8601':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2353 return preg_match('/^[0-9: .,ZWT+-]+$/', $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2354 case 'std11':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2355 return preg_match('/^((Sun|Mon|Tue|Wed|Thu|Fri|Sat),\s+)?[0-9]{1,2}\s+'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2356 . '(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+[0-9]{2,4}\s+'
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2357 . '[0-9]{2}:[0-9]{2}(:[0-9]{2})?\s+([+-]*[0-9]{4}|[A-Z]{1,3})$', $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2358 case 'julian':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2359 return preg_match('/^[0-9]+$/', $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2360 case 'time': // hh:mm:ss
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2361 return preg_match('/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2362 case 'year':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2363 return preg_match('/^[0-9]{4}$/', $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2364 case 'month':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2365 return preg_match('/^[0-9]{2}$/', $value) && $value > 0 && $value < 13;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2366 case 'day':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2367 return preg_match('/^[0-9]{2}$/', $value) && $value > 0 && $value < 32;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2368 case 'hour':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2369 return preg_match('/^[0-9]{2}$/', $value) && $value < 24;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2370 case 'minute':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2371 return preg_match('/^[0-9]{2}$/', $value) && $value < 60;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2372 case 'second':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2373 // According to RFC5260, seconds can be from 00 to 60
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2374 return preg_match('/^[0-9]{2}$/', $value) && $value < 61;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2375 case 'weekday':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2376 return preg_match('/^[0-9]$/', $value) && $value < 7;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2377 case 'zone':
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2378 return preg_match('/^[+-][0-9]{4}$/', $value);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2379 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2380 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2381
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2382 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2383 * Converts mailbox name from/to UTF7-IMAP from/to internal Sieve encoding
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2384 * with delimiter replacement.
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2385 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2386 * @param string $mailbox Mailbox name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2387 * @param string $mode Conversion direction ('in'|'out')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2388 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2389 * @return string Mailbox name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2390 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2391 protected function mod_mailbox($mailbox, $mode = 'out')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2392 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2393 $delimiter = $_SESSION['imap_delimiter'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2394 $replace_delimiter = $this->rc->config->get('managesieve_replace_delimiter');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2395 $mbox_encoding = $this->rc->config->get('managesieve_mbox_encoding', 'UTF7-IMAP');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2396
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2397 if ($mode == 'out') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2398 $mailbox = rcube_charset::convert($mailbox, $mbox_encoding, 'UTF7-IMAP');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2399 if ($replace_delimiter && $replace_delimiter != $delimiter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2400 $mailbox = str_replace($replace_delimiter, $delimiter, $mailbox);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2401 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2402 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2403 $mailbox = rcube_charset::convert($mailbox, 'UTF7-IMAP', $mbox_encoding);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2404 if ($replace_delimiter && $replace_delimiter != $delimiter)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2405 $mailbox = str_replace($delimiter, $replace_delimiter, $mailbox);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2406 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2407
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2408 return $mailbox;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2409 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2410
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2411 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2412 * List sieve scripts
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2413 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2414 * @return array Scripts list
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2415 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2416 public function list_scripts()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2417 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2418 if ($this->list !== null) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2419 return $this->list;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2420 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2421
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2422 $this->list = $this->sieve->get_scripts();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2423
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2424 // Handle active script(s) and list of scripts according to Kolab's KEP:14
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2425 if ($this->rc->config->get('managesieve_kolab_master')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2426 // Skip protected names
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2427 foreach ((array)$this->list as $idx => $name) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2428 $_name = strtoupper($name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2429 if ($_name == 'MASTER')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2430 $master_script = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2431 else if ($_name == 'MANAGEMENT')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2432 $management_script = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2433 else if($_name == 'USER')
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2434 $user_script = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2435 else
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2436 continue;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2437
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2438 unset($this->list[$idx]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2439 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2440
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2441 // get active script(s), read USER script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2442 if ($user_script) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2443 $extension = $this->rc->config->get('managesieve_filename_extension', '.sieve');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2444 $filename_regex = '/'.preg_quote($extension, '/').'$/';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2445 $_SESSION['managesieve_user_script'] = $user_script;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2446
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2447 $this->sieve->load($user_script);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2448
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2449 foreach ($this->sieve->script->as_array() as $rules) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2450 foreach ($rules['actions'] as $action) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2451 if ($action['type'] == 'include' && empty($action['global'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2452 $name = preg_replace($filename_regex, '', $action['target']);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2453 // make sure the script exist
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2454 if (in_array($name, $this->list)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2455 $this->active[] = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2456 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2457 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2458 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2459 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2460 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2461 // create USER script if it doesn't exist
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2462 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2463 $content = "# USER Management Script\n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2464 ."#\n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2465 ."# This script includes the various active sieve scripts\n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2466 ."# it is AUTOMATICALLY GENERATED. DO NOT EDIT MANUALLY!\n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2467 ."#\n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2468 ."# For more information, see http://wiki.kolab.org/KEP:14#USER\n"
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2469 ."#\n";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2470 if ($this->sieve->save_script('USER', $content)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2471 $_SESSION['managesieve_user_script'] = 'USER';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2472 if (empty($this->master_file))
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2473 $this->sieve->activate('USER');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2474 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2475 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2476 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2477 else if (!empty($this->list)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2478 // Get active script name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2479 if ($active = $this->sieve->get_active()) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2480 $this->active = array($active);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2481 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2482
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2483 // Hide scripts from config
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2484 $exceptions = $this->rc->config->get('managesieve_filename_exceptions');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2485 if (!empty($exceptions)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2486 $this->list = array_diff($this->list, (array)$exceptions);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2487 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2488 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2489
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2490 // reindex
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2491 if (!empty($this->list)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2492 $this->list = array_values($this->list);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2493 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2494
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2495 return $this->list;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2496 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2497
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2498 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2499 * Removes sieve script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2500 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2501 * @param string $name Script name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2502 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2503 * @return bool True on success, False on failure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2504 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2505 public function remove_script($name)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2506 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2507 $result = $this->sieve->remove($name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2508
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2509 // Kolab's KEP:14
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2510 if ($result && $this->rc->config->get('managesieve_kolab_master')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2511 $this->deactivate_script($name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2512 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2513
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2514 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2515 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2516
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2517 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2518 * Activates sieve script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2519 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2520 * @param string $name Script name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2521 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2522 * @return bool True on success, False on failure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2523 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2524 public function activate_script($name)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2525 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2526 // Kolab's KEP:14
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2527 if ($this->rc->config->get('managesieve_kolab_master')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2528 $extension = $this->rc->config->get('managesieve_filename_extension', '.sieve');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2529 $user_script = $_SESSION['managesieve_user_script'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2530
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2531 // if the script is not active...
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2532 if ($user_script && array_search($name, $this->active) === false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2533 // ...rewrite USER file adding appropriate include command
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2534 if ($this->sieve->load($user_script)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2535 $script = $this->sieve->script->as_array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2536 $list = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2537 $regexp = '/' . preg_quote($extension, '/') . '$/';
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2538
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2539 // Create new include entry
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2540 $rule = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2541 'actions' => array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2542 0 => array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2543 'target' => $name.$extension,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2544 'type' => 'include',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2545 'personal' => true,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2546 )));
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2547
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2548 // get all active scripts for sorting
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2549 foreach ($script as $rid => $rules) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2550 foreach ($rules['actions'] as $action) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2551 if ($action['type'] == 'include' && empty($action['global'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2552 $target = $extension ? preg_replace($regexp, '', $action['target']) : $action['target'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2553 $list[] = $target;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2554 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2555 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2556 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2557 $list[] = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2558
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2559 // Sort and find current script position
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2560 asort($list, SORT_LOCALE_STRING);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2561 $list = array_values($list);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2562 $index = array_search($name, $list);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2563
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2564 // add rule at the end of the script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2565 if ($index === false || $index == count($list)-1) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2566 $this->sieve->script->add_rule($rule);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2567 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2568 // add rule at index position
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2569 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2570 $script2 = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2571 foreach ($script as $rid => $rules) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2572 if ($rid == $index) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2573 $script2[] = $rule;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2574 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2575 $script2[] = $rules;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2576 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2577 $this->sieve->script->content = $script2;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2578 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2579
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2580 $result = $this->sieve->save();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2581 if ($result) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2582 $this->active[] = $name;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2583 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2584 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2585 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2586 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2587 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2588 $result = $this->sieve->activate($name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2589 if ($result)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2590 $this->active = array($name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2591 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2592
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2593 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2594 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2595
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2596 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2597 * Deactivates sieve script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2598 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2599 * @param string $name Script name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2600 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2601 * @return bool True on success, False on failure
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2602 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2603 public function deactivate_script($name)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2604 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2605 // Kolab's KEP:14
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2606 if ($this->rc->config->get('managesieve_kolab_master')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2607 $extension = $this->rc->config->get('managesieve_filename_extension', '.sieve');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2608 $user_script = $_SESSION['managesieve_user_script'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2609
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2610 // if the script is active...
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2611 if ($user_script && ($key = array_search($name, $this->active)) !== false) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2612 // ...rewrite USER file removing appropriate include command
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2613 if ($this->sieve->load($user_script)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2614 $script = $this->sieve->script->as_array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2615 $name = $name.$extension;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2616
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2617 foreach ($script as $rid => $rules) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2618 foreach ($rules['actions'] as $action) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2619 if ($action['type'] == 'include' && empty($action['global'])
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2620 && $action['target'] == $name
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2621 ) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2622 break 2;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2623 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2624 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2625 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2626
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2627 // Entry found
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2628 if ($rid < count($script)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2629 $this->sieve->script->delete_rule($rid);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2630 $result = $this->sieve->save();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2631 if ($result) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2632 unset($this->active[$key]);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2633 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2634 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2635 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2636 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2637 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2638 else {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2639 $result = $this->sieve->deactivate();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2640 if ($result)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2641 $this->active = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2642 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2643
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2644 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2645 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2646
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2647 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2648 * Saves current script (adding some variables)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2649 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2650 public function save_script($name = null)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2651 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2652 // Kolab's KEP:14
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2653 if ($this->rc->config->get('managesieve_kolab_master')) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2654 $this->sieve->script->set_var('EDITOR', self::PROGNAME);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2655 $this->sieve->script->set_var('EDITOR_VERSION', self::VERSION);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2656 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2657
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2658 return $this->sieve->save($name);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2659 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2660
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2661 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2662 * Returns list of rules from the current script
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2663 *
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2664 * @return array List of rules
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2665 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2666 public function list_rules()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2667 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2668 $result = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2669 $i = 1;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2670
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2671 foreach ($this->script as $idx => $filter) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2672 if (empty($filter['actions'])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2673 continue;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2674 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2675 $fname = $filter['name'] ?: "#$i";
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2676 $result[] = array(
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2677 'id' => $idx,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2678 'name' => $fname,
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2679 'class' => $filter['disabled'] ? 'disabled' : '',
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2680 );
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2681 $i++;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2682 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2683
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2684 return $result;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2685 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2686
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2687 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2688 * Initializes internal script data
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2689 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2690 protected function init_script()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2691 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2692 if (!$this->sieve->script) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2693 return;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2694 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2695
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2696 $this->script = $this->sieve->script->as_array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2697
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2698 $headers = array();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2699 $exceptions = array('date', 'currentdate', 'size', 'body');
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2700
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2701 // find common headers used in script, will be added to the list
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2702 // of available (predefined) headers (#1489271)
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2703 foreach ($this->script as $rule) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2704 foreach ((array) $rule['tests'] as $test) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2705 if ($test['test'] == 'header') {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2706 foreach ((array) $test['arg1'] as $header) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2707 $lc_header = strtolower($header);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2708
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2709 // skip special names to not confuse UI
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2710 if (in_array($lc_header, $exceptions)) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2711 continue;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2712 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2713
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2714 if (!isset($this->headers[$lc_header]) && !isset($headers[$lc_header])) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2715 $headers[$lc_header] = $header;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2716 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2717 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2718 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2719 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2720 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2721
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2722 ksort($headers);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2723
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2724 $this->headers += $headers;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2725 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2726
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2727 /**
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2728 * Get all e-mail addresses of the user
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2729 */
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2730 protected function user_emails()
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2731 {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2732 $addresses = $this->rc->user->list_emails();
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2733
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2734 foreach ($addresses as $idx => $email) {
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2735 $addresses[$idx] = $email['email'];
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2736 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2737
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2738 $addresses = array_unique($addresses);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2739 sort($addresses);
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2740
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2741 return $addresses;
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2742 }
1e000243b222 vanilla 1.3.3 distro, I hope
Charlie Root
parents:
diff changeset
2743 }