Skip to content
Snippets Groups Projects
Commit 4cb2f0c9 authored by rswindell's avatar rswindell
Browse files

Support reject option without specifying threshold to reject all SPAM messages.

Support debug option (to enable debug output in salib.js).
Re-arranged the code a bit.
parent fc1bc96a
No related branches found
No related tags found
No related merge requests found
......@@ -3,15 +3,35 @@
// SpamAssasin client for Synchronet
// For use as mailproc.ini script to check messages against a running/listening spamd
// $Id$
// ---------------------------------------------------------------------------
// Example mailproc.ini entries:
// ;Process and pass-through all messages:
// ;Modify and pass-through all messages:
// [spamc.js]
// ;Check for and reject SPAM messages over specified score threshold
// ;Modify SPAM messages only, pass-through all:
// [spamc.js spamonly]
// ;Reject SPAM messages, modify and pass-through HAM:
// [spamc.js reject]
// ;Reject SPAM messages over specified score threshold, modify and pass-through HAM:
// [spamc.js reject 8.0]
// $Id$
// ;Reject SPAM messages over specified score threshold, modify SPAM, and pass-through HAM&SPAM:
// [spamc.js reject 8.0 spamonly]
// ---------------------------------------------------------------------------
// Options:
// dest [ip_address]
// port [tcp_port]
// username [user]
// max-size [bytes]
// spamonly
// debug
load('sockdefs.js');
load('salib.js');
......@@ -21,8 +41,10 @@ function main()
var address = '127.0.0.1';
var tcp_port = 783;
var user;
var reject = false;
var reject_threshold;
var spamonly = false;
var debug = false;
var max_size = 500000; /* bytes */
// Process arguments:
......@@ -43,10 +65,15 @@ function main()
max_size = Number(argv[++i]);
// spamc.js command:
else if(argv[i]=='reject')
reject_threshold = parseFloat(argv[++i]);
else if(argv[i]=='reject') {
reject = true;
if(!isNaN(reject_threshold = parseFloat(argv[i+1])))
i++;
}
else if(argv[i]=='spamonly')
spamonly = true;
else if(argv[i]=='debug')
debug = true;
}
if(max_size && file_size(message_text_filename) > max_size) {
log(LOG_INFO,"SPAMC: message size > max_size (" + max_size + ")");
......@@ -57,7 +84,9 @@ function main()
log(LOG_ERR,"SPAMC: !ERROR "+msg.error);
return;
}
// msg.debug=true;
log(LOG_INFO, "SPAMC: processing message with SPAMD at " + address + " port " + tcp_port);
msg.debug=debug;
var ret=msg.process();
if(ret.warning != undefined)
log(LOG_WARNING, "SPAMC: WARNING "+ret.warning);
......@@ -72,29 +101,34 @@ function main()
log(LOG_INFO, "SPAMC: " + details);
if(!reject_threshold || isNaN(ret.score) || ret.score < reject_threshold) {
if(spamonly && !ret.isSpam)
return;
var msg_file = new File(message_text_filename);
if(!msg_file.open("w")) {
log(LOG_ERR,format("SPAMC: !ERROR %d opening message text file: %s"
,msg_file.error, message_text_filename));
if(!ret.isSpam || ret.score < reject_threshold)
reject = false;
if(reject) {
log(LOG_INFO, "SPAMC: rejecting SPAM with SMTP error");
var error_file = new File(processing_error_filename);
if(!error_file.open("w")) {
log(LOG_ERR,format("SPAMC: !ERROR %d opening processing error file: %s"
,error_file.error, processing_error_filename));
return;
}
msg_file.write(ret.message);
msg_file.close();
error_file.writeln("SpamAssassin rejected your mail: " + details);
error_file.close();
return;
}
log(LOG_INFO, "SPAMC: rejecting SPAM with SMTP error");
var error_file = new File(processing_error_filename);
if(!error_file.open("w")) {
log(LOG_ERR,format("SPAMC: !ERROR %d opening processing error file: %s"
,error_file.error, processing_error_filename));
// Modify message
if(spamonly && !ret.isSpam)
return;
log(LOG_INFO, "SPAMC: re-writing message");
var msg_file = new File(message_text_filename);
if(!msg_file.open("w")) {
log(LOG_ERR,format("SPAMC: !ERROR %d opening message text file: %s"
,msg_file.error, message_text_filename));
return;
}
error_file.writeln("SpamAssassin rejected your mail: " + details);
error_file.close();
msg_file.write(ret.message);
msg_file.close();
}
main();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment