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