From 82e06a6f15ca816e385d454fc644329523eeaedd Mon Sep 17 00:00:00 2001
From: downtownallday <downtownallday@gmail.com>
Date: Fri, 9 Apr 2021 07:33:49 -0400
Subject: [PATCH] Include remote_host, remote_ip and failure_info with user's
 received mail details

---
 management/reporting/ui/panel-user-activity.html | 2 ++
 management/reporting/ui/panel-user-activity.js   | 3 +++
 management/reporting/uidata/user_activity.2.sql  | 2 ++
 management/reporting/uidata/user_activity.py     | 8 +++++++-
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/management/reporting/ui/panel-user-activity.html b/management/reporting/ui/panel-user-activity.html
index 31981f25..b5acbb51 100644
--- a/management/reporting/ui/panel-user-activity.html
+++ b/management/reporting/ui/panel-user-activity.html
@@ -61,6 +61,7 @@
         </template>
         <template #row-details="row">
           <b-card>
+            <div><strong>Remote host</strong>: {{ row.item.remote_host }}[{{ row.item.remote_ip }}]</div>
             <div><strong>Connection disposition</strong>: {{ disposition_formatter(row.item.disposition) }}</div>
             <div v-if="row.item.orig_to"><strong>Sent to alias</strong>: {{ row.item.orig_to }}</div>
             <div v-if="row.item.dkim_reason"><strong>Dkim reason</strong>: {{row.item.dkim_reason}}</div>
@@ -68,6 +69,7 @@
             <div v-if="row.item.postgrey_reason"><strong>Postgrey reason</strong>: {{row.item.postgrey_reason}}</div>
             <div v-if="row.item.postgrey_delay"><strong>Postgrey delay</strong>: {{received_mail.x_fields.postgrey_delay.formatter(row.item.postgrey_delay)}}</div>
             <div v-if="row.item.spam_result"><strong>Spam score</strong>: {{received_mail.x_fields.spam_score.formatter(row.item.spam_score)}}</div>
+            <div v-if="row.item.failure_info"><strong>Failure info</strong>: {{row.item.failure_info}}</div>
           </b-card>
         </template>
       </b-table>
diff --git a/management/reporting/ui/panel-user-activity.js b/management/reporting/ui/panel-user-activity.js
index 7ec5e24d..7542b523 100644
--- a/management/reporting/ui/panel-user-activity.js
+++ b/management/reporting/ui/panel-user-activity.js
@@ -137,8 +137,11 @@ Vue.component('panel-user-activity', function(resolve, reject) {
             combine_received_mail_fields: function() {
                 // remove these fields
                 this.received_mail.combine_fields([
+                    'remote_host',
+                    'remote_ip',
                     'dkim_reason',
                     'dmarc_reason',
+                    'failure_info',
                     'postgrey_reason',
                     'postgrey_delay',
                     'spam_score',
diff --git a/management/reporting/uidata/user_activity.2.sql b/management/reporting/uidata/user_activity.2.sql
index a2a433e7..45614707 100644
--- a/management/reporting/uidata/user_activity.2.sql
+++ b/management/reporting/uidata/user_activity.2.sql
@@ -4,8 +4,10 @@
 SELECT
 -- mta_connection
 connect_time, mta_connection.service AS service, sasl_username, disposition,
+remote_host, remote_ip,
 -- mta_accept
 envelope_from, spf_result, dkim_result, dkim_reason, dmarc_result, dmarc_reason,
+failure_info,
 -- mta_delivery
 postgrey_result, postgrey_reason, postgrey_delay, spam_score, spam_result, message_size, orig_to
 FROM mta_accept
diff --git a/management/reporting/uidata/user_activity.py b/management/reporting/uidata/user_activity.py
index 8d2ea945..ed135ba1 100644
--- a/management/reporting/uidata/user_activity.py
+++ b/management/reporting/uidata/user_activity.py
@@ -113,6 +113,8 @@ def user_activity(conn, args):
             'connect_time',
             'service',
             'sasl_username',
+            'remote_host',
+            'remote_ip',
             
             # mta_accept
             'envelope_from',
@@ -122,6 +124,7 @@ def user_activity(conn, args):
             'dkim_reason',
             'dmarc_result',
             'dmarc_reason',
+            'failure_info',
             
             # mta_delivery
             'orig_to',
@@ -136,13 +139,16 @@ def user_activity(conn, args):
             { 'type':'datetime', 'format': '%Y-%m-%d %H:%M:%S' },# connect_time
             'text/plain',    # mta_connection.service
             'text/email',    # sasl_username
+            'text/plain',    # remote_host
+            'text/plain',    # remote_ip
             'text/email',    # envelope_from
             'text/plain',    # disposition
             'text/plain',    # spf_result
             'text/plain',    # dkim_result
             'text/plain',    # dkim_result
             'text/plain',    # dmarc_result
-            'text/plain',    # dmarc_result
+            'text/plain',    # dmarc_reason
+            'text/plain',    # failure_info
             'text/email',    # orig_to
             'text/plain',    # postgrey_result
             'text/plain',    # postgrey_reason