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 @@ ...@@ -3,15 +3,35 @@
// SpamAssasin client for Synchronet // SpamAssasin client for Synchronet
// For use as mailproc.ini script to check messages against a running/listening spamd // For use as mailproc.ini script to check messages against a running/listening spamd
// $Id$
// ---------------------------------------------------------------------------
// Example mailproc.ini entries: // Example mailproc.ini entries:
// ;Process and pass-through all messages: // ;Modify and pass-through all messages:
// [spamc.js] // [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] // [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('sockdefs.js');
load('salib.js'); load('salib.js');
...@@ -21,8 +41,10 @@ function main() ...@@ -21,8 +41,10 @@ function main()
var address = '127.0.0.1'; var address = '127.0.0.1';
var tcp_port = 783; var tcp_port = 783;
var user; var user;
var reject = false;
var reject_threshold; var reject_threshold;
var spamonly = false; var spamonly = false;
var debug = false;
var max_size = 500000; /* bytes */ var max_size = 500000; /* bytes */
// Process arguments: // Process arguments:
...@@ -43,10 +65,15 @@ function main() ...@@ -43,10 +65,15 @@ function main()
max_size = Number(argv[++i]); max_size = Number(argv[++i]);
// spamc.js command: // spamc.js command:
else if(argv[i]=='reject') else if(argv[i]=='reject') {
reject_threshold = parseFloat(argv[++i]); reject = true;
if(!isNaN(reject_threshold = parseFloat(argv[i+1])))
i++;
}
else if(argv[i]=='spamonly') else if(argv[i]=='spamonly')
spamonly = true; spamonly = true;
else if(argv[i]=='debug')
debug = true;
} }
if(max_size && file_size(message_text_filename) > max_size) { if(max_size && file_size(message_text_filename) > max_size) {
log(LOG_INFO,"SPAMC: message size > max_size (" + max_size + ")"); log(LOG_INFO,"SPAMC: message size > max_size (" + max_size + ")");
...@@ -57,7 +84,9 @@ function main() ...@@ -57,7 +84,9 @@ function main()
log(LOG_ERR,"SPAMC: !ERROR "+msg.error); log(LOG_ERR,"SPAMC: !ERROR "+msg.error);
return; return;
} }
// msg.debug=true;
log(LOG_INFO, "SPAMC: processing message with SPAMD at " + address + " port " + tcp_port);
msg.debug=debug;
var ret=msg.process(); var ret=msg.process();
if(ret.warning != undefined) if(ret.warning != undefined)
log(LOG_WARNING, "SPAMC: WARNING "+ret.warning); log(LOG_WARNING, "SPAMC: WARNING "+ret.warning);
...@@ -72,20 +101,10 @@ function main() ...@@ -72,20 +101,10 @@ function main()
log(LOG_INFO, "SPAMC: " + details); log(LOG_INFO, "SPAMC: " + details);
if(!reject_threshold || isNaN(ret.score) || ret.score < reject_threshold) { if(!ret.isSpam || ret.score < reject_threshold)
if(spamonly && !ret.isSpam) reject = false;
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));
return;
}
msg_file.write(ret.message);
msg_file.close();
return;
}
if(reject) {
log(LOG_INFO, "SPAMC: rejecting SPAM with SMTP error"); log(LOG_INFO, "SPAMC: rejecting SPAM with SMTP error");
var error_file = new File(processing_error_filename); var error_file = new File(processing_error_filename);
if(!error_file.open("w")) { if(!error_file.open("w")) {
...@@ -95,6 +114,21 @@ function main() ...@@ -95,6 +114,21 @@ function main()
} }
error_file.writeln("SpamAssassin rejected your mail: " + details); error_file.writeln("SpamAssassin rejected your mail: " + details);
error_file.close(); error_file.close();
return;
}
// 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;
}
msg_file.write(ret.message);
msg_file.close();
} }
main(); main();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment