]> git.proxmox.com Git - pmg-api.git/commitdiff
add logging to disclaimer action
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 18 Jun 2020 11:33:17 +0000 (13:33 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 18 Jun 2020 16:29:47 +0000 (18:29 +0200)
the disclaimer action currently does not log, if a disclaimer got added or not.
given that there are a few not directly obvious cases where a disclaimer does
not get added (e.g. it depends on the mail's encoding) - logging success or
failure should help in debugging

Tested by sending mails, where adding the disclaimer works, and where it fails.
verified that the log-tracker also adds those lines to its output.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PMG/RuleDB/Disclaimer.pm

index 3d2120bb06afadf72192c9941db63d3fb36919ff..104be72ca0cfd29664ca20349ad67bee3b7227f3 100644 (file)
@@ -10,6 +10,8 @@ use MIME::Body;
 use IO::File;
 use Encode qw(decode encode);
 
+use PVE::SafeSyslog;
+
 use PMG::Utils;
 use PMG::ModGroup;
 use PMG::RuleDB::Object;;
@@ -143,17 +145,17 @@ sub add_data {
 }
 
 sub sign {
-    my ($self, $entity, $html, $text) = @_;
+    my ($self, $entity, $html, $text, $logid, $rulename) = @_;
 
     my $found = 0;
 
     if ($entity->head->mime_type =~ m{multipart/alternative}) {
        foreach my $p ($entity->parts) {
-           $found = 1 if $self->sign ($p, $html, $text);
+           $found = 1 if $self->sign ($p, $html, $text, $logid, $rulename);
        }
     } elsif ($entity->head->mime_type =~ m{multipart/}) {
        foreach my $p ($entity->parts) {
-           if ($self->sign ($p, $html, $text)) {
+           if ($self->sign ($p, $html, $text, $logid, $rulename)) {
                $found = 1;
                last;
            }
@@ -168,6 +170,11 @@ sub sign {
            };
            # simply ignore if we can't represent the disclainer
            # with that encoding
+           if ($@) {
+               syslog('info', "%s: adding disclaimer failed (rule: %s)", $logid, $rulename);
+           } else {
+               syslog('info', "%s: added disclaimer (rule: %s)", $logid, $rulename);
+           }
            $found = 1;
        } else {
            # do nothing - unknown format
@@ -181,6 +188,8 @@ sub execute {
     my ($self, $queue, $ruledb, $mod_group, $targets, 
        $msginfo, $vars, $marks) = @_;
 
+    my $rulename = $vars->{RULE} // 'unknown';
+
     my $subgroups = $mod_group->subgroups($targets);
 
     foreach my $ta (@$subgroups) {
@@ -199,7 +208,7 @@ sub execute {
        $parser->parse($tmp);
        $parser->eof;
            
-       $self->sign($entity, "$html\n", "$text\n");
+       $self->sign($entity, "$html\n", "$text\n", $queue->{logid}, $rulename);
 
        return;
     }