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