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.