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