Fix variable name typo
[squirrelmail.git] / plugins / filters / options.php
CommitLineData
849bdf42 1<?php
4b4abf93 2
15e6162e 3/**
0a1dc88e 4 * Message and Spam Filter Plugin - Filtering Options
15e6162e 5 *
c4faef33 6 * @copyright 1999-2020 The SquirrelMail Project Team
b2d8bc6c 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
4b4abf93 8 * @version $Id$
ea5f4b8e 9 * @package plugins
10 * @subpackage filters
15e6162e 11 */
4eee5968 12
5b4ba967 13/**
202bcbcc 14 * Include the SquirrelMail initialization file.
5b4ba967 15 */
202bcbcc 16require('../../include/init.php');
17include_once(SM_PATH . 'functions/imap_general.php');
2b0224f5 18include_once(SM_PATH . 'functions/forms.php');
e5c8ec61 19include_once(SM_PATH . 'plugins/filters/filters.php');
849bdf42 20
876fdb60 21displayPageHeader($color);
849bdf42 22
3c66c567 23/* get globals */
3c66c567 24sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
25
26sqgetGlobalVar('theid', $theid);
27sqgetGlobalVar('action', $action, SQ_GET);
a9805897 28global $imap_stream_options; // in case not defined in config
3c66c567 29
0a1dc88e 30if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) {
31
32 if(! isset($theid) ) $theid = 0;
33
34 $complete_post=true;
35
36 // FIXME: write human readable error messages
37 sqgetGlobalVar('filter_what', $filter_what, SQ_POST);
38 if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST)) {
3b94163a 39 do_error("Post error");
40 $complete_post=false;
0a1dc88e 41 }
42
43 sqgetGlobalVar('filter_where', $filter_where, SQ_POST);
44 if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST)) {
3b94163a 45 do_error("Post error");
46 $complete_post=false;
0a1dc88e 47 }
48
49 sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST);
50 if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST)) {
3b94163a 51 do_error("Post error");
52 $complete_post=false;
0a1dc88e 53 }
54
55 if ($complete_post) {
eceb3fe5 56 $filter_what = str_replace(',', '###COMMA###', $filter_what);
0a1dc88e 57 $filter_what = str_replace("\\\\", "\\", $filter_what);
58 $filter_what = str_replace("\\\"", '"', $filter_what);
59 $filter_what = str_replace('"', '&quot;', $filter_what);
60
174523e3 61 if (empty($filter_what)) {
62 do_error(_("WARNING! You must enter something to search for."));
63 $action = 'edit';
64 }
65
0a1dc88e 66 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
3b94163a 67 do_error(_("WARNING! Header filters should be of the format &quot;Header: value&quot;"));
68 $action = 'edit';
69 }
174523e3 70 if ($action != 'edit') {
3b94163a 71 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
174523e3 72 }
3b94163a 73 $filters[$theid]['where'] = $filter_where;
74 $filters[$theid]['what'] = $filter_what;
75 $filters[$theid]['folder'] = $filter_folder;
0a1dc88e 76 }
3b94163a 77} elseif (isset($action) && $action == 'delete') {
849bdf42 78 remove_filter($theid);
3b94163a 79} elseif (isset($action) && $action == 'move_up') {
849bdf42 80 filter_swap($theid, $theid - 1);
3b94163a 81} elseif (isset($action) && $action == 'move_down') {
849bdf42 82 filter_swap($theid, $theid + 1);
3b94163a 83} elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) {
84 sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST);
85 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
f265009a 86 echo '<br /><div style="text-align: center;"><b>'._("Saved Scan type")."</b></div>\n";
3b94163a 87}
849bdf42 88
849bdf42 89 $filters = load_filters();
c8a2c24d 90 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
849bdf42 91
6206f6c4 92 echo html_tag( 'table',
b01b21d0 93 html_tag( 'tr',
94 html_tag( 'td',
f265009a 95 '<div style="text-align: center;"><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></div>' ,
3b94163a 96 'left', $color[0]
97 )
98 ),
99 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
100 ) .
0a1dc88e 101 '<br /><form method="post" action="options.php">'.
24fec4fd 102 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
b01b21d0 103 html_tag( 'tr' ) .
c435f076 104 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
b01b21d0 105 html_tag( 'td', '', 'left' ) .
106 '<select name="filters_user_scan_set">'.
c8a2c24d 107 '<option value=""';
108 if ($filters_user_scan == '') {
e1728a7a 109 echo ' selected="selected"';
c8a2c24d 110 }
111 echo '>' . _("All messages") . '</option>'.
112 '<option value="new"';
113 if ($filters_user_scan == 'new') {
e1728a7a 114 echo ' selected="selected"';
c8a2c24d 115 }
116 echo '>' . _("Only unread messages") . '</option>' .
117 '</select>'.
118 '</td>'.
0a1dc88e 119 html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
c8a2c24d 120 '</table>'.
c8a2c24d 121 '</form>'.
122
b01b21d0 123 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
81f652a1 124 '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' ,
0a1dc88e 125 'center' ) . '<br />';
0e838332 126
3fd1252d 127 if (isset($action) && ($action == 'add' || $action == 'edit')) {
41100fce 128
a9805897 129 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
3fd1252d 130 $boxes = sqimap_mailbox_list($imapConnection);
174523e3 131
132 for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++) {
133 if (strtolower($boxes[$a]['formatted']) == 'inbox') {
134 unset($boxes[$a]);
135 }
136 }
137
3fd1252d 138 sqimap_logout($imapConnection);
139 if ( !isset($theid) ) {
849bdf42 140 $theid = count($filters);
3fd1252d 141 }
b01b21d0 142 echo html_tag( 'div', '', 'center' ) .
0a1dc88e 143 '<form action="options.php" method="post">'.
831a25d5 144 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
b01b21d0 145 html_tag( 'tr' ) .
146 html_tag( 'td', _("Match:"), 'left' ) .
147 html_tag( 'td', '', 'left' ) .
0a1dc88e 148 '<select name="filter_where">';
849bdf42 149
3fd1252d 150 $L = isset($filters[$theid]['where']);
151
e1728a7a 152 $sel = (($L && $filters[$theid]['where'] == 'From')?' selected="selected"':'');
153 echo "<option value=\"From\"$sel>" . _("From") . '</option>';
4eee5968 154
e1728a7a 155 $sel = (($L && $filters[$theid]['where'] == 'To')?' selected="selected"':'');
156 echo "<option value=\"To\"$sel>" . _("To") . '</option>';
3fd1252d 157
e1728a7a 158 $sel = (($L && $filters[$theid]['where'] == 'Cc')?' selected="selected"':'');
159 echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
3fd1252d 160
e1728a7a 161 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?' selected="selected"':'');
162 echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
3fd1252d 163
e1728a7a 164 $sel = (($L && $filters[$theid]['where'] == 'Subject')?' selected="selected"':'');
165 echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
3fd1252d 166
8a7ccd82 167 $sel = (($L && $filters[$theid]['where'] == 'Message Body')?' selected="selected"':'');
168 echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>';
169
170 $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?' selected="selected"':'');
171 echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>';
172
e1728a7a 173 $sel = (($L && $filters[$theid]['where'] == 'Header')?' selected="selected"':'');
174 echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
9da6bdde 175
3fd1252d 176 echo '</select>'.
4eee5968 177 '</td>'.
178 '</tr>'.
b01b21d0 179 html_tag( 'tr' ) .
180 html_tag( 'td', _("Contains:"), 'right' ) .
181 html_tag( 'td', '', 'left' ) .
0a1dc88e 182 '<input type="text" size="32" name="filter_what" value="';
3fd1252d 183 if (isset($filters[$theid]['what'])) {
3047e291 184 echo sm_encode_html_special_chars($filters[$theid]['what']);
3fd1252d 185 }
0a1dc88e 186 echo '" />'.
4eee5968 187 '</td>'.
188 '</tr>'.
b01b21d0 189 html_tag( 'tr' ) .
190 html_tag( 'td', _("Move to:"), 'left' ) .
191 html_tag( 'td', '', 'left' ) .
4eee5968 192 '<tt>'.
0a1dc88e 193 '<select name="filter_folder">';
81f652a1 194 $selected = 0;
195 if ( isset($filters[$theid]['folder']) )
196 $selected = array(strtolower($filters[$theid]['folder']));
197 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
24fec4fd 198 echo '</select>'.
199 '</tt>'.
4eee5968 200 '</td>'.
201 '</tr>'.
3fd1252d 202 '</table>'.
0a1dc88e 203 '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
a9e1e670 204 addHidden('theid', $theid).
3fd1252d 205 '</form>'.
b01b21d0 206 '</div>';
3fd1252d 207
3fd1252d 208 }
cb2ccf4b 209
24fec4fd 210if (count($filters)) {
3b94163a 211 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
cb2ccf4b 212
ae48f757 213 for ($i=0, $num = count($filters); $i < $num; $i++) {
cb2ccf4b 214
215 $clr = (($i % 2)?$color[0]:$color[9]);
216 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
831a25d5 217 echo html_tag( 'tr', '', '', $clr ) .
b01b21d0 218 html_tag( 'td',
219 '<small>' .
0a1dc88e 220 "[<a href=\"options.php?theid=$i&amp;action=edit\">" . _("Edit") . '</a>]'.
b01b21d0 221 '</small>' ,
222 'left' ) .
223 html_tag( 'td',
224 '<small>' .
0a1dc88e 225 "[<a href=\"options.php?theid=$i&amp;action=delete\">" . _("Delete") . '</a>]'.
b01b21d0 226 '</small>' ,
3b94163a 227 'left' );
228
229 if ($num > 1) {
230 echo html_tag( 'td', '', 'center' ) . '<small>[';
231 if (isset($filters[$i + 1])) {
232 echo "<a href=\"options.php?theid=$i&amp;action=move_down\">" . _("Down") . '</a>';
233 if ($i > 0) {
234 echo '&nbsp;|&nbsp;';
235 }
236 }
cb2ccf4b 237 if ($i > 0) {
3b94163a 238 echo "<a href=\"options.php?theid=$i&amp;action=move_up\">" . _("Up") . '</a>';
cb2ccf4b 239 }
3b94163a 240 echo ']</small></td>';
cb2ccf4b 241 }
3b94163a 242 echo html_tag( 'td', '-', 'left' ) .
243 html_tag( 'td', '', 'left' );
0a1dc88e 244 printf( _("If %s contains %s then move to %s"),
3b94163a 245 '<b>'.$filters[$i]['where'].'</b>',
246 '<b>'.$filters[$i]['what'].'</b>',
3047e291 247 '<b>'.sm_encode_html_special_chars(imap_utf7_decode_local($fdr)).'</b>');
cb2ccf4b 248 echo '</td></tr>';
249
250 }
24fec4fd 251 echo '</table>';
252}
253 echo html_tag( 'table',
b01b21d0 254 html_tag( 'tr',
8e724112 255 html_tag( 'td', '&nbsp;', 'left' )
b01b21d0 256 ) ,
257 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
dcc1cc82 258 echo '</body></html>';