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