Set default value of YourHop
[squirrelmail.git] / plugins / filters / options.php
1 <?php
2 /**
3 * Message and Spam Filter Plugin
4 *
5 * Copyright (c) 1999-2001 The Squirrelmail Development Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This plugin filters your inbox into different folders based upon given
9 * criteria. It is most useful for people who are subscibed to mailing lists
10 * to help organize their messages. The argument stands that filtering is
11 * not the place of the client, which is why this has been made a plugin for
12 * SquirrelMail. You may be better off using products such as Sieve or
13 * Procmail to do your filtering so it happens even when SquirrelMail isn't
14 * running.
15 *
16 * If you need help with this, or see improvements that can be made, please
17 * email me directly at the address above. I definately welcome suggestions
18 * and comments. This plugin, as is the case with all SquirrelMail plugins,
19 * is not directly supported by the developers. Please come to me off the
20 * mailing list if you have trouble with it.
21 *
22 * Also view plugins/README.plugins for more information.
23 *
24 */
25
26 chdir ('..');
27 require_once('../src/validate.php');
28 require_once('../functions/page_header.php');
29 require_once('../functions/imap.php');
30 require_once('../src/load_prefs.php');
31
32 global $AllowSpamFilters;
33
34 displayPageHeader($color, 'None');
35
36 if (isset($filter_submit)) {
37 if (!isset($theid)) $theid = 0;
38 $filter_what = ereg_replace(",", " ", $filter_what);
39 $filter_what = str_replace("\\\\", "\\", $filter_what);
40 $filter_what = str_replace("\\\"", "\"", $filter_what);
41 $filter_what = str_replace("\"", "&quot;", $filter_what);
42
43 setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
44 $filters[$theid]["where"] = $filter_where;
45 $filters[$theid]["what"] = $filter_what;
46 $filters[$theid]["folder"] = $filter_folder;
47 } elseif (isset($action) && $action == 'delete') {
48 remove_filter($theid);
49 } elseif (isset($action) && $action == 'move_up') {
50 filter_swap($theid, $theid - 1);
51 } elseif (isset($action) && $action == 'move_down') {
52 filter_swap($theid, $theid + 1);
53 }
54
55 $filters = load_filters();
56
57 echo '<br>' .
58 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
59 "<tr><td bgcolor=\"$color[0]\">".
60 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
61 '</td></tr></table>'.
62 '<br><center>[<a href="options.php?action=add">' . _("New") .
63 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>';
64
65 if (isset($action) && ($action == 'add' || $action == 'edit')) {
66 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
67 $boxes = sqimap_mailbox_list($imapConnection);
68 sqimap_logout($imapConnection);
69 if ( !isset($theid) ) {
70 $theid = count($filters);
71 }
72 echo '<center>'.
73 '<form action="options.php" method=post>'.
74 '<table cellpadding=2 cellspacing=0 border=0>'.
75 '<tr>'.
76 '<td>' . _("Match:") . '</td>'.
77 '<td>'.
78 '<select name=filter_where>';
79
80 $L = isset($filters[$theid]['where']);
81
82 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
83 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
84
85 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
86 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
87
88 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
89 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
90
91 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
92 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
93
94 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
95 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
96
97 echo '</select>'.
98 '</td>'.
99 '</tr>'.
100 '<tr>'.
101 '<td align=right>'.
102 _("Contains:").
103 '</td>'.
104 '<td>'.
105 '<input type=text size=32 name=filter_what value="';
106 if (isset($filters[$theid]['what'])) {
107 echo $filters[$theid]["what"];
108 }
109 echo '">'.
110 '</td>'.
111 '</tr>'.
112 '<tr>'.
113 '<td>'.
114 _("Move to:").
115 '</td>'.
116 '<td>'.
117 '<tt>'.
118 '<select name=filter_folder>';
119
120 for ($i = 0; $i < count($boxes); $i++) {
121 if (! in_array('noselect', $boxes[$i]['flags'])) {
122 $box = $boxes[$i]['unformatted'];
123 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
124 if (isset($filters[$theid]['folder']) &&
125 $filters[$theid]['folder'] == $box)
126 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
127 else
128 echo "<OPTION VALUE=\"$box\">$box2</option>";
129 }
130 }
131 echo '</tt>'.
132 '</select>'.
133 '</td>'.
134 '</tr>'.
135 '</table>'.
136 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
137 "<input type=hidden name=theid value=$theid>".
138 '</form>'.
139 '</center>';
140
141 }
142
143 echo '<table border=0 cellpadding=3 cellspacing=0 align=center>';
144
145 for ($i=0; $i < count($filters); $i++) {
146
147 $clr = (($i % 2)?$color[0]:$color[9]);
148 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
149 echo "<tr bgcolor=\"$clr\"><td><small>".
150 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
151 '</small></td><td><small>'.
152 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
153 '</small></td><td align=center><small>[';
154
155 if (isset($filters[$i + 1])) {
156 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
157 if ($i > 0) {
158 echo ' | ';
159 }
160 }
161 if ($i > 0) {
162 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
163 }
164 echo ']</small></td><td> - ';
165 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
166 echo '</td></tr>';
167
168 }
169 echo '</table>'.
170 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
171 '<tr><td>&nbsp</td></tr>'.
172 '</table>';
173
174 ?>