Fix prefs so they work under 4.2 as well as 4.1.x. This really needs to
[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 chdir ('..');
29 require_once('../src/validate.php');
30 require_once('../functions/page_header.php');
31 require_once('../functions/imap.php');
32 require_once('../src/load_prefs.php');
33
34 global $AllowSpamFilters;
35
36 displayPageHeader($color, 'None');
37
38 if (isset($filter_submit)) {
39 if (!isset($theid)) $theid = 0;
40 $filter_what = ereg_replace(",", " ", $filter_what);
41 $filter_what = str_replace("\\\\", "\\", $filter_what);
42 $filter_what = str_replace("\\\"", "\"", $filter_what);
43 $filter_what = str_replace("\"", "&quot;", $filter_what);
44
45 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
46 print ('WARNING! Header filters should be of the format "Header: value"<BR>');
47 $action = 'edit';
48 }
49 setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
50 $filters[$theid]["where"] = $filter_where;
51 $filters[$theid]["what"] = $filter_what;
52 $filters[$theid]["folder"] = $filter_folder;
53 } elseif (isset($action) && $action == 'delete') {
54 remove_filter($theid);
55 } elseif (isset($action) && $action == 'move_up') {
56 filter_swap($theid, $theid - 1);
57 } elseif (isset($action) && $action == 'move_down') {
58 filter_swap($theid, $theid + 1);
59 }
60
61 $filters = load_filters();
62
63 echo '<br>' .
64 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
65 "<tr><td bgcolor=\"$color[0]\">".
66 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
67 '</td></tr></table>'.
68 '<br><center>[<a href="options.php?action=add">' . _("New") .
69 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>';
70
71 if (isset($action) && ($action == 'add' || $action == 'edit')) {
72 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
73 $boxes = sqimap_mailbox_list($imapConnection);
74 sqimap_logout($imapConnection);
75 if ( !isset($theid) ) {
76 $theid = count($filters);
77 }
78 echo '<center>'.
79 '<form action="options.php" method=post>'.
80 '<table cellpadding=2 cellspacing=0 border=0>'.
81 '<tr>'.
82 '<td>' . _("Match:") . '</td>'.
83 '<td>'.
84 '<select name=filter_where>';
85
86 $L = isset($filters[$theid]['where']);
87
88 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
89 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
90
91 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
92 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
93
94 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
95 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
96
97 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
98 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
99
100 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
101 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
102
103 $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
104 echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>';
105
106 echo '</select>'.
107 '</td>'.
108 '</tr>'.
109 '<tr>'.
110 '<td align=right>'.
111 _("Contains:").
112 '</td>'.
113 '<td>'.
114 '<input type=text size=32 name=filter_what value="';
115 if (isset($filters[$theid]['what'])) {
116 echo $filters[$theid]["what"];
117 }
118 echo '">'.
119 '</td>'.
120 '</tr>'.
121 '<tr>'.
122 '<td>'.
123 _("Move to:").
124 '</td>'.
125 '<td>'.
126 '<tt>'.
127 '<select name=filter_folder>';
128
129 for ($i = 0; $i < count($boxes); $i++) {
130 if (! in_array('noselect', $boxes[$i]['flags'])) {
131 $box = $boxes[$i]['unformatted'];
132 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
133 if (isset($filters[$theid]['folder']) &&
134 $filters[$theid]['folder'] == $box)
135 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
136 else
137 echo "<OPTION VALUE=\"$box\">$box2</option>";
138 }
139 }
140 echo '</tt>'.
141 '</select>'.
142 '</td>'.
143 '</tr>'.
144 '</table>'.
145 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
146 "<input type=hidden name=theid value=$theid>".
147 '</form>'.
148 '</center>';
149
150 }
151
152 echo '<table border=0 cellpadding=3 cellspacing=0 align=center>';
153
154 for ($i=0; $i < count($filters); $i++) {
155
156 $clr = (($i % 2)?$color[0]:$color[9]);
157 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
158 echo "<tr bgcolor=\"$clr\"><td><small>".
159 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
160 '</small></td><td><small>'.
161 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
162 '</small></td><td align=center><small>[';
163
164 if (isset($filters[$i + 1])) {
165 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
166 if ($i > 0) {
167 echo '&nbsp;|&nbsp;';
168 }
169 }
170 if ($i > 0) {
171 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
172 }
173 echo ']</small></td><td>-</td><td>';
174 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
175 echo '</td></tr>';
176
177 }
178 echo '</table>'.
179 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
180 '<tr><td>&nbsp</td></tr>'.
181 '</table>';
182
183 ?>