[Bps-public-commit] rt-extension-spamfilter branch, fix-not-spam-action, created. bdaabaa0314ac9ecc2ce54a8aa8efc68523cea64

? sunnavy sunnavy at bestpractical.com
Mon Feb 1 15:36:48 EST 2021


The branch, fix-not-spam-action has been created
        at  bdaabaa0314ac9ecc2ce54a8aa8efc68523cea64 (commit)

- Log -----------------------------------------------------------------
commit ebe004eb7b5b8767a64c68ce3e36906ebe2963ba
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Feb 1 06:46:19 2021 +0800

    Store Queue/Action/Ticket info to correctly route back to RT
    
    Otherwise, "Not Spam" emails would always create tickets in the default
    General queue.

diff --git a/etc/schema.Pg b/etc/schema.Pg
index 8b9031d..937c27d 100644
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -5,6 +5,9 @@ create table Spams (
   Headers text null,
   Content text null,
   Score integer null default 0,
+  Queue integer null,
+  Action varchar(255) null,
+  Ticket integer null,
   Creator integer not null default 0,
   Created timestamp null,
   primary key (id)
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index a9d30e1..bce4a0a 100644
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -3,6 +3,9 @@ create table Spams (
   Status varchar(255) default 'new',
   Headers text null,
   Content text null,
+  Queue integer null,
+  Action varchar(255) null,
+  Ticket integer null,
   Score integer null default 0,
   Creator integer null default 0,
   Created datetime null
diff --git a/etc/schema.mysql b/etc/schema.mysql
index b9ba144..78ddbaa 100644
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -4,6 +4,9 @@ create table Spams (
   Headers text null,
   Content text null,
   Score integer null default 0,
+  Queue integer null,
+  Action varchar(255) null,
+  Ticket integer null,
   Creator integer null default 0,
   Created datetime null
 ) ENGINE=InnoDB CHARACTER SET utf8;
diff --git a/etc/upgrade/0.03/schema.Pg b/etc/upgrade/0.03/schema.Pg
new file mode 100644
index 0000000..245a810
--- /dev/null
+++ b/etc/upgrade/0.03/schema.Pg
@@ -0,0 +1,4 @@
+ALTER TABLE Spams
+    ADD COLUMN Queue INTEGER NULL,
+    ADD COLUMN Action VARCHAR(255) NULL,
+    ADD COLUMN Ticket INTEGER NULL;
diff --git a/etc/upgrade/0.03/schema.SQLite b/etc/upgrade/0.03/schema.SQLite
new file mode 100644
index 0000000..2618d57
--- /dev/null
+++ b/etc/upgrade/0.03/schema.SQLite
@@ -0,0 +1,3 @@
+ALTER TABLE Spams ADD COLUMN Queue INTEGER NULL;
+ALTER TABLE Spams ADD COLUMN Action VARCHAR(255) NULL;
+ALTER TABLE Spams ADD COLUMN Ticket INTEGER NULL;
diff --git a/etc/upgrade/0.03/schema.mysql b/etc/upgrade/0.03/schema.mysql
new file mode 100644
index 0000000..245a810
--- /dev/null
+++ b/etc/upgrade/0.03/schema.mysql
@@ -0,0 +1,4 @@
+ALTER TABLE Spams
+    ADD COLUMN Queue INTEGER NULL,
+    ADD COLUMN Action VARCHAR(255) NULL,
+    ADD COLUMN Ticket INTEGER NULL;
diff --git a/html/Tools/SpamFilter/Display.html b/html/Tools/SpamFilter/Display.html
index 06efcc7..0c0f730 100644
--- a/html/Tools/SpamFilter/Display.html
+++ b/html/Tools/SpamFilter/Display.html
@@ -106,7 +106,11 @@ if ( $Action ) {
             EmailAddress => $address,
             Comments     => 'Created by SpamFilter',
         );
-        my ( $ret, $msg, $ticket) = RT::Interface::Email::Gateway( { message => $email->Content } );
+        my ( $ret, $msg, $ticket ) = RT::Interface::Email::Gateway(
+            {   message => $email->Content,
+                map { lc $_ => $email->$_ } grep { $email->$_ } qw/Queue Action Ticket/,
+            }
+        );
         if ( $ret == 1 && $ticket ) {
             $email->SetStatus('resolved');
             push @results, $msg;
diff --git a/html/Tools/SpamFilter/Elements/ShowBasics b/html/Tools/SpamFilter/Elements/ShowBasics
index abbd72e..838b8e6 100644
--- a/html/Tools/SpamFilter/Elements/ShowBasics
+++ b/html/Tools/SpamFilter/Elements/ShowBasics
@@ -71,6 +71,12 @@
     <div class="label col-1"><&|/l&>Date</&>:</div>
     <div class="value col-11"><% $Spam->GetHeader('Date') %></div>
   </div>
+% for my $field ( qw/Queue Action Ticket/ ) {
+  <div class="date form-row"">
+    <div class="label col-1"><% loc($field) %>:</div>
+    <div class="value col-11"><% $Spam->$field // '' %></div>
+  </div>
+% }
 </div>
 <%ARGS>
 $Spam => undef
diff --git a/lib/RT/Interface/Email/SpamFilter.pm b/lib/RT/Interface/Email/SpamFilter.pm
index 91d9e0b..200dccb 100644
--- a/lib/RT/Interface/Email/SpamFilter.pm
+++ b/lib/RT/Interface/Email/SpamFilter.pm
@@ -67,7 +67,9 @@ RT::Interface::Email::SpamFilter
 
 sub GetCurrentUser {
     my %args = (
-        Message => undef,
+        Message   => undef,
+        Queue     => undef,
+        RawAction => undef,
         @_,
     );
 
@@ -91,8 +93,15 @@ sub GetCurrentUser {
     my ( $score ) = RT::Extension::SpamFilter->MessageScore($args{'Message'});
     if ( $score >= RT->Config->Get( 'SpamFilterThreshold' ) || 0 ) {
         my $email = RT::Spam->new( RT->SystemUser );
-        my ( $ret, $message ) =
-          $email->Create( Message => $args{Message}, RawMessage => ${ $args{RawMessage} }, Status => 'new', Score => $score );
+        my ( $ret, $message ) = $email->Create(
+            Message    => $args{Message},
+            RawMessage => ${ $args{RawMessage} },
+            Status     => 'new',
+            Score      => $score,
+            Queue      => $args{Queue}->Id,
+            Action     => $args{RawAction},
+            Ticket     => $args{Ticket}->Id,
+        );
         if ( !$ret ) {
             RT->Logger->error( "Failed to create Spam record: $message" );
         }
diff --git a/lib/RT/Spam.pm b/lib/RT/Spam.pm
index 848a526..5bd7628 100644
--- a/lib/RT/Spam.pm
+++ b/lib/RT/Spam.pm
@@ -94,6 +94,7 @@ sub Create {
         Headers => $headers,
         Content => encode_base64($args{Message}->as_string),
         Score => $args{Score},
+        map { $_ => $args{$_} } qw/Queue Action Ticket/,
     );
 
     unless ( $id ) {
@@ -197,6 +198,12 @@ sub _CoreAccessible {
 		{read => 1, sql_type => -4, length => 0,  is_blob => 1,  is_numeric => 0,  type => 'longtext', default => ''},
         Score =>
 		{read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
+        Queue =>
+		{read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
+        Action =>
+		{read => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varchar(255)', default => ''},
+        Ticket =>
+		{read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
         Creator =>
 		{read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
         Created =>

commit 720650b46463e90afca22debb6e7509d268c08ac
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Feb 2 04:18:14 2021 +0800

    Drop the unused and incorrect RawMessage argument
    
    The correct name is "RawMessageRef", but since we don't use it anyway,
    here we simply delete the incorrect version.

diff --git a/lib/RT/Interface/Email/SpamFilter.pm b/lib/RT/Interface/Email/SpamFilter.pm
index 200dccb..8b95080 100644
--- a/lib/RT/Interface/Email/SpamFilter.pm
+++ b/lib/RT/Interface/Email/SpamFilter.pm
@@ -95,7 +95,6 @@ sub GetCurrentUser {
         my $email = RT::Spam->new( RT->SystemUser );
         my ( $ret, $message ) = $email->Create(
             Message    => $args{Message},
-            RawMessage => ${ $args{RawMessage} },
             Status     => 'new',
             Score      => $score,
             Queue      => $args{Queue}->Id,

commit bdaabaa0314ac9ecc2ce54a8aa8efc68523cea64
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Feb 2 04:28:03 2021 +0800

    Add patch to get action info from RT mailgate

diff --git a/README b/README
index 931e206..cd8d8da 100644
--- a/README
+++ b/README
@@ -27,6 +27,9 @@ INSTALLATION
         If you are upgrading this module, check for upgrading instructions
         in case changes need to be made to your database.
 
+    Patch RT earlier than 5.0.2
+            patch -d /opt/rt5 -p1 < patches/0001-Pass-action-info-to-GetCurrentUser-for-email-interfa.patch
+
     Set up spam filter rules (see "CONFIGURATION" for details.)
     Clear your mason cache
             rm -rf /opt/rt5/var/mason_data/obj
diff --git a/lib/RT/Extension/SpamFilter.pm b/lib/RT/Extension/SpamFilter.pm
index f90af15..30ecb33 100644
--- a/lib/RT/Extension/SpamFilter.pm
+++ b/lib/RT/Extension/SpamFilter.pm
@@ -72,6 +72,10 @@ in your database.
 If you are upgrading this module, check for upgrading instructions
 in case changes need to be made to your database.
 
+=item Patch RT earlier than 5.0.2
+
+    patch -d /opt/rt5 -p1 < patches/0001-Pass-action-info-to-GetCurrentUser-for-email-interfa.patch
+
 =item Set up spam filter rules (see L</"CONFIGURATION"> for details.)
 
 =item Clear your mason cache
diff --git a/patches/0001-Pass-action-info-to-GetCurrentUser-for-email-interfa.patch b/patches/0001-Pass-action-info-to-GetCurrentUser-for-email-interfa.patch
new file mode 100644
index 0000000..f6d082e
--- /dev/null
+++ b/patches/0001-Pass-action-info-to-GetCurrentUser-for-email-interfa.patch
@@ -0,0 +1,43 @@
+From efdb343d37525b07d929581db8ef4215f53f6295 Mon Sep 17 00:00:00 2001
+From: sunnavy <sunnavy at bestpractical.com>
+Date: Tue, 2 Feb 2021 03:32:53 +0800
+Subject: [PATCH] Pass action info to GetCurrentUser for email interface
+
+Usually GetCurrentUser doen't need to know action. This is initially for
+SpamFilter so it could get enough info to re-route emails back to RT's
+normal workflow.
+---
+ lib/RT/Interface/Email.pm | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
+index 7255b14e8a..f1cbb8df8d 100644
+--- a/lib/RT/Interface/Email.pm
++++ b/lib/RT/Interface/Email.pm
+@@ -229,6 +229,7 @@ sub Gateway {
+         RawMessageRef => \$args{message},
+         Ticket        => $SystemTicket,
+         Queue         => $SystemQueueObj,
++        RawAction     => $args{action},
+     );
+ 
+     # We only care about ACLs on the _first_ action, as later actions
+@@ -334,6 +335,7 @@ sub GetCurrentUser {
+         RawMessageRef => undef,
+         Ticket        => undef,
+         Queue         => undef,
++        RawAction     => undef,
+         @_,
+     );
+ 
+@@ -344,6 +346,7 @@ sub GetCurrentUser {
+             RawMessageRef => $args{RawMessageRef},
+             Ticket        => $args{Ticket},
+             Queue         => $args{Queue},
++            RawAction     => $args{RawAction},
+         );
+         return $CurrentUser if $CurrentUser and $CurrentUser->id;
+     }
+-- 
+2.24.3 (Apple Git-128)
+

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list