Gossamer Forum
Home : Products : Gossamer Mail : Development, Plugins and Globals :

SpamAssassin and GT::Mail::Parse/Parts

Quote Reply
SpamAssassin and GT::Mail::Parse/Parts
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)
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
Quote Reply
Re: [Chaz] SpamAssassin and GT::Mail::Parse/Parts In reply to
I'm getting closer. Adding

Code:
$mail->crlf($/);

gets the message to insert, sort of. If I add in a debug statement to print the $part->header_as_string() it shows all the SA marked up headers but when I look at the mail in GMail it's not marked up. Will GMail::Messages->insert_data overwrite a message if it already exists on disk? Looking at the code it looks like it tries to clobber any existing file before writing to disk.

~Charlie
Quote Reply
Re: SpamAssassin and GT::Mail::Parse/Parts In reply to
Got it sorted, thanks.

~Charlie
Quote Reply
Re: [Chaz] SpamAssassin and GT::Mail::Parse/Parts In reply to
Hi Charlie.

Are you planning to release this plugin for other GM users?
Long time after that dTree.js integration from you. Something good is overdue :)

Thanks
Anup
Quote Reply
Re: [anup123] SpamAssassin and GT::Mail::Parse/Parts In reply to
I'l like to. I really should run it by Adrian first as it's a modification of his. I'll let you know.

~Charlie
Quote Reply
Re: [Chaz] SpamAssassin and GT::Mail::Parse/Parts In reply to
There's actually quite a few features missing in the SpamAssassin plugin that could be implemented. Aki's also done a bit of work on the plugin that I don't think is in the plugin available in the download manager - he did automatic whitelisting of people in your address book.

When I originally wrote the plugin, I wanted to keep it as simple as possible since most of the SpamAssassin options would just confuse the user. I guess you could just split up the configuration page into two sections: basic and advanced.

Adrian
Quote Reply
Re: [brewt] SpamAssassin and GT::Mail::Parse/Parts In reply to
I like the idea of having a split config. That would help aleviate some of the confusion for people not familiar with SA. Anyhow, If you don't mind, I'd like to send you the code once I have it done and see if you're OK with me re-releasing your plugin.

Also, is there any chance you can talk Aki into releasing his plugin? Maybe what I'm doing has already been done?

Thanks,
Charlie
Quote Reply
Re: [Chaz] SpamAssassin and GT::Mail::Parse/Parts In reply to
Sure, send me it when you're done and when I get some time, I can integrate it into the plugin.

In Reply To:
Also, is there any chance you can talk Aki into releasing his plugin? Maybe what I'm doing has already been done?
Well, the code has been committed into cvs, but its just that no one has updated the package available for download :)

Adrian