849bdf42 |
1 | <?php |
15e6162e |
2 | /** |
3 | * Message and Spam Filter Plugin |
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 | */ |
849bdf42 |
28 | |
ea5f4b8e |
29 | /** SquirrelMail required files. */ |
08185f2a |
30 | require_once(SM_PATH . 'plugins/filters/filters.php'); |
31 | |
0a1dc88e |
32 | /** |
33 | * Imap connection control |
34 | * |
10a26cea |
35 | * Set this to true if you have problems -- check the README file |
36 | * Note: This doesn't work all of the time (No idea why) |
37 | * Seems to be related to UW |
0a1dc88e |
38 | * @global bool $UseSeparateImapConnection |
10a26cea |
39 | */ |
40 | global $UseSeparateImapConnection; |
41 | $UseSeparateImapConnection = false; |
3fd1252d |
42 | |
0a1dc88e |
43 | /** |
44 | * User level spam filters control |
45 | * |
10a26cea |
46 | * Set this to false if you do not want the user to be able to enable |
47 | * spam filters |
0a1dc88e |
48 | * @global bool $AllowSpamFilters |
10a26cea |
49 | */ |
50 | global $AllowSpamFilters; |
51 | $AllowSpamFilters = true; |
3fd1252d |
52 | |
0a1dc88e |
53 | /** |
54 | * SpamFilters YourHop Setting |
55 | * |
10a26cea |
56 | * Set this to a string containing something unique to the line in the |
57 | * header you want me to find IPs to scan the databases with. For example, |
58 | * All the email coming IN from the internet to my site has a line in |
59 | * the header that looks like (all on one line): |
60 | * Received: [from usw-sf-list1.sourceforge.net (usw-sf-fw2.sourceforge.net |
61 | * [216.136.171.252]) by firewall.persistence.com (SYSADMIN-antispam |
62 | * 0.2) with |
63 | * Since this line indicates the FIRST hop the email takes into my network, |
64 | * I set my SpamFilters_YourHop to 'by firewall.persistence.com' but any |
65 | * case-sensitive string will do. You can set it to something found on |
66 | * every line in the header (like ' ') if you want to scan all IPs in |
67 | * the header (lots of false alarms here tho). |
0a1dc88e |
68 | * @global string $SpamFilters_YourHop |
10a26cea |
69 | */ |
70 | global $SpamFilters_YourHop; |
71 | $SpamFilters_YourHop = ' '; |
849bdf42 |
72 | |
0a1dc88e |
73 | /** |
74 | * Commercial Spam Filters Control |
75 | * |
51199e7a |
76 | * Some of the SPAM filters are COMMERCIAL and require a fee. If your users |
77 | * select them and you're not allowed to use them, it will make SPAM filtering |
78 | * very slow. If you don't want them to even be offered to the users, you |
a2a566eb |
79 | * should set SpamFilters_ShowCommercial to false. |
0a1dc88e |
80 | * @global bool $SpamFilters_ShowCommercial |
51199e7a |
81 | */ |
82 | global $SpamFilters_ShowCommercial; |
a2a566eb |
83 | $SpamFilters_ShowCommercial = false; |
51199e7a |
84 | |
0a1dc88e |
85 | /** |
86 | * SpamFiltring Cache |
87 | * |
10a26cea |
88 | * A cache of IPs we've already checked or are known bad boys or good boys |
89 | * ie. $SpamFilters_DNScache["210.54.220.18"] = true; |
90 | * would tell filters to not even bother doing the DNS queries for that |
91 | * IP and any email coming from it are SPAM - false would mean that any |
92 | * email coming from it would NOT be SPAM |
0a1dc88e |
93 | * @global array $SpamFilters_DNScache |
10a26cea |
94 | */ |
95 | global $SpamFilters_DNScache; |
849bdf42 |
96 | |
0a1dc88e |
97 | /** |
98 | * Path to bulkquery program |
99 | * |
a2a566eb |
100 | * Absolute path to the bulkquery program. Leave blank if you don't have |
101 | * bulkquery compiled, installed, and lwresd running. See the README file |
102 | * in the bulkquery directory for more information on using bulkquery. |
0a1dc88e |
103 | * @global string $SpamFilters_BulkQuery |
a2a566eb |
104 | */ |
105 | global $SpamFilters_BulkQuery; |
ae48f757 |
106 | $SpamFilters_BulkQuery = ''; |
a2a566eb |
107 | |
0a1dc88e |
108 | /** |
109 | * Shared filtering cache control |
110 | * |
a2a566eb |
111 | * Do you want to use a shared file for the DNS cache or a session variable? |
112 | * Using a shared file means that every user can benefit from any queries |
113 | * made by other users. The shared file is named "dnscache" and is in the |
114 | * data directory. |
0a1dc88e |
115 | * @global bool $SpamFilters_SharedCache |
a2a566eb |
116 | */ |
117 | global $SpamFilters_SharedCache; |
118 | $SpamFilters_SharedCache = true; |
119 | |
0a1dc88e |
120 | /** |
121 | * DNS query TTL |
122 | * |
a2a566eb |
123 | * How long should DNS query results be cached for by default (in seconds)? |
0a1dc88e |
124 | * @global integer $SpamFilters_CacheTTL |
a2a566eb |
125 | */ |
126 | global $SpamFilters_CacheTTL; |
127 | $SpamFilters_CacheTTL = 7200; |
128 | |
0a1dc88e |
129 | /** |
130 | * Init plugin |
131 | * @access private |
132 | */ |
10a26cea |
133 | function squirrelmail_plugin_init_filters() { |
134 | global $squirrelmail_plugin_hooks; |
41100fce |
135 | |
0a1dc88e |
136 | if (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM)) { |
137 | sqgetGlobalVar('mailbox',$mailbox,SQ_FORM); |
138 | } else { |
41100fce |
139 | $mailbox = 'INBOX'; |
140 | } |
849bdf42 |
141 | |
10a26cea |
142 | $squirrelmail_plugin_hooks['left_main_before']['filters'] = 'start_filters'; |
41100fce |
143 | if (isset($mailbox) && $mailbox == 'INBOX') { |
10a26cea |
144 | $squirrelmail_plugin_hooks['right_main_after_header']['filters'] = 'start_filters'; |
145 | } |
f1b526cd |
146 | $squirrelmail_plugin_hooks['optpage_register_block']['filters'] = 'filters_optpage_register_block'; |
c3fe0644 |
147 | $squirrelmail_plugin_hooks['special_mailbox']['filters'] = 'filters_special_mailbox'; |
f5ab1fb9 |
148 | $squirrelmail_plugin_hooks['rename_or_delete_folder']['filters'] = 'update_for_folder'; |
753ce838 |
149 | $squirrelmail_plugin_hooks['webmail_bottom']['filters'] = 'start_filters'; |
10a26cea |
150 | } |
a2a566eb |
151 | |
0a1dc88e |
152 | /** |
153 | * Report spam folter as special mailbox |
154 | * @param string $mb variable used by hook |
155 | * @return string spam folder name |
156 | * @access private |
157 | */ |
10a26cea |
158 | function filters_special_mailbox( $mb ) { |
0a1dc88e |
159 | global $data_dir, $username; |
2586d588 |
160 | |
10a26cea |
161 | return( $mb == getPref($data_dir, $username, 'filters_spam_folder', 'na' ) ); |
2586d588 |
162 | |
10a26cea |
163 | } |
849bdf42 |
164 | |
0a1dc88e |
165 | /** |
166 | * Register option blocks |
167 | * @access private |
168 | */ |
f1b526cd |
169 | function filters_optpage_register_block() { |
10a26cea |
170 | global $optpage_blocks; |
171 | global $AllowSpamFilters; |
849bdf42 |
172 | |
10a26cea |
173 | $optpage_blocks[] = array( |
174 | 'name' => _("Message Filters"), |
175 | 'url' => '../plugins/filters/options.php', |
176 | 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."), |
177 | 'js' => false |
178 | ); |
eec81600 |
179 | |
10a26cea |
180 | if ($AllowSpamFilters) { |
181 | $optpage_blocks[] = array( |
eec81600 |
182 | 'name' => _("SPAM Filters"), |
183 | 'url' => '../plugins/filters/spamoptions.php', |
184 | '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)."), |
185 | 'js' => false |
10a26cea |
186 | ); |
187 | } |
188 | } |
c528d955 |
189 | ?> |