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