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