How to log subjects of all incoming email?

Hello,

I'm trying to achieve the same but in the tracking center, i don't see any subject being logged. Also, is it possible to export the tracking center output to CSV ?
1.Please check whether the line
$self->log (3, "$queue->{logid}: Subject: %s", PMG::Utils::rfc1522_to_html($entity->head->get ('subject', 0)) || 'No Subject');
is really inserted under “PHASE 2” part in the "/usr/bin/pmg-smtp-filter" file.

Then...
systemctl restart pmg-smtp-filter

2. Direct export is not possible.
But you can maybe use the "/var/log/mail.log" file.
 
Hello. The line works.
$self->log (3, "$queue->{logid}: Subject: %s", PMG::Utils::decode_rfc1522(PVE::Tools::trim($entity->head->get('subject'))) || 'No Subject');
But non-ANSI symbols are not displayed in the log.

This line works better.
$self->log (3, "$queue->{logid}: Subject: %s", PMG::Utils::rfc1522_to_html($entity->head->get ('subject', 0)) || 'No Subject');
But it is much more convenient to immediately see the decoded text in the log.

When viewing, you can decode it like this.
cat mail.log | grep Subj | perl -MHTML::Entities -pe 'decode_entities($_);'

How to decode from HTML to UTF-8 immediately when writing to the log?
 
... not nice but better than no subject in the log.(UTF-8 characters fix)

$self->log (3, "$queue->{logid}: Subject: %s", PMG::Utils::rfc1522_to_html($entity->head->get ('subject', 0)) || 'No Subject');
You can use this:

Perl:
$self->log (3, "$queue->{logid}: Subject: %s", encode('UTF-8',PMG::Utils::decode_rfc1522(PVE::Tools::trim($entity->head->get('subject')))) || 'No Subject');
 
Thanks so much for all who contributed on this subject. I can confirm that it works with PMG 8.1.4.

To wrap things up, I'm sharing the code additions made so far below.

File to edit: /usr/bin/pmg-smtp-filter

Perl:
use PVE::SafeSyslog;
use PVE::ProcFSTools;
use PVE::INotify;
# Code added to log subject - start
use PVE::Tools;
# Code added to log subject  - end
...
...
...
Perl:
# PHASE 2 - parse mail
# on error: exit

        my $maxfiles = $pmg_cfg->get('clamav', 'archivemaxfiles');

        my ($entity, $max_aid) = $queue->parse_mail($maxfiles);
        $msginfo->{max_aid} = $max_aid;

        $self->log (3, "$queue->{logid}: new mail message-id=%s", $queue->{msgid});
# Code added to log subject - start
        $self->log (3, "$queue->{logid}: Subject: %s", encode('UTF-8',PMG::Utils::decode_rfc1522(PVE::Tools::trim($entity->head->get('subject')))) || 'No Subject');
        my @fromarray = split('\s*,\s*', PMG::Utils::decode_rfc1522($entity->head->get('from')) || $msginfo->{sender});
        $self->log (3, "$queue->{logid}: From: %s", PMG::Utils::decode_rfc1522(PVE::Tools::trim($fromarray[0])) );
# Code added to log subject - end

I can now see the Subject on the Message Details section.
1727252267800.png

Is it possible to add a Subject column to the GUI to see the subject information directly on the Tracking Center screen?
 
Last edited:
Is it possible to add a Subject column to the GUI to see the subject information directly on the Tracking Center screen?
I once looked into this and didn't find an easy way.

/usr/share/javascript/pmg-gui/js/pmgmanagerlib.js would need addition for the GUI, but the question is where to get the data.

/usr/share/perl5/PMG/API2/MailTracker.pm would have to supply that, but I think the data would have to come from /usr/bin/pmg-log-tracker, which is written in Rust: https://git.proxmox.com/?p=pmg-log-tracker.git;a=blob;f=src/main.rs;hb=HEAD

I gave up at that point.

However, I would still be very interested in this to close the gap to our old Sophos UTM 9 solution.
 
Hi all,

Forgive me, I'm not expert on pmg, it's "yust works for me". But now I have a problem.

A little bit different, but based on this solution. I want to log some custom header, let say x-custom-header.
I made the above mentioned modifications.
I'm using this call:
Code:
PMG::Utils::decode_rfc1522(PVE::Tools::trim($entity->head->get('x-custom-header')));
strage thing: it works mails with local destination, but get empy for outgoing mails.

Then I started to use different aproach: postfix custom header log. Setted up a proper header_checks in /etc/postfix/main.cf, but it behaves exactly the same.

Is there a different $entity content if mail is outgoing? Can I change this with some pmg settings?
Or - which postfix config do I need to modify to achive proper logs?

Thanks in advance,
Lajbi
 
Hello

In version 8.2.2 the line no longer exists:

$self->log (3, "$queue->{logid}: new mail message-id=%s", $queue->{msgid});

I was using the subject line feature, as it really helps find emails in some cases.

Which line should it be inserted below now?
 
I just looked at the git files from PMG and found the line of code you mentioned in both version 8.2.2 and version 8.2.3 of the file /usr/bin/pmg-smtp-filter. The {logid} entry still exists in line 708. This means that adding entries for the subject as described should still work.