2 # Show details of one filter
4 require './filter-lib.pl';
5 &foreign_require("mailbox", "mailbox-lib.pl");
8 # Show page header and get the filter
10 &ui_print_header(undef, $text{'edit_title1'}, "");
11 $filter = { 'actiondefault' => 1,
14 # Initial filter is based on URL params
15 $filter->{'condheader'} = $in{'header'};
16 $filter->{'condvalue'} = $in{'value'};
20 &ui_print_header(undef, $text{'edit_title2'}, "");
21 @filters = &list_filters();
22 ($filter) = grep { $_->{'index'} == $in{'idx'} } @filters;
25 @tds = ( "nowrap width=30%", "width=70%" );
26 print &ui_form_start("save.cgi", "post");
27 print &ui_hidden("new", $in{'new'});
28 print &ui_hidden("idx", $in{'idx'});
30 # Start of condition section
31 $cmode = $filter->{'condspam'} ? 5 :
32 $filter->{'condlevel'} ? 6 :
33 $filter->{'condheader'} ? 4 :
34 $filter->{'condtype'} eq '<' ? 3 :
35 $filter->{'condtype'} eq '>' ? 2 :
36 $filter->{'cond'} ? 1 : 0;
37 print &ui_table_start($text{'edit_header1'}, "width=100%", 2);
41 &ui_oneradio("cmode", 0, $text{'edit_cmode0'}, $cmode == 0),
46 &ui_oneradio("cmode", 5, $text{'edit_cmode5'}, $cmode == 5),
49 # Spam level is at or above
51 &ui_oneradio("cmode", 6, $text{'edit_cmode6'}, $cmode == 6),
52 &ui_textbox("condlevel", $filter->{'condlevel'}, 4, 0, undef,
53 "onFocus='form.cmode[2].checked = true'"), undef, \@tds);
56 @headers = ( "From", "To", "Subject", "Cc", "Reply-To", "List-Id" );
57 $common = &indexoflc($filter->{'condheader'}, @headers) >= 0;
58 if ($filter->{'condvalue'} =~ /^\.\*(.*)\$$/) {
63 elsif ($filter->{'condvalue'} =~ /^\.\*(.*)\.\*$/ ||
64 $filter->{'condvalue'} =~ /^\.\*(.*)$/) {
69 elsif ($filter->{'condvalue'} =~ /^(.*)\.\*$/ ||
70 $filter->{'condvalue'} =~ /^(.*)$/) {
75 if ($condvalue =~ /^[a-zA-Z0-9_ ]*$/) {
76 # Contains no special chars, so not a regexp
80 # Has special chars .. but if they are all escaped, then not a regexp
83 if ($condre =~ /^[a-zA-Z0-9_ ]*$/) {
84 $condvalue =~ s/\\(.)/$1/g;
92 &ui_oneradio("cmode", 4, $text{'edit_cmode4'}, $cmode == 4),
93 &text('edit_cheader2',
94 &ui_select("condmenu", $cmode != 4 ? "From" :
95 $common ? $filter->{'condheader'} : "",
96 [ (map { [ $_ ] } @headers),
97 [ "", $text{'edit_other'} ] ],
99 "onChange='form.condheader.disabled = (form.condmenu.value!=\"\")'"),
100 &ui_textbox("condheader",
101 $common ? "" : $filter->{'condheader'}, 20,
102 $cmode != 4 || $common),
103 &ui_select("condmode", $condmode,
104 [ [ 0, $text{'edit_modestart'} ],
105 [ 1, $text{'edit_modecont'} ],
106 [ 2, $text{'edit_modeend'} ] ]),
107 &ui_textbox("condvalue", $condvalue, 40, 0, undef,
108 "onFocus='form.cmode[3].checked = true'")." ".
109 &ui_checkbox("condregexp", 1, $text{'edit_regexp'}, $regexp)),
114 &ui_oneradio("cmode", 3, $text{'edit_cmode3'}, $cmode == 3),
115 &ui_bytesbox("condsmall", $cmode == 3 ? $filter->{'cond'} : "",
116 undef, 0, "onFocus='form.cmode[4].checked = true'"),
121 &ui_oneradio("cmode", 2, $text{'edit_cmode2'}, $cmode == 2),
122 &ui_bytesbox("condlarge", $cmode == 2 ? $filter->{'cond'} : "",
123 undef, 0, "onFocus='form.cmode[5].checked = true'"),
128 &ui_oneradio("cmode", 1, $text{'edit_cmode1'}, $cmode == 1),
129 &ui_textbox("cond", $cmode == 1 ? $filter->{'cond'} : "", 70, 0, undef,
130 "onFocus='form.cmode[6].checked = true'")."<br>".
131 &ui_checkbox("body", 1, $text{'edit_cbody'}, $filter->{'body'}),
134 print &ui_table_end();
136 # Start of action section
137 $amode = $filter->{'actionreply'} ? 6 :
138 $filter->{'actionspam'} ? 5 :
139 $filter->{'actionthrow'} ? 4 :
140 $filter->{'actiondefault'} ? 3 :
141 $filter->{'actionreply'} ? 2 :
142 $filter->{'actiontype'} eq '!' ? 1 : 0;
143 print &ui_table_start($text{'edit_header2'}, "width=100%", 2);
147 &ui_oneradio("amode", 3, $text{'edit_amode3'}, $amode == 3),
150 if ($amode == 5 || &has_spamassassin()) {
153 &ui_oneradio("amode", 5, $text{'edit_amode5'}, $amode == 5),
159 &ui_oneradio("amode", 4, $text{'edit_amode4'}, $amode == 4),
162 # Forward to some addresses
164 &ui_oneradio("amode", 1, $text{'edit_amode1'}, $amode == 1),
165 &ui_textarea("forward", $amode == 1 ?
166 join("\n", split(/,/, $filter->{'action'})) : "", 3, 70).
168 &ui_checkbox("nobounce", 1, $text{'edit_nobounce'},
169 $filter->{'nobounce'}),
172 # Save to a folder or file
173 @folders = grep { $_->{'file'} } &mailbox::list_folders_sorted();
175 $folder = &file_to_folder($filter->{'action'}, \@folders);
178 $folder = $folders[0];
181 &ui_oneradio("amode", 0, $text{'edit_amode0'}, $amode == 0),
182 &ui_select("folder", $folder ? &mailbox::folder_name($folder) : "",
183 [ (map { [ &mailbox::folder_name($_), $_->{'name'} ] }
185 [ "", $text{'edit_file'} ] ],
187 "onChange='form.file.disabled = (form.folder.value!=\"\")'").
189 &ui_textbox("file", $folder ? "" : $filter->{'action'}, 50,
193 # Save to a new folder
195 &ui_oneradio("amode", 7, $text{'edit_amode7'}, 0),
196 &ui_textbox("newfolder", undef, 20),
201 $r = $filter->{'reply'};
202 $period = $in{'new'} ? 60 :
203 $r->{'replies'} && $r->{'period'} ? int($r->{'period'}/60) :
204 $r->{'replies'} ? 60 : undef;
205 if ($r->{'autoreply_start'}) {
206 @stm = localtime($r->{'autoreply_start'});
207 $stm[4]++; $stm[5] += 1900;
209 if ($r->{'autoreply_end'}) {
210 @etm = localtime($r->{'autoreply_end'});
211 $etm[4]++; $etm[5] += 1900;
217 if ($config{'reply_force'}) {
220 elsif ($config{'reply_min'}) {
221 $replyblock = "<tr> <td><b>$text{'index_period'}</b></td> ".
222 "<td>".&ui_textbox("period", $period, 3)." ".
223 $text{'index_mins'}."</td> </tr>\n";
226 $replyblock = "<tr> <td><b>$text{'index_period'}</b></td> ".
227 "<td>".&ui_opt_textbox("period", $period, 3,
228 $text{'index_noperiod'})." ".$text{'index_mins'}.
231 $cs = !$in{'new'} ? $r->{'charset'} :
232 &get_charset() eq $default_charset ? undef : &get_charset();
234 &ui_oneradio("amode", 6, $text{'edit_amode6'}, $amode == 6),
235 &ui_textarea("reply", $filter->{'reply'}->{'autotext'}, 5, 60)."<br>".
238 "<tr> <td><b>$text{'index_astart'}</b></td> ".
239 "<td>".&ui_date_input($stm[3], $stm[4], $stm[5],
240 "dstart", "mstart", "ystart")." ".
241 &date_chooser_button("dstart", "mstart", "ystart")."</td> </tr>\n".
242 "<tr> <td><b>$text{'index_aend'}</b></td> ".
243 "<td>".&ui_date_input($etm[3], $etm[4], $etm[5],
244 "dend", "mend", "yend")." ".
245 &date_chooser_button("dend", "mend", "yend")."</td> </tr>\n".
246 "<tr> <td><b>$text{'index_charset'}</b></td> ".
247 "<td>".&ui_opt_textbox("charset", $cs, 20,
248 $text{'default'}." ($default_charset)")."</td> </tr>\n".
254 undef, &ui_checkbox("continue", 1, $text{'edit_continue'},
255 $filter->{'continue'}), 2);
257 print &ui_table_end();
259 # End of the form, with buttons
261 print &ui_form_end([ [ "create", $text{'create'} ] ]);
264 print &ui_form_end([ [ "save", $text{'save'} ],
265 [ "delete", $text{'delete'} ] ]);
269 &ui_print_footer("", $text{'index_return'});