Updated changelog.
[squirrelmail.git] / plugins / filters / options.php
CommitLineData
849bdf42 1<?php
4eee5968 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 ('..');
849bdf42 27 require_once('../src/validate.php');
3fd1252d 28 require_once('../functions/page_header.php');
29 require_once('../functions/imap.php');
30 require_once('../src/load_prefs.php');
849bdf42 31
32 global $AllowSpamFilters;
33
3fd1252d 34 displayPageHeader($color, 'None');
849bdf42 35
36 if (isset($filter_submit)) {
37 if (!isset($theid)) $theid = 0;
4eee5968 38 $filter_what = ereg_replace(",", " ", $filter_what);
849bdf42 39 $filter_what = str_replace("\\\\", "\\", $filter_what);
40 $filter_what = str_replace("\\\"", "\"", $filter_what);
41 $filter_what = str_replace("\"", "&quot;", $filter_what);
42
4eee5968 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;
3fd1252d 47 } elseif (isset($action) && $action == 'delete') {
849bdf42 48 remove_filter($theid);
3fd1252d 49 } elseif (isset($action) && $action == 'move_up') {
849bdf42 50 filter_swap($theid, $theid - 1);
3fd1252d 51 } elseif (isset($action) && $action == 'move_down') {
849bdf42 52 filter_swap($theid, $theid + 1);
53 }
54
849bdf42 55 $filters = load_filters();
56
3fd1252d 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) ) {
849bdf42 62 $theid = count($filters);
3fd1252d 63 }
64 echo '<center>'.
4eee5968 65 '<form action="options.php" method=post>'.
66 '<br><table cellpadding=2 cellspacing=0 border=0>'.
67 '<tr>'.
68 '<td>&nbsp;</td>'.
69 '<td>'.
70 '<select name=filter_where>';
849bdf42 71
3fd1252d 72 $L = isset($filters[$theid]['where']);
73
74 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
75 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
4eee5968 76
3fd1252d 77 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
78 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
79
80 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
81 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
82
83 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
84 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
85
86 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
87 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
88
89 echo '</select>'.
4eee5968 90 '</td>'.
91 '</tr>'.
92 '<tr>'.
93 '<td align=right>'.
94 _("Contains:").
95 '</td>'.
96 '<td>'.
97 '<input type=text size=32 name=filter_what value="';
3fd1252d 98 if (isset($filters[$theid]['what'])) {
4eee5968 99 echo $filters[$theid]["what"];
3fd1252d 100 }
101 echo '">'.
4eee5968 102 '</td>'.
103 '</tr>'.
104 '<tr>'.
105 '<td>'.
106 _("Move to:").
107 '</td>'.
108 '<td>'.
109 '<tt>'.
110 '<select name=filter_folder>';
3fd1252d 111
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(' ', '&nbsp;', $boxes[$i]['formatted']);
116 if (isset($filters[$theid]['folder']) &&
117 $filters[$theid]['folder'] == $box)
4eee5968 118 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
3fd1252d 119 else
4eee5968 120 echo "<OPTION VALUE=\"$box\">$box2</option>";
849bdf42 121 }
3fd1252d 122 }
123 echo '</tt>'.
4eee5968 124 '</select>'.
125 '</td>'.
126 '</tr>'.
3fd1252d 127 '</table>'.
128 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
129 "<input type=hidden name=theid value=$theid>".
130 '</form>'.
131 '</center>';
132
3fd1252d 133 }
cb2ccf4b 134
135 echo '<br>' .
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>';
143
144 for ($i=0; $i < count($filters); $i++) {
145
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>[';
153
154 if (isset($filters[$i + 1])) {
155 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
156 if ($i > 0) {
157 echo ' | ';
158 }
159 }
160 if ($i > 0) {
161 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
162 }
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 );
165 echo '</td></tr>';
166
167 }
168 echo '</table>'.
169 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
170 '<tr><td>&nbsp</td></tr>'.
171 '</table>';
172
4eee5968 173?>