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