]>
git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/BCC.pm
1 package PMG
::RuleDB
::BCC
;
13 use PMG
::RuleDB
::Object
;
15 use base
qw(PMG::RuleDB::Object);
34 return 'Blind carbon copy.';
50 my ($type, $target, $original, $ogroup) = @_;
52 my $class = ref($type) || $type;
54 my $self = $class->SUPER::new
(otype
(), $ogroup);
56 $self->{target
} = $target || 'receiver@domain.tld';
58 defined ($original) || ($original = 1);
60 $self->{original
} = $original;
66 my ($type, $ruledb, $id, $ogroup, $value) = @_;
68 my $class = ref($type) || $type;
70 defined($value) || return undef;
72 $value =~ m/^([01]):(.*)/ || return undef;
74 my ($target, $original) = ($2, $1);
76 my $obj = $class->new($target, $original, $ogroup);
79 $obj->{digest
} = Digest
::SHA
::sha1_hex
($id, $target, $original, $ogroup);
85 my ($self, $ruledb) = @_;
87 defined($self->{ogroup
}) || croak
"undefined object attribute: ERROR";
88 defined($self->{target
}) || croak
"undefined object attribute: ERROR";
89 defined($self->{original
}) || croak
"undefined object attribute: ERROR";
91 if ($self->{original
}) {
92 $self->{original
} = 1;
94 $self->{original
} = 0;
97 my $value = "$self->{original}:$self->{target}";
99 if (defined($self->{id
})) {
103 "UPDATE Object SET Value = ? WHERE ID = ?",
104 undef, $value, $self->{id
});
109 my $sth = $ruledb->{dbh
}->prepare(
110 "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
111 "VALUES (?, ?, ?);");
113 $sth->execute($self->{ogroup
}, $self->otype, $value);
115 $self->{id
} = PMG
::Utils
::lastid
($ruledb->{dbh
}, 'object_id_seq');
122 my ($self, $queue, $ruledb, $mod_group, $targets,
123 $msginfo, $vars, $marks) = @_;
125 my $subgroups = $mod_group->subgroups($targets, 1);
127 my $bcc_to = PMG
::Utils
::subst_values
($self->{target
}, $vars);
129 if ($bcc_to =~ m/^\s*$/) {
130 # this happens if a notification is triggered by bounce mails
131 # which notifies the sender <> - we just log and then ignore it
132 syslog
('info', "%s: bcc to <> (ignored)", $queue->{logid
});
136 my @bcc_targets = split (/\s*,\s*/, $bcc_to);
138 if ($self->{original
}) {
139 $subgroups = [[\
@bcc_targets, $mod_group->{entity
}]];
142 foreach my $ta (@$subgroups) {
143 my ($tg, $entity) = (@$ta[0], @$ta[1]);
145 $entity = $entity->dup();
146 Proxmox
::Utils
::remove_marks
($entity);
148 if ($msginfo->{testmode
}) {
149 my $fh = $msginfo->{test_fh
};
150 print $fh "bcc from: $msginfo->{sender}\n";
151 printf $fh "bcc to: %s\n", join (',', @$tg);
152 print $fh "bcc content:\n";
153 $entity->print ($fh);
154 print $fh "bcc end\n";
156 my $qid = PMG
::Utils
::reinject_mail
(
157 $entity, $msginfo->{sender
}, \
@bcc_targets,
158 $msginfo->{xforward
}, $msginfo->{fqdn
}, 1);
159 foreach (@bcc_targets) {
161 syslog
('info', "%s: bcc to <%s> (%s)", $queue->{logid
}, $_, $qid);
163 syslog
('err', "%s: bcc to <%s> failed", $queue->{logid
}, $_);
169 # warn if no subgroups
175 return "send bcc to: $self->{target}";
182 =head1 PMG::RuleDB::BCC