3 ** Message and Spam Filter Plugin
5 ** Copyright (c) 1999-2001 The Squirrelmail Development Team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
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
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.
22 ** Also view plugins/README.plugins for more information.
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');
32 global $AllowSpamFilters;
34 displayPageHeader($color, 'None');
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("\"", """, $filter_what);
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);
55 $filters = load_filters();
57 if (isset($action) && ($action == 'add' ||
$action == 'edit')) {
58 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
59 $boxes = sqimap_mailbox_list($imapConnection);
60 sqimap_logout($imapConnection);
61 if ( !isset($theid) ) {
62 $theid = count($filters);
65 '<form action="options.php" method=post>'.
66 '<br><table cellpadding=2 cellspacing=0 border=0>'.
70 '<select name=filter_where>';
72 $L = isset($filters[$theid]['where']);
74 $sel = (($L && $filters[$theid]['where'] == 'From')?
'selected':'');
75 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
77 $sel = (($L && $filters[$theid]['where'] == 'To')?
'selected':'');
78 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
80 $sel = (($L && $filters[$theid]['where'] == 'Cc')?
'selected':'');
81 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
83 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?
'selected':'');
84 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
86 $sel = (($L && $filters[$theid]['where'] == 'Subject')?
'selected':'');
87 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
97 '<input type=text size=32 name=filter_what value="';
98 if (isset($filters[$theid]['what'])) {
99 echo $filters[$theid]["what"];
110 '<select name=filter_folder>';
112 for ($i = 0; $i < count($boxes); $i++
) {
113 if (! in_array('noselect', $boxes[$i]['flags'])) {
114 $box = $boxes[$i]['unformatted'];
115 $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']);
116 if (isset($filters[$theid]['folder']) &&
117 $filters[$theid]['folder'] == $box)
118 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
120 echo "<OPTION VALUE=\"$box\">$box2</option>";
128 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
129 "<input type=hidden name=theid value=$theid>".
136 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
137 "<tr><td bgcolor=\"$color[0]\">".
138 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
139 '</td></tr></table>'.
140 '<br><center>[<a href="options.php?action=add">' . _("New") .
141 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>' .
142 '<table border=0 cellpadding=3 cellspacing=0 align=center>';
144 for ($i=0; $i < count($filters); $i++
) {
146 $clr = (($i %
2)?
$color[0]:$color[9]);
147 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
148 echo "<tr bgcolor=\"$clr\"><td><small>".
149 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
150 '</small></td><td><small>'.
151 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
152 '</small></td><td align=center><small>[';
154 if (isset($filters[$i +
1])) {
155 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
161 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
163 echo ']</small></td><td> - ';
164 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
169 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
170 '<tr><td> </td></tr>'.