]>
git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/BCC.pm
8987f2fa5adf5a295f8b9ea7fc676143de77fa44
1 package PMG
::RuleDB
::BCC
;
12 use PMG
::RuleDB
::Object
;
14 use base
qw(PMG::RuleDB::Object);
33 return 'Blind carbon copy.';
49 my ($type, $target, $original, $ogroup) = @_;
51 my $class = ref($type) || $type;
53 my $self = $class->SUPER::new
($class->otype(), $ogroup);
55 $self->{target
} = $target || 'receiver@domain.tld';
57 defined ($original) || ($original = 1);
59 $self->{original
} = $original;
65 my ($type, $ruledb, $id, $ogroup, $value) = @_;
67 my $class = ref($type) || $type;
69 defined($value) || return undef;
71 $value =~ m/^([01]):(.*)/ || return undef;
73 my ($target, $original) = ($2, $1);
75 my $obj = $class->new($target, $original, $ogroup);
78 $obj->{digest
} = Digest
::SHA
::sha1_hex
($id, $target, $original, $ogroup);
84 my ($self, $ruledb) = @_;
86 defined($self->{ogroup
}) || croak
"undefined object attribute: ERROR";
87 defined($self->{target
}) || croak
"undefined object attribute: ERROR";
88 defined($self->{original
}) || croak
"undefined object attribute: ERROR";
90 if ($self->{original
}) {
91 $self->{original
} = 1;
93 $self->{original
} = 0;
96 my $value = "$self->{original}:$self->{target}";
98 if (defined($self->{id
})) {
102 "UPDATE Object SET Value = ? WHERE ID = ?",
103 undef, $value, $self->{id
});
108 my $sth = $ruledb->{dbh
}->prepare(
109 "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
110 "VALUES (?, ?, ?);");
112 $sth->execute($self->{ogroup
}, $self->otype, $value);
114 $self->{id
} = PMG
::Utils
::lastid
($ruledb->{dbh
}, 'object_id_seq');
121 my ($self, $queue, $ruledb, $mod_group, $targets,
122 $msginfo, $vars, $marks) = @_;
124 my $subgroups = $mod_group->subgroups($targets, 1);
126 my $bcc_to = PMG
::Utils
::subst_values
($self->{target
}, $vars);
128 if ($bcc_to =~ m/^\s*$/) {
129 # this happens if a notification is triggered by bounce mails
130 # which notifies the sender <> - we just log and then ignore it
131 syslog
('info', "%s: bcc to <> (ignored)", $queue->{logid
});
135 my @bcc_targets = split (/\s*,\s*/, $bcc_to);
137 if ($self->{original
}) {
138 $subgroups = [[\
@bcc_targets, $mod_group->{entity
}]];
141 foreach my $ta (@$subgroups) {
142 my ($tg, $entity) = (@$ta[0], @$ta[1]);
144 $entity = $entity->dup();
145 PMG
::Utils
::remove_marks
($entity);
147 if ($msginfo->{testmode
}) {
148 my $fh = $msginfo->{test_fh
};
149 print $fh "bcc from: $msginfo->{sender}\n";
150 printf $fh "bcc to: %s\n", join (',', @$tg);
151 print $fh "bcc content:\n";
152 $entity->print ($fh);
153 print $fh "bcc end\n";
155 my $qid = PMG
::Utils
::reinject_mail
(
156 $entity, $msginfo->{sender
}, \
@bcc_targets,
157 $msginfo->{xforward
}, $msginfo->{fqdn
}, 1);
158 foreach (@bcc_targets) {
160 syslog
('info', "%s: bcc to <%s> (%s)", $queue->{logid
}, $_, $qid);
162 syslog
('err', "%s: bcc to <%s> failed", $queue->{logid
}, $_);
168 # warn if no subgroups
174 return "send bcc to: $self->{target}";
181 =head1 PMG::RuleDB::BCC