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