You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Reindl Harald <h....@thelounge.net> on 2016/06/27 00:11:06 UTC
spamd protocol
i try to pass samples directly over spamd protocol
in therory that looks good but log and scan starts after the client
closes the conenction or the script exists, as long it tries ot read the
response nothing happens at all
without the "fread($socket, 1024);" it terminates immediately, log shows
scanning, with the fread() ut take some time, nothing happens on the
server side and after a while the script finishes and spamd scans the data
well, the whole purpose is to fread(9 or fgets() the response
_______________________________________________
un 27 02:05:44 mail-gw spamd[2991]: spamd: checking message
<56...@testserver.rhsoft.net> for sa-milt:189
Jun 27 02:05:46 mail-gw spamd[2991]: spamd: identified spam (13.1/5.5)
for sa-milt:189 in 12.0 seconds, 1552 bytes.
Jun 27 02:05:46 mail-gw spamd[2991]: spamd: result: Y 13 -
BAYES_50,CUST_BODY_BEGINS_VL,RAZOR2_CF_RANGE_51_100,RAZOR2_CF_RANGE_E8_51_100,RAZOR2_CHECK,SPF_HELO_FAIL,TVD_SPACE_RATIO,URIBL_DBL_SPAM,URIBL_LOCAL
scantime=12.0,size=1552,user=sa-milt,uid=189,required_score=5.5,rhost=localhost,raddr=127.0.0.1,rport=/run/spamassassin/spamassassin.sock,mid=<56...@testserver.rhsoft.net>,bayes=0.498469,autolearn=disabled,shortcircuit=no
_______________________________________________
<?php
$socket_path = '/run/spamassassin/spamassassin.sock';
echo spamc_headers($socket_path, __DIR__ . '/test1.eml',
/**$bayes_only*/0);
function spamc_headers($socket_path, $eml_path, $bayes_only=0,
$user='sa-milt')
{
$protocol_version = '1.5';
$socket = fsockopen('unix://' . $socket_path, NULL);
if($socket)
{
$raw_eml = trim(file_get_contents($eml_path)) . "\r\n";
$cmd = 'HEADERS SPAMC/' . $protocol_version . "\r\n";
$cmd .= 'Content-Length: ' . strlen($raw_eml) . "\r\n";
$cmd .= 'User: ' . $user . "\r\n";
$cmd .= "\r\n";
$cmd .= $raw_eml;
$cmd .= "\r\n";
fwrite($socket, $cmd);
echo fread($socket, 1024);
}
}
?>
Re: spamd protocol
Posted by Reindl Harald <h....@thelounge.net>.
'Content-length' needs to be 'Content-Length'
are you kidding me?
/**
* Scan RAW-Message with spamd
*
* @param string $socket_path spamd-socket
* @param string $eml_path sample-file
* @param boolean $bayes_only only return bayes-classification
('BAYES_00', 'BAYES_05'...)
* @return string
* @access public
*/
function spamc_report($socket_path, $eml_path, $bayes_only=false,
$user='sa-milt')
{
$response = '';
$protocol_version = '1.5';
$socket = fsockopen('unix://' . $socket_path);
if($socket)
{
$raw_eml = trim(file_get_contents($eml_path)) . "\r\n";
fwrite($socket, 'REPORT SPAMC/' . $protocol_version . "\r\n");
fwrite($socket, 'Content-length: ' . strlen($raw_eml) . "\r\n");
fwrite($socket, 'User: ' . $user . "\r\n");
fwrite($socket, "\r\n");
fwrite($socket, $raw_eml);
fwrite($socket, "\r\n");
while(true)
{
$buffer = fgets($socket, 128);
$response .= $buffer;
if(feof($socket))
{
break;
}
}
$response = substr($response, strpos($response, 'Content analysis
details'));
if($bayes_only)
{
$result = '';
$result_types = array('BAYES_00', 'BAYES_05', 'BAYES_20',
'BAYES_40', 'BAYES_50', 'BAYES_60', 'BAYES_80', 'BAYES_95', 'BAYES_99',
'BAYES_999');
foreach($result_types as $result_type)
{
if(strpos($response, ' ' . $result_type . ' ') !== false)
{
$result = $result_type;
break;
}
}
return $result;
}
else
{
return $response;
}
}
}
Am 27.06.2016 um 02:11 schrieb Reindl Harald:
> i try to pass samples directly over spamd protocol
>
> in therory that looks good but log and scan starts after the client
> closes the conenction or the script exists, as long it tries ot read the
> response nothing happens at all
>
> without the "fread($socket, 1024);" it terminates immediately, log shows
> scanning, with the fread() ut take some time, nothing happens on the
> server side and after a while the script finishes and spamd scans the data
>
> well, the whole purpose is to fread(9 or fgets() the response
> _______________________________________________
>
> un 27 02:05:44 mail-gw spamd[2991]: spamd: checking message
> <56...@testserver.rhsoft.net> for sa-milt:189
> Jun 27 02:05:46 mail-gw spamd[2991]: spamd: identified spam (13.1/5.5)
> for sa-milt:189 in 12.0 seconds, 1552 bytes.
> Jun 27 02:05:46 mail-gw spamd[2991]: spamd: result: Y 13 -
> BAYES_50,CUST_BODY_BEGINS_VL,RAZOR2_CF_RANGE_51_100,RAZOR2_CF_RANGE_E8_51_100,RAZOR2_CHECK,SPF_HELO_FAIL,TVD_SPACE_RATIO,URIBL_DBL_SPAM,URIBL_LOCAL
> scantime=12.0,size=1552,user=sa-milt,uid=189,required_score=5.5,rhost=localhost,raddr=127.0.0.1,rport=/run/spamassassin/spamassassin.sock,mid=<56...@testserver.rhsoft.net>,bayes=0.498469,autolearn=disabled,shortcircuit=no
>
> _______________________________________________
>
> <?php
> $socket_path = '/run/spamassassin/spamassassin.sock';
> echo spamc_headers($socket_path, __DIR__ . '/test1.eml',
> /**$bayes_only*/0);
> function spamc_headers($socket_path, $eml_path, $bayes_only=0,
> $user='sa-milt')
> {
> $protocol_version = '1.5';
> $socket = fsockopen('unix://' . $socket_path, NULL);
> if($socket)
> {
> $raw_eml = trim(file_get_contents($eml_path)) . "\r\n";
> $cmd = 'HEADERS SPAMC/' . $protocol_version . "\r\n";
> $cmd .= 'Content-Length: ' . strlen($raw_eml) . "\r\n";
> $cmd .= 'User: ' . $user . "\r\n";
> $cmd .= "\r\n";
> $cmd .= $raw_eml;
> $cmd .= "\r\n";
> fwrite($socket, $cmd);
> echo fread($socket, 1024);
> }
> }
> ?>