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