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