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