public HookResult onMessage(SMTPSession session, Mail mail) {
try {
MimeMessage message = mail.getMessage();
SpamAssassinInvoker sa = new SpamAssassinInvoker(spamdHost,
spamdPort);
sa.scanMail(message);
Iterator<String> headers = sa.getHeadersAsAttribute().keySet().iterator();
// Add the headers
while (headers.hasNext()) {
String key = headers.next();
mail.setAttribute(key, (String) sa.getHeadersAsAttribute().get(
key));
}
// Check if rejectionHits was configured
if (spamdRejectionHits > 0) {
try {
double hits = Double.parseDouble(sa.getHits());
// if the hits are bigger the rejectionHits reject the
// message
if (spamdRejectionHits <= hits) {
StringBuffer buffer = new StringBuffer(256).append(