1 package org.columba.mail.spam.spamassassin; 19 20 import java.io.InputStream ; 21 import java.util.logging.Logger ; 22 23 import org.columba.mail.folder.IMailbox; 24 import org.columba.mail.spam.ISpamPlugin; 25 26 public class SpamAssassinPlugin implements ISpamPlugin { 27 28 29 private static final Logger LOG = Logger 30 .getLogger("org.columba.core.gui.htmlviewer"); 31 32 public SpamAssassinPlugin() { 33 super(); 34 35 } 36 37 public boolean scoreMessage(IMailbox mailbox, Object uid) throws Exception { 38 InputStream rawMessageSource = mailbox.getMessageSourceStream(uid); 39 IPCHelper ipcHelper = new IPCHelper(); 40 41 String cmd = ExternalToolsHelper.getSpamc() + " -c"; 45 46 String result = null; 47 int exitVal = -1; 48 49 try { 50 LOG.info("creating process.."); 51 52 ipcHelper.executeCommand(cmd); 53 54 LOG.info("sending to stdin.."); 55 56 ipcHelper.send(rawMessageSource); 57 58 exitVal = ipcHelper.waitFor(); 59 60 LOG.info("exitcode=" + exitVal); 61 62 LOG.info("retrieving output.."); 63 result = ipcHelper.getOutputString(); 64 65 ipcHelper.waitForThreads(); 66 } catch (Exception ex) { 67 ex.printStackTrace(); 68 } 69 70 if (result == null) { 71 return false; 72 } 73 74 if (exitVal == 1) { 75 return true; 77 } else { 78 return false; 79 } 80 81 } 82 83 public void trainMessageAsSpam(IMailbox mailbox, Object uid) 84 throws Exception { 85 86 InputStream rawMessageSource = mailbox.getMessageSourceStream(uid); 87 88 IPCHelper ipcHelper = new IPCHelper(); 89 90 LOG.info("creating process.."); 91 92 97 98 ipcHelper.executeCommand(ExternalToolsHelper.getSALearn() 99 + " --no-sync --spam --single"); 100 101 102 LOG.info("sending to stdin.."); 103 104 ipcHelper.send(rawMessageSource); 105 106 int exitVal = ipcHelper.waitFor(); 107 108 LOG.info("exitcode=" + exitVal); 109 110 LOG.info("retrieving output.."); 111 112 String result = ipcHelper.getOutputString(); 113 114 LOG.info("output=" + result); 115 116 ipcHelper.waitForThreads(); 117 118 } 119 120 public void trainMessageAsHam(IMailbox mailbox, Object uid) 121 throws Exception { 122 InputStream rawMessageSource = mailbox.getMessageSourceStream(uid); 123 124 IPCHelper ipcHelper = new IPCHelper(); 125 126 LOG.info("creating process.."); 127 ipcHelper.executeCommand(ExternalToolsHelper.getSALearn() 129 + " --no-sync --ham --single"); 130 131 LOG.info("sending to stdin.."); 132 133 ipcHelper.send(rawMessageSource); 134 135 int exitVal = ipcHelper.waitFor(); 136 137 LOG.info("exitcode=" + exitVal); 138 139 LOG.info("retrieving output.."); 140 141 String result = ipcHelper.getOutputString(); 142 143 LOG.info("output=" + result); 144 145 ipcHelper.waitForThreads(); 146 147 } 148 149 public void save() { 150 } 152 153 public void load() { 154 } 156 157 } 158 | Popular Tags |