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