222ca7493d071f7c1e66fb35c080b0a56f03d095
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
. 'plugins/filters/filters.php');
20 displayPageHeader($color, 'None');
23 sqgetGlobalVar('username', $username, SQ_SESSION
);
24 sqgetGlobalVar('key', $key, SQ_COOKIE
);
25 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
26 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
28 sqgetGlobalVar('theid', $theid);
29 sqgetGlobalVar('action', $action, SQ_GET
);
31 if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST
)) {
33 if(! isset($theid) ) $theid = 0;
37 // FIXME: write human readable error messages
38 sqgetGlobalVar('filter_what', $filter_what, SQ_POST
);
39 if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST
)) {
40 do_error("Post error");
44 sqgetGlobalVar('filter_where', $filter_where, SQ_POST
);
45 if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST
)) {
46 do_error("Post error");
50 sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
);
51 if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST
)) {
52 do_error("Post error");
57 $filter_what = str_replace(',', ' ', $filter_what);
58 $filter_what = str_replace("\\\\", "\\", $filter_what);
59 $filter_what = str_replace("\\\"", '"', $filter_what);
60 $filter_what = str_replace('"', '"', $filter_what);
62 if (empty($filter_what)) {
63 do_error(_("WARNING! You must enter something to search for."));
67 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
68 do_error(_("WARNING! Header filters should be of the format "Header: value""));
71 if ($action != 'edit') {
72 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
74 $filters[$theid]['where'] = $filter_where;
75 $filters[$theid]['what'] = $filter_what;
76 $filters[$theid]['folder'] = $filter_folder;
78 } elseif (isset($action) && $action == 'delete') {
79 remove_filter($theid);
80 } elseif (isset($action) && $action == 'move_up') {
81 filter_swap($theid, $theid - 1);
82 } elseif (isset($action) && $action == 'move_down') {
83 filter_swap($theid, $theid +
1);
84 } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST
)) {
85 sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST
);
86 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
87 echo '<br /><div style="text-align: center;"><b>'._("Saved Scan type")."</b></div>\n";
90 $filters = load_filters();
91 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
93 echo html_tag( 'table',
96 '<div style="text-align: center;"><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></div>' ,
100 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"'
102 '<br /><form method="post" action="options.php">'.
103 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
105 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
106 html_tag( 'td', '', 'left' ) .
107 '<select name="filters_user_scan_set">'.
109 if ($filters_user_scan == '') {
110 echo ' selected="selected"';
112 echo '>' . _("All messages") . '</option>'.
113 '<option value="new"';
114 if ($filters_user_scan == 'new') {
115 echo ' selected="selected"';
117 echo '>' . _("Only unread messages") . '</option>' .
120 html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) .
124 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
125 '</a>] - [<a href="'.SM_PATH
.'src/options.php">' . _("Done") . '</a>]' ,
126 'center' ) . '<br />';
128 if (isset($action) && ($action == 'add' ||
$action == 'edit')) {
130 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
131 $boxes = sqimap_mailbox_list($imapConnection);
133 for ($a = 0, $cnt = count($boxes); $a < $cnt; $a++
) {
134 if (strtolower($boxes[$a]['formatted']) == 'inbox') {
139 sqimap_logout($imapConnection);
140 if ( !isset($theid) ) {
141 $theid = count($filters);
143 echo html_tag( 'div', '', 'center' ) .
144 '<form action="options.php" method="post">'.
145 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
147 html_tag( 'td', _("Match:"), 'left' ) .
148 html_tag( 'td', '', 'left' ) .
149 '<select name="filter_where">';
151 $L = isset($filters[$theid]['where']);
153 $sel = (($L && $filters[$theid]['where'] == 'From')?
' selected="selected"':'');
154 echo "<option value=\"From\"$sel>" . _("From") . '</option>';
156 $sel = (($L && $filters[$theid]['where'] == 'To')?
' selected="selected"':'');
157 echo "<option value=\"To\"$sel>" . _("To") . '</option>';
159 $sel = (($L && $filters[$theid]['where'] == 'Cc')?
' selected="selected"':'');
160 echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>';
162 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?
' selected="selected"':'');
163 echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>';
165 $sel = (($L && $filters[$theid]['where'] == 'Subject')?
' selected="selected"':'');
166 echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>';
168 $sel = (($L && $filters[$theid]['where'] == 'Message Body')?
' selected="selected"':'');
169 echo "<option value=\"Message Body\"$sel>" . _("Message Body") . '</option>';
171 $sel = (($L && $filters[$theid]['where'] == 'Header and Body')?
' selected="selected"':'');
172 echo "<option value=\"Header and Body\"$sel>" . _("Header and Body") . '</option>';
174 $sel = (($L && $filters[$theid]['where'] == 'Header')?
' selected="selected"':'');
175 echo "<option value=\"Header\"$sel>" . _("Header") . '</option>';
181 html_tag( 'td', _("Contains:"), 'right' ) .
182 html_tag( 'td', '', 'left' ) .
183 '<input type="text" size="32" name="filter_what" value="';
184 if (isset($filters[$theid]['what'])) {
185 echo htmlspecialchars($filters[$theid]['what']);
191 html_tag( 'td', _("Move to:"), 'left' ) .
192 html_tag( 'td', '', 'left' ) .
194 '<select name="filter_folder">';
196 if ( isset($filters[$theid]['folder']) )
197 $selected = array(strtolower($filters[$theid]['folder']));
198 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
204 '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n".
205 addHidden('theid', $theid).
211 if (count($filters)) {
212 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
214 for ($i=0, $num = count($filters); $i < $num; $i++
) {
216 $clr = (($i %
2)?
$color[0]:$color[9]);
217 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
218 echo html_tag( 'tr', '', '', $clr ) .
221 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
226 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
231 echo html_tag( 'td', '', 'center' ) . '<small>[';
232 if (isset($filters[$i +
1])) {
233 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
235 echo ' | ';
239 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
241 echo ']</small></td>';
243 echo html_tag( 'td', '-', 'left' ) .
244 html_tag( 'td', '', 'left' );
245 printf( _("If %s contains %s then move to %s"),
246 '<b>'.$filters[$i]['where'].'</b>',
247 '<b>'.$filters[$i]['what'].'</b>',
248 '<b>'.imap_utf7_decode_local($fdr).'</b>');
254 echo html_tag( 'table',
256 html_tag( 'td', ' ', 'left' )
258 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
259 echo '</body></html>';