Author: dbkr
Date: 2008-04-12 14:40:09 +0000 (Sat, 12 Apr 2008)
New Revision: 19233

Modified:
   trunk/apps/Freemail/src/freemail/Freemail.java
   trunk/apps/Freemail/src/freemail/FreemailCli.java
   trunk/apps/Freemail/src/freemail/FreemailPlugin.java
Log:
Fix my shonky object initialisation that caused 2262.


Modified: trunk/apps/Freemail/src/freemail/Freemail.java
===================================================================
--- trunk/apps/Freemail/src/freemail/Freemail.java      2008-04-12 14:16:52 UTC 
(rev 19232)
+++ trunk/apps/Freemail/src/freemail/Freemail.java      2008-04-12 14:40:09 UTC 
(rev 19233)
@@ -22,6 +22,7 @@
 package freemail;

 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;

@@ -56,15 +57,15 @@
        private Thread ackInserterThread;
        private Thread imapThread;

-       private ArrayList singleAccountWatcherList = new ArrayList();
-       private MessageSender sender;
-       private SMTPListener smtpl;
-       private AckProcrastinator ackinserter;
-       private IMAPListener imapl;
+       private final ArrayList singleAccountWatcherList = new ArrayList();
+       private final MessageSender sender;
+       private final SMTPListener smtpl;
+       private final AckProcrastinator ackinserter;
+       private final IMAPListener imapl;

        protected final Configurator configurator;

-       protected Freemail(String cfgfile) {
+       protected Freemail(String cfgfile) throws IOException {
                configurator = new Configurator(new File(cfgfile));

                configurator.register("loglevel", new Logger(), "normal|error");
@@ -73,7 +74,7 @@
                if (!getDataDir().exists()) {
                        if (!getDataDir().mkdir()) {
                                Logger.error(this,"Freemail: Couldn't create 
data directory. Please ensure that the user you are running Freemail as has 
write access to its working directory");
-                               return;
+                               throw new IOException("Couldn't create data 
dir");
                        }
                }

@@ -81,6 +82,7 @@
                if (!getGlobalDataDir().exists()) {
                        if (!getGlobalDataDir().mkdir()) {
                                Logger.error(this,"Freemail: Couldn't create 
global data directory. Please ensure that the user you are running Freemail as 
has write access to its working directory");
+                               throw new IOException("Couldn't create data 
dir");
                        }
                }

@@ -88,9 +90,25 @@
                if (!getTempDir().exists()) {
                        if (!Freemail.getTempDir().mkdir()) {
                                Logger.error(this,"Freemail: Couldn't create 
temporary directory. Please ensure that the user you are running Freemail as 
has write access to its working directory");
-                               return;
+                               throw new IOException("Couldn't create data 
dir");
                        }
                }
+               
+               FCPContext fcpctx = new FCPContext();
+               configurator.register("fcp_host", fcpctx, "localhost");
+               configurator.register("fcp_port", fcpctx, "9481");
+               
+               Freemail.fcpconn = new FCPConnection(fcpctx);
+               
+               sender = new MessageSender(getDataDir());
+               
+               File ackdir = new File(getGlobalDataDir(), ACKDIR);
+               AckProcrastinator.setAckDir(ackdir);
+               ackinserter = new AckProcrastinator();
+               
+               
+               imapl = new IMAPListener(configurator);
+               smtpl = new SMTPListener(sender, configurator);
        }

        public static File getTempDir() {
@@ -120,11 +138,6 @@
        }

        protected void startFcp(boolean daemon) {
-               FCPContext fcpctx = new FCPContext();
-               configurator.register("fcp_host", fcpctx, "localhost");
-               configurator.register("fcp_port", fcpctx, "9481");
-               
-               Freemail.fcpconn = new FCPConnection(fcpctx);
                fcpThread = new Thread(fcpconn, "Freemail FCP Connection");
                fcpThread.setDaemon(true);
                fcpThread.start();
@@ -134,13 +147,12 @@
        // (so startWorkers has to be called before)
        protected void startServers(boolean daemon) {
                // start the SMTP Listener
-               smtpl = new SMTPListener(sender, configurator);
+               
                smtpThread = new Thread(smtpl, "Freemail SMTP Listener");
                smtpThread.setDaemon(daemon);
                smtpThread.start();

                // start the IMAP listener
-               imapl = new IMAPListener(configurator);
                imapThread = new Thread(imapl, "Freemail IMAP Listener");
                imapThread.setDaemon(daemon);
                imapThread.start();
@@ -171,16 +183,12 @@
                        singleAccountWatcherThreadList.add(t);
                }

-               // and a sender thread
-               sender = new MessageSender(getDataDir());
+               // start the sender thread
                messageSenderThread = new Thread(sender, "Freemail Message 
sender");
                messageSenderThread.setDaemon(daemon);
                messageSenderThread.start();

                // start the delayed ACK inserter
-               File ackdir = new File(getGlobalDataDir(), ACKDIR);
-               AckProcrastinator.setAckDir(ackdir);
-               ackinserter = new AckProcrastinator();
                ackInserterThread = new Thread(ackinserter, "Freemail Delayed 
ACK Inserter");
                ackInserterThread.setDaemon(daemon);
                ackInserterThread.start();

Modified: trunk/apps/Freemail/src/freemail/FreemailCli.java
===================================================================
--- trunk/apps/Freemail/src/freemail/FreemailCli.java   2008-04-12 14:16:52 UTC 
(rev 19232)
+++ trunk/apps/Freemail/src/freemail/FreemailCli.java   2008-04-12 14:40:09 UTC 
(rev 19233)
@@ -24,9 +24,10 @@
 import java.io.IOException;

 import freemail.Freemail;
+import freemail.utils.Logger;

 public class FreemailCli extends Freemail {
-       public FreemailCli(String cfgfile) {
+       public FreemailCli(String cfgfile) throws IOException {
                super(cfgfile);
        }

@@ -78,7 +79,14 @@
                        }
                }

-               FreemailCli freemail = new FreemailCli(cfgfile);
+               
+               FreemailCli freemail;
+               try {
+                       freemail = new FreemailCli(cfgfile);
+               } catch(IOException ioe) {
+                       Logger.error(FreemailCli.class, "Failed to start 
Freemail: "+ioe.getMessage());
+                       return;
+               }
                freemail.startFcp(false);

                if (action.equals("--newaccount")) {

Modified: trunk/apps/Freemail/src/freemail/FreemailPlugin.java
===================================================================
--- trunk/apps/Freemail/src/freemail/FreemailPlugin.java        2008-04-12 
14:16:52 UTC (rev 19232)
+++ trunk/apps/Freemail/src/freemail/FreemailPlugin.java        2008-04-12 
14:40:09 UTC (rev 19233)
@@ -39,7 +39,7 @@
                                                         FredPluginThreadless {
        private PluginRespirator pluginResp;

-       public FreemailPlugin() {
+       public FreemailPlugin() throws IOException {
                super(CFGFILE);
        }



Reply via email to