849bdf42 |
1 | <?php |
15e6162e |
2 | |
3 | /** |
4 | * Message and Spam Filter Plugin |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
15e6162e |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This plugin filters your inbox into different folders based upon given |
10 | * criteria. It is most useful for people who are subscibed to mailing lists |
11 | * to help organize their messages. The argument stands that filtering is |
12 | * not the place of the client, which is why this has been made a plugin for |
13 | * SquirrelMail. You may be better off using products such as Sieve or |
14 | * Procmail to do your filtering so it happens even when SquirrelMail isn't |
15 | * running. |
16 | * |
17 | * If you need help with this, or see improvements that can be made, please |
18 | * email me directly at the address above. I definately welcome suggestions |
19 | * and comments. This plugin, as is the case with all SquirrelMail plugins, |
20 | * is not directly supported by the developers. Please come to me off the |
21 | * mailing list if you have trouble with it. |
22 | * |
23 | * Also view plugins/README.plugins for more information. |
24 | * |
25 | * $Id$ |
26 | */ |
4eee5968 |
27 | |
08185f2a |
28 | /* Path for SquirrelMail required files. */ |
29 | define('SM_PATH','../../'); |
30 | |
31 | /* SquirrelMail required files. */ |
fca6d99e |
32 | require_once(SM_PATH . 'include/validate.php'); |
08185f2a |
33 | require_once(SM_PATH . 'functions/page_header.php'); |
34 | require_once(SM_PATH . 'functions/imap.php'); |
81f652a1 |
35 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
fca6d99e |
36 | require_once(SM_PATH . 'include/load_prefs.php'); |
37 | require_once(SM_PATH . 'plugins/filters/filters.php'); |
849bdf42 |
38 | |
3c66c567 |
39 | global $AllowSpamFilters; |
849bdf42 |
40 | |
3c66c567 |
41 | displayPageHeader($color, 'None'); |
849bdf42 |
42 | |
3c66c567 |
43 | /* get globals */ |
44 | sqgetGlobalVar('username', $username, SQ_SESSION); |
45 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
46 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
47 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
48 | |
49 | sqgetGlobalVar('theid', $theid); |
50 | sqgetGlobalVar('action', $action, SQ_GET); |
51 | |
52 | // FIXME: use sqgetGlobalVar below. |
41100fce |
53 | |
54 | if (isset($_POST['filter_submit'])) { |
55 | if(isset($_GET['theid'])) { |
56 | $theid = $_GET['theid']; |
57 | } elseif (isset($_POST['theid'])) { |
58 | $theid = $_POST['theid']; |
59 | } else { |
60 | $theid = 0; |
61 | } |
62 | $filter_what = $_POST['filter_what']; |
63 | $filter_where = $_POST['filter_where']; |
64 | $filter_folder = $_POST['filter_folder']; |
65 | |
ae48f757 |
66 | $filter_what = str_replace(',', ' ', $filter_what); |
849bdf42 |
67 | $filter_what = str_replace("\\\\", "\\", $filter_what); |
ae48f757 |
68 | $filter_what = str_replace("\\\"", '"', $filter_what); |
69 | $filter_what = str_replace('"', '"', $filter_what); |
849bdf42 |
70 | |
8e485f9b |
71 | if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) { |
72 | print ('WARNING! Header filters should be of the format "Header: value"<BR>'); |
73 | $action = 'edit'; |
74 | } |
ae48f757 |
75 | setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder); |
76 | $filters[$theid]['where'] = $filter_where; |
77 | $filters[$theid]['what'] = $filter_what; |
78 | $filters[$theid]['folder'] = $filter_folder; |
3fd1252d |
79 | } elseif (isset($action) && $action == 'delete') { |
849bdf42 |
80 | remove_filter($theid); |
3fd1252d |
81 | } elseif (isset($action) && $action == 'move_up') { |
849bdf42 |
82 | filter_swap($theid, $theid - 1); |
3fd1252d |
83 | } elseif (isset($action) && $action == 'move_down') { |
849bdf42 |
84 | filter_swap($theid, $theid + 1); |
41100fce |
85 | } elseif (isset($_POST['user_submit'])) { |
86 | setPref($data_dir, $username, 'filters_user_scan', $_POST['filters_user_scan_set']); |
87 | echo '<br><center><b>'._("Saved Scan type")."</b></center>\n"; |
849bdf42 |
88 | } |
89 | |
849bdf42 |
90 | $filters = load_filters(); |
c8a2c24d |
91 | $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan'); |
849bdf42 |
92 | |
6206f6c4 |
93 | echo html_tag( 'table', |
b01b21d0 |
94 | html_tag( 'tr', |
95 | html_tag( 'td', |
96 | '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' , |
97 | 'left', $color[0] ) |
98 | ) , |
99 | 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) . |
c8a2c24d |
100 | |
101 | '<br><form method=post action="options.php">'. |
102 | '<center>'. |
831a25d5 |
103 | html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) . |
b01b21d0 |
104 | html_tag( 'tr' ) . |
105 | html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) . |
106 | html_tag( 'td', '', 'left' ) . |
107 | '<select name="filters_user_scan_set">'. |
c8a2c24d |
108 | '<option value=""'; |
109 | if ($filters_user_scan == '') { |
b01b21d0 |
110 | echo ' selected'; |
c8a2c24d |
111 | } |
112 | echo '>' . _("All messages") . '</option>'. |
113 | '<option value="new"'; |
114 | if ($filters_user_scan == 'new') { |
b01b21d0 |
115 | echo ' selected'; |
c8a2c24d |
116 | } |
117 | echo '>' . _("Only unread messages") . '</option>' . |
118 | '</select>'. |
119 | '</td>'. |
b01b21d0 |
120 | html_tag( 'td', '<input type=submit name="user_submit" value="' . _("Save") . '">', 'left' ) . |
c8a2c24d |
121 | '</table>'. |
122 | '</center>'. |
123 | '</form>'. |
124 | |
b01b21d0 |
125 | html_tag( 'div', '[<a href="options.php?action=add">' . _("New") . |
81f652a1 |
126 | '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' , |
b01b21d0 |
127 | 'center' ) . '<br>'; |
0e838332 |
128 | |
3fd1252d |
129 | if (isset($action) && ($action == 'add' || $action == 'edit')) { |
41100fce |
130 | |
3fd1252d |
131 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
132 | $boxes = sqimap_mailbox_list($imapConnection); |
133 | sqimap_logout($imapConnection); |
134 | if ( !isset($theid) ) { |
849bdf42 |
135 | $theid = count($filters); |
3fd1252d |
136 | } |
b01b21d0 |
137 | echo html_tag( 'div', '', 'center' ) . |
72570d58 |
138 | '<form action="options.php" method=post>'. |
831a25d5 |
139 | html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) . |
b01b21d0 |
140 | html_tag( 'tr' ) . |
141 | html_tag( 'td', _("Match:"), 'left' ) . |
142 | html_tag( 'td', '', 'left' ) . |
4eee5968 |
143 | '<select name=filter_where>'; |
849bdf42 |
144 | |
3fd1252d |
145 | $L = isset($filters[$theid]['where']); |
146 | |
147 | $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':''); |
148 | echo "<option value=\"From\" $sel>" . _ ("From") . '</option>'; |
4eee5968 |
149 | |
3fd1252d |
150 | $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':''); |
151 | echo "<option value=\"To\" $sel>" . _ ("To") . '</option>'; |
152 | |
153 | $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':''); |
154 | echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>'; |
155 | |
156 | $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':''); |
157 | echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>'; |
158 | |
159 | $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':''); |
160 | echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>'; |
161 | |
9da6bdde |
162 | $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':''); |
163 | echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>'; |
164 | |
3fd1252d |
165 | echo '</select>'. |
4eee5968 |
166 | '</td>'. |
167 | '</tr>'. |
b01b21d0 |
168 | html_tag( 'tr' ) . |
169 | html_tag( 'td', _("Contains:"), 'right' ) . |
170 | html_tag( 'td', '', 'left' ) . |
4eee5968 |
171 | '<input type=text size=32 name=filter_what value="'; |
3fd1252d |
172 | if (isset($filters[$theid]['what'])) { |
4eee5968 |
173 | echo $filters[$theid]["what"]; |
3fd1252d |
174 | } |
175 | echo '">'. |
4eee5968 |
176 | '</td>'. |
177 | '</tr>'. |
b01b21d0 |
178 | html_tag( 'tr' ) . |
179 | html_tag( 'td', _("Move to:"), 'left' ) . |
180 | html_tag( 'td', '', 'left' ) . |
4eee5968 |
181 | '<tt>'. |
182 | '<select name=filter_folder>'; |
81f652a1 |
183 | $selected = 0; |
184 | if ( isset($filters[$theid]['folder']) ) |
185 | $selected = array(strtolower($filters[$theid]['folder'])); |
186 | echo sqimap_mailbox_option_list(0, $selected, 0, $boxes); |
3fd1252d |
187 | echo '</tt>'. |
4eee5968 |
188 | '</select>'. |
189 | '</td>'. |
190 | '</tr>'. |
3fd1252d |
191 | '</table>'. |
192 | '<input type=submit name=filter_submit value=' . _("Submit") . '>'. |
193 | "<input type=hidden name=theid value=$theid>". |
194 | '</form>'. |
b01b21d0 |
195 | '</div>'; |
3fd1252d |
196 | |
3fd1252d |
197 | } |
cb2ccf4b |
198 | |
831a25d5 |
199 | echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' ); |
cb2ccf4b |
200 | |
ae48f757 |
201 | for ($i=0, $num = count($filters); $i < $num; $i++) { |
cb2ccf4b |
202 | |
203 | $clr = (($i % 2)?$color[0]:$color[9]); |
204 | $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"]; |
831a25d5 |
205 | echo html_tag( 'tr', '', '', $clr ) . |
b01b21d0 |
206 | html_tag( 'td', |
207 | '<small>' . |
208 | "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'. |
209 | '</small>' , |
210 | 'left' ) . |
211 | html_tag( 'td', |
212 | '<small>' . |
213 | "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'. |
214 | '</small>' , |
215 | 'left' ) . |
216 | html_tag( 'td', '', 'center' ) . '<small>['; |
cb2ccf4b |
217 | |
218 | if (isset($filters[$i + 1])) { |
219 | echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>'; |
220 | if ($i > 0) { |
2a61e066 |
221 | echo ' | '; |
cb2ccf4b |
222 | } |
223 | } |
224 | if ($i > 0) { |
225 | echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>'; |
226 | } |
b01b21d0 |
227 | echo ']</small></td>'. |
228 | html_tag( 'td', '-', 'left' ) . |
229 | html_tag( 'td', '', 'left' ); |
cb2ccf4b |
230 | printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr ); |
231 | echo '</td></tr>'; |
232 | |
233 | } |
234 | echo '</table>'. |
b01b21d0 |
235 | html_tag( 'table', |
236 | html_tag( 'tr', |
8e724112 |
237 | html_tag( 'td', ' ', 'left' ) |
b01b21d0 |
238 | ) , |
239 | 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' ); |
4eee5968 |
240 | ?> |