You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by BG Mahesh <bg...@gmail.com> on 2007/05/09 10:36:05 UTC

Re: How to use SpamAssassin from PHP?

On 4/17/07, Derek Harding <de...@innovyx.com> wrote:
>
> On Tue, 2007-04-17 at 16:52 +0530, BG Mahesh wrote:
> >
> > hi
> >
> > I want to pass the comments/text entered by users on a form to
> > SpamAssassin for approval. If it approves it only then I want to
> > accept the text, else I want to inform the user that the text is Spam
> > and reject the user's comments.
> >
> > We use PHP and want to know how to implement this.
>
> Someone asked about SA from PHP on this list back in March. Here is what
> I wrote then:
>
> #!/usr/bin/php -q
> <?
> $fname = tempnam("/tmp", "sa");
> file_put_contents($fname, $message);
>
> exec("/usr/bin/spamc -c <$fname", $score, $res);
>
> if ($res == 1)
>   echo "It's spam.\n";
>
> unlink($fname);
> ?>
>
> TBH I'm not sure SA is really going to help you here since you'll have
> zero headers for it to work on meaning you're pretty much down to
> content & URIBL checks.
>
> Derek
>
>
>
We have tested this on http://cause.greynium.com/spamtest.php
We have constructed a Mail header, concatenating $message to $header and
passing the contents of $header to the code given above.


We have installed the script from rulesemporium to update the cf files.

What could we be missing?

-- 
--
B.G. Mahesh
http://www.greynium.com/
http://www.oneindia.in/
http://www.click.in/ - Free Indian Classifieds

Re: How to use SpamAssassin from PHP?

Posted by .
I ran your first sample through SA here and got the following score :-

X-Spam-Status: Yes, score=6.5 required=5.0 tests=BAYES_50,FRT_PENIS1,
        HTML_MESSAGE,HTML_MIME_NO_HTML_TAG,MIME_HTML_ONLY,MISSING_DATE,MISSING_HB_SEP,
        MISSING_MID,NO_RECEIVED,NO_RELAYS autolearn=no version=3.2.0

Regards,

On Wed, 9 May 2007 10:22:55 +0100, --[ UxBoD ]-- <ux...@splatnix.net> wrote:
> To ensure all is working okay, why not take a existing SPAM message and
> construct the $message from that and test ?
> 
> On Wed, 9 May 2007 14:40:52 +0530, "BG Mahesh" <bg...@gmail.com> wrote:
>> On 5/9/07, Duncan Hill <sp...@cricalix.net> wrote:
>>>
>>> On Wed, May 9, 2007 09:36, BG Mahesh wrote:
>>>
>>> > We have tested this on http://cause.greynium.com/spamtest.php
>>> > We have constructed a Mail header, concatenating $message to $header
>> and
>>> > passing the contents of $header to the code given above.
>>> >
>>> > We have installed the script from rulesemporium to update the cf
>> files.
>>> >
>>> > What could we be missing?
>>>
>>> Are you saying something isn't working?
>>>
>>>
>> 
>> The content should be reported as Spam. The score (when I run from
> command
>> line is just about 1.0 and required is 5.0). The text in $message have
>> very
>> hardcore words. Shouldn't it be marked as spam?
>> 
>> Are we formating the header correctly (i.e. each line is ending with
> \n)?
>> 
>> regards,
>> 
>> --
>> --
>> B.G. Mahesh
>> http://www.greynium.com/
>> http://www.oneindia.in/
>> http://www.click.in/ - Free Indian Classifieds
>> 
>> --
>> This message has been scanned for viruses and dangerous content by
>> MailScanner, and is
>> believed to be clean.
> -- 
> --[ UxBoD ]--
> // PGP Key: "curl -s http://www.splatnix.net/uxbod.asc | gpg --import"
> // Fingerprint: 543A E778 7F2D 98F1 3E50 9C1F F190 93E0 E8E8 0CF8
> // Keyserver: www.keyserver.net Key-ID: 0xE8E80CF8
> // Phone: +44 (0) 845 869 2749  SIP: uxbod@sip.splatnix.net
> 
> 
>
-- 
--[ UxBoD ]--
// PGP Key: "curl -s http://www.splatnix.net/uxbod.asc | gpg --import"
// Fingerprint: 543A E778 7F2D 98F1 3E50 9C1F F190 93E0 E8E8 0CF8
// Keyserver: www.keyserver.net Key-ID: 0xE8E80CF8
// Phone: +44 (0) 845 869 2749  SIP: uxbod@sip.splatnix.net


-- 
This message has been scanned for viruses and dangerous content by MailScanner, and is
believed to be clean.


Re: How to use SpamAssassin from PHP?

Posted by .
To ensure all is working okay, why not take a existing SPAM message and construct the $message from that and test ?

On Wed, 9 May 2007 14:40:52 +0530, "BG Mahesh" <bg...@gmail.com> wrote:
> On 5/9/07, Duncan Hill <sp...@cricalix.net> wrote:
>>
>> On Wed, May 9, 2007 09:36, BG Mahesh wrote:
>>
>> > We have tested this on http://cause.greynium.com/spamtest.php
>> > We have constructed a Mail header, concatenating $message to $header
> and
>> > passing the contents of $header to the code given above.
>> >
>> > We have installed the script from rulesemporium to update the cf
> files.
>> >
>> > What could we be missing?
>>
>> Are you saying something isn't working?
>>
>>
> 
> The content should be reported as Spam. The score (when I run from command
> line is just about 1.0 and required is 5.0). The text in $message have
> very
> hardcore words. Shouldn't it be marked as spam?
> 
> Are we formating the header correctly (i.e. each line is ending with \n)?
> 
> regards,
> 
> --
> --
> B.G. Mahesh
> http://www.greynium.com/
> http://www.oneindia.in/
> http://www.click.in/ - Free Indian Classifieds
> 
> --
> This message has been scanned for viruses and dangerous content by
> MailScanner, and is
> believed to be clean.
-- 
--[ UxBoD ]--
// PGP Key: "curl -s http://www.splatnix.net/uxbod.asc | gpg --import"
// Fingerprint: 543A E778 7F2D 98F1 3E50 9C1F F190 93E0 E8E8 0CF8
// Keyserver: www.keyserver.net Key-ID: 0xE8E80CF8
// Phone: +44 (0) 845 869 2749  SIP: uxbod@sip.splatnix.net


-- 
This message has been scanned for viruses and dangerous content by MailScanner, and is
believed to be clean.


Re: How to use SpamAssassin from PHP?

Posted by Henrik Krohns <he...@hege.li>.
On Wed, May 09, 2007 at 02:40:52PM +0530, BG Mahesh wrote:
> On 5/9/07, Duncan Hill <sp...@cricalix.net> wrote:
> >
> >On Wed, May 9, 2007 09:36, BG Mahesh wrote:
> >
> >> We have tested this on http://cause.greynium.com/spamtest.php
> >> We have constructed a Mail header, concatenating $message to $header and
> >> passing the contents of $header to the code given above.
> >>
> >> We have installed the script from rulesemporium to update the cf files.
> >>
> >> What could we be missing?

Common sense?

> The content should be reported as Spam. The score (when I run from command
> line is just about 1.0 and required is 5.0). The text in $message have very
> hardcore words. Shouldn't it be marked as spam?

Why should hardcore words be marked as spam? SpamAssassin is designed for
"complex cases" like spam emails. There would be lot of messages dropped if
the only rule would be hardcore words.

You are much better off coding your own stuff in PHP, like:
if ( preg_match("/\b(word1|word2)\b/", $message) ) die("Spam");

Ofcourse you can write your own SpamAssassin rules, if you still insist
on using SA.

Cheers,
Henrik

Re: How to use SpamAssassin from PHP?

Posted by Duncan Hill <dh...@cricalix.net>.
On Wed, May 9, 2007 10:10, BG Mahesh wrote:
> On 5/9/07, Duncan Hill <sp...@cricalix.net> wrote:
>
>>
>> On Wed, May 9, 2007 09:36, BG Mahesh wrote:
>>
>>
>>> We have tested this on http://cause.greynium.com/spamtest.php
>>> We have constructed a Mail header, concatenating $message to $header
>>> and passing the contents of $header to the code given above.
>>>
>>> We have installed the script from rulesemporium to update the cf
>>> files.
>>>
>>> What could we be missing?
>>>
>>
>> Are you saying something isn't working?
>>
>>
>>
>
> The content should be reported as Spam. The score (when I run from
> command line is just about 1.0 and required is 5.0). The text in $message
> have very hardcore words. Shouldn't it be marked as spam?
>
> Are we formating the header correctly (i.e. each line is ending with \n)?

'hardcore' words are not necessarily enough to determine that an item is
spam.

I suggest you start your testing with a real spam mail (and you can find
quite a lot of those in places like news.admin.net-abuse.sightings), using
the SpamAssassin command line interface.  Once you're happy that it scores
mail properly, feed the body plus your custom headers to the command line
interface.  Bear in mind that a good chunk of the SA rules check headers
for things like invalid timestamps, spam signs etc, so your effectiveness
may be crippled.


Re: How to use SpamAssassin from PHP?

Posted by BG Mahesh <bg...@gmail.com>.
On 5/9/07, Duncan Hill <sp...@cricalix.net> wrote:
>
> On Wed, May 9, 2007 09:36, BG Mahesh wrote:
>
> > We have tested this on http://cause.greynium.com/spamtest.php
> > We have constructed a Mail header, concatenating $message to $header and
> > passing the contents of $header to the code given above.
> >
> > We have installed the script from rulesemporium to update the cf files.
> >
> > What could we be missing?
>
> Are you saying something isn't working?
>
>

The content should be reported as Spam. The score (when I run from command
line is just about 1.0 and required is 5.0). The text in $message have very
hardcore words. Shouldn't it be marked as spam?

Are we formating the header correctly (i.e. each line is ending with \n)?

regards,

-- 
--
B.G. Mahesh
http://www.greynium.com/
http://www.oneindia.in/
http://www.click.in/ - Free Indian Classifieds

Re: How to use SpamAssassin from PHP?

Posted by Duncan Hill <sp...@cricalix.net>.
On Wed, May 9, 2007 09:36, BG Mahesh wrote:

> We have tested this on http://cause.greynium.com/spamtest.php
> We have constructed a Mail header, concatenating $message to $header and
> passing the contents of $header to the code given above.
>
> We have installed the script from rulesemporium to update the cf files.
>
> What could we be missing?

Are you saying something isn't working?