HTML escaping.
[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$
b2d8bc6c 22 * @copyright (c) 1999-2004 The SquirrelMail Project Team
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/page_header.php');
37require_once(SM_PATH . 'functions/imap.php');
81f652a1 38require_once(SM_PATH . 'functions/imap_mailbox.php');
fca6d99e 39require_once(SM_PATH . 'include/load_prefs.php');
40require_once(SM_PATH . 'plugins/filters/filters.php');
849bdf42 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)) {
64 do_error("Post error");
65 $complete_post=false;
66 }
67
68 sqgetGlobalVar('filter_where', $filter_where, SQ_POST);
69 if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST)) {
70 do_error("Post error");
71 $complete_post=false;
72 }
73
74 sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST);
75 if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST)) {
76 do_error("Post error");
77 $complete_post=false;
78 }
79
80 if ($complete_post) {
81 $filter_what = str_replace(',', ' ', $filter_what);
82 $filter_what = str_replace("\\\\", "\\", $filter_what);
83 $filter_what = str_replace("\\\"", '"', $filter_what);
84 $filter_what = str_replace('"', '&quot;', $filter_what);
85
86 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
87 do_error(_("WARNING! Header filters should be of the format \"Header: value\""));
88 $action = 'edit';
89 }
90 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
91 $filters[$theid]['where'] = $filter_where;
92 $filters[$theid]['what'] = $filter_what;
93 $filters[$theid]['folder'] = $filter_folder;
94 }
3fd1252d 95 } elseif (isset($action) && $action == 'delete') {
849bdf42 96 remove_filter($theid);
3fd1252d 97 } elseif (isset($action) && $action == 'move_up') {
849bdf42 98 filter_swap($theid, $theid - 1);
3fd1252d 99 } elseif (isset($action) && $action == 'move_down') {
849bdf42 100 filter_swap($theid, $theid + 1);
0a1dc88e 101 } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) {
102 sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST);
103 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
104 echo '<br /><center><b>'._("Saved Scan type")."</b></center>\n";
849bdf42 105 }
106
849bdf42 107 $filters = load_filters();
c8a2c24d 108 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
849bdf42 109
6206f6c4 110 echo html_tag( 'table',
b01b21d0 111 html_tag( 'tr',
112 html_tag( 'td',
113 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' ,
114 'left', $color[0] )
115 ) ,
116 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
c8a2c24d 117
0a1dc88e 118 '<br /><form method="post" action="options.php">'.
c8a2c24d 119 '<center>'.
831a25d5 120 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
b01b21d0 121 html_tag( 'tr' ) .
122 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
123 html_tag( 'td', '', 'left' ) .
124 '<select name="filters_user_scan_set">'.
c8a2c24d 125 '<option value=""';
126 if ($filters_user_scan == '') {
b01b21d0 127 echo ' selected';
c8a2c24d 128 }
129 echo '>' . _("All messages") . '</option>'.
130 '<option value="new"';
131 if ($filters_user_scan == 'new') {
b01b21d0 132 echo ' selected';
c8a2c24d 133 }
134 echo '>' . _("Only unread messages") . '</option>' .
135 '</select>'.
136 '</td>'.
0a1dc88e 137 html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
c8a2c24d 138 '</table>'.
139 '</center>'.
140 '</form>'.
141
b01b21d0 142 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
81f652a1 143 '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' ,
0a1dc88e 144 'center' ) . '<br />';
0e838332 145
3fd1252d 146 if (isset($action) && ($action == 'add' || $action == 'edit')) {
41100fce 147
3fd1252d 148 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
149 $boxes = sqimap_mailbox_list($imapConnection);
150 sqimap_logout($imapConnection);
151 if ( !isset($theid) ) {
849bdf42 152 $theid = count($filters);
3fd1252d 153 }
b01b21d0 154 echo html_tag( 'div', '', 'center' ) .
0a1dc88e 155 '<form action="options.php" method="post">'.
831a25d5 156 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
b01b21d0 157 html_tag( 'tr' ) .
158 html_tag( 'td', _("Match:"), 'left' ) .
159 html_tag( 'td', '', 'left' ) .
0a1dc88e 160 '<select name="filter_where">';
849bdf42 161
3fd1252d 162 $L = isset($filters[$theid]['where']);
163
164 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
0a1dc88e 165 echo "<option value=\"From\" $sel>" . _("From") . '</option>';
4eee5968 166
3fd1252d 167 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
0a1dc88e 168 echo "<option value=\"To\" $sel>" . _("To") . '</option>';
3fd1252d 169
170 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
0a1dc88e 171 echo "<option value=\"Cc\" $sel>" . _("Cc") . '</option>';
3fd1252d 172
173 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
0a1dc88e 174 echo "<option value=\"To or Cc\" $sel>" . _("To or Cc") . '</option>';
3fd1252d 175
176 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
0a1dc88e 177 echo "<option value=\"Subject\" $sel>" . _("Subject") . '</option>';
3fd1252d 178
9da6bdde 179 $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
0a1dc88e 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".
210 '<input type="hidden" name="theid" value="' . $theid . "\" />\n".
3fd1252d 211 '</form>'.
b01b21d0 212 '</div>';
3fd1252d 213
3fd1252d 214 }
cb2ccf4b 215
831a25d5 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>' ,
232 'left' ) .
233 html_tag( 'td', '', 'center' ) . '<small>[';
cb2ccf4b 234
235 if (isset($filters[$i + 1])) {
0a1dc88e 236 echo "<a href=\"options.php?theid=$i&amp;action=move_down\">" . _("Down") . '</a>';
cb2ccf4b 237 if ($i > 0) {
2a61e066 238 echo '&nbsp;|&nbsp;';
cb2ccf4b 239 }
240 }
241 if ($i > 0) {
0a1dc88e 242 echo "<a href=\"options.php?theid=$i&amp;action=move_up\">" . _("Up") . '</a>';
cb2ccf4b 243 }
b01b21d0 244 echo ']</small></td>'.
245 html_tag( 'td', '-', 'left' ) .
246 html_tag( 'td', '', 'left' );
0a1dc88e 247 printf( _("If %s contains %s then move to %s"),
248 '<b>'.$filters[$i]['where'].'</b>',
249 '<b>'.$filters[$i]['what'].'</b>',
250 '<b>'.imap_utf7_decode_local($fdr).'</b>');
cb2ccf4b 251 echo '</td></tr>';
252
253 }
254 echo '</table>'.
b01b21d0 255 html_tag( 'table',
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>';
c528d955 261?>