01: package org.claros.intouch.webmail.controllers;
02:
03: import javax.mail.Flags;
04: import javax.mail.Message;
05: import javax.mail.internet.MimeMessage;
06:
07: import org.claros.commons.auth.models.AuthProfile;
08: import org.claros.intouch.common.utility.Constants;
09: import org.claros.intouch.preferences.controllers.UserPrefsController;
10: import org.jasen.JasenScanner;
11: import org.jasen.interfaces.JasenScanResult;
12:
13: /**
14: * @author Umut Gokbayrak
15: */
16: public class SpamController {
17:
18: /**
19: * @param auth
20: * @param msg
21: * @return
22: */
23: public static boolean isSpam(AuthProfile auth, Message msg)
24: throws Exception {
25: System.setProperty("java.awt.headless", "true");
26: // String spam = UserPrefsController.getUserSetting(auth, UserPrefConstants.spamAnalysis);
27: String spam = null;
28: boolean spamAnalysis = true;
29: if (spam != null && spam.equals("no")) {
30: spamAnalysis = false;
31: }
32:
33: if (spamAnalysis) {
34: if (msg instanceof MimeMessage) {
35: if (Constants.spamScanner == null) {
36: JasenScanner.getInstance().init();
37: Constants.spamScanner = JasenScanner.getInstance();
38: }
39: /*
40: if (!msg.getFolder().isOpen()) {
41: msg.getFolder().open(Folder.READ_WRITE);
42: }
43: */
44: // msg = msg.getFolder().getMessage(msg.getMessageNumber());
45: JasenScanResult result = Constants.spamScanner
46: .scan((MimeMessage) msg);
47: double probability = result.getProbability();
48:
49: msg.setFlag(Flags.Flag.SEEN, false);
50: String accepts = UserPrefsController.getUserSetting(
51: auth, "spamUserAccepts");
52: accepts = "0.2";
53: Double d = null;
54: if (accepts == null) {
55: d = new Double(0.9);
56: } else {
57: d = new Double(accepts);
58: }
59: if (probability >= d.doubleValue()) {
60: // it is spam
61: return true;
62: } else {
63: return false;
64: }
65: }
66: }
67: return false;
68: }
69:
70: }
|