A start for a new change_password master plugin. This is not finished
[squirrelmail.git] / plugins / filters / options.php
1 <?php
2
3 /**
4 * Message and Spam Filter Plugin
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
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 *
25 * $Id$
26 * @package plugins
27 * @subpackage filters
28 */
29
30 /** Path for SquirrelMail required files. */
31 define('SM_PATH','../../');
32
33 /* SquirrelMail required files. */
34 require_once(SM_PATH . 'include/validate.php');
35 require_once(SM_PATH . 'functions/page_header.php');
36 require_once(SM_PATH . 'functions/imap.php');
37 require_once(SM_PATH . 'functions/imap_mailbox.php');
38 require_once(SM_PATH . 'include/load_prefs.php');
39 require_once(SM_PATH . 'plugins/filters/filters.php');
40
41 global $AllowSpamFilters;
42
43 displayPageHeader($color, 'None');
44
45 /* get globals */
46 sqgetGlobalVar('username', $username, SQ_SESSION);
47 sqgetGlobalVar('key', $key, SQ_COOKIE);
48 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
49 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
50
51 sqgetGlobalVar('theid', $theid);
52 sqgetGlobalVar('action', $action, SQ_GET);
53
54 // FIXME: use sqgetGlobalVar below.
55
56 if (isset($_POST['filter_submit'])) {
57 if(isset($_GET['theid'])) {
58 $theid = $_GET['theid'];
59 } elseif (isset($_POST['theid'])) {
60 $theid = $_POST['theid'];
61 } else {
62 $theid = 0;
63 }
64 $filter_what = $_POST['filter_what'];
65 $filter_where = $_POST['filter_where'];
66 $filter_folder = $_POST['filter_folder'];
67
68 $filter_what = str_replace(',', ' ', $filter_what);
69 $filter_what = str_replace("\\\\", "\\", $filter_what);
70 $filter_what = str_replace("\\\"", '"', $filter_what);
71 $filter_what = str_replace('"', '&quot;', $filter_what);
72
73 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
74 print ('WARNING! Header filters should be of the format "Header: value"<BR>');
75 $action = 'edit';
76 }
77 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
78 $filters[$theid]['where'] = $filter_where;
79 $filters[$theid]['what'] = $filter_what;
80 $filters[$theid]['folder'] = $filter_folder;
81 } elseif (isset($action) && $action == 'delete') {
82 remove_filter($theid);
83 } elseif (isset($action) && $action == 'move_up') {
84 filter_swap($theid, $theid - 1);
85 } elseif (isset($action) && $action == 'move_down') {
86 filter_swap($theid, $theid + 1);
87 } elseif (isset($_POST['user_submit'])) {
88 setPref($data_dir, $username, 'filters_user_scan', $_POST['filters_user_scan_set']);
89 echo '<br><center><b>'._("Saved Scan type")."</b></center>\n";
90 }
91
92 $filters = load_filters();
93 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
94
95 echo html_tag( 'table',
96 html_tag( 'tr',
97 html_tag( 'td',
98 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' ,
99 'left', $color[0] )
100 ) ,
101 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
102
103 '<br><form method=post action="options.php">'.
104 '<center>'.
105 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
106 html_tag( 'tr' ) .
107 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
108 html_tag( 'td', '', 'left' ) .
109 '<select name="filters_user_scan_set">'.
110 '<option value=""';
111 if ($filters_user_scan == '') {
112 echo ' selected';
113 }
114 echo '>' . _("All messages") . '</option>'.
115 '<option value="new"';
116 if ($filters_user_scan == 'new') {
117 echo ' selected';
118 }
119 echo '>' . _("Only unread messages") . '</option>' .
120 '</select>'.
121 '</td>'.
122 html_tag( 'td', '<input type=submit name="user_submit" value="' . _("Save") . '">', 'left' ) .
123 '</table>'.
124 '</center>'.
125 '</form>'.
126
127 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
128 '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' ,
129 'center' ) . '<br>';
130
131 if (isset($action) && ($action == 'add' || $action == 'edit')) {
132
133 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
134 $boxes = sqimap_mailbox_list($imapConnection);
135 sqimap_logout($imapConnection);
136 if ( !isset($theid) ) {
137 $theid = count($filters);
138 }
139 echo html_tag( 'div', '', 'center' ) .
140 '<form action="options.php" method=post>'.
141 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
142 html_tag( 'tr' ) .
143 html_tag( 'td', _("Match:"), 'left' ) .
144 html_tag( 'td', '', 'left' ) .
145 '<select name=filter_where>';
146
147 $L = isset($filters[$theid]['where']);
148
149 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
150 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
151
152 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
153 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
154
155 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
156 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
157
158 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
159 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
160
161 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
162 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
163
164 $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
165 echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>';
166
167 echo '</select>'.
168 '</td>'.
169 '</tr>'.
170 html_tag( 'tr' ) .
171 html_tag( 'td', _("Contains:"), 'right' ) .
172 html_tag( 'td', '', 'left' ) .
173 '<input type=text size=32 name=filter_what value="';
174 if (isset($filters[$theid]['what'])) {
175 echo $filters[$theid]["what"];
176 }
177 echo '">'.
178 '</td>'.
179 '</tr>'.
180 html_tag( 'tr' ) .
181 html_tag( 'td', _("Move to:"), 'left' ) .
182 html_tag( 'td', '', 'left' ) .
183 '<tt>'.
184 '<select name=filter_folder>';
185 $selected = 0;
186 if ( isset($filters[$theid]['folder']) )
187 $selected = array(strtolower($filters[$theid]['folder']));
188 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
189 echo '</tt>'.
190 '</select>'.
191 '</td>'.
192 '</tr>'.
193 '</table>'.
194 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
195 "<input type=hidden name=theid value=$theid>".
196 '</form>'.
197 '</div>';
198
199 }
200
201 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
202
203 for ($i=0, $num = count($filters); $i < $num; $i++) {
204
205 $clr = (($i % 2)?$color[0]:$color[9]);
206 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
207 echo html_tag( 'tr', '', '', $clr ) .
208 html_tag( 'td',
209 '<small>' .
210 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
211 '</small>' ,
212 'left' ) .
213 html_tag( 'td',
214 '<small>' .
215 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
216 '</small>' ,
217 'left' ) .
218 html_tag( 'td', '', 'center' ) . '<small>[';
219
220 if (isset($filters[$i + 1])) {
221 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
222 if ($i > 0) {
223 echo '&nbsp;|&nbsp;';
224 }
225 }
226 if ($i > 0) {
227 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
228 }
229 echo ']</small></td>'.
230 html_tag( 'td', '-', 'left' ) .
231 html_tag( 'td', '', 'left' );
232 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
233 echo '</td></tr>';
234
235 }
236 echo '</table>'.
237 html_tag( 'table',
238 html_tag( 'tr',
239 html_tag( 'td', '&nbsp;', 'left' )
240 ) ,
241 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
242 echo '</body></html>';
243 ?>