3 # Create, update or delete a procmail recipe
5 require './procmail-lib.pl';
7 &lock_file($procmailrc);
8 @conf = &get_procmailrc();
9 $rec = $conf[$in{'idx'}] if (!$in{'new'});
12 # Just delete the recipe
17 &error_setup($text{'save_err'});
19 # Conditional code block
20 $in{'bdata'} =~ s/\r//g;
21 $rec->{'block'} = $in{'bdata'};
25 $in{'action'} =~ /\S/ ||
26 &error($text{'save_eaction_'.$in{'amode'}});
27 delete($rec->{'type'});
28 if ($in{'amode'} == 0) {
29 $rec->{'action'} = $in{'action'};
31 elsif ($in{'amode'} == 1) {
32 $rec->{'action'} = $in{'action'}."/.";
34 elsif ($in{'amode'} == 2) {
35 $rec->{'action'} = $in{'action'}."/";
37 elsif ($in{'amode'} == 3) {
39 $rec->{'action'} = $in{'action'};
41 elsif ($in{'amode'} == 6) {
43 $in{'action'} =~ /^(\S+)=(.*)$/ ||
44 &error($text{'save_eactionvar'});
45 $rec->{'action'} = $in{'action'};
49 $rec->{'action'} = $in{'action'};
53 map { $flag{$_}++ } split(/\0/, $in{'flag'});
54 @flags = @{$rec->{'flags'}};
55 foreach $f (@known_flags) {
60 @flags = grep { $_ ne $f } @flags;
63 $rec->{'flags'} = [ &unique(@flags) ];
65 if ($in{'lockfile_def'} == 1) {
66 delete($rec->{'lockfile'});
68 elsif ($in{'lockfile_def'} == 2) {
69 $rec->{'lockfile'} = "";
72 $in{'lockfile'} =~ /\S/ || &error($text{'save_elockfile'});
73 $rec->{'lockfile'} = $in{'lockfile'};
76 for($i=0; defined($m = $in{"cmode_$i"}); $i++) {
79 if ($m eq '<' || $m eq '>') {
80 $c =~ /^\d+$/ || &error(&text('save_esize', $i+1));
82 elsif ($m eq '$' || $m eq '?') {
83 $c =~ /\S/ || &error(&text('save_eshell', $i+1));
86 $c =~ /\S/ || &error(&text('save_ere', $i+1));
88 push(@conds, [ $m, $c ]);
90 $rec->{'conds'} = \@conds;
94 if ($in{'before'} ne '') {
95 $before = $conf[$in{'before'}];
96 &create_recipe_before($rec, $before);
98 elsif ($in{'after'} ne '') {
99 if ($in{'after'} == @conf-1) {
100 &create_recipe($rec);
103 $before = $conf[$in{'after'}+1];
104 &create_recipe_before($rec, $before);
108 &create_recipe($rec);
112 &modify_recipe($rec);
115 &unlock_file($procmailrc);
116 &webmin_log($in{'delete'} ? "delete" : $in{'new'} ? "create" : "modify",
117 "recipe", undef, $rec);