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