39b47beec40b9b234a0b4f15081b660584e40a41
4 * Message and Spam Filter Plugin - Filtering Options
6 * @copyright © 1999-2009 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);
24 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
26 sqgetGlobalVar('theid', $theid);
27 sqgetGlobalVar('action', $action, SQ_GET
);
29 if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST
)) {
31 if(! isset($theid) ) $theid = 0;
35 // FIXME: write human readable error messages
36 sqgetGlobalVar('filter_what', $filter_what, SQ_POST
);
37 if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST
)) {
38 do_error("Post error");
42 sqgetGlobalVar('filter_where', $filter_where, SQ_POST
);
43 if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST
)) {
44 do_error("Post error");
48 sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
);
49 if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
)) {
50 do_error("Post error");
55 $filter_what = str_replace(',', '###COMMA###', $filter_what);
56 $filter_what = str_replace("\\\\", "\\", $filter_what);
57 $filter_what = str_replace("\\\"", '"', $filter_what);
58 $filter_what = str_replace('"', '"', $filter_what);
60 if (empty($filter_what)) {
61 do_error(_("WARNING! You must enter something to search for."));
65 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
66 do_error(_("WARNING! Header filters should be of the format "Header: value""));
69 if ($action != 'edit') {
70 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
72 $filters[$theid]['where'] = $filter_where;
73 $filters[$theid]['what'] = $filter_what;
74 $filters[$theid]['folder'] = $filter_folder;
76 } elseif (isset($action) && $action == 'delete') {
77 remove_filter($theid);
78 } elseif (isset($action) && $action == 'move_up') {
79 filter_swap($theid, $theid - 1);
80 } elseif (isset($action) && $action == 'move_down') {
81 filter_swap($theid, $theid +
1);
82 } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST
)) {
83 sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST
);
84 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
85 echo '<br /><div style="text-align: center;"><b>'._("Saved Scan type")."</b></div>\n";
88 $filters = load_filters();
89 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
91 echo html_tag( 'table',
94 '<div style="text-align: center;"><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></div>' ,
98 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
100 '<br /><form method="post" action="options.php">'.
101 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
103 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
104 html_tag( 'td', '', 'left' ) .
105 '<select name="filters_user_scan_set">'.
107 if ($filters_user_scan == '') {
108 echo ' selected="selected"';
110 echo '>' . _("All messages") . '</option>'.
111 '<option value="new"';
112 if ($filters_user_scan == 'new') {
113 echo ' selected="selected"';
115 echo '>' . _("Only unread messages") . '</option>' .
118 html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
122 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
123 '</a>] - [<a href="'.SM_PATH
.'src/options.php">' . _("Done") . '</a>]' ,
124 'center' ) . '<br />';
126 if (isset($action) && ($action == 'add' ||
$action == 'edit')) {
128 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
129 $boxes = sqimap_mailbox_list($imapConnection);
131 for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++
) {
132 if (strtolower($boxes[$a]['formatted']) == 'inbox') {
137 sqimap_logout($imapConnection);
138 if ( !isset($theid) ) {
139 $theid = count($filters);
141 echo html_tag( 'div', '', 'center' ) .
142 '<form action="options.php" method="post">'.
143 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
145 html_tag( 'td', _("Match:"), 'left' ) .
146 html_tag( 'td', '', 'left' ) .
147 '<select name="filter_where">';
149 $L = isset($filters[$theid]['where']);
151 $sel = (($L && $filters[$theid]['where'] == 'From')?
' selected="selected"':'');
152 echo "<option value=\"From\"$sel>" . _("From") . '</option>';
154 $sel = (($L && $filters[$theid]['where'] == 'To')?
' selected="selected"':'');
155 echo "<option value=\"To\"$sel>" . _("To") . '</option>';
157 $sel = (($L && $filters[$theid]['where'] == 'Cc')?
' selected="selected"':'');
158 echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
160 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?
' selected="selected"':'');
161 echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
163 $sel = (($L && $filters[$theid]['where'] == 'Subject')?
' selected="selected"':'');
164 echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
166 $sel = (($L && $filters[$theid]['where'] == 'Message Body')?
' selected="selected"':'');
167 echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>';
169 $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?
' selected="selected"':'');
170 echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>';
172 $sel = (($L && $filters[$theid]['where'] == 'Header')?
' selected="selected"':'');
173 echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
179 html_tag( 'td', _("Contains:"), 'right' ) .
180 html_tag( 'td', '', 'left' ) .
181 '<input type="text" size="32" name="filter_what" value="';
182 if (isset($filters[$theid]['what'])) {
183 echo htmlspecialchars($filters[$theid]['what']);
189 html_tag( 'td', _("Move to:"), 'left' ) .
190 html_tag( 'td', '', 'left' ) .
192 '<select name="filter_folder">';
194 if ( isset($filters[$theid]['folder']) )
195 $selected = array(strtolower($filters[$theid]['folder']));
196 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
202 '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
203 addHidden('theid', $theid).
209 if (count($filters)) {
210 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
212 for ($i=0, $num = count($filters); $i < $num; $i++
) {
214 $clr = (($i %
2)?
$color[0]:$color[9]);
215 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
216 echo html_tag( 'tr', '', '', $clr ) .
219 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
224 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
229 echo html_tag( 'td', '', 'center' ) . '<small>[';
230 if (isset($filters[$i +
1])) {
231 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
233 echo ' | ';
237 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
239 echo ']</small></td>';
241 echo html_tag( 'td', '-', 'left' ) .
242 html_tag( 'td', '', 'left' );
243 printf( _("If %s contains %s then move to %s"),
244 '<b>'.$filters[$i]['where'].'</b>',
245 '<b>'.$filters[$i]['what'].'</b>',
246 '<b>'.htmlspecialchars(imap_utf7_decode_local($fdr)).'</b>');
252 echo html_tag( 'table',
254 html_tag( 'td', ' ', 'left' )
256 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
257 echo '</body></html>';