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