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