3 * Message and Spam Filter Plugin - Filtering Options
6 * @copyright (c) 1999-2005 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * Path for SquirrelMail required files.
16 define('SM_PATH','../../');
18 /* SquirrelMail required files. */
19 require_once(SM_PATH
. 'include/validate.php');
20 require_once(SM_PATH
. 'functions/imap.php');
21 require_once(SM_PATH
. 'plugins/filters/filters.php');
23 if (!file_exists(SM_PATH
. 'plugins/filters/config.php')) return;
24 include_once (SM_PATH
. 'plugins/filters/config.php');
26 global $AllowSpamFilters;
28 displayPageHeader($color, 'None');
31 sqgetGlobalVar('username', $username, SQ_SESSION
);
32 sqgetGlobalVar('key', $key, SQ_COOKIE
);
33 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
34 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
36 sqgetGlobalVar('theid', $theid);
37 sqgetGlobalVar('action', $action, SQ_GET
);
39 if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST
)) {
41 if(! isset($theid) ) $theid = 0;
45 // FIXME: write human readable error messages
46 sqgetGlobalVar('filter_what', $filter_what, SQ_POST
);
47 if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST
)) {
48 do_error("Post error");
52 sqgetGlobalVar('filter_where', $filter_where, SQ_POST
);
53 if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST
)) {
54 do_error("Post error");
58 sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
);
59 if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
)) {
60 do_error("Post error");
65 $filter_what = str_replace(',', ' ', $filter_what);
66 $filter_what = str_replace("\\\\", "\\", $filter_what);
67 $filter_what = str_replace("\\\"", '"', $filter_what);
68 $filter_what = str_replace('"', '"', $filter_what);
70 if (empty($filter_what)) {
71 do_error(_("WARNING! You must enter something to search for."));
75 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
76 do_error(_("WARNING! Header filters should be of the format "Header: value""));
79 if ($action != 'edit') {
80 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
82 $filters[$theid]['where'] = $filter_where;
83 $filters[$theid]['what'] = $filter_what;
84 $filters[$theid]['folder'] = $filter_folder;
86 } elseif (isset($action) && $action == 'delete') {
87 remove_filter($theid);
88 } elseif (isset($action) && $action == 'move_up') {
89 filter_swap($theid, $theid - 1);
90 } elseif (isset($action) && $action == 'move_down') {
91 filter_swap($theid, $theid +
1);
92 } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST
)) {
93 sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST
);
94 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
95 echo '<br /><center><b>'._("Saved Scan type")."</b></center>\n";
98 $filters = load_filters();
99 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
101 echo html_tag( 'table',
104 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' ,
108 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
110 '<br /><form method="post" action="options.php">'.
112 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
114 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
115 html_tag( 'td', '', 'left' ) .
116 '<select name="filters_user_scan_set">'.
118 if ($filters_user_scan == '') {
119 echo ' selected="selected"';
121 echo '>' . _("All messages") . '</option>'.
122 '<option value="new"';
123 if ($filters_user_scan == 'new') {
124 echo ' selected="selected"';
126 echo '>' . _("Only unread messages") . '</option>' .
129 html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
134 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
135 '</a>] - [<a href="'.SM_PATH
.'src/options.php">' . _("Done") . '</a>]' ,
136 'center' ) . '<br />';
138 if (isset($action) && ($action == 'add' ||
$action == 'edit')) {
140 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
141 $boxes = sqimap_mailbox_list($imapConnection);
143 for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++
) {
144 if (strtolower($boxes[$a]['formatted']) == 'inbox') {
149 sqimap_logout($imapConnection);
150 if ( !isset($theid) ) {
151 $theid = count($filters);
153 echo html_tag( 'div', '', 'center' ) .
154 '<form action="options.php" method="post">'.
155 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
157 html_tag( 'td', _("Match:"), 'left' ) .
158 html_tag( 'td', '', 'left' ) .
159 '<select name="filter_where">';
161 $L = isset($filters[$theid]['where']);
163 $sel = (($L && $filters[$theid]['where'] == 'From')?
' selected="selected"':'');
164 echo "<option value=\"From\"$sel>" . _("From") . '</option>';
166 $sel = (($L && $filters[$theid]['where'] == 'To')?
' selected="selected"':'');
167 echo "<option value=\"To\"$sel>" . _("To") . '</option>';
169 $sel = (($L && $filters[$theid]['where'] == 'Cc')?
' selected="selected"':'');
170 echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
172 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?
' selected="selected"':'');
173 echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
175 $sel = (($L && $filters[$theid]['where'] == 'Subject')?
' selected="selected"':'');
176 echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
178 $sel = (($L && $filters[$theid]['where'] == 'Message Body')?
' selected="selected"':'');
179 echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>';
181 $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?
' selected="selected"':'');
182 echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>';
184 $sel = (($L && $filters[$theid]['where'] == 'Header')?
' selected="selected"':'');
185 echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
191 html_tag( 'td', _("Contains:"), 'right' ) .
192 html_tag( 'td', '', 'left' ) .
193 '<input type="text" size="32" name="filter_what" value="';
194 if (isset($filters[$theid]['what'])) {
195 echo $filters[$theid]['what'];
201 html_tag( 'td', _("Move to:"), 'left' ) .
202 html_tag( 'td', '', 'left' ) .
204 '<select name="filter_folder">';
206 if ( isset($filters[$theid]['folder']) )
207 $selected = array(strtolower($filters[$theid]['folder']));
208 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
214 '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
215 addHidden('theid', $theid).
221 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
223 for ($i=0, $num = count($filters); $i < $num; $i++
) {
225 $clr = (($i %
2)?
$color[0]:$color[9]);
226 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
227 echo html_tag( 'tr', '', '', $clr ) .
230 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
235 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
240 echo html_tag( 'td', '', 'center' ) . '<small>[';
241 if (isset($filters[$i +
1])) {
242 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
244 echo ' | ';
248 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
250 echo ']</small></td>';
252 echo html_tag( 'td', '-', 'left' ) .
253 html_tag( 'td', '', 'left' );
254 printf( _("If %s contains %s then move to %s"),
255 '<b>'.$filters[$i]['where'].'</b>',
256 '<b>'.$filters[$i]['what'].'</b>',
257 '<b>'.imap_utf7_decode_local($fdr).'</b>');
264 html_tag( 'td', ' ', 'left' )
266 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
267 echo '</body></html>';