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