I'm having problems trying to parse a SpamAssassin marked up mail into GT::Mail::Parts. Here is a snippet of the code I'm using to parse the mail:
(This started out as a simple modification of Adrian's SA Plugin)
my $status = $sa->check_message_text($email);
$email = undef;
if ($status->is_spam()) {
if (lc($user_cfg->{action}) eq 'delete') {
$DB->table('msgs')->delete({ msgs_mid => $msgtrack->{msgtrack_mid} });
GT::Plugins->action(STOP);
}
else {
$status->rewrite_mail;
# Re-insert the SA tagged message
require GMail::Messages;
require GT::Mail;
my $mail = GT::Mail->new(debug => $CFG->{debug});
my $part = $mail->parse(\$status->get_full_message_as_text());
my ($msize, $mid) = GMail::Messages->insert_data($mail, $checksum);
GMail::Messages->insert_user(
{
msgtrack_fid => $user_cfg->{move_to_fid},
msgtrack_userid => $USER->{userid},
msgtrack_status => 'Read',
msgtrack_mid => $mid,
msgtrack_account => 0,
msgtrack_look => ($USER->{opts}->{display}->{default_look} || 'clear'),
}, $msize);
GT::Plugins->action(STOP);
}
}
}
The problem is that the whole messages gets stuffed into the top part and the body part is empty causing the message to not be reinserted. I think it has something to do with the output of $status->get_full_message_as_text(); but I don't know for sure. Messages that come into GMail already marked up by SA get inserted just fine.
Here is the output of get_full_messages_as_text:
with SpamAssassin (2.63 2004-01-11);
Wed, 07 Jul 2004 20:20:43 +0530
From: Charlie Piper my_remote@address.net>
To: my_gmail_account@gmail_domain.com
Subject: *****SPAM***** SA Test message
Date: Wed, 7 Jul 2004 07:50:34 -0700 (PDT)
Message-Id: <20040707145034.28076.qmail@web80606.my.isp.com>
X-Spam-Status: Yes, hits=1000.0 required=5.0 tests=GTUBE autolearn=no
version=2.63
X-Spam-Level: **************************************************
X-Spam-Flag: YES
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on
mail.domain.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_40EC0DC3.6A4212EA"
This is a multi-part message in MIME format.
------------=_40EC0DC3.6A4212EA
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
Spam detection software, running on the system "mail.domain.com", has
identified this incoming email as possible spam. The original message
has been attached to this so you can view it (if it isn't spam) or block
similar future email. If you have any questions, see
@@CONTACT_ADDRESS@@ for details.
Content preview: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
[..]
Content analysis details: (1000.0 points, 5.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
1000 GTUBE BODY: Generic Test for Unsolicited Bulk Email
------------=_40EC0DC3.6A4212EA
Content-Type: message/rfc822; x-spam-type=original
Content-Description: original message before SpamAssassin
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
Return-Path: <my_remote@adress.net>
Received: from [xx.xx.xx.xx] (helo=web80606.my.isp.com) by
mail.domain.com with smtp (Exim 4.34) id
1BiDkg-0000hC-Rr for my_gmail_account@gmail_domain.com; Wed, 07 Jul 2004 20:20:26
+0530
Received: from [xx.xx.xx.xx] by web80606.my.isp.com via HTTP; Wed, 07 Jul
2004 07:50:34 PDT
Date: Wed, 7 Jul 2004 07:50:34 -0700 (PDT)
From: Charlie Piper <my_remote@address.net>
Subject: SA Test message
To: my_gmail_account@gmail_domain.com
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Message-Id: <20040707145034.28076.qmail@web80606.my.isp.com>
Delivery-Date: Wed, 07 Jul 2004 20:20:27 +0530
Envelope-To: my_gmail_account@gmail_domain.com
Mime-Version: 1.0
Reply-To: my_remote@address.net
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
------------=_40EC0DC3.6A4212EA--
Any ideas?
Thanks,
Charlie
(This started out as a simple modification of Adrian's SA Plugin)
Code:
my $sa = Mail::SpamAssassin->new(__PACKAGE__->_sa_config); my $status = $sa->check_message_text($email);
$email = undef;
if ($status->is_spam()) {
if (lc($user_cfg->{action}) eq 'delete') {
$DB->table('msgs')->delete({ msgs_mid => $msgtrack->{msgtrack_mid} });
GT::Plugins->action(STOP);
}
else {
$status->rewrite_mail;
# Re-insert the SA tagged message
require GMail::Messages;
require GT::Mail;
my $mail = GT::Mail->new(debug => $CFG->{debug});
my $part = $mail->parse(\$status->get_full_message_as_text());
my ($msize, $mid) = GMail::Messages->insert_data($mail, $checksum);
GMail::Messages->insert_user(
{
msgtrack_fid => $user_cfg->{move_to_fid},
msgtrack_userid => $USER->{userid},
msgtrack_status => 'Read',
msgtrack_mid => $mid,
msgtrack_account => 0,
msgtrack_look => ($USER->{opts}->{display}->{default_look} || 'clear'),
}, $msize);
GT::Plugins->action(STOP);
}
}
}
The problem is that the whole messages gets stuffed into the top part and the body part is empty causing the message to not be reinserted. I think it has something to do with the output of $status->get_full_message_as_text(); but I don't know for sure. Messages that come into GMail already marked up by SA get inserted just fine.
Here is the output of get_full_messages_as_text:
Code:
Received: from localhost by mail.domain.com with SpamAssassin (2.63 2004-01-11);
Wed, 07 Jul 2004 20:20:43 +0530
From: Charlie Piper my_remote@address.net>
To: my_gmail_account@gmail_domain.com
Subject: *****SPAM***** SA Test message
Date: Wed, 7 Jul 2004 07:50:34 -0700 (PDT)
Message-Id: <20040707145034.28076.qmail@web80606.my.isp.com>
X-Spam-Status: Yes, hits=1000.0 required=5.0 tests=GTUBE autolearn=no
version=2.63
X-Spam-Level: **************************************************
X-Spam-Flag: YES
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on
mail.domain.com
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_40EC0DC3.6A4212EA"
This is a multi-part message in MIME format.
------------=_40EC0DC3.6A4212EA
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
Spam detection software, running on the system "mail.domain.com", has
identified this incoming email as possible spam. The original message
has been attached to this so you can view it (if it isn't spam) or block
similar future email. If you have any questions, see
@@CONTACT_ADDRESS@@ for details.
Content preview: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
[..]
Content analysis details: (1000.0 points, 5.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
1000 GTUBE BODY: Generic Test for Unsolicited Bulk Email
------------=_40EC0DC3.6A4212EA
Content-Type: message/rfc822; x-spam-type=original
Content-Description: original message before SpamAssassin
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
Return-Path: <my_remote@adress.net>
Received: from [xx.xx.xx.xx] (helo=web80606.my.isp.com) by
mail.domain.com with smtp (Exim 4.34) id
1BiDkg-0000hC-Rr for my_gmail_account@gmail_domain.com; Wed, 07 Jul 2004 20:20:26
+0530
Received: from [xx.xx.xx.xx] by web80606.my.isp.com via HTTP; Wed, 07 Jul
2004 07:50:34 PDT
Date: Wed, 7 Jul 2004 07:50:34 -0700 (PDT)
From: Charlie Piper <my_remote@address.net>
Subject: SA Test message
To: my_gmail_account@gmail_domain.com
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Message-Id: <20040707145034.28076.qmail@web80606.my.isp.com>
Delivery-Date: Wed, 07 Jul 2004 20:20:27 +0530
Envelope-To: my_gmail_account@gmail_domain.com
Mime-Version: 1.0
Reply-To: my_remote@address.net
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
------------=_40EC0DC3.6A4212EA--
Any ideas?
Thanks,
Charlie