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