]>
Commit | Line | Data |
---|---|---|
6fc0045f DM |
1 | package PMG::ModGroup; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use Carp; | |
6 | ||
7 | sub new { | |
8 | my ($type, $entity, $targets) = @_; | |
9 | ||
10 | my $self = { | |
11 | targets => $targets, | |
12 | ea => [$entity], | |
13 | groups => [$targets], | |
14 | entity => $entity, | |
15 | }; | |
16 | ||
17 | bless $self, $type; | |
18 | ||
19 | return $self; | |
20 | } | |
21 | ||
22 | # compute subgroups | |
23 | # set ro (read only) to 1 if you do not plan to modify the | |
24 | # entity (in actions like 'accept' od 'bcc'). This | |
25 | # just return the existing groups but does not create new groups. | |
26 | ||
27 | sub subgroups { | |
28 | my ($self, $targets, $ro) = @_; | |
29 | ||
30 | my $groups; | |
31 | if ($ro) { | |
32 | my @copy = @{$self->{groups}}; | |
33 | $groups = \@copy; | |
34 | } else { | |
35 | $groups = $self->{groups}; | |
36 | } | |
37 | ||
38 | my $ea = $self->{ea}; | |
39 | ||
40 | my $res; | |
41 | ||
42 | for my $i (0..$#$groups) { | |
43 | my $g = @$groups[$i]; | |
44 | ||
45 | my $tcount = -1; | |
46 | my ($ma, $ua); | |
47 | foreach my $member (@$g) { | |
48 | my $found = 0; | |
49 | foreach my $t (@$targets) { | |
50 | if ($member eq $t) { | |
51 | $found = 1; | |
52 | $tcount++; | |
53 | } | |
54 | } | |
55 | if ($found) { | |
56 | push @$ma, $member; | |
57 | } else { | |
58 | push @$ua, $member; | |
59 | } | |
60 | } | |
61 | ||
62 | next if $tcount == -1; | |
63 | ||
64 | if ($tcount < $#$g) { | |
65 | @$groups[$i] = $ma; | |
66 | push @$groups, $ua; | |
67 | if ($ro) { | |
68 | push @$ea, @$ea[$i]; | |
69 | } else { | |
70 | my $e = @$ea[$i]; | |
71 | my $copy = $e->dup; | |
72 | ||
73 | # also copy proxmox attribute | |
74 | foreach (keys %$e) {$copy->{$_} = $e->{$_} if $_ =~ m/^PMX_/}; | |
75 | ||
76 | push @$ea, $copy; | |
77 | } | |
78 | } | |
79 | push @$res, [$ma, @$ea[$i]]; | |
80 | } | |
81 | ||
82 | return $res; | |
83 | } | |
84 | ||
85 | 1; | |
86 | ||
87 | __END__ | |
88 | ||
89 | =head1 PMG::RuleDB::ModGroup | |
90 | ||
91 | The idea behind the modification group object (ModGroup) is that some | |
92 | modification are target specific. For example a mail can be posted to | |
93 | two receiver: | |
94 | ||
95 | TO: user1@domain1.com, user2@domain2.com | |
96 | ||
97 | and we have different rules to add disclaimers for those domains: | |
98 | ||
99 | Rule1: .*@domain1.com --> add disclaimer one | |
100 | Rule2: .*@domain2.com --> add disclaimer two | |
101 | ||
102 | Both Rules are matching, because there are two different receivers, | |
103 | one in each domain. If we simply modify the original mail we end up | |
104 | with a mail containing both disclaimers, which is not what we want. | |
105 | ||
106 | Another example is when you have receiver specific content filters, | |
107 | for example you don't want to get .exe files for a specific user, but | |
108 | allow it for everone else: | |
109 | ||
110 | Rule1: user1@domain1.com && .exe attachments --> remove attachments | |
111 | Rule1: .*@domain2.com && .exe attachments --> accept | |
112 | ||
113 | So you don't want to remeove the .exe file for user2@domain.com | |
114 | ||
115 | Instead we want to group modification by matching rule targets. | |
116 | ||
117 | $mod_group = PMG::RuleDB::ModGroup->new ($targets, $entity); | |
118 | ||
119 | $targets ... array of all receivers | |
120 | $entity ... original mail | |
121 | ||
122 | return a new ModGroup Object. Action Objects which do target specific | |
123 | modification have to call: | |
124 | ||
125 | my $subgroups = $mod_group->subgroups ($rule_targets); | |
126 | ||
127 | foreach my $ta (@$subgroups) { | |
128 | my ($targets, $entity) = (@$ta[0], @$ta[1]); | |
129 | my_modify_entity ($entity, $targets); | |
130 | } | |
131 | ||
132 | That way we seemlessly hide the fact that mails are delivered to more | |
133 | than one receipient, without the requirement to make a copy for each | |
134 | receipient (which would lead to many unnecessays notification | |
135 | mail). Insead we only make a minimum number of copies for specific | |
136 | target groups. |