Changeset 183
- Timestamp:
- 02/23/08 01:20:15 (11 months ago)
- Files:
-
- trunk/jsmtpd/src/org/jsmtpd/Controler.java (modified) (14 diffs)
- trunk/jsmtpd/src/org/jsmtpd/GetOpt.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/config/PluginLoader.java (modified) (16 diffs)
- trunk/jsmtpd/src/org/jsmtpd/config/ReadConfig.java (modified) (3 diffs)
- trunk/jsmtpd/src/org/jsmtpd/core/common/PluginStore.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/core/common/smtpExtension/ISmtpExtension.java (modified) (2 diffs)
- trunk/jsmtpd/src/org/jsmtpd/core/mail/Email.java (modified) (7 diffs)
- trunk/jsmtpd/src/org/jsmtpd/core/mail/EmailAddress.java (modified) (5 diffs)
- trunk/jsmtpd/src/org/jsmtpd/core/mail/InvalidAddress.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/core/mail/Rcpt.java (modified) (5 diffs)
- trunk/jsmtpd/src/org/jsmtpd/core/receive/Receiver.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/core/receive/ReceiverWorkerImpl.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/core/send/DeliveryPicker.java (modified) (2 diffs)
- trunk/jsmtpd/src/org/jsmtpd/core/send/DeliveryWorker.java (modified) (2 diffs)
- trunk/jsmtpd/src/org/jsmtpd/core/send/QueueService.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/plugins/AbstractRblPlugin.java (moved) (moved from trunk/jsmtpd/src/org/jsmtpd/plugins/GenericRBLFilter.java) (4 diffs)
- trunk/jsmtpd/src/org/jsmtpd/plugins/acls/LdapACL.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/plugins/inputIPFilters/BlackList.java (modified) (4 diffs)
- trunk/jsmtpd/src/org/jsmtpd/plugins/inputIPFilters/RBLFilter.java (modified) (3 diffs)
- trunk/jsmtpd/src/org/jsmtpd/plugins/smtpExtension/ConnectBackCheck.java (deleted)
- trunk/jsmtpd/src/org/jsmtpd/plugins/smtpExtension/RblCheck.java (modified) (4 diffs)
- trunk/jsmtpd/src/org/jsmtpd/plugins/smtpExtension/SmtpAuthenticator.java (modified) (1 diff)
- trunk/jsmtpd/src/org/jsmtpd/tools/cache/SimpleCache.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/jsmtpd/src/org/jsmtpd/Controler.java
r180 r183 42 42 43 43 /** 44 *45 44 * Initialises config & plugins<br> 46 45 * Starts and shutdown listening service and delivery service<br> 47 * TODO: Check paths, rebuild them, ensure they are writable<br>48 46 * @author Jean-Francois POUX 49 47 */ 50 48 public class Controler extends Thread { 51 /**52 * Log4j instance53 */54 49 private Log log = LogFactory.getLog(Controler.class); 55 /** 56 * smtp receiver services 57 */ 58 private Receiver rec = null; 59 50 private Receiver receiver = null; 60 51 private SslReceiver sslReceiver = null; 61 /**62 * mail delivery services63 */64 52 private DeliveryPicker delivery = null; 65 53 66 54 private String configFile = "etc/jsmtpd.ini"; 67 68 55 private String xmlPluginFileName = "jsmtpd-plugin-config.xml"; 69 56 … … 75 62 } 76 63 } 77 public void startup()78 {64 65 public void startup() { 79 66 Runtime.getRuntime().addShutdownHook(this); 80 if (!init Environement()) {67 if (!init()) { 81 68 System.exit(-1); 82 69 return; … … 96 83 } 97 84 98 /**99 * Initialises the delivery services100 *101 */102 85 public boolean initDeliveryService() { 103 86 try { 104 87 delivery = new DeliveryPicker(); 105 } catch (InstantiationException e) { 106 return false; 107 } catch (IllegalAccessException e) { 108 return false; 109 } catch (ClassNotFoundException e) { 88 } catch (Exception e) { 110 89 return false; 111 90 } … … 114 93 } 115 94 116 /** 117 * Read config 118 * Set up Log4J 119 * Load the plugins 120 */ 121 public boolean initEnvironement() { 95 public boolean init() { 122 96 try { 123 97 ReadConfig.getInstance().loadConfig(configFile); … … 134 108 // Init plugin Loader 135 109 136 PluginLoader ldr = new PluginLoader();137 ldr.setXmlFileName(xmlPluginFileName);138 try { 139 ldr.init();110 PluginLoader pluginLoader = new PluginLoader(); 111 pluginLoader.setXmlFileName(xmlPluginFileName); 112 try { 113 pluginLoader.init(); 140 114 } catch (SAXException e2) { 141 115 log.fatal("Parse error in plugin-config.xml, " + e2.getMessage()); … … 152 126 } 153 127 154 //Load the DNSService plugin 155 try { 156 ldr.loadDNSService(); 128 try { 129 pluginLoader.loadDNSService(); 157 130 } catch (PluginLoaderException e) { 158 131 log.fatal("DNSService could not be loaded, " + e.getMessage(),e); … … 161 134 log.info("DNS Service plugin loaded : " + PluginStore.getInstance().getResolver().getPluginName()); 162 135 163 // Load the ACL plugin 164 try { 165 ldr.loadACL(); 136 try { 137 pluginLoader.loadACL(); 166 138 } catch (PluginLoaderException e) { 167 139 log.fatal("ACL plugin could not be loaded, " + e.getMessage(),e); … … 170 142 log.info("ACL Service plugin loaded : " + PluginStore.getInstance().getAcl().getPluginName()); 171 143 172 // Load the LocalDelivery plugin 173 try { 174 ldr.loadLocalDeliveryService(); 144 try { 145 pluginLoader.loadLocalDeliveryService(); 175 146 } catch (PluginLoaderException e) { 176 147 log.fatal("LocalDeliveryService plugin could not be loaded, " + e.getMessage(),e); … … 179 150 log.info("Local Delivery Service plugin loaded : " + PluginStore.getInstance().getLocalDeliveryService().getPluginName()); 180 151 181 // Load the RemoteDelivery plugin 182 try { 183 ldr.loadRemoteDeliveryService(); 152 try { 153 pluginLoader.loadRemoteDeliveryService(); 184 154 } catch (PluginLoaderException e) { 185 155 log.fatal("RemoteDeliveryService plugin could not be loaded, " + e.getMessage(),e); … … 188 158 log.info("Remote Delivery Service plugin loaded : " + PluginStore.getInstance().getRemoteDeliveryService().getPluginName()); 189 159 190 // Load the RemoteDelivery plugin 191 try { 192 ldr.loadFilters(); 193 } catch (PluginLoaderException e) { 194 log.fatal("filter plugin could not be loaded, " + e.getMessage(),e); 195 return false; 196 } 197 198 try { 199 ldr.loadSmtpExtensions(); 200 } catch (PluginLoaderException e) { 201 log.fatal("smtp extension plugin could not be loaded, " + e.getMessage(),e); 160 try { 161 pluginLoader.loadFilters(); 162 } catch (PluginLoaderException e) { 163 log.fatal("Filter plugin could not be loaded, " + e.getMessage(),e); 164 return false; 165 } 166 167 try { 168 pluginLoader.loadSmtpExtensions(); 169 } catch (PluginLoaderException e) { 170 log.fatal("Smtp extension plugin could not be loaded, " + e.getMessage(),e); 202 171 return false; 203 172 } … … 209 178 210 179 try { 211 ldr.loadInputIPFilterChain();180 pluginLoader.loadInputIPFilterChain(); 212 181 } catch (ModuleNotFoundException e4) { 213 182 log.fatal( "Error while loading input IP filter chain , " + e4.getModName() 214 183 + " is declared in the inputIPFilter, but not configured in filtersetup"); 215 216 } 217 log.info("Input IP filter chain loaded"); 218 219 try { 220 ldr.loadFilterTree(); 184 } 185 log.info("Input ip filter chain loaded"); 186 187 try { 188 pluginLoader.loadFilterTree(); 221 189 } catch (ModuleNotFoundException e1) { 222 190 log.fatal("Error while loading filter tree, " + e1.getModName() … … 227 195 } 228 196 229 /**230 * Starts the receiver services231 */232 197 public boolean initReceiver() { 233 198 try { 234 rec = new Receiver(ReadConfig.getInstance().getIntegerProperty("rPort"), ReadConfig.getInstance().getIntegerProperty("rMaxInstances"));199 receiver = new Receiver(ReadConfig.getInstance().getIntegerProperty("rPort"), ReadConfig.getInstance().getIntegerProperty("rMaxInstances")); 235 200 if ("on".equals(ReadConfig.getInstance().getProperty("ssl"))) { 236 201 int sslPort = Integer.parseInt(ReadConfig.getInstance().getProperty("sslPort")); … … 248 213 } 249 214 250 /** 251 * Shutdown JSMTPD services 252 * 253 */ 254 private void shutdownServices() { 255 if (rec != null) { 256 rec.shutdown(); 215 private void shutdown() { 216 if (receiver != null) { 217 receiver.shutdown(); 257 218 } 258 219 … … 277 238 } 278 239 279 /**280 * Shutdown hook invoked on VM shutdown281 */282 240 public void run() { 283 shutdown Services();241 shutdown(); 284 242 } 285 243 trunk/jsmtpd/src/org/jsmtpd/GetOpt.java
r136 r183 30 30 public class GetOpt extends HashMap<String,String> { 31 31 32 public GetOpt (String[] args) throws OptException{ 33 super(); 32 public GetOpt (String[] args) throws OptException { 34 33 if (args==null) 35 34 return; trunk/jsmtpd/src/org/jsmtpd/config/PluginLoader.java
r180 r183 26 26 import java.lang.reflect.Method; 27 27 import java.lang.reflect.Modifier; 28 29 28 import javax.xml.parsers.DocumentBuilder; 30 29 import javax.xml.parsers.DocumentBuilderFactory; 31 30 import javax.xml.parsers.ParserConfigurationException; 32 33 31 import org.apache.commons.logging.Log; 34 32 import org.apache.commons.logging.LogFactory; 35 33 import org.jsmtpd.core.common.IGenericPlugin; 36 34 import org.jsmtpd.core.common.PluginInitException; 37 import org.jsmtpd.core.common.PluginLoadingException;38 35 import org.jsmtpd.core.common.PluginStore; 39 36 import org.jsmtpd.core.common.acl.IACL; … … 53 50 54 51 /** 55 * Loads the plugins, configure them and stores them in the pluginstore52 * Loads the plugins, configure them using reflection 56 53 * @author Jean-Francois POUX 57 54 * @see org.jsmtpd.core.common.PluginStore 58 55 */ 59 56 public class PluginLoader implements ErrorHandler { 60 61 /**62 * Loaded plugins are stored in this instance63 */64 57 private PluginStore store = PluginStore.getInstance(); 65 58 66 /**67 * To catch parse errors at end of init68 */69 59 private SAXParseException lastEx = null; 70 71 /**72 * DOM document instance of plugin config file73 */74 60 private Document document; 75 /**76 * This is the root node of the filter tree77 */78 61 private FilterTreeNode filterRoot = null; 79 /**80 * Log4j instance81 */82 62 private Log log = LogFactory.getLog(PluginLoader.class); 83 63 … … 124 104 } 125 105 126 /**127 * Loads the DNS plugin128 * @throws PluginLoaderException129 */130 106 public void loadDNSService() throws PluginLoaderException { 131 132 107 NodeList tmp = document.getElementsByTagName("DNSSetup"); 133 108 Node dnsset = tmp.item(0); … … 143 118 } 144 119 145 /**146 * Loads the local delivery service147 * @throws PluginLoaderException148 */149 150 120 public void loadLocalDeliveryService() throws PluginLoaderException { 151 121 … … 163 133 } 164 134 165 /**166 * loads the remote delivery service167 * @throws PluginLoaderException168 */169 135 public void loadRemoteDeliveryService() throws PluginLoaderException { 170 136 … … 182 148 } 183 149 184 /**185 * Load the acl plugin186 * @throws PluginLoaderException187 */188 150 public void loadACL() throws PluginLoaderException { 189 151 … … 233 195 } 234 196 235 /** 236 * Adds 2 nodes to a node 237 * @param node the node to append in the xml file 238 * @param pNode the image node of the xml file 239 * @throws ModuleNotFoundException thrown when the module can't be found in the PluginStore 240 */ 241 public void appendFilterTreeNode(Node node, FilterTreeNode pNode) throws ModuleNotFoundException { 242 // input node is a filter 243 // if it has true filter attached 244 // lookup filter, create nod and attahce it to true, then repeat 245 197 public void appendFilterTreeNode(Node node, FilterTreeNode parentNode) throws ModuleNotFoundException { 246 198 NodeList childs = node.getChildNodes(); 247 199 if (childs == null) 248 return; //has no child ?200 return; 249 201 250 202 for (int i = 0; i < childs.getLength(); i++) { 251 203 Node tmp = childs.item(i); 252 253 if (t mp.getNodeName().equals("true")) {254 NodeList tchilds = tmp.getChildNodes();255 if (tchilds != null) {256 for (int j = 0; j < tchilds.getLength(); j++) {257 N ode ch = tchilds.item(j);258 if (ch.getNodeName().equals("filter")) {259 NamedNodeMap mp = ch.getAttributes();260 String modName = mp.getNamedItem("name").getNodeValue();261 log.debug("[tree] adding " + modName + " as true node to node " + pNode.getFilter().getPluginName());262 I GenericPlugin plugin = (IGenericPlugin) PluginStore.getInstance().getPluginByLogicalName(modName);263 if (plugin instanceof IFilter) {264 IFilter flt = (IFilter) plugin;265 FilterTreeNode newNode = new FilterTreeNode();266 newNode.setFilter(flt);267 pNode.setTrueNode(newNode);268 newNode.setParent(pNode);269 appendFilterTreeNode(ch, newNode);270 } else {271 log.debug( "The filter " + modName + " is not a body filter tree plugin !");272 throw new ModuleNotFoundException(modName);273 }204 NodeList tchilds = tmp.getChildNodes(); 205 if (tchilds != null) { 206 for (int j = 0; j < tchilds.getLength(); j++) { 207 Node ch = tchilds.item(j); 208 if (ch.getNodeName().equals("filter")) { 209 NamedNodeMap mp = ch.getAttributes(); 210 String modName = mp.getNamedItem("name").getNodeValue(); 211 log.debug("[tree] adding " + modName + " as "+tmp.getNodeName()+" node to node " + parentNode.getFilter().getPluginName()); 212 IGenericPlugin plugin = (IGenericPlugin) PluginStore.getInstance().getPluginByLogicalName(modName); 213 if (plugin instanceof IFilter) { 214 IFilter flt = (IFilter) plugin; 215 FilterTreeNode newNode = new FilterTreeNode(); 216 newNode.setFilter(flt); 217 if (tmp.getNodeName().equals("true")) 218 parentNode.setTrueNode(newNode); 219 else 220 parentNode.setFalseNode(newNode); 221 newNode.setParent(parentNode); 222 appendFilterTreeNode(ch, newNode); 223 } else { 224 log.debug( "The filter " + modName + " is not a body filter tree plugin !"); 225 throw new ModuleNotFoundException(modName); 274 226 } 275 227 } 276 228 } 277 229 } 278 279 if (tmp.getNodeName().equals("false")) { 280 NodeList tchilds = tmp.getChildNodes(); 281 if (tchilds != null) { 282 for (int j = 0; j < tchilds.getLength(); j++) { 283 Node ch = tchilds.item(j); 284 if (ch.getNodeName().equals("filter")) { 285 NamedNodeMap mp = ch.getAttributes(); 286 String modName = mp.getNamedItem("name").getNodeValue(); 287 log.debug("[tree] adding " + modName + " as false node to node " + pNode.getFilter().getPluginName()); 288 289 IGenericPlugin plugin = (IGenericPlugin) PluginStore.getInstance().getPluginByLogicalName(modName); 290 if (plugin instanceof IFilter) { 291 IFilter flt = (IFilter) PluginStore.getInstance().getPluginByLogicalName(modName); 292 FilterTreeNode newNode = new FilterTreeNode(); 293 newNode.setFilter(flt); 294 pNode.setFalseNode(newNode); 295 newNode.setParent(pNode); 296 appendFilterTreeNode(ch, newNode); 297 } else { 298 log.fatal("The filter " + modName + " is not a body filter tree plugin !"); 299 throw new ModuleNotFoundException(modName); 300 } 301 } 302 } 303 } 304 } 305 306 } 307 308 } 309 310 /** 311 * Loads the instances of filter plugins 312 * @throws PluginLoaderException 313 */ 230 } 231 } 232 314 233 public void loadFilters() throws PluginLoaderException { 315 234 NodeList tmp = document.getElementsByTagName("filtersetup"); 316 235 Node filterSetup = tmp.item(0); 317 318 236 NodeList filters = filterSetup.getChildNodes(); 319 320 237 for (int i = 0; i < filters.getLength(); i++) { 321 238 Node current = filters.item(i); … … 335 252 } 336 253 } 337 338 } 339 340 /** 341 * Loads the inputIPFilter chain 342 * @throws ModuleNotFoundException 343 */ 254 } 255 344 256 public void loadInputIPFilterChain() throws ModuleNotFoundException { 345 257 NodeList tmp = document.getElementsByTagName("inputIPFilterChain"); 346 258 Node treeRoot = tmp.item(0); 347 348 259 NodeList childs = treeRoot.getChildNodes(); 349 260 for (int i = 0; i < childs.getLength(); i++) { … … 369 280 NodeList tmp = document.getElementsByTagName("smtpExtensions"); 370 281 Node treeRoot = tmp.item(0); 371 372 282 NodeList childs = treeRoot.getChildNodes(); 373 283 for (int i = 0; i < childs.getLength(); i++) { … … 397 307 } 398 308 399 /**400 * Load a generic plugin (any services/filters)401 * @param className the class name to use402 * @param pNode node in the xml (will determine it's propertyset childs and apply them)403 * @return the plugin instance configured404 * @throws PluginLoadingException405 * @throws IllegalArgumentException406 * @throws MethodNotFoundException407 * @throws MethodParameterNotSupported408 * @throws IllegalAccessException409 * @throws InvocationTargetException410 */411 309 private IGenericPlugin loadGenericPlugin(String className, Node pNode) throws PluginLoaderException { 412 310 … … 423 321 424 322 NodeList tmp = pNode.getChildNodes(); 425 //Apply each propertySet426 323 for (int i = 0; i < tmp.getLength(); i++) { 427 324 Node cur = tmp.item(i); … … 435 332 } 436 333 437 /**438 * Queries the class to find out the function to use439 * Sets a parameter (eg propertyset in the xml config file) to an instance of plugin440 * @param plug the plugin instance441 * @param name name of the parameter442 * @param value the string value of the parameter, another method will do the casts if necessary443 * @throws PluginLoaderException444 */445 334 private void setParam(IGenericPlugin plug, String name, String value) throws PluginLoaderException { 446 335 String rName = name.substring(0,1).toUpperCase()+name.substring(1); … … 451 340 } 452 341 453 /**454 * Performs a recursive method lookup throught parent classes (extended)455 * @param clazz originating class456 * @param methodName457 * @return the method when found458 * @throws MethodNotFoundException459 */460 342 private Method methodLookup(Class clazz, String methodName) throws PluginLoaderException { 461 343 Method[] meths = clazz.getDeclaredMethods(); … … 482 364 } 483 365 484 /**485 * invoques a setPropertyName, casts the string value to something required by reflection486 * @param plug plugin instance487 * @param meth name of the method (will determine the cast needed)488 * @param value value to apply489 * @throws MethodParameterNotSupported490 * @throws IllegalArgumentException491 * @throws IllegalAccessException492 * @throws InvocationTargetException493 */494 366 private void invoke(IGenericPlugin plug, Method meth, String value) throws PluginLoaderException { 495 367 Class[] params = meth.getParameterTypes(); … … 504 376 505 377 if (params[0].getName().equals("int")) { 506 effectiveParams[0] = new Integer(value); //note: this is correct, the invoke() will cast Interger to int type378 effectiveParams[0] = new Integer(value); 507 379 meth.invoke(plug, effectiveParams); 508 380 return; … … 510 382 511 383 if (params[0].getName().equals("boolean")) { 512 effectiveParams[0] = new Boolean(value); //note: this is correct, the invoke() will cast Boolean to boolean type384 effectiveParams[0] = new Boolean(value); 513 385 meth.invoke(plug, effectiveParams); 514 386 return; trunk/jsmtpd/src/org/jsmtpd/config/ReadConfig.java
r178 r183 25 25 26 26 /** 27 *28 27 * Loads the config file<br> 29 28 * Should be initialised in thread safe environnement<br> … … 41 40 } 42 41 43 /**44 *45 * @param configFile the configuration file path used46 * @throws ConfigErrorException when it can't load its config file47 */48 42 public void loadConfig(String configFile) throws ConfigErrorException { 49 43 try { … … 61 55 return Boolean.parseBoolean(getProperty(name)); 62 56 } 63 64 /**65 *66 * @return true if in safe mode, false otherwise67 */68 public boolean getSafeMode() {69 if (getProperty("safeMode", "on").trim().equals("on"))70 return true;71 return false;72 }73 57 } trunk/jsmtpd/src/org/jsmtpd/core/common/PluginStore.java
r175 r183 49 49 private List<ISmtpExtension> smtpExtensions = new LinkedList<ISmtpExtension>(); 50 50 51 private PluginStore() { 52 53 } 51 private PluginStore() {} 54 52 55 53 public void addPlugin(IGenericPlugin module, String logicalName) { trunk/jsmtpd/src/org/jsmtpd/core/common/smtpExtension/ISmtpExtension.java
r141 r183 46 46 * @return true if command has been handled 47 47 */ 48 public boolean smtpTrigger(String command, IProtocolHandler protocol) throws SmtpExtensionException, IOException, InputSizeToBig, IOException, 49 BareLFException; 48 public boolean smtpTrigger(String command, IProtocolHandler protocol) throws SmtpExtensionException, IOException, InputSizeToBig, BareLFException; 50 49 51 50 /** … … 65 64 * @throws IOException 66 65 * @throws InputSizeToBig 67 * @throws IOException68 66 * @throws BareLFException 69 67 */ 70 public boolean smtpPreTrigger (String command, IProtocolHandler protocol) throws SmtpExtensionException, IOException, InputSizeToBig, IOException, 71 BareLFException; 68 public boolean smtpPreTrigger (String command, IProtocolHandler protocol) throws SmtpExtensionException, IOException, InputSizeToBig, BareLFException; 72 69 } trunk/jsmtpd/src/org/jsmtpd/core/mail/Email.java
r180 r183 94 94 } 95 95 96 /**97 * Adds a recipient98 */99 96 public void addRcpt(EmailAddress in) { 100 97 rcpt.add(new Rcpt(in)); 101 98 } 102 99 103 /**104 * get the reception date105 * @return reception data106 */107 100 public Date getArrival() { 108 101 return arrival; … … 136 129 return rcpt; 137 130 } 138 139 /** 140 * usefull for debugging, error mails. puts all the recipient into a String 141 * @return the string of RCPT 142 */ 131 143 132 public String getRcptAsString() { 144 133 String rcp = ""; … … 149 138 } 150 139 151 /**152 * Dump for debugging153 */154 140 public String toString() { 155 141 String out = "Message Dump\n"; 156 157 142 out += "Received on " + arrival + " From " + receivedFrom + "\n"; 158 143 out += "Attempts :" + attemps + "\n"; … … 163 148 out += "RCPT: " + re.getEmailAddress().toString() + "\n"; 164 149 } 165 166 150 return out; 167 151 } … … 181 165 } 182 166 183 /**184 * Saves the mail on disk185 * @param fileName filename to use186 * @param e the mail instance to save187 * @throws IOException188 */189 167 public static void save(String fileName, Email e) throws IOException { 190 168 ObjectOutput out = new ObjectOutputStream(new FileOutputStream(fileName)); … … 193 171 } 194 172 195 /**196 * Creates an instance from a file on disk197 * @param fileName the name of the serialized email198 * @return the instance199 * @throws IOException200 */201 173 public static Email load(String fileName) throws IOException { 202 174 RandomAccessFile fp = new RandomAccessFile(fileName, "r"); … … 224 196 return true; } 225 197 226 /**227 * acces to the data buffer228 * @return the buffer containing the mail229 */230 198 public byte[] getDataAsByte() { 231 199 return dataBuffer; 232 200 } 233 201 234 /**235 * Convenient method to create an error message, as long as message parsing/processing tools are not thoughts yet ;)236 * @param to recipient237 * @param subject238 * @param mailMessages a linkedlist of strings of the error message239 * @param attach not implemented, but will attach a copy of the mail generating the error240 * @return the error Email instance241 */242 202 public static Email createInternalMail(EmailAddress to, String subject, LinkedList<String> mailMessages, Email attach) { 243 203 Email e = new Email(); trunk/jsmtpd/src/org/jsmtpd/core/mail/EmailAddress.java
r164 r183 63 63 64 64 String[] res = mailPart.split("@"); 65 66 67 65 68 66 if ((res[0].length() > 512) || (res[1].length() > 512)) 69 67 throw new InvalidAddress(); 70 68 71 72 69 e.setUser(res[0]); 73 70 e.setHost(res[1].toLowerCase()); … … 75 72 } 76 73 77 /**78 * builds a user@domain string79 */80 74 public String toString() { 81 75 if (user.equals("<>")) 82 76 return user; 83 84 77 return (user + "@" + host); 85 78 } … … 101 94 } 102 95 103 /**104 * test if to instances are equals. matches user and domain, or * as user @ domain105 * @param in106 * @return true if equals107 */108 96 public boolean isEqual(EmailAddress in) { 109 97 if (in == this) 110 98 return true; 111 112 99 if (in.getHost().equals(this.host) && in.getUser().equals(this.user)) 113 100 return true; 114 115 101 if (in.getHost().equals(this.host) && in.getUser().equals("*")) 116 102 return true; 117 118 103 return false; 119 120 104 } 121 122 123 105 124 106 public int hashCode() { 125 107 String tmp=host; … … 132 114 } 133 115 134 public EmailAddress () { 135 136 } 116 public EmailAddress () {} 137 117 138 118 public EmailAddress (EmailAddress original) { … … 141 121 } 142 122 143 144 123 public String getAuthContext() { 145 124 return authContext; 146 125 } 147 126 148 149 127 public void setAuthContext(String authContext) { 150 128 this.authContext = authContext; trunk/jsmtpd/src/org/jsmtpd/core/mail/InvalidAddress.java
r136 r183 25 25 * @author Jean-Francois POUX 26 26 */ 27 public class InvalidAddress extends Exception { 28 29 } 27 public class InvalidAddress extends Exception {} trunk/jsmtpd/src/org/jsmtpd/core/mail/Rcpt.java
r136 r183 28 28 */ 29 29 public class Rcpt implements Serializable { 30 31 30 private EmailAddress emailAddress = null; 32 31 private int deliveryAttempts = STATUS_PENDING; … … 53 52 } 54 53 55 /**56 *57 * @return number of attempts failed to deliver the mail58 */59 54 public int getDeliveryAttempts() { 60 55 return deliveryAttempts; … … 62 57 63 58 /** 64 *65 59 * @return the RCPT is consired delivered when : 66 60 * Successufully delivered … … 84 78 this.lastError = lastError; 85 79 } 80 81 public int getStatus() { 82 return status; 83 } 84 85 public String toString() { 86 if (emailAddress==null) 87 return "null adress"; 88 return this.emailAddress.toString(); 89 } 86 90 87 91 public static final int STATUS_PENDING = 0; … … 89 93 public static final int STATUS_ERROR_FATAL = 2; 90 94 public static final int STATUS_DELIVERED = 3; 91 92 93 public int getStatus() {94 return status;95 }96 97 @Override98 public String toString() {99 if (emailAddress==null)100 return "null adress";101 return this.emailAddress.toString();102 }103 95 } trunk/jsmtpd/src/org/jsmtpd/core/receive/Receiver.java
r174 r183 48 48 protected Socket inc = null; 49 49 50 public Receiver () { 51 52 } 50 public Receiver () {} 53 51 54 52 public Receiver(int port, int maxInst) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { trunk/jsmtpd/src/org/jsmtpd/core/receive/ReceiverWorkerImpl.java
r174 r183 32 32 */ 33 33 public class ReceiverWorkerImpl implements IThreadedClass { 34 35 34 private ProtocolHandler proto = new ProtocolHandler(); 36 35 private Socket rec = null; trunk/jsmtpd/src/org/jsmtpd/core/send/DeliveryPicker.java
r176 r183 47 47 public void run() { 48 48 while (running) { 49 if (pool.hasFreeThread()) //TODO: Also check if memory is available ?49 if (pool.hasFreeThread()) 50 50 { 51 51 Email e = null; … … 75 75 running = false; 76 76 wake(); 77 78 // Wait for the running loop to end ?79 80 77 try { 81 78 this.join(); 82 79 } catch (InterruptedException e) { 83 e.printStackTrace();84 80 } 85 86 81 pool.forceShutdown(); 87 82 queueService.shutdownService(); 88 89 83 } 90 84 trunk/jsmtpd/src/org/jsmtpd/core/send/DeliveryWorker.java
r180 r183 53 53 handler.clearMail(); //this will generate a null pointer exception excplicitly. Catched in doJob for requeing 54 54 //wait for curmail to b
