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