Missed a spelling change
[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
28 chdir ('..');
849bdf42 29 require_once('../src/validate.php');
3fd1252d 30 require_once('../functions/page_header.php');
31 require_once('../functions/imap.php');
32 require_once('../src/load_prefs.php');
849bdf42 33
34 global $AllowSpamFilters;
35
3fd1252d 36 displayPageHeader($color, 'None');
849bdf42 37
38 if (isset($filter_submit)) {
39 if (!isset($theid)) $theid = 0;
4eee5968 40 $filter_what = ereg_replace(",", " ", $filter_what);
849bdf42 41 $filter_what = str_replace("\\\\", "\\", $filter_what);
42 $filter_what = str_replace("\\\"", "\"", $filter_what);
43 $filter_what = str_replace("\"", "&quot;", $filter_what);
44
8e485f9b 45 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
46 print ('WARNING! Header filters should be of the format "Header: value"<BR>');
47 $action = 'edit';
48 }
4eee5968 49 setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
50 $filters[$theid]["where"] = $filter_where;
51 $filters[$theid]["what"] = $filter_what;
52 $filters[$theid]["folder"] = $filter_folder;
3fd1252d 53 } elseif (isset($action) && $action == 'delete') {
849bdf42 54 remove_filter($theid);
3fd1252d 55 } elseif (isset($action) && $action == 'move_up') {
849bdf42 56 filter_swap($theid, $theid - 1);
3fd1252d 57 } elseif (isset($action) && $action == 'move_down') {
849bdf42 58 filter_swap($theid, $theid + 1);
c8a2c24d 59 } elseif (isset($user_submit)) {
60 echo "<br><center><b>"._("Saved Scan type")."</b></center>\n";
61 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
849bdf42 62 }
63
849bdf42 64 $filters = load_filters();
c8a2c24d 65 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
849bdf42 66
0e838332 67 echo '<br>' .
b01b21d0 68 html_tag( 'table',
69 html_tag( 'tr',
70 html_tag( 'td',
71 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' ,
72 'left', $color[0] )
73 ) ,
74 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' ) .
c8a2c24d 75
76 '<br><form method=post action="options.php">'.
77 '<center>'.
831a25d5 78 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
b01b21d0 79 html_tag( 'tr' ) .
80 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
81 html_tag( 'td', '', 'left' ) .
82 '<select name="filters_user_scan_set">'.
c8a2c24d 83 '<option value=""';
84 if ($filters_user_scan == '') {
b01b21d0 85 echo ' selected';
c8a2c24d 86 }
87 echo '>' . _("All messages") . '</option>'.
88 '<option value="new"';
89 if ($filters_user_scan == 'new') {
b01b21d0 90 echo ' selected';
c8a2c24d 91 }
92 echo '>' . _("Only unread messages") . '</option>' .
93 '</select>'.
94 '</td>'.
b01b21d0 95 html_tag( 'td', '<input type=submit name="user_submit" value="' . _("Save") . '">', 'left' ) .
c8a2c24d 96 '</table>'.
97 '</center>'.
98 '</form>'.
99
b01b21d0 100 html_tag( 'div', '[<a href="options.php?action=add">' . _("New") .
101 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]' ,
102 'center' ) . '<br>';
0e838332 103
3fd1252d 104 if (isset($action) && ($action == 'add' || $action == 'edit')) {
105 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
106 $boxes = sqimap_mailbox_list($imapConnection);
107 sqimap_logout($imapConnection);
108 if ( !isset($theid) ) {
849bdf42 109 $theid = count($filters);
3fd1252d 110 }
b01b21d0 111 echo html_tag( 'div', '', 'center' ) .
72570d58 112 '<form action="options.php" method=post>'.
831a25d5 113 html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) .
b01b21d0 114 html_tag( 'tr' ) .
115 html_tag( 'td', _("Match:"), 'left' ) .
116 html_tag( 'td', '', 'left' ) .
4eee5968 117 '<select name=filter_where>';
849bdf42 118
3fd1252d 119 $L = isset($filters[$theid]['where']);
120
121 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
122 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
4eee5968 123
3fd1252d 124 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
125 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
126
127 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
128 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
129
130 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
131 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
132
133 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
134 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
135
9da6bdde 136 $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
137 echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>';
138
3fd1252d 139 echo '</select>'.
4eee5968 140 '</td>'.
141 '</tr>'.
b01b21d0 142 html_tag( 'tr' ) .
143 html_tag( 'td', _("Contains:"), 'right' ) .
144 html_tag( 'td', '', 'left' ) .
4eee5968 145 '<input type=text size=32 name=filter_what value="';
3fd1252d 146 if (isset($filters[$theid]['what'])) {
4eee5968 147 echo $filters[$theid]["what"];
3fd1252d 148 }
149 echo '">'.
4eee5968 150 '</td>'.
151 '</tr>'.
b01b21d0 152 html_tag( 'tr' ) .
153 html_tag( 'td', _("Move to:"), 'left' ) .
154 html_tag( 'td', '', 'left' ) .
4eee5968 155 '<tt>'.
156 '<select name=filter_folder>';
3fd1252d 157
158 for ($i = 0; $i < count($boxes); $i++) {
159 if (! in_array('noselect', $boxes[$i]['flags'])) {
160 $box = $boxes[$i]['unformatted'];
161 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
162 if (isset($filters[$theid]['folder']) &&
163 $filters[$theid]['folder'] == $box)
4eee5968 164 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
3fd1252d 165 else
4eee5968 166 echo "<OPTION VALUE=\"$box\">$box2</option>";
849bdf42 167 }
3fd1252d 168 }
169 echo '</tt>'.
4eee5968 170 '</select>'.
171 '</td>'.
172 '</tr>'.
3fd1252d 173 '</table>'.
174 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
175 "<input type=hidden name=theid value=$theid>".
176 '</form>'.
b01b21d0 177 '</div>';
3fd1252d 178
3fd1252d 179 }
cb2ccf4b 180
831a25d5 181 echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' );
cb2ccf4b 182
183 for ($i=0; $i < count($filters); $i++) {
184
185 $clr = (($i % 2)?$color[0]:$color[9]);
186 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
831a25d5 187 echo html_tag( 'tr', '', '', $clr ) .
b01b21d0 188 html_tag( 'td',
189 '<small>' .
190 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
191 '</small>' ,
192 'left' ) .
193 html_tag( 'td',
194 '<small>' .
195 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
196 '</small>' ,
197 'left' ) .
198 html_tag( 'td', '', 'center' ) . '<small>[';
cb2ccf4b 199
200 if (isset($filters[$i + 1])) {
201 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
202 if ($i > 0) {
2a61e066 203 echo '&nbsp;|&nbsp;';
cb2ccf4b 204 }
205 }
206 if ($i > 0) {
207 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
208 }
b01b21d0 209 echo ']</small></td>'.
210 html_tag( 'td', '-', 'left' ) .
211 html_tag( 'td', '', 'left' );
cb2ccf4b 212 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
213 echo '</td></tr>';
214
215 }
216 echo '</table>'.
b01b21d0 217 html_tag( 'table',
218 html_tag( 'tr',
219 html_tag( 'td', '&nbsp', 'left' )
220 ) ,
221 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' );
4eee5968 222?>