Changeset 183

Show
Ignore:
Timestamp:
02/23/08 01:20:15 (11 months ago)
Author:
jfp
Message:

cleanup/refact

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/jsmtpd/src/org/jsmtpd/Controler.java

    r180 r183  
    4242 
    4343/** 
    44  *  
    4544 * Initialises config & plugins<br> 
    4645 * Starts and shutdown listening service and delivery service<br> 
    47  * TODO: Check paths, rebuild them, ensure they are writable<br> 
    4846 * @author Jean-Francois POUX 
    4947 */ 
    5048public class Controler extends Thread { 
    51     /** 
    52      * Log4j instance 
    53      */ 
    5449    private Log log = LogFactory.getLog(Controler.class); 
    55     /** 
    56      * smtp receiver services 
    57      */ 
    58     private Receiver rec = null; 
    59      
     50    private Receiver receiver = null;     
    6051    private SslReceiver sslReceiver = null; 
    61     /** 
    62      * mail delivery services 
    63      */ 
    6452    private DeliveryPicker delivery = null; 
    6553 
    6654    private String configFile = "etc/jsmtpd.ini"; 
    67      
    6855    private String xmlPluginFileName = "jsmtpd-plugin-config.xml"; 
    6956     
     
    7562        } 
    7663    } 
    77     public void startup() 
    78    
     64     
     65    public void startup()
    7966        Runtime.getRuntime().addShutdownHook(this); 
    80         if (!initEnvironement()) { 
     67        if (!init()) { 
    8168            System.exit(-1); 
    8269            return; 
     
    9683    } 
    9784 
    98     /** 
    99      * Initialises the delivery services 
    100      * 
    101      */ 
    10285    public boolean initDeliveryService() { 
    10386        try { 
    10487            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) { 
    11089            return false; 
    11190        } 
     
    11493    } 
    11594 
    116     /** 
    117      * Read config 
    118      * Set up Log4J 
    119      * Load the plugins 
    120      */ 
    121     public boolean initEnvironement() { 
     95    public boolean init() { 
    12296        try { 
    12397                ReadConfig.getInstance().loadConfig(configFile); 
     
    134108        // Init plugin Loader 
    135109 
    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(); 
    140114        } catch (SAXException e2) { 
    141115            log.fatal("Parse error in plugin-config.xml, " + e2.getMessage()); 
     
    152126        } 
    153127 
    154         //Load the DNSService plugin 
    155         try { 
    156             ldr.loadDNSService(); 
     128        try { 
     129            pluginLoader.loadDNSService(); 
    157130        } catch (PluginLoaderException e) { 
    158131            log.fatal("DNSService could not be loaded, " + e.getMessage(),e); 
     
    161134        log.info("DNS Service plugin loaded : " + PluginStore.getInstance().getResolver().getPluginName()); 
    162135 
    163         // Load the ACL plugin 
    164         try { 
    165             ldr.loadACL(); 
     136        try { 
     137            pluginLoader.loadACL(); 
    166138        } catch (PluginLoaderException e) { 
    167139            log.fatal("ACL plugin could not be loaded, " + e.getMessage(),e); 
     
    170142        log.info("ACL Service plugin loaded : " + PluginStore.getInstance().getAcl().getPluginName()); 
    171143 
    172         // Load the LocalDelivery plugin 
    173         try { 
    174             ldr.loadLocalDeliveryService(); 
     144        try { 
     145            pluginLoader.loadLocalDeliveryService(); 
    175146        } catch (PluginLoaderException e) { 
    176147            log.fatal("LocalDeliveryService plugin could not be loaded, " + e.getMessage(),e); 
     
    179150        log.info("Local Delivery Service plugin loaded : " + PluginStore.getInstance().getLocalDeliveryService().getPluginName()); 
    180151 
    181         // Load the RemoteDelivery plugin 
    182         try { 
    183             ldr.loadRemoteDeliveryService(); 
     152        try { 
     153            pluginLoader.loadRemoteDeliveryService(); 
    184154        } catch (PluginLoaderException e) { 
    185155            log.fatal("RemoteDeliveryService plugin could not be loaded, " + e.getMessage(),e); 
     
    188158        log.info("Remote Delivery Service plugin loaded : " + PluginStore.getInstance().getRemoteDeliveryService().getPluginName()); 
    189159 
    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); 
    202171            return false; 
    203172        }  
     
    209178 
    210179        try { 
    211             ldr.loadInputIPFilterChain(); 
     180            pluginLoader.loadInputIPFilterChain(); 
    212181        } catch (ModuleNotFoundException e4) { 
    213182            log.fatal( "Error while loading input IP filter chain , " + e4.getModName() 
    214183                    + " 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(); 
    221189        } catch (ModuleNotFoundException e1) { 
    222190            log.fatal("Error while loading filter tree, " + e1.getModName() 
     
    227195    } 
    228196 
    229     /** 
    230      * Starts the receiver services 
    231      */ 
    232197    public boolean initReceiver() { 
    233198        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")); 
    235200            if ("on".equals(ReadConfig.getInstance().getProperty("ssl"))) { 
    236201                int sslPort = Integer.parseInt(ReadConfig.getInstance().getProperty("sslPort")); 
     
    248213    } 
    249214 
    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(); 
    257218        } 
    258219 
     
    277238    } 
    278239 
    279     /** 
    280      * Shutdown hook invoked on VM shutdown 
    281      */ 
    282240    public void run() { 
    283         shutdownServices(); 
     241        shutdown(); 
    284242    } 
    285243 
  • trunk/jsmtpd/src/org/jsmtpd/GetOpt.java

    r136 r183  
    3030public class GetOpt extends HashMap<String,String> { 
    3131     
    32     public GetOpt (String[] args) throws OptException{ 
    33         super(); 
     32    public GetOpt (String[] args) throws OptException { 
    3433        if (args==null) 
    3534            return; 
  • trunk/jsmtpd/src/org/jsmtpd/config/PluginLoader.java

    r180 r183  
    2626import java.lang.reflect.Method; 
    2727import java.lang.reflect.Modifier; 
    28  
    2928import javax.xml.parsers.DocumentBuilder; 
    3029import javax.xml.parsers.DocumentBuilderFactory; 
    3130import javax.xml.parsers.ParserConfigurationException; 
    32  
    3331import org.apache.commons.logging.Log; 
    3432import org.apache.commons.logging.LogFactory; 
    3533import org.jsmtpd.core.common.IGenericPlugin; 
    3634import org.jsmtpd.core.common.PluginInitException; 
    37 import org.jsmtpd.core.common.PluginLoadingException; 
    3835import org.jsmtpd.core.common.PluginStore; 
    3936import org.jsmtpd.core.common.acl.IACL; 
     
    5350 
    5451/** 
    55  * Loads the plugins, configure them and stores them in the pluginstore 
     52 * Loads the plugins, configure them using reflection 
    5653 * @author Jean-Francois POUX 
    5754 * @see org.jsmtpd.core.common.PluginStore 
    5855 */ 
    5956public class PluginLoader implements ErrorHandler { 
    60  
    61     /** 
    62      * Loaded plugins are stored in this instance 
    63      */ 
    6457    private PluginStore store = PluginStore.getInstance(); 
    6558 
    66     /** 
    67      * To catch parse errors at end of init 
    68      */ 
    6959    private SAXParseException lastEx = null; 
    70  
    71     /** 
    72      * DOM document instance of plugin config file 
    73      */ 
    7460    private Document document; 
    75     /** 
    76      * This is the root node of the filter tree 
    77      */ 
    7861    private FilterTreeNode filterRoot = null; 
    79     /** 
    80      * Log4j instance 
    81      */ 
    8262    private Log log = LogFactory.getLog(PluginLoader.class); 
    8363 
     
    124104    } 
    125105 
    126     /** 
    127      * Loads the DNS plugin 
    128      * @throws PluginLoaderException 
    129      */ 
    130106    public void loadDNSService() throws PluginLoaderException { 
    131  
    132107        NodeList tmp = document.getElementsByTagName("DNSSetup"); 
    133108        Node dnsset = tmp.item(0); 
     
    143118    } 
    144119 
    145     /** 
    146      * Loads the local delivery service 
    147      * @throws PluginLoaderException 
    148      */ 
    149  
    150120    public void loadLocalDeliveryService() throws PluginLoaderException { 
    151121 
     
    163133    } 
    164134 
    165     /** 
    166      * loads the remote delivery service 
    167      * @throws PluginLoaderException 
    168      */ 
    169135    public void loadRemoteDeliveryService() throws PluginLoaderException { 
    170136 
     
    182148    } 
    183149 
    184     /** 
    185      * Load the acl plugin 
    186      * @throws PluginLoaderException 
    187      */ 
    188150    public void loadACL() throws PluginLoaderException { 
    189151 
     
    233195    } 
    234196 
    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 { 
    246198        NodeList childs = node.getChildNodes(); 
    247199        if (childs == null) 
    248             return;//has no child ? 
     200            return; 
    249201 
    250202        for (int i = 0; i < childs.getLength(); i++) { 
    251203            Node tmp = childs.item(i); 
    252  
    253             if (tmp.getNodeName().equals("true")) { 
    254                 NodeList tchilds = tmp.getChildNodes(); 
    255                 if (tchilds != null) { 
    256                     for (int j = 0; j < tchilds.getLength(); j++) { 
    257                         Node 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                             IGenericPlugin 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); 
    274226                        } 
    275227                    } 
    276228                } 
    277229            } 
    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 
    314233    public void loadFilters() throws PluginLoaderException { 
    315234        NodeList tmp = document.getElementsByTagName("filtersetup"); 
    316235        Node filterSetup = tmp.item(0); 
    317  
    318236        NodeList filters = filterSetup.getChildNodes(); 
    319  
    320237        for (int i = 0; i < filters.getLength(); i++) { 
    321238            Node current = filters.item(i); 
     
    335252            } 
    336253        } 
    337  
    338     } 
    339  
    340     /** 
    341      * Loads the inputIPFilter chain 
    342      * @throws ModuleNotFoundException 
    343      */ 
     254    } 
     255 
    344256    public void loadInputIPFilterChain() throws ModuleNotFoundException { 
    345257        NodeList tmp = document.getElementsByTagName("inputIPFilterChain"); 
    346258        Node treeRoot = tmp.item(0); 
    347  
    348259        NodeList childs = treeRoot.getChildNodes(); 
    349260        for (int i = 0; i < childs.getLength(); i++) { 
     
    369280        NodeList tmp = document.getElementsByTagName("smtpExtensions"); 
    370281        Node treeRoot = tmp.item(0); 
    371  
    372282        NodeList childs = treeRoot.getChildNodes(); 
    373283        for (int i = 0; i < childs.getLength(); i++) { 
     
    397307    } 
    398308 
    399     /** 
    400      * Load a generic plugin (any services/filters) 
    401      * @param className the class name to use 
    402      * @param pNode node in the xml (will determine it's propertyset childs and apply them) 
    403      * @return the plugin instance configured 
    404      * @throws PluginLoadingException 
    405      * @throws IllegalArgumentException 
    406      * @throws MethodNotFoundException 
    407      * @throws MethodParameterNotSupported 
    408      * @throws IllegalAccessException 
    409      * @throws InvocationTargetException 
    410      */ 
    411309    private IGenericPlugin loadGenericPlugin(String className, Node pNode) throws PluginLoaderException { 
    412310 
     
    423321 
    424322        NodeList tmp = pNode.getChildNodes(); 
    425         //Apply each propertySet  
    426323        for (int i = 0; i < tmp.getLength(); i++) { 
    427324            Node cur = tmp.item(i); 
     
    435332    } 
    436333 
    437     /** 
    438      * Queries the class to find out the function to use 
    439      * Sets a parameter (eg propertyset in the xml config file) to an instance of plugin 
    440      * @param plug the plugin instance 
    441      * @param name name of the parameter 
    442      * @param value the string value of the parameter, another method will do the casts if necessary 
    443      * @throws PluginLoaderException 
    444      */ 
    445334    private void setParam(IGenericPlugin plug, String name, String value) throws PluginLoaderException { 
    446335        String rName = name.substring(0,1).toUpperCase()+name.substring(1); 
     
    451340    } 
    452341 
    453     /** 
    454      * Performs a recursive method lookup throught parent classes (extended) 
    455      * @param clazz originating class 
    456      * @param methodName 
    457      * @return the method when found 
    458      * @throws MethodNotFoundException 
    459      */ 
    460342    private Method methodLookup(Class clazz, String methodName) throws PluginLoaderException { 
    461343        Method[] meths = clazz.getDeclaredMethods(); 
     
    482364    } 
    483365 
    484     /** 
    485      * invoques a setPropertyName, casts the string value to something required by reflection 
    486      * @param plug plugin instance 
    487      * @param meth name of the method (will determine the cast needed) 
    488      * @param value value to apply 
    489      * @throws MethodParameterNotSupported 
    490      * @throws IllegalArgumentException 
    491      * @throws IllegalAccessException 
    492      * @throws InvocationTargetException 
    493      */ 
    494366    private void invoke(IGenericPlugin plug, Method meth, String value) throws PluginLoaderException { 
    495367        Class[] params = meth.getParameterTypes(); 
     
    504376 
    505377            if (params[0].getName().equals("int")) { 
    506                 effectiveParams[0] = new Integer(value); //note: this is correct, the invoke() will cast Interger to int type 
     378                effectiveParams[0] = new Integer(value); 
    507379                meth.invoke(plug, effectiveParams); 
    508380                return; 
     
    510382 
    511383            if (params[0].getName().equals("boolean")) { 
    512                 effectiveParams[0] = new Boolean(value); //note: this is correct, the invoke() will cast Boolean to boolean type 
     384                effectiveParams[0] = new Boolean(value); 
    513385                meth.invoke(plug, effectiveParams); 
    514386                return; 
  • trunk/jsmtpd/src/org/jsmtpd/config/ReadConfig.java

    r178 r183  
    2525 
    2626/** 
    27  *  
    2827 * Loads the config file<br> 
    2928 * Should be initialised in thread safe environnement<br> 
     
    4140    } 
    4241 
    43     /** 
    44      *  
    45      * @param configFile the configuration file path used 
    46      * @throws ConfigErrorException when it can't load its config file 
    47      */ 
    4842    public void loadConfig(String configFile) throws ConfigErrorException { 
    4943        try { 
     
    6155        return Boolean.parseBoolean(getProperty(name)); 
    6256    } 
    63      
    64     /** 
    65      *  
    66      * @return true if in safe mode, false otherwise 
    67      */ 
    68     public boolean getSafeMode() { 
    69         if (getProperty("safeMode", "on").trim().equals("on")) 
    70             return true; 
    71         return false; 
    72     }     
    7357} 
  • trunk/jsmtpd/src/org/jsmtpd/core/common/PluginStore.java

    r175 r183  
    4949    private List<ISmtpExtension> smtpExtensions = new LinkedList<ISmtpExtension>(); 
    5050 
    51     private PluginStore() { 
    52  
    53     } 
     51    private PluginStore() {} 
    5452 
    5553    public void addPlugin(IGenericPlugin module, String logicalName) { 
  • trunk/jsmtpd/src/org/jsmtpd/core/common/smtpExtension/ISmtpExtension.java

    r141 r183  
    4646     * @return true if command has been handled 
    4747     */ 
    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; 
    5049 
    5150    /** 
     
    6564     * @throws IOException 
    6665     * @throws InputSizeToBig 
    67      * @throws IOException 
    6866     * @throws BareLFException 
    6967     */ 
    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; 
    7269} 
  • trunk/jsmtpd/src/org/jsmtpd/core/mail/Email.java

    r180 r183  
    9494    } 
    9595 
    96     /** 
    97      * Adds a recipient 
    98      */ 
    9996    public void addRcpt(EmailAddress in) { 
    10097        rcpt.add(new Rcpt(in)); 
    10198    } 
    10299 
    103     /** 
    104      * get the reception date 
    105      * @return reception data 
    106      */ 
    107100    public Date getArrival() { 
    108101        return arrival; 
     
    136129        return rcpt; 
    137130    } 
    138  
    139     /** 
    140      * usefull for debugging, error mails. puts all the recipient into a String 
    141      * @return the string of RCPT 
    142      */ 
     131     
    143132    public String getRcptAsString() { 
    144133        String rcp = ""; 
     
    149138    } 
    150139 
    151     /** 
    152      * Dump for debugging 
    153      */ 
    154140    public String toString() { 
    155141        String out = "Message Dump\n"; 
    156  
    157142        out += "Received on " + arrival + " From " + receivedFrom + "\n"; 
    158143        out += "Attempts :" + attemps + "\n"; 
     
    163148            out += "RCPT: " + re.getEmailAddress().toString() + "\n"; 
    164149        } 
    165  
    166150        return out; 
    167151    } 
     
    181165    } 
    182166 
    183     /** 
    184      * Saves the mail on disk 
    185      * @param fileName filename to use 
    186      * @param e the mail instance to save 
    187      * @throws IOException 
    188      */ 
    189167    public static void save(String fileName, Email e) throws IOException { 
    190168        ObjectOutput out = new ObjectOutputStream(new FileOutputStream(fileName)); 
     
    193171    } 
    194172 
    195     /** 
    196      * Creates an instance from a file on disk 
    197      * @param fileName the name of the serialized email 
    198      * @return the instance 
    199      * @throws IOException 
    200      */ 
    201173    public static Email load(String fileName) throws IOException { 
    202174        RandomAccessFile fp = new RandomAccessFile(fileName, "r"); 
     
    224196        return true;    } 
    225197 
    226     /** 
    227      * acces to the data buffer 
    228      * @return the buffer containing the mail 
    229      */ 
    230198    public byte[] getDataAsByte() { 
    231199        return dataBuffer; 
    232200    } 
    233201 
    234     /** 
    235      * Convenient method to create an error message, as long as message parsing/processing tools are not thoughts yet ;) 
    236      * @param to recipient 
    237      * @param subject  
    238      * @param mailMessages a linkedlist of strings of the error message 
    239      * @param attach not implemented, but will attach a copy of the mail generating the error 
    240      * @return the error Email instance 
    241      */ 
    242202    public static Email createInternalMail(EmailAddress to, String subject, LinkedList<String> mailMessages, Email attach) { 
    243203        Email e = new Email(); 
  • trunk/jsmtpd/src/org/jsmtpd/core/mail/EmailAddress.java

    r164 r183  
    6363         
    6464        String[] res = mailPart.split("@"); 
    65  
    66       
    6765         
    6866        if ((res[0].length() > 512) || (res[1].length() > 512)) 
    6967            throw new InvalidAddress(); 
    7068 
    71          
    7269        e.setUser(res[0]); 
    7370        e.setHost(res[1].toLowerCase()); 
     
    7572    } 
    7673 
    77     /** 
    78      * builds a user@domain string 
    79      */ 
    8074    public String toString() { 
    8175        if (user.equals("<>")) 
    8276            return user; 
    83  
    8477        return (user + "@" + host); 
    8578    } 
     
    10194    } 
    10295 
    103     /** 
    104      * test if to instances are equals. matches user and domain, or * as user @ domain 
    105      * @param in 
    106      * @return true if equals 
    107      */ 
    10896    public boolean isEqual(EmailAddress in) { 
    10997        if (in == this) 
    11098            return true; 
    111  
    11299        if (in.getHost().equals(this.host) && in.getUser().equals(this.user)) 
    113100            return true; 
    114  
    115101        if (in.getHost().equals(this.host) && in.getUser().equals("*")) 
    116102            return true; 
    117  
    118103        return false; 
    119  
    120104    } 
    121      
    122      
    123      
     105      
    124106    public int hashCode() { 
    125107        String tmp=host; 
     
    132114    } 
    133115     
    134     public EmailAddress () { 
    135          
    136     } 
     116    public EmailAddress () {} 
    137117     
    138118    public EmailAddress (EmailAddress original) { 
     
    141121    } 
    142122 
    143      
    144123    public String getAuthContext() { 
    145124        return authContext; 
    146125    } 
    147126 
    148      
    149127    public void setAuthContext(String authContext) { 
    150128        this.authContext = authContext; 
  • trunk/jsmtpd/src/org/jsmtpd/core/mail/InvalidAddress.java

    r136 r183  
    2525 * @author Jean-Francois POUX 
    2626 */ 
    27 public class InvalidAddress extends Exception { 
    28  
    29 
     27public class InvalidAddress extends Exception {} 
  • trunk/jsmtpd/src/org/jsmtpd/core/mail/Rcpt.java

    r136 r183  
    2828 */ 
    2929public class Rcpt implements Serializable { 
    30  
    3130    private EmailAddress emailAddress = null; 
    3231    private int deliveryAttempts = STATUS_PENDING; 
     
    5352    } 
    5453 
    55     /** 
    56      *  
    57      * @return number of attempts failed to deliver the mail 
    58      */ 
    5954    public int getDeliveryAttempts() { 
    6055        return deliveryAttempts; 
     
    6257 
    6358    /** 
    64      *  
    6559     * @return the RCPT is consired delivered when : 
    6660     *          Successufully delivered 
     
    8478        this.lastError = lastError; 
    8579    } 
     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        } 
    8690     
    8791    public static final int STATUS_PENDING = 0; 
     
    8993    public static final int STATUS_ERROR_FATAL = 2; 
    9094    public static final int STATUS_DELIVERED = 3; 
    91      
    92      
    93     public int getStatus() { 
    94         return status; 
    95     } 
    96  
    97         @Override 
    98         public String toString() { 
    99                 if (emailAddress==null) 
    100                         return "null adress"; 
    101                 return this.emailAddress.toString(); 
    102         } 
    10395} 
  • trunk/jsmtpd/src/org/jsmtpd/core/receive/Receiver.java

    r174 r183  
    4848    protected Socket inc = null; 
    4949 
    50     public Receiver () { 
    51          
    52     } 
     50    public Receiver () {} 
    5351     
    5452    public Receiver(int port, int maxInst) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { 
  • trunk/jsmtpd/src/org/jsmtpd/core/receive/ReceiverWorkerImpl.java

    r174 r183  
    3232 */ 
    3333public class ReceiverWorkerImpl implements IThreadedClass { 
    34  
    3534    private ProtocolHandler proto = new ProtocolHandler(); 
    3635    private Socket rec = null; 
  • trunk/jsmtpd/src/org/jsmtpd/core/send/DeliveryPicker.java

    r176 r183  
    4747    public void run() { 
    4848        while (running) { 
    49             if (pool.hasFreeThread()) //TODO: Also check if memory is available ? 
     49            if (pool.hasFreeThread()) 
    5050            { 
    5151                Email e = null; 
     
    7575        running = false; 
    7676        wake(); 
    77  
    78         // Wait for the running loop to end ? 
    79  
    8077        try { 
    8178            this.join(); 
    8279        } catch (InterruptedException e) { 
    83             e.printStackTrace(); 
    8480        } 
    85  
    8681        pool.forceShutdown(); 
    8782        queueService.shutdownService(); 
    88  
    8983    } 
    9084 
  • trunk/jsmtpd/src/org/jsmtpd/core/send/DeliveryWorker.java

    r180 r183  
    5353        handler.clearMail(); //this will generate a null pointer exception excplicitly. Catched in doJob for requeing 
    5454        //wait for curmail to b