]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/RuleDB/BCC.pm
1 package PMG
::RuleDB
::BCC
;
12 use PMG
::RuleDB
::Object
;
14 use base
qw(PMG::RuleDB::Object);
41 my ($type, $target, $original, $ogroup) = @_;
43 my $class = ref($type) || $type;
45 my $self = $class->SUPER::new
($class->otype(), $ogroup);
47 $self->{target
} = $target || 'receiver@domain.tld';
49 defined ($original) || ($original = 1);
51 $self->{original
} = $original;
57 my ($type, $ruledb, $id, $ogroup, $value) = @_;
59 my $class = ref($type) || $type;
61 defined($value) || return undef;
63 $value =~ m/^([01]):(.*)/ || return undef;
65 my ($target, $original) = ($2, $1);
67 my $obj = $class->new($target, $original, $ogroup);
70 $obj->{digest
} = Digest
::SHA
::sha1_hex
($id, $target, $original, $ogroup);
76 my ($self, $ruledb) = @_;
78 defined($self->{ogroup
}) || die "undefined object attribute: ERROR";
79 defined($self->{target
}) || die "undefined object attribute: ERROR";
80 defined($self->{original
}) || die "undefined object attribute: ERROR";
82 if ($self->{original
}) {
83 $self->{original
} = 1;
85 $self->{original
} = 0;
88 my $value = "$self->{original}:$self->{target}";
90 if (defined($self->{id
})) {
94 "UPDATE Object SET Value = ? WHERE ID = ?",
95 undef, $value, $self->{id
});
100 my $sth = $ruledb->{dbh
}->prepare(
101 "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
102 "VALUES (?, ?, ?);");
104 $sth->execute($self->{ogroup
}, $self->otype, $value);
106 $self->{id
} = PMG
::Utils
::lastid
($ruledb->{dbh
}, 'object_id_seq');
113 my ($self, $queue, $ruledb, $mod_group, $targets,
114 $msginfo, $vars, $marks) = @_;
116 my $subgroups = $mod_group->subgroups($targets, 1);
118 my $rulename = $vars->{RULE
} // 'unknown';
120 my $bcc_to = PMG
::Utils
::subst_values_for_header
($self->{target
}, $vars);
122 if ($bcc_to =~ m/^\s*$/) {
123 # this happens if a notification is triggered by bounce mails
124 # which notifies the sender <> - we just log and then ignore it
125 syslog
('info', "%s: bcc to <> (rule: %s, ignored)", $queue->{logid
}, $rulename);
129 my @bcc_targets = split (/\s*,\s*/, $bcc_to);
131 if ($self->{original
}) {
132 $subgroups = [[\
@bcc_targets, $mod_group->{entity
}]];
135 foreach my $ta (@$subgroups) {
136 my ($tg, $entity) = (@$ta[0], @$ta[1]);
138 $entity = $entity->dup();
139 PMG
::Utils
::remove_marks
($entity);
141 my $dkim = $msginfo->{dkim
} // {};
144 $entity = PMG
::DKIMSign
::sign_entity
($entity,
145 $dkim->{selector
}, $msginfo->{sender
}, $dkim->{sign_all
});
148 "Could not create DKIM-Signature - disabling Signing: $@") if $@;
151 if ($msginfo->{testmode
}) {
152 my $fh = $msginfo->{test_fh
};
153 print $fh "bcc from: $msginfo->{sender}\n";
154 printf $fh "bcc to: %s\n", join (',', @$tg);
155 print $fh "bcc content:\n";
156 $entity->print ($fh);
157 print $fh "bcc end\n";
160 for my $bcc (@bcc_targets) {
161 $param->{rcpt
}->{$bcc}->{notify
} = "never";
163 my $qid = PMG
::Utils
::reinject_mail
(
164 $entity, $msginfo->{sender
}, \
@bcc_targets,
165 $msginfo->{xforward
}, $msginfo->{fqdn
}, $param);
166 foreach (@bcc_targets) {
168 syslog
('info', "%s: bcc to <%s> (rule: %s, %s)", $queue->{logid
}, $_, $rulename, $qid);
170 syslog
('err', "%s: bcc to <%s> (rule: %s) failed", $queue->{logid
}, $_, $rulename);
176 # warn if no subgroups
182 my $descr = "send bcc to: $self->{target}";
184 $descr .= " (original)" if $self->{original
};
194 description
=> "Send a Blind Carbon Copy to this email address.",
195 type
=> 'string', format
=> 'email',
198 description
=> "Send the original, unmodified mail.",
210 target
=> $self->{target
},
211 original
=> $self->{original
},
216 my ($self, $param) = @_;
218 $self->{target
} = $param->{target
};
219 $self->{original
} = $param->{original
} ?
1 : 0;
226 =head1 PMG::RuleDB::BCC