]>
git.proxmox.com Git - pmg-api.git/blob - src/PMG/RuleDB/BCC.pm
1 package PMG
::RuleDB
::BCC
;
13 use PMG
::RuleDB
::Object
;
15 use base
qw(PMG::RuleDB::Object);
42 my ($type, $target, $original, $ogroup) = @_;
44 my $class = ref($type) || $type;
46 my $self = $class->SUPER::new
($class->otype(), $ogroup);
48 $self->{target
} = $target || 'receiver@domain.tld';
50 defined ($original) || ($original = 1);
52 $self->{original
} = $original;
58 my ($type, $ruledb, $id, $ogroup, $value) = @_;
60 my $class = ref($type) || $type;
62 defined($value) || return undef;
64 $value =~ m/^([01]):(.*)/ || return undef;
66 my ($target, $original) = ($2, $1);
68 my $obj = $class->new($target, $original, $ogroup);
71 $obj->{digest
} = Digest
::SHA
::sha1_hex
($id, $target, $original, $ogroup);
77 my ($self, $ruledb) = @_;
79 defined($self->{ogroup
}) || die "undefined object attribute: ERROR";
80 defined($self->{target
}) || die "undefined object attribute: ERROR";
81 defined($self->{original
}) || die "undefined object attribute: ERROR";
83 if ($self->{original
}) {
84 $self->{original
} = 1;
86 $self->{original
} = 0;
89 my $value = "$self->{original}:$self->{target}";
91 if (defined($self->{id
})) {
95 "UPDATE Object SET Value = ? WHERE ID = ?",
96 undef, $value, $self->{id
});
101 my $sth = $ruledb->{dbh
}->prepare(
102 "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
103 "VALUES (?, ?, ?);");
105 $sth->execute($self->{ogroup
}, $self->otype, $value);
107 $self->{id
} = PMG
::Utils
::lastid
($ruledb->{dbh
}, 'object_id_seq');
114 my ($self, $queue, $ruledb, $mod_group, $targets,
115 $msginfo, $vars, $marks) = @_;
117 my $subgroups = $mod_group->subgroups($targets, 1);
119 my $rulename = encode
('UTF-8', $vars->{RULE
} // 'unknown');
121 my $bcc_to = PMG
::Utils
::subst_values_for_header
($self->{target
}, $vars);
123 if ($bcc_to =~ m/^\s*$/) {
124 # this happens if a notification is triggered by bounce mails
125 # which notifies the sender <> - we just log and then ignore it
126 syslog
('info', "%s: bcc to <> (rule: %s, ignored)", $queue->{logid
}, $rulename);
130 my @bcc_targets = split (/\s*,\s*/, $bcc_to);
132 if ($self->{original
}) {
133 $subgroups = [[\
@bcc_targets, $mod_group->{entity
}]];
136 foreach my $ta (@$subgroups) {
137 my ($tg, $entity) = (@$ta[0], @$ta[1]);
139 $entity = $entity->dup();
140 PMG
::Utils
::remove_marks
($entity);
142 my $dkim = $msginfo->{dkim
} // {};
145 $entity = PMG
::DKIMSign
::sign_entity
($entity,
146 $dkim->{selector
}, $msginfo->{sender
}, $dkim->{sign_all
});
149 "Could not create DKIM-Signature - disabling Signing: $@") if $@;
152 if ($msginfo->{testmode
}) {
153 my $fh = $msginfo->{test_fh
};
154 print $fh "bcc from: $msginfo->{sender}\n";
155 printf $fh "bcc to: %s\n", join (',', @$tg);
156 print $fh "bcc content:\n";
157 $entity->print ($fh);
158 print $fh "bcc end\n";
161 for my $bcc (@bcc_targets) {
162 $param->{rcpt
}->{$bcc}->{notify
} = "never";
164 my $qid = PMG
::Utils
::reinject_mail
(
165 $entity, $msginfo->{sender
}, \
@bcc_targets,
166 $msginfo->{xforward
}, $msginfo->{fqdn
}, $param);
167 foreach (@bcc_targets) {
168 my $target = encode
('UTF-8', $_);
172 "%s: bcc to <%s> (rule: %s, %s)",
181 "%s: bcc to <%s> (rule: %s) failed",
191 # warn if no subgroups
197 my $descr = "send bcc to: $self->{target}";
199 $descr .= " (original)" if $self->{original
};
209 description
=> "Send a Blind Carbon Copy to this email address.",
210 type
=> 'string', format
=> 'email',
213 description
=> "Send the original, unmodified mail.",
225 target
=> $self->{target
},
226 original
=> $self->{original
},
231 my ($self, $param) = @_;
233 $self->{target
} = $param->{target
};
234 $self->{original
} = $param->{original
} ?
1 : 0;
241 =head1 PMG::RuleDB::BCC