849bdf42 |
1 | <?php |
15e6162e |
2 | /** |
0a1dc88e |
3 | * Message and Spam Filter Plugin - Filtering Functions |
15e6162e |
4 | * |
15e6162e |
5 | * This plugin filters your inbox into different folders based upon given |
6 | * criteria. It is most useful for people who are subscibed to mailing lists |
7 | * to help organize their messages. The argument stands that filtering is |
8 | * not the place of the client, which is why this has been made a plugin for |
9 | * SquirrelMail. You may be better off using products such as Sieve or |
10 | * Procmail to do your filtering so it happens even when SquirrelMail isn't |
11 | * running. |
12 | * |
13 | * If you need help with this, or see improvements that can be made, please |
9c655416 |
14 | * email me directly at the address above. I definitely welcome suggestions |
15e6162e |
15 | * and comments. This plugin, as is the case with all SquirrelMail plugins, |
16 | * is not directly supported by the developers. Please come to me off the |
17 | * mailing list if you have trouble with it. |
18 | * |
19 | * Also view plugins/README.plugins for more information. |
20 | * |
5b4ba967 |
21 | * @version $Id$ |
6c84ba1e |
22 | * @copyright (c) 1999-2005 The SquirrelMail Project Team |
b2d8bc6c |
23 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
ea5f4b8e |
24 | * @package plugins |
25 | * @subpackage filters |
15e6162e |
26 | */ |
4eee5968 |
27 | |
9c655416 |
28 | @include_once (SM_PATH . 'plugins/filters/config.php'); |
29 | |
ea5f4b8e |
30 | /** |
9c655416 |
31 | * Init Hooks |
32 | * @access private |
33 | */ |
34 | function filters_init_hooks () { |
35 | global $squirrelmail_plugin_hooks; |
36 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
37 | if (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM)) { |
38 | sqgetGlobalVar('mailbox',$mailbox,SQ_FORM); |
39 | } else { |
40 | $mailbox = 'INBOX'; |
41 | } |
42 | |
43 | $squirrelmail_plugin_hooks['left_main_before']['filters'] = 'start_filters_hook'; |
44 | if (isset($mailbox) && $mailbox == 'INBOX') { |
45 | $squirrelmail_plugin_hooks['right_main_after_header']['filters'] = 'start_filters_hook'; |
46 | } |
47 | $squirrelmail_plugin_hooks['optpage_register_block']['filters'] = 'filters_optpage_register_block_hook'; |
48 | $squirrelmail_plugin_hooks['special_mailbox']['filters'] = 'filters_special_mailbox'; |
49 | $squirrelmail_plugin_hooks['rename_or_delete_folder']['filters'] = 'update_for_folder_hook'; |
50 | $squirrelmail_plugin_hooks['webmail_bottom']['filters'] = 'start_filters_hook'; |
51 | } |
52 | |
53 | /** |
54 | * Register option blocks |
55 | * @access private |
56 | */ |
57 | function filters_optpage_register_block() { |
58 | global $optpage_blocks, $AllowSpamFilters; |
59 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
60 | |
61 | $optpage_blocks[] = array( |
62 | 'name' => _("Message Filters"), |
63 | 'url' => SM_PATH . 'plugins/filters/options.php', |
64 | 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."), |
65 | 'js' => false |
66 | ); |
67 | |
68 | if ($AllowSpamFilters) { |
69 | $optpage_blocks[] = array( |
70 | 'name' => _("SPAM Filters"), |
71 | 'url' => SM_PATH . 'plugins/filters/spamoptions.php', |
72 | 'desc' => _("SPAM filters allow you to select from various DNS based blacklists to detect junk email in your INBOX and move it to another folder (like Trash)."), |
73 | 'js' => false |
74 | ); |
75 | } |
76 | } |
77 | |
78 | /** |
79 | * Saves the DNS Cache to disk |
0a1dc88e |
80 | * @access private |
5b4ba967 |
81 | */ |
a2a566eb |
82 | function filters_SaveCache () { |
83 | global $data_dir, $SpamFilters_DNScache; |
84 | |
ae48f757 |
85 | if (file_exists($data_dir . '/dnscache')) { |
86 | $fp = fopen($data_dir . '/dnscache', 'r'); |
a2a566eb |
87 | } else { |
88 | $fp = false; |
89 | } |
90 | if ($fp) { |
91 | flock($fp,LOCK_EX); |
92 | } else { |
ae48f757 |
93 | $fp = fopen($data_dir . '/dnscache', 'w+'); |
a2a566eb |
94 | fclose($fp); |
ae48f757 |
95 | $fp = fopen($data_dir . '/dnscache', 'r'); |
a2a566eb |
96 | flock($fp,LOCK_EX); |
97 | } |
9c655416 |
98 | $fp1 = fopen($data_dir . '/dnscache', 'w+'); |
a2a566eb |
99 | |
100 | foreach ($SpamFilters_DNScache as $Key=> $Value) { |
101 | $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n"; |
102 | fputs ($fp1, $tstr); |
103 | } |
104 | fclose($fp1); |
105 | flock($fp,LOCK_UN); |
106 | fclose($fp); |
107 | } |
108 | |
0a1dc88e |
109 | /** |
9c655416 |
110 | * Loads the DNS Cache from disk |
0a1dc88e |
111 | * @access private |
112 | */ |
a2a566eb |
113 | function filters_LoadCache () { |
114 | global $data_dir, $SpamFilters_DNScache; |
115 | |
ae48f757 |
116 | if (file_exists($data_dir . '/dnscache')) { |
6ade76e0 |
117 | $SpamFilters_DNScache = array(); |
ae48f757 |
118 | if ($fp = fopen ($data_dir . '/dnscache', 'r')) { |
a2a566eb |
119 | flock($fp,LOCK_SH); |
9c655416 |
120 | while ($data = fgetcsv($fp,1024)) { |
a2a566eb |
121 | if ($data[2] > time()) { |
122 | $SpamFilters_DNScache[$data[0]]['L'] = $data[1]; |
123 | $SpamFilters_DNScache[$data[0]]['T'] = $data[2]; |
124 | } |
125 | } |
a2a566eb |
126 | flock($fp,LOCK_UN); |
127 | } |
128 | } |
129 | } |
130 | |
0a1dc88e |
131 | /** |
9c655416 |
132 | * Uses the BulkQuery executable to query all the RBLs at once |
133 | * @param array $filters Array of SPAM Fitlers |
134 | * @param array $IPs Array of IP Addresses |
0a1dc88e |
135 | * @access private |
136 | */ |
fb577a4d |
137 | function filters_bulkquery($filters, $IPs) { |
ce68b76b |
138 | global $attachment_dir, $username, |
6ade76e0 |
139 | $SpamFilters_DNScache, $SpamFilters_BulkQuery, |
140 | $SpamFilters_CacheTTL; |
a2a566eb |
141 | |
a2a566eb |
142 | if (count($IPs) > 0) { |
143 | $rbls = array(); |
144 | foreach ($filters as $key => $value) { |
145 | if ($filters[$key]['enabled']) { |
146 | if ($filters[$key]['dns']) { |
147 | $rbls[$filters[$key]['dns']] = true; |
148 | } |
149 | } |
150 | } |
151 | |
ae48f757 |
152 | $bqfil = $attachment_dir . $username . '-bq.in'; |
153 | $fp = fopen($bqfil, 'w'); |
6ade76e0 |
154 | fputs ($fp, $SpamFilters_CacheTTL . "\n"); |
a2a566eb |
155 | foreach ($rbls as $key => $value) { |
ae48f757 |
156 | fputs ($fp, '.' . $key . "\n"); |
a2a566eb |
157 | } |
158 | fputs ($fp, "----------\n"); |
159 | foreach ($IPs as $key => $value) { |
160 | fputs ($fp, $key . "\n"); |
161 | } |
162 | fclose ($fp); |
163 | $bqout = array(); |
ae48f757 |
164 | exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout); |
a2a566eb |
165 | foreach ($bqout as $value) { |
166 | $Chunks = explode(',', $value); |
167 | $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1]; |
168 | $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time(); |
169 | } |
170 | unlink($bqfil); |
171 | } |
172 | } |
173 | |
0a1dc88e |
174 | /** |
9c655416 |
175 | * Starts the filtering process |
0a1dc88e |
176 | * @access private |
177 | */ |
10a26cea |
178 | function start_filters() { |
ce68b76b |
179 | global $imapServerAddress, $imapPort, $imap_stream, $imapConnection, |
3c66c567 |
180 | $UseSeparateImapConnection, $AllowSpamFilters; |
9c655416 |
181 | |
182 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
183 | |
3c66c567 |
184 | sqgetGlobalVar('username', $username, SQ_SESSION); |
185 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
10a26cea |
186 | |
2714d4ff |
187 | // Detect if we have already connected to IMAP or not. |
188 | // Also check if we are forced to use a separate IMAP connection |
189 | if ((!isset($imap_stream) && !isset($imapConnection)) || |
190 | $UseSeparateImapConnection ) { |
191 | $stream = sqimap_login($username, $key, $imapServerAddress, |
192 | $imapPort, 10); |
193 | $previously_connected = false; |
194 | } else if (isset($imapConnection)) { |
195 | $stream = $imapConnection; |
196 | $previously_connected = true; |
197 | } else { |
198 | $previously_connected = true; |
199 | $stream = $imap_stream; |
200 | } |
201 | $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES')); |
4eee5968 |
202 | |
2714d4ff |
203 | if ($aStatus['MESSAGES']) { |
204 | sqimap_mailbox_select($stream, 'INBOX'); |
205 | // Filter spam from inbox before we sort them into folders |
206 | if ($AllowSpamFilters) { |
207 | spam_filters($stream); |
10a26cea |
208 | } |
4eee5968 |
209 | |
2714d4ff |
210 | // Sort into folders |
211 | user_filters($stream); |
212 | } |
213 | |
214 | if (!$previously_connected) { |
215 | sqimap_logout($stream); |
216 | } |
10a26cea |
217 | } |
218 | |
0a1dc88e |
219 | /** |
9c655416 |
220 | * Does the loop through each filter |
221 | * @param stream imap_stream the stream to read from |
0a1dc88e |
222 | * @access private |
223 | */ |
10a26cea |
224 | function user_filters($imap_stream) { |
c8a2c24d |
225 | global $data_dir, $username; |
10a26cea |
226 | $filters = load_filters(); |
227 | if (! $filters) return; |
c8a2c24d |
228 | $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan'); |
10a26cea |
229 | |
fb577a4d |
230 | $expunge = false; |
53fcc494 |
231 | // For every rule |
ae48f757 |
232 | for ($i=0, $num = count($filters); $i < $num; $i++) { |
10a26cea |
233 | // If it is the "combo" rule |
234 | if ($filters[$i]['where'] == 'To or Cc') { |
53fcc494 |
235 | /* |
236 | * If it's "TO OR CC", we have to do two searches, one for TO |
237 | * and the other for CC. |
238 | */ |
fb577a4d |
239 | $expunge = filter_search_and_delete($imap_stream, 'TO', |
240 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
241 | $expunge = filter_search_and_delete($imap_stream, 'CC', |
242 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
8a7ccd82 |
243 | } else if ($filters[$i]['where'] == 'Header and Body') { |
244 | $expunge = filter_search_and_delete($imap_stream, 'TEXT', |
245 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
246 | } else if ($filters[$i]['where'] == 'Message Body') { |
247 | $expunge = filter_search_and_delete($imap_stream, 'BODY', |
248 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
10a26cea |
249 | } else { |
53fcc494 |
250 | /* |
251 | * If it's a normal TO, CC, SUBJECT, or FROM, then handle it |
252 | * normally. |
253 | */ |
fb577a4d |
254 | $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'], |
255 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
4eee5968 |
256 | } |
4eee5968 |
257 | } |
53fcc494 |
258 | // Clean out the mailbox whether or not auto_expunge is on |
259 | // That way it looks like it was redirected properly |
fb577a4d |
260 | if ($expunge) { |
4f6915b0 |
261 | sqimap_mailbox_expunge($imap_stream, 'INBOX'); |
53fcc494 |
262 | } |
10a26cea |
263 | } |
264 | |
0a1dc88e |
265 | /** |
9c655416 |
266 | * Creates and runs the IMAP command to filter messages |
267 | * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...) |
268 | * @param string $what String to search for |
269 | * @param string $where_to Folder it will move to |
270 | * @param string $user_scan Whether to search all or just unseen |
271 | * @param string $should_expunge |
272 | * @param boolean $where Which part of location to search |
0a1dc88e |
273 | * @access private |
274 | */ |
2714d4ff |
275 | function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan, |
fb577a4d |
276 | $should_expunge) { |
6201339c |
277 | global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type; |
278 | |
174523e3 |
279 | if (strtolower($where_to) == 'inbox') { |
280 | return array(); |
281 | } |
282 | |
c8a2c24d |
283 | if ($user_scan == 'new') { |
284 | $category = 'UNSEEN'; |
285 | } else { |
286 | $category = 'ALL'; |
287 | } |
86e6d79f |
288 | $category .= ' UNDELETED'; |
c8a2c24d |
289 | |
3eea00ca |
290 | if ($allow_charset_search && |
291 | isset($languages[$squirrelmail_language]['CHARSET']) && |
53fcc494 |
292 | $languages[$squirrelmail_language]['CHARSET']) { |
3eea00ca |
293 | $search_str = 'SEARCH CHARSET ' |
294 | . strtoupper($languages[$squirrelmail_language]['CHARSET']) |
295 | . ' ' . $category; |
f9ca4be0 |
296 | } else { |
3eea00ca |
297 | $search_str = 'SEARCH CHARSET US-ASCII ' . $category; |
f9ca4be0 |
298 | } |
ae48f757 |
299 | if ($where == 'Header') { |
3eea00ca |
300 | $what = explode(':', $what); |
301 | $where = trim($where . ' ' . $what[0]); |
302 | $what = addslashes(trim($what[1])); |
9da6bdde |
303 | } |
f18ea37e |
304 | |
cf2aa192 |
305 | // see comments in squirrelmail sqimap_search function |
306 | if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') { |
91e0dccc |
307 | $search_str .= ' ' . $where . ' ' . $what; |
f18ea37e |
308 | } else { |
91e0dccc |
309 | $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n" |
f18ea37e |
310 | . $what . "\r\n"; |
311 | } |
10a26cea |
312 | |
53fcc494 |
313 | /* read data back from IMAP */ |
6201339c |
314 | $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE); |
2714d4ff |
315 | if (isset($read[0])) { |
316 | $ids = array(); |
9c655416 |
317 | for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { |
2714d4ff |
318 | if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) { |
319 | $ids = preg_split("/ /", trim($regs[1])); |
320 | break; |
fb577a4d |
321 | } |
2714d4ff |
322 | } |
323 | if ($response == 'OK' && count($ids)) { |
324 | if (sqimap_mailbox_exists($imap_stream, $where_to)) { |
325 | $should_expunge = true; |
326 | sqimap_msgs_list_move ($imap_stream, $ids, $where_to); |
4eee5968 |
327 | } |
328 | } |
329 | } |
fb577a4d |
330 | return $should_expunge; |
10a26cea |
331 | } |
4eee5968 |
332 | |
0a1dc88e |
333 | /** |
9c655416 |
334 | * Loops through all the Received Headers to find IP Addresses |
335 | * @param stream imap_stream the stream to read from |
0a1dc88e |
336 | * @access private |
337 | */ |
10a26cea |
338 | function spam_filters($imap_stream) { |
6201339c |
339 | global $data_dir, $username; |
10a26cea |
340 | global $SpamFilters_YourHop; |
341 | global $SpamFilters_DNScache; |
a2a566eb |
342 | global $SpamFilters_SharedCache; |
343 | global $SpamFilters_BulkQuery; |
fb577a4d |
344 | global $SpamFilters_CacheTTL; |
4eee5968 |
345 | |
10a26cea |
346 | $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan'); |
347 | $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder'); |
348 | $filters = load_spam_filters(); |
4eee5968 |
349 | |
a2a566eb |
350 | if ($SpamFilters_SharedCache) { |
351 | filters_LoadCache(); |
352 | } |
353 | |
fb577a4d |
354 | $run = false; |
4eee5968 |
355 | |
fb577a4d |
356 | foreach ($filters as $Key => $Value) { |
10a26cea |
357 | if ($Value['enabled']) { |
fb577a4d |
358 | $run = true; |
359 | break; |
4eee5968 |
360 | } |
10a26cea |
361 | } |
4eee5968 |
362 | |
10a26cea |
363 | // short-circuit |
fb577a4d |
364 | if (!$run) { |
10a26cea |
365 | return; |
366 | } |
4eee5968 |
367 | |
10a26cea |
368 | // Ask for a big list of all "Received" headers in the inbox with |
369 | // flags for each message. Kinda big. |
2714d4ff |
370 | |
371 | if ($filters_spam_scan == 'new') { |
372 | $search_array = array(); |
6201339c |
373 | $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE); |
2714d4ff |
374 | if (isset($read[0])) { |
9c655416 |
375 | for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { |
2714d4ff |
376 | if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) { |
6174dcc7 |
377 | $search_array = preg_split("/ /", trim($regs[1])); |
2714d4ff |
378 | break; |
6174dcc7 |
379 | } |
c8a2c24d |
380 | } |
2714d4ff |
381 | } |
c8a2c24d |
382 | } |
2714d4ff |
383 | if ($filters_spam_scan == 'new' && count($search_array)) { |
d3fae94f |
384 | $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array()); |
2714d4ff |
385 | } else if ($filters_spam_scan != 'new') { |
d3fae94f |
386 | $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array()); |
2714d4ff |
387 | } else { |
388 | return; |
389 | } |
390 | if (!count($headers)) { |
10a26cea |
391 | return; |
392 | } |
fb577a4d |
393 | $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false); |
394 | $IPs = array(); |
395 | $aSpamIds = array(); |
396 | foreach ($headers as $id => $aValue) { |
2714d4ff |
397 | if (isset($aValue['UID'])) { |
fb577a4d |
398 | $MsgNum = $aValue['UID']; |
399 | } else { |
400 | $MsgNum = $id; |
10a26cea |
401 | } |
10a26cea |
402 | // Look through all of the Received headers for IP addresses |
2714d4ff |
403 | if (isset($aValue['RECEIVED'])) { |
404 | foreach ($aValue['RECEIVED'] as $received) { |
fb577a4d |
405 | // Check to see if this line is the right "Received from" line |
406 | // to check |
2714d4ff |
407 | |
408 | // $aValue['Received'] is an array with all the received lines. |
fb577a4d |
409 | // We should check them from bottom to top and only check the first 2. |
410 | // Currently we check only the header where $SpamFilters_YourHop in occures |
2714d4ff |
411 | |
fb577a4d |
412 | if (is_int(strpos($received, $SpamFilters_YourHop))) { |
413 | if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) { |
414 | $isspam = false; |
415 | if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) { |
416 | $aSpamIds[] = $MsgNum; |
417 | $isspam = true; |
418 | } |
419 | if ($bulkquery) { |
420 | array_shift($aMatch); |
421 | $IP = explode('.',$aMatch); |
422 | foreach ($filters as $key => $value) { |
423 | if ($filters[$key]['enabled'] && $filters[$key]['dns']) { |
424 | if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) { |
425 | $IPs[$IP] = true; |
426 | break; |
427 | } |
428 | } |
429 | } |
c8a2c24d |
430 | } |
431 | // If we've checked one IP and YourHop is |
432 | // just a space |
fb577a4d |
433 | if ($SpamFilters_YourHop == ' ' || $isspam) { |
c8a2c24d |
434 | break; // don't check any more |
a9aa7ab7 |
435 | } |
a9aa7ab7 |
436 | } |
4eee5968 |
437 | } |
4eee5968 |
438 | } |
4eee5968 |
439 | } |
10a26cea |
440 | } |
fb577a4d |
441 | // Lookie! It's spam! Yum! |
442 | if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) { |
443 | sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder); |
444 | sqimap_mailbox_expunge($imap_stream, 'INBOX'); |
445 | } |
4eee5968 |
446 | |
fb577a4d |
447 | if ($bulkquery && count($IPs)) { |
448 | filters_bulkquery($filters, $IPs); |
449 | } |
4eee5968 |
450 | |
a2a566eb |
451 | if ($SpamFilters_SharedCache) { |
452 | filters_SaveCache(); |
453 | } else { |
41100fce |
454 | sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache'); |
a2a566eb |
455 | } |
10a26cea |
456 | } |
4eee5968 |
457 | |
0a1dc88e |
458 | /** |
0a1dc88e |
459 | * Does the loop through each enabled filter for the specified IP address. |
460 | * IP format: $a.$b.$c.$d |
9c655416 |
461 | * @param int $a First subset of IP |
462 | * @param int $b Second subset of IP |
463 | * @param int $c Third subset of IP |
464 | * @param int $d Forth subset of IP |
465 | * @param array $filters The Spam Filters |
466 | * @return boolean Whether the IP is Spam |
0a1dc88e |
467 | * @access private |
468 | */ |
10a26cea |
469 | function filters_spam_check_site($a, $b, $c, $d, &$filters) { |
a2a566eb |
470 | global $SpamFilters_DNScache, $SpamFilters_CacheTTL; |
10a26cea |
471 | foreach ($filters as $key => $value) { |
472 | if ($filters[$key]['enabled']) { |
473 | if ($filters[$key]['dns']) { |
474 | $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' . |
475 | $filters[$key]['dns']; |
ae48f757 |
476 | |
477 | if(!isset($SpamFilters_DNScache[$filter_revip]['L'])) |
478 | $SpamFilters_DNScache[$filter_revip]['L'] = ''; |
479 | |
480 | if(!isset($SpamFilters_DNScache[$filter_revip]['T'])) |
481 | $SpamFilters_DNScache[$filter_revip]['T'] = ''; |
482 | |
a7cd90dd |
483 | if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) { |
484 | $SpamFilters_DNScache[$filter_revip]['L'] = |
485 | gethostbyname($filter_revip); |
486 | $SpamFilters_DNScache[$filter_revip]['T'] = |
487 | time() + $SpamFilters_CacheTTL; |
488 | } |
489 | if ($SpamFilters_DNScache[$filter_revip]['L'] == |
490 | $filters[$key]['result']) { |
491 | return 1; |
4eee5968 |
492 | } |
493 | } |
494 | } |
4eee5968 |
495 | } |
10a26cea |
496 | return 0; |
497 | } |
498 | |
0a1dc88e |
499 | /** |
9c655416 |
500 | * Loads the filters from the user preferences |
501 | * @return array All the user filters |
0a1dc88e |
502 | * @access private |
503 | */ |
10a26cea |
504 | function load_filters() { |
505 | global $data_dir, $username; |
c8a2c24d |
506 | |
10a26cea |
507 | $filters = array(); |
9c655416 |
508 | for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) { |
10a26cea |
509 | $ary = explode(',', $fltr); |
510 | $filters[$i]['where'] = $ary[0]; |
511 | $filters[$i]['what'] = $ary[1]; |
512 | $filters[$i]['folder'] = $ary[2]; |
4eee5968 |
513 | } |
10a26cea |
514 | return $filters; |
515 | } |
516 | |
0a1dc88e |
517 | /** |
9c655416 |
518 | * Loads the Spam Filters and checks the preferences for the enabled status |
519 | * @return array All the spam filters |
0a1dc88e |
520 | * @access private |
521 | */ |
10a26cea |
522 | function load_spam_filters() { |
51199e7a |
523 | global $data_dir, $username, $SpamFilters_ShowCommercial; |
524 | |
525 | if ($SpamFilters_ShowCommercial) { |
526 | $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl'; |
527 | $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List'; |
528 | $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/'; |
529 | $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org'; |
530 | $filters['MAPS RBL']['result'] = '127.0.0.2'; |
531 | $filters['MAPS RBL']['comment'] = |
532 | _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from."); |
533 | |
534 | $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss'; |
535 | $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper'; |
536 | $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/'; |
537 | $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org'; |
538 | $filters['MAPS RSS']['result'] = '127.0.0.2'; |
539 | $filters['MAPS RSS']['comment'] = |
99aaff8b |
540 | _("COMMERCIAL - Servers that are configured (or misconfigured) to allow spam to be relayed through their system will be banned with this. Another good one to use."); |
51199e7a |
541 | |
542 | $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul'; |
543 | $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List'; |
544 | $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/'; |
545 | $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org'; |
546 | $filters['MAPS DUL']['result'] = '127.0.0.3'; |
547 | $filters['MAPS DUL']['comment'] = |
99aaff8b |
548 | _("COMMERCIAL - Dial-up users are often filtered out since they should use their ISP's mail servers to send mail. Spammers typically get a dial-up account and send spam directly from there."); |
51199e7a |
549 | |
550 | $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl'; |
551 | $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List'; |
552 | $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/'; |
553 | $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org'; |
554 | $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2'; |
555 | $filters['MAPS RBLplus-RBL']['comment'] = |
556 | _("COMMERCIAL - RBL+ Blackhole entries."); |
557 | |
558 | $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss'; |
559 | $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries'; |
560 | $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/'; |
561 | $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org'; |
562 | $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2'; |
563 | $filters['MAPS RBLplus-RSS']['comment'] = |
564 | _("COMMERCIAL - RBL+ OpenRelay entries."); |
565 | |
566 | $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul'; |
567 | $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries'; |
568 | $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/'; |
569 | $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org'; |
570 | $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3'; |
571 | $filters['MAPS RBLplus-DUL']['comment'] = |
572 | _("COMMERCIAL - RBL+ Dial-up entries."); |
573 | } |
10a26cea |
574 | |
10a26cea |
575 | $filters['ORDB']['prefname'] = 'filters_spam_ordb'; |
576 | $filters['ORDB']['name'] = 'Open Relay Database List'; |
577 | $filters['ORDB']['link'] = 'http://www.ordb.org/'; |
578 | $filters['ORDB']['dns'] = 'relays.ordb.org'; |
579 | $filters['ORDB']['result'] = '127.0.0.2'; |
580 | $filters['ORDB']['comment'] = |
581 | _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though."); |
582 | |
10a26cea |
583 | $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src'; |
584 | $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources'; |
585 | $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
586 | $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com'; |
587 | $filters['FiveTen Direct']['result'] = '127.0.0.2'; |
588 | $filters['FiveTen Direct']['comment'] = |
589 | _("FREE - Five-Ten-sg.com - Direct SPAM sources."); |
590 | |
591 | $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul'; |
592 | $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists'; |
593 | $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
594 | $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com'; |
595 | $filters['FiveTen DUL']['result'] = '127.0.0.3'; |
596 | $filters['FiveTen DUL']['comment'] = |
597 | _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs."); |
598 | |
599 | $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi'; |
600 | $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists'; |
601 | $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
602 | $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com'; |
603 | $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4'; |
604 | $filters['FiveTen Unc. OptIn']['comment'] = |
605 | _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in."); |
606 | |
607 | $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth'; |
608 | $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers'; |
609 | $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
610 | $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com'; |
611 | $filters['FiveTen Others']['result'] = '127.0.0.5'; |
612 | $filters['FiveTen Others']['comment'] = |
613 | _("FREE - Five-Ten-sg.com - Other misc. servers."); |
614 | |
615 | $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss'; |
616 | $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers'; |
617 | $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
618 | $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com'; |
619 | $filters['FiveTen Single Stage']['result'] = '127.0.0.6'; |
620 | $filters['FiveTen Single Stage']['comment'] = |
621 | _("FREE - Five-Ten-sg.com - Single Stage servers."); |
622 | |
623 | $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp'; |
624 | $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers'; |
625 | $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
626 | $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com'; |
627 | $filters['FiveTen SPAM Support']['result'] = '127.0.0.7'; |
628 | $filters['FiveTen SPAM Support']['comment'] = |
629 | _("FREE - Five-Ten-sg.com - SPAM Support servers."); |
630 | |
631 | $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf'; |
632 | $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs'; |
633 | $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
634 | $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com'; |
635 | $filters['FiveTen Web forms']['result'] = '127.0.0.8'; |
636 | $filters['FiveTen Web forms']['comment'] = |
637 | _("FREE - Five-Ten-sg.com - Web Form IPs."); |
638 | |
639 | $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks'; |
640 | $filters['Dorkslayers']['name'] = 'Dorkslayers Lists'; |
641 | $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com'; |
642 | $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com'; |
643 | $filters['Dorkslayers']['result'] = '127.0.0.2'; |
644 | $filters['Dorkslayers']['comment'] = |
645 | _("FREE - Dorkslayers appears to include only really bad open relays outside the US to avoid being sued. Interestingly enough, their website recommends you NOT use their service."); |
646 | |
647 | $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus'; |
648 | $filters['SPAMhaus']['name'] = 'SPAMhaus Lists'; |
649 | $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org'; |
650 | $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org'; |
651 | $filters['SPAMhaus']['result'] = '127.0.0.6'; |
652 | $filters['SPAMhaus']['comment'] = |
653 | _("FREE - SPAMhaus - A list of well-known SPAM sources."); |
654 | |
655 | $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop'; |
656 | $filters['SPAMcop']['name'] = 'SPAM Cop Lists'; |
657 | $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml'; |
658 | $filters['SPAMcop']['dns'] = 'bl.spamcop.net'; |
659 | $filters['SPAMcop']['result'] = '127.0.0.2'; |
660 | $filters['SPAMcop']['comment'] = |
ace4e0d3 |
661 | _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more)."); |
10a26cea |
662 | |
46a184ff |
663 | $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull'; |
664 | $filters['dev.null.dk']['name'] = 'dev.null.dk Lists'; |
665 | $filters['dev.null.dk']['link'] = 'http://dev.null.dk/'; |
666 | $filters['dev.null.dk']['dns'] = 'dev.null.dk'; |
667 | $filters['dev.null.dk']['result'] = '127.0.0.2'; |
668 | $filters['dev.null.dk']['comment'] = |
669 | _("FREE - dev.null.dk - I don't have any detailed info on this list."); |
670 | |
671 | $filters['visi.com']['prefname'] = 'filters_spam_visi'; |
672 | $filters['visi.com']['name'] = 'visi.com Relay Stop List'; |
673 | $filters['visi.com']['link'] = 'http://relays.visi.com'; |
674 | $filters['visi.com']['dns'] = 'relays.visi.com'; |
675 | $filters['visi.com']['result'] = '127.0.0.2'; |
676 | $filters['visi.com']['comment'] = |
677 | _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List."); |
678 | |
bd35ab2b |
679 | $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or'; |
680 | $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List'; |
681 | $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/'; |
682 | $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org'; |
683 | $filters['ahbl.org Open Relays']['result'] = '127.0.0.2'; |
684 | $filters['ahbl.org Open Relays']['comment'] = |
685 | _("FREE - ahbl.org Open Relays - Another list of Open Relays."); |
686 | |
687 | $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss'; |
688 | $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List'; |
689 | $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/'; |
690 | $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org'; |
691 | $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4'; |
692 | $filters['ahbl.org SPAM Source']['comment'] = |
693 | _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources."); |
694 | |
695 | $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp'; |
696 | $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List'; |
697 | $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/'; |
698 | $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org'; |
699 | $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7'; |
700 | $filters['ahbl.org SPAM ISPs']['comment'] = |
701 | _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs."); |
46a184ff |
702 | |
703 | $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul'; |
704 | $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List'; |
705 | $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/'; |
706 | $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net'; |
707 | $filters['Leadmon DUL']['result'] = '127.0.0.2'; |
708 | $filters['Leadmon DUL']['comment'] = |
709 | _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs."); |
710 | |
711 | $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss'; |
712 | $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List'; |
713 | $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/'; |
714 | $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net'; |
715 | $filters['Leadmon SPAM Source']['result'] = '127.0.0.3'; |
716 | $filters['Leadmon SPAM Source']['comment'] = |
717 | _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from."); |
718 | |
719 | $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm'; |
720 | $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List'; |
721 | $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/'; |
722 | $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net'; |
723 | $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4'; |
724 | $filters['Leadmon Bulk Mailers']['comment'] = |
725 | _("FREE - Leadmon Bulk Mailers - Bulk mailers that do not require confirmed opt-in or that have allowed known spammers to become clients and abuse their services."); |
726 | |
727 | $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or'; |
728 | $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List'; |
729 | $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/'; |
730 | $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net'; |
731 | $filters['Leadmon Open Relays']['result'] = '127.0.0.5'; |
732 | $filters['Leadmon Open Relays']['comment'] = |
733 | _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs."); |
734 | |
735 | $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms'; |
736 | $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List'; |
737 | $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/'; |
738 | $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net'; |
739 | $filters['Leadmon Multi-stage']['result'] = '127.0.0.6'; |
740 | $filters['Leadmon Multi-stage']['comment'] = |
741 | _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net."); |
742 | |
743 | $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb'; |
744 | $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List'; |
745 | $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/'; |
746 | $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net'; |
747 | $filters['Leadmon SpamBlock']['result'] = '127.0.0.7'; |
748 | $filters['Leadmon SpamBlock']['comment'] = |
749 | _("FREE - Leadmon SpamBlock - Sites on this listing have sent Leadmon.net direct SPAM from IPs in netblocks where the entire block has no DNS mappings. It's a list of BLOCKS of IPs being used by people who have SPAMmed Leadmon.net."); |
750 | |
751 | $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or'; |
752 | $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List'; |
753 | $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/'; |
754 | $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org'; |
755 | $filters['NJABL Open Relays']['result'] = '127.0.0.2'; |
756 | $filters['NJABL Open Relays']['comment'] = |
757 | _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources."); |
758 | |
759 | $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul'; |
760 | $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List'; |
761 | $filters['NJABL DUL']['link'] = 'http://www.njabl.org/'; |
762 | $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org'; |
763 | $filters['NJABL DUL']['result'] = '127.0.0.3'; |
764 | $filters['NJABL DUL']['comment'] = |
765 | _("FREE, for now - Not Just Another Blacklist - Dial-up IPs."); |
766 | |
18b078e9 |
767 | $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss'; |
768 | $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List'; |
769 | $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/'; |
770 | $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org'; |
771 | $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2'; |
772 | $filters['Conf DSBL.ORG Relay']['comment'] = |
773 | _("FREE - Distributed Sender Boycott List - Confirmed Relays"); |
774 | |
775 | $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms'; |
776 | $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List'; |
777 | $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/'; |
778 | $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org'; |
779 | $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2'; |
780 | $filters['Conf DSBL.ORG Multi-Stage']['comment'] = |
781 | _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays"); |
782 | |
783 | $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc'; |
784 | $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List'; |
785 | $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/'; |
786 | $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org'; |
787 | $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2'; |
788 | $filters['UN-Conf DSBL.ORG']['comment'] = |
789 | _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays"); |
790 | |
10a26cea |
791 | foreach ($filters as $Key => $Value) { |
9c655416 |
792 | $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']); |
4eee5968 |
793 | } |
794 | |
10a26cea |
795 | return $filters; |
796 | } |
4eee5968 |
797 | |
0a1dc88e |
798 | /** |
9c655416 |
799 | * Removes a User filter |
800 | * @param int $id ID of the filter to remove |
0a1dc88e |
801 | * @access private |
802 | */ |
10a26cea |
803 | function remove_filter ($id) { |
804 | global $data_dir, $username; |
4eee5968 |
805 | |
9c655416 |
806 | while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id + 1))) { |
10a26cea |
807 | setPref($data_dir, $username, 'filter' . $id, $nextFilter); |
808 | $id ++; |
4eee5968 |
809 | } |
810 | |
10a26cea |
811 | removePref($data_dir, $username, 'filter' . $id); |
812 | } |
4eee5968 |
813 | |
0a1dc88e |
814 | /** |
9c655416 |
815 | * Swaps two filters |
816 | * @param int $id1 ID of first filter to swap |
817 | * @param int $id2 ID of second filter to swap |
0a1dc88e |
818 | * @access private |
819 | */ |
10a26cea |
820 | function filter_swap($id1, $id2) { |
821 | global $data_dir, $username; |
4eee5968 |
822 | |
10a26cea |
823 | $FirstFilter = getPref($data_dir, $username, 'filter' . $id1); |
824 | $SecondFilter = getPref($data_dir, $username, 'filter' . $id2); |
825 | |
826 | if ($FirstFilter && $SecondFilter) { |
827 | setPref($data_dir, $username, 'filter' . $id2, $FirstFilter); |
828 | setPref($data_dir, $username, 'filter' . $id1, $SecondFilter); |
4eee5968 |
829 | } |
10a26cea |
830 | } |
4eec80a7 |
831 | |
0a1dc88e |
832 | /** |
9c655416 |
833 | * This updates the filter rules when renaming or deleting folders |
0a1dc88e |
834 | * @param array $args |
b2d8bc6c |
835 | * @access private |
0a1dc88e |
836 | */ |
f5ab1fb9 |
837 | function update_for_folder ($args) { |
9c655416 |
838 | |
839 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
840 | |
f5ab1fb9 |
841 | $old_folder = $args[0]; |
9c655416 |
842 | $new_folder = $args[2]; |
843 | $action = $args[1]; |
ce68b76b |
844 | global $data_dir, $username; |
4eec80a7 |
845 | $filters = array(); |
846 | $filters = load_filters(); |
847 | $filter_count = count($filters); |
848 | $p = 0; |
9c655416 |
849 | for ($i = 0; $i < $filter_count; $i++) { |
4eec80a7 |
850 | if (!empty($filters)) { |
851 | if ($old_folder == $filters[$i]['folder']) { |
852 | if ($action == 'rename') { |
853 | $filters[$i]['folder'] = $new_folder; |
854 | setPref($data_dir, $username, 'filter'.$i, |
855 | $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder); |
856 | } |
857 | elseif ($action == 'delete') { |
858 | remove_filter($p); |
859 | $p = $p-1; |
860 | } |
861 | } |
862 | $p++; |
863 | } |
864 | } |
865 | } |
0a1dc88e |
866 | |
0a1dc88e |
867 | /** |
868 | * Display formated error message |
869 | * @param string $string text message |
870 | * @return string html formated text message |
871 | * @access private |
872 | */ |
873 | function do_error($string) { |
874 | global $color; |
875 | echo "<p align=\"center\"><font color=\"$color[2]\">"; |
876 | echo $string; |
877 | echo "</font></p>\n"; |
878 | } |
9c655416 |
879 | |
880 | ?> |