4 * Message and Spam Filter Plugin - Filtering Options
6 * @copyright © 1999-2006 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 * Include the SquirrelMail initialization file.
16 require('../../include/init.php');
17 include_once(SM_PATH
. 'functions/imap_general.php');
18 include_once(SM_PATH
. 'functions/forms.php');
19 include_once(SM_PATH
. 'plugins/filters/filters.php');
21 displayPageHeader($color, 'None');
24 sqgetGlobalVar('username', $username, SQ_SESSION
);
25 sqgetGlobalVar('key', $key, SQ_COOKIE
);
26 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
27 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
29 sqgetGlobalVar('theid', $theid);
30 sqgetGlobalVar('action', $action, SQ_GET
);
32 if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST
)) {
34 if(! isset($theid) ) $theid = 0;
38 // FIXME: write human readable error messages
39 sqgetGlobalVar('filter_what', $filter_what, SQ_POST
);
40 if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST
)) {
41 do_error("Post error");
45 sqgetGlobalVar('filter_where', $filter_where, SQ_POST
);
46 if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST
)) {
47 do_error("Post error");
51 sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
);
52 if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
)) {
53 do_error("Post error");
58 $filter_what = str_replace(',', ' ', $filter_what);
59 $filter_what = str_replace("\\\\", "\\", $filter_what);
60 $filter_what = str_replace("\\\"", '"', $filter_what);
61 $filter_what = str_replace('"', '"', $filter_what);
63 if (empty($filter_what)) {
64 do_error(_("WARNING! You must enter something to search for."));
68 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
69 do_error(_("WARNING! Header filters should be of the format "Header: value""));
72 if ($action != 'edit') {
73 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
75 $filters[$theid]['where'] = $filter_where;
76 $filters[$theid]['what'] = $filter_what;
77 $filters[$theid]['folder'] = $filter_folder;
79 } elseif (isset($action) && $action == 'delete') {
80 remove_filter($theid);
81 } elseif (isset($action) && $action == 'move_up') {
82 filter_swap($theid, $theid - 1);
83 } elseif (isset($action) && $action == 'move_down') {
84 filter_swap($theid, $theid +
1);
85 } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST
)) {
86 sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST
);
87 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
88 echo '<br /><div style="text-align: center;"><b>'._("Saved Scan type")."</b></div>\n";
91 $filters = load_filters();
92 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
94 echo html_tag( 'table',
97 '<div style="text-align: center;"><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></div>' ,
101 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
103 '<br /><form method="post" action="options.php">'.
104 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
106 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
107 html_tag( 'td', '', 'left' ) .
108 '<select name="filters_user_scan_set">'.
110 if ($filters_user_scan == '') {
111 echo ' selected="selected"';
113 echo '>' . _("All messages") . '</option>'.
114 '<option value="new"';
115 if ($filters_user_scan == 'new') {
116 echo ' selected="selected"';
118 echo '>' . _("Only unread messages") . '</option>' .
121 html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
125 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
126 '</a>] - [<a href="'.SM_PATH
.'src/options.php">' . _("Done") . '</a>]' ,
127 'center' ) . '<br />';
129 if (isset($action) && ($action == 'add' ||
$action == 'edit')) {
131 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
132 $boxes = sqimap_mailbox_list($imapConnection);
134 for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++
) {
135 if (strtolower($boxes[$a]['formatted']) == 'inbox') {
140 sqimap_logout($imapConnection);
141 if ( !isset($theid) ) {
142 $theid = count($filters);
144 echo html_tag( 'div', '', 'center' ) .
145 '<form action="options.php" method="post">'.
146 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
148 html_tag( 'td', _("Match:"), 'left' ) .
149 html_tag( 'td', '', 'left' ) .
150 '<select name="filter_where">';
152 $L = isset($filters[$theid]['where']);
154 $sel = (($L && $filters[$theid]['where'] == 'From')?
' selected="selected"':'');
155 echo "<option value=\"From\"$sel>" . _("From") . '</option>';
157 $sel = (($L && $filters[$theid]['where'] == 'To')?
' selected="selected"':'');
158 echo "<option value=\"To\"$sel>" . _("To") . '</option>';
160 $sel = (($L && $filters[$theid]['where'] == 'Cc')?
' selected="selected"':'');
161 echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
163 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?
' selected="selected"':'');
164 echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
166 $sel = (($L && $filters[$theid]['where'] == 'Subject')?
' selected="selected"':'');
167 echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
169 $sel = (($L && $filters[$theid]['where'] == 'Message Body')?
' selected="selected"':'');
170 echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>';
172 $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?
' selected="selected"':'');
173 echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>';
175 $sel = (($L && $filters[$theid]['where'] == 'Header')?
' selected="selected"':'');
176 echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
182 html_tag( 'td', _("Contains:"), 'right' ) .
183 html_tag( 'td', '', 'left' ) .
184 '<input type="text" size="32" name="filter_what" value="';
185 if (isset($filters[$theid]['what'])) {
186 echo htmlspecialchars($filters[$theid]['what']);
192 html_tag( 'td', _("Move to:"), 'left' ) .
193 html_tag( 'td', '', 'left' ) .
195 '<select name="filter_folder">';
197 if ( isset($filters[$theid]['folder']) )
198 $selected = array(strtolower($filters[$theid]['folder']));
199 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
205 '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
206 addHidden('theid', $theid).
212 if (count($filters)) {
213 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
215 for ($i=0, $num = count($filters); $i < $num; $i++
) {
217 $clr = (($i %
2)?
$color[0]:$color[9]);
218 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
219 echo html_tag( 'tr', '', '', $clr ) .
222 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
227 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
232 echo html_tag( 'td', '', 'center' ) . '<small>[';
233 if (isset($filters[$i +
1])) {
234 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
236 echo ' | ';
240 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
242 echo ']</small></td>';
244 echo html_tag( 'td', '-', 'left' ) .
245 html_tag( 'td', '', 'left' );
246 printf( _("If %s contains %s then move to %s"),
247 '<b>'.$filters[$i]['where'].'</b>',
248 '<b>'.$filters[$i]['what'].'</b>',
249 '<b>'.htmlspecialchars(imap_utf7_decode_local($fdr)).'</b>');
255 echo html_tag( 'table',
257 html_tag( 'td', ' ', 'left' )
259 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
260 echo '</body></html>';