]>
git.proxmox.com Git - pmg-api.git/blob - PMG/RuleDB/BCC.pm
1 package PMG
::RuleDB
::BCC
;
11 use PMG
::RuleDB
::Object
;
13 use base
qw(PMG::RuleDB::Object);
40 my ($type, $target, $original, $ogroup) = @_;
42 my $class = ref($type) || $type;
44 my $self = $class->SUPER::new
($class->otype(), $ogroup);
46 $self->{target
} = $target || 'receiver@domain.tld';
48 defined ($original) || ($original = 1);
50 $self->{original
} = $original;
56 my ($type, $ruledb, $id, $ogroup, $value) = @_;
58 my $class = ref($type) || $type;
60 defined($value) || return undef;
62 $value =~ m/^([01]):(.*)/ || return undef;
64 my ($target, $original) = ($2, $1);
66 my $obj = $class->new($target, $original, $ogroup);
69 $obj->{digest
} = Digest
::SHA
::sha1_hex
($id, $target, $original, $ogroup);
75 my ($self, $ruledb) = @_;
77 defined($self->{ogroup
}) || die "undefined object attribute: ERROR";
78 defined($self->{target
}) || die "undefined object attribute: ERROR";
79 defined($self->{original
}) || die "undefined object attribute: ERROR";
81 if ($self->{original
}) {
82 $self->{original
} = 1;
84 $self->{original
} = 0;
87 my $value = "$self->{original}:$self->{target}";
89 if (defined($self->{id
})) {
93 "UPDATE Object SET Value = ? WHERE ID = ?",
94 undef, $value, $self->{id
});
99 my $sth = $ruledb->{dbh
}->prepare(
100 "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " .
101 "VALUES (?, ?, ?);");
103 $sth->execute($self->{ogroup
}, $self->otype, $value);
105 $self->{id
} = PMG
::Utils
::lastid
($ruledb->{dbh
}, 'object_id_seq');
112 my ($self, $queue, $ruledb, $mod_group, $targets,
113 $msginfo, $vars, $marks) = @_;
115 my $subgroups = $mod_group->subgroups($targets, 1);
117 my $rulename = $vars->{RULE
} // 'unknown';
119 my $bcc_to = PMG
::Utils
::subst_values
($self->{target
}, $vars);
121 if ($bcc_to =~ m/^\s*$/) {
122 # this happens if a notification is triggered by bounce mails
123 # which notifies the sender <> - we just log and then ignore it
124 syslog
('info', "%s: bcc to <> (rule: %s, ignored)", $queue->{logid
}, $rulename);
128 my @bcc_targets = split (/\s*,\s*/, $bcc_to);
130 if ($self->{original
}) {
131 $subgroups = [[\
@bcc_targets, $mod_group->{entity
}]];
134 foreach my $ta (@$subgroups) {
135 my ($tg, $entity) = (@$ta[0], @$ta[1]);
137 $entity = $entity->dup();
138 PMG
::Utils
::remove_marks
($entity);
140 if ($msginfo->{testmode
}) {
141 my $fh = $msginfo->{test_fh
};
142 print $fh "bcc from: $msginfo->{sender}\n";
143 printf $fh "bcc to: %s\n", join (',', @$tg);
144 print $fh "bcc content:\n";
145 $entity->print ($fh);
146 print $fh "bcc end\n";
148 my $qid = PMG
::Utils
::reinject_mail
(
149 $entity, $msginfo->{sender
}, \
@bcc_targets,
150 $msginfo->{xforward
}, $msginfo->{fqdn
}, 1);
151 foreach (@bcc_targets) {
153 syslog
('info', "%s: bcc to <%s> (rule: %s, %s)", $queue->{logid
}, $_, $rulename, $qid);
155 syslog
('err', "%s: bcc to <%s> (rule: %s) failed", $queue->{logid
}, $_, $rulename);
161 # warn if no subgroups
167 my $descr = "send bcc to: $self->{target}";
169 $descr .= " (original)" if $self->{original
};
179 description
=> "Send a Blind Carbon Copy to this email address.",
180 type
=> 'string', format
=> 'email',
183 description
=> "Send the original, unmodified mail.",
195 target
=> $self->{target
},
196 original
=> $self->{original
},
201 my ($self, $param) = @_;
203 $self->{target
} = $param->{target
};
204 $self->{original
} = $param->{original
} ?
1 : 0;
211 =head1 PMG::RuleDB::BCC