axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r357187 [23/25] - in /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2: ./ addressing/ client/ client/async/ context/ deployment/ deployment/listener/ deployment/repository/util/ deployment/scheduler/ deployment/util/ descript...
Date Fri, 16 Dec 2005 17:18:08 GMT
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/local/LocalTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/local/LocalTransportSender.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/local/LocalTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/local/LocalTransportSender.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.local;
 
@@ -27,31 +28,34 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
-
 public class LocalTransportSender extends AbstractTransportSender {
     private ByteArrayOutputStream out;
     private ByteArrayOutputStream response;
 
     public LocalTransportSender() {
+    }
 
+    public void cleanUp(MessageContext msgContext) throws AxisFault {
     }
 
-    public OutputStream startSendWithToAddress(MessageContext msgContext,
-                                               OutputStream out) throws AxisFault {
-        return out;
+    public void finalizeSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
+                                                                   OutputStream out)
+            throws AxisFault {
+        throw new UnsupportedOperationException();
     }
 
-    public void finalizeSendWithToAddress(MessageContext msgContext,
-                                          OutputStream out)
+    public void finalizeSendWithToAddress(MessageContext msgContext, OutputStream out)
             throws AxisFault {
         try {
             InputStream in = new ByteArrayInputStream(this.out.toByteArray());
+
             response = new ByteArrayOutputStream();
+
             LocalTransportReceiver localTransportReceiver = new LocalTransportReceiver(this);
+
             localTransportReceiver.processMessage(in, msgContext.getTo());
             in.close();
             out.close();
-
             in = new ByteArrayInputStream(response.toByteArray());
             msgContext.setProperty(MessageContext.TRANSPORT_IN, in);
         } catch (IOException e) {
@@ -59,35 +63,32 @@
         }
     }
 
-    /* (non-Javadoc)
+    /*
+     *  (non-Javadoc)
      * @see org.apache.axis2.transport.AbstractTransportSender#openTheConnection(org.apache.axis2.addressing.EndpointReference)
      */
-    protected OutputStream openTheConnection(EndpointReference epr,
-                                             MessageContext msgContext) throws AxisFault {
-        //out = new PipedOutputStream();
+    protected OutputStream openTheConnection(EndpointReference epr, MessageContext msgContext)
+            throws AxisFault {
+
+        // out = new PipedOutputStream();
         out = new ByteArrayOutputStream();
+
         return out;
     }
 
-    /* (non-Javadoc)
+    /*
+     *  (non-Javadoc)
      * @see org.apache.axis2.transport.AbstractTransportSender#startSendWithOutputStreamFromIncomingConnection(org.apache.axis2.context.MessageContext, java.io.Writer)
      */
-    public OutputStream startSendWithOutputStreamFromIncomingConnection(
-            MessageContext msgContext,
-            OutputStream out)
+    public OutputStream startSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
+                                                                        OutputStream out)
             throws AxisFault {
         throw new UnsupportedOperationException();
-
     }
 
-    public void finalizeSendWithOutputStreamFromIncomingConnection(
-            MessageContext msgContext, OutputStream out)
+    public OutputStream startSendWithToAddress(MessageContext msgContext, OutputStream out)
             throws AxisFault {
-        throw new UnsupportedOperationException();
-
-    }
-
-    public void cleanUp(MessageContext msgContext) throws AxisFault {
+        return out;
     }
 
     OutputStream getResponse() {

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EMailSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EMailSender.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EMailSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EMailSender.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.mail;
 
@@ -32,49 +33,78 @@
 import java.util.Properties;
 
 public class EMailSender {
-    private String user;
     private String host;
-    private String smtpPort;
     private String password;
+    private String smtpPort;
+    private String user;
 
-    public EMailSender(String user,
-                       String host,
-                       String smtpPort,
-                       String password) {
+    public EMailSender(String user, String host, String smtpPort, String password) {
         this.user = user;
         this.host = host;
         this.smtpPort = smtpPort;
         this.password = password;
     }
 
-    public void send(String subject, String targetEmail, String message, String charSet) throws AxisFault {
+    public static void main(String[] args) throws Exception {
+        String user = "hemapani";
+        String host = "127.0.0.1";
+        String smtpPort = "25";
+        String password = "hemapani";
+        EMailSender sender = new EMailSender(user, host, smtpPort, password);
+
+        sender.send("Testing mail sending", "hemapani@127.0.0.1", "Hellp, testing",
+                MailSrvConstants.DEFAULT_CHAR_SET);
+
+        EmailReceiver receiver = new EmailReceiver(user, host, "110", password);
+
+        receiver.connect();
+
+        Message[] msgs = receiver.receive();
+
+        if (msgs != null) {
+            for (int i = 0; i < msgs.length; i++) {
+                MimeMessage msg = (MimeMessage) msgs[i];
+
+                if (msg != null) {
+                }
+
+                msg.setFlag(Flags.Flag.DELETED, true);
+            }
+        }
+
+        receiver.disconnect();
+    }
+
+    public void send(String subject, String targetEmail, String message, String charSet)
+            throws AxisFault {
         try {
-            final PasswordAuthentication authentication =
-                    new PasswordAuthentication(user, password);
+            final PasswordAuthentication authentication = new PasswordAuthentication(user,
+                    password);
             Properties props = new Properties();
+
             props.put("mail.user", user);
             props.put("mail.host", host);
             props.put("mail.store.protocol", "pop3");
             props.put("mail.transport.protocol", "smtp");
             props.put("mail.smtp.port", smtpPort);
+
             Session session = Session.getInstance(props, new Authenticator() {
                 protected PasswordAuthentication getPasswordAuthentication() {
                     return authentication;
                 }
             });
-
             MimeMessage msg = new MimeMessage(session);
+
             msg.setFrom(new InternetAddress((user)));
-            msg.addRecipient(Message.RecipientType.TO,
-                    new InternetAddress(targetEmail));
+            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(targetEmail));
             msg.setSubject(subject);
 
-            if (charSet == null){
+            if (charSet == null) {
                 charSet = MailSrvConstants.DEFAULT_CHAR_SET;
             }
 
-            msg.addHeaderLine("Content-Type: " + MailSrvConstants.DEFAULT_CONTENT_TYPE + "; charset=" + charSet);
-
+            msg.addHeaderLine("Content-Type: " + MailSrvConstants.DEFAULT_CONTENT_TYPE
+                    + "; charset=" + charSet);
             msg.setText(message);
             msg.setHeader("Content-Transfer-Encoding", MailSrvConstants.DEFAULT_CHAR_SET_ENCODING);
             Transport.send(msg);
@@ -83,36 +113,5 @@
         } catch (MessagingException e) {
             throw new AxisFault(e);
         }
-    }
-
-    public static void main(String[] args) throws Exception {
-
-        String user = "hemapani";
-        String host = "127.0.0.1";
-        String smtpPort = "25";
-        String password = "hemapani";
-        EMailSender sender = new EMailSender(user, host, smtpPort, password);
-
-        sender.send("Testing mail sending",
-                "hemapani@127.0.0.1",
-                "Hellp, testing",  MailSrvConstants.DEFAULT_CHAR_SET);
-
-        EmailReceiver receiver = new EmailReceiver(user,
-                host,
-                "110",
-                password);
-        receiver.connect();
-        Message[] msgs = receiver.receive();
-        if (msgs != null) {
-            for (int i = 0; i < msgs.length; i++) {
-                MimeMessage msg = (MimeMessage) msgs[i];
-                if (msg != null) {
-                }
-                msg.setFlag(Flags.Flag.DELETED, true);
-            }
-
-        }
-        receiver.disconnect();
-
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EmailReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EmailReceiver.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EmailReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/EmailReceiver.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.mail;
 
@@ -30,49 +31,49 @@
 import java.util.Properties;
 
 public class EmailReceiver {
-
-    private String user;
     private String host;
-    private String popPort;
+    private Folder inbox;
     private String password;
+    private String popPort;
     private Store store;
-    private Folder inbox;
+    private String user;
 
-    public EmailReceiver(
-        String user,
-        String host,
-        String popPort,
-        String password)
-        throws AxisFault {
+    public EmailReceiver(String user, String host, String popPort, String password)
+            throws AxisFault {
         this.user = user;
         this.host = host;
         this.popPort = popPort;
         this.password = password;
+
         if (this.user == null) {
-            throw new AxisFault(Messages.getMessage("canNotBeNull","User"));
+            throw new AxisFault(Messages.getMessage("canNotBeNull", "User"));
         }
+
         if (this.host == null) {
-            throw new AxisFault(Messages.getMessage("canNotBeNull","Host"));
+            throw new AxisFault(Messages.getMessage("canNotBeNull", "Host"));
         }
+
         if (this.popPort == null) {
-            throw new AxisFault(Messages.getMessage("canNotBeNull","port"));
+            throw new AxisFault(Messages.getMessage("canNotBeNull", "port"));
         }
+
         if (this.password == null) {
-            throw new AxisFault(Messages.getMessage("canNotBeNull","Password"));
+            throw new AxisFault(Messages.getMessage("canNotBeNull", "Password"));
         }
-
     }
 
     public void connect() throws AxisFault {
         try {
-            final PasswordAuthentication authentication =
-                new PasswordAuthentication(user, password);
+            final PasswordAuthentication authentication = new PasswordAuthentication(user,
+                    password);
             Properties props = new Properties();
+
             props.put("mail.user", user);
             props.put("mail.host", host);
             props.put("mail.store.protocol", "pop3");
             props.put("mail.transport.protocol", "smtp");
             props.put("mail.pop3.port", popPort);
+
             Session session = Session.getInstance(props, new Authenticator() {
                 protected PasswordAuthentication getPasswordAuthentication() {
                     return authentication;
@@ -81,15 +82,15 @@
 
             store = session.getStore();
             store.connect();
+
             Folder root = store.getDefaultFolder();
-            inbox = root.getFolder("inbox");
 
+            inbox = root.getFolder("inbox");
         } catch (NoSuchProviderException e) {
             throw new AxisFault(e);
         } catch (MessagingException e) {
             throw new AxisFault(e);
         }
-
     }
 
     public void disconnect() throws AxisFault {
@@ -104,20 +105,19 @@
     public Message[] receive() throws AxisFault {
         try {
             inbox.open(Folder.READ_WRITE);
-            Message[] msgs = inbox.getMessages();
 
+            Message[] msgs = inbox.getMessages();
             int numMessages = msgs.length;
+
             if (msgs.length == 0) {
                 return null;
             } else {
                 return msgs;
             }
-
         } catch (NoSuchProviderException e) {
             throw new AxisFault(e);
         } catch (MessagingException e) {
             throw new AxisFault(e);
         }
     }
-
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailClient.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailClient.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailClient.java Fri Dec 16 09:13:57 2005
@@ -16,17 +16,14 @@
 import java.io.IOException;
 import java.util.Properties;
 
-public class MailClient
-        extends Authenticator {
+public class MailClient extends Authenticator {
     public static final int SHOW_MESSAGES = 1;
     public static final int CLEAR_MESSAGES = 2;
-    public static final int SHOW_AND_CLEAR =
-            SHOW_MESSAGES + CLEAR_MESSAGES;
-
+    public static final int SHOW_AND_CLEAR = SHOW_MESSAGES + CLEAR_MESSAGES;
+    private Log log = LogFactory.getLog(getClass());
+    protected PasswordAuthentication authentication;
     protected String from;
     protected Session session;
-    protected PasswordAuthentication authentication;
-    private Log log = LogFactory.getLog(getClass());
 
     public MailClient(String user, String host) {
         this(user, host, user, false);
@@ -36,73 +33,92 @@
         this(user, host, password, false);
     }
 
-    public MailClient(String user,
-                      String host,
-                      String password,
-                      boolean debug) {
+    public MailClient(String user, String host, String password, boolean debug) {
         from = user + '@' + host;
         authentication = new PasswordAuthentication(user, password);
+
         Properties props = new Properties();
+
         props.put("mail.user", user);
         props.put("mail.host", host);
-        props.put("mail.debug", debug ? "true" : "false");
+        props.put("mail.debug", debug
+                ? "true"
+                : "false");
         props.put("mail.store.protocol", "pop3");
         props.put("mail.transport.protocol", "smtp");
         session = Session.getInstance(props, this);
     }
 
-    public PasswordAuthentication getPasswordAuthentication() {
-        return authentication;
-    }
+    public int checkInbox(int mode) throws MessagingException, IOException {
+        int numMessages = 0;
 
-    public void sendMessage(String to,
-                            String subject,
-                            String content,
-                            String soapAction)
-            throws MessagingException {
-        log.info("SENDING message from " + from + " to " + to);
-        MimeMessage msg = new MimeMessage(session);
-        msg.setHeader("transport.mail.soapaction", soapAction);
-        msg.addRecipients(Message.RecipientType.TO, to);
-        msg.setSubject(subject);
-        msg.setText(content);
-        Transport.send(msg);
-    }
+        if (mode == 0) {
+            return 0;
+        }
 
-    public int checkInbox(int mode)
-            throws MessagingException, IOException {
-        int numMessages = 0;
-        if (mode == 0) return 0;
         boolean show = (mode & SHOW_MESSAGES) > 0;
         boolean clear = (mode & CLEAR_MESSAGES) > 0;
-        String action =
-                (show ? "Show" : "") +
-                (show && clear ? " and " : "") +
-                (clear ? "Clear" : "");
+        String action = (show
+                ? "Show"
+                : "") + ((show && clear)
+                ? " and "
+                : "") + (clear
+                ? "Clear"
+                : "");
+
         log.info(action + " INBOX for " + from);
+
         Store store = session.getStore();
+
         store.connect();
+
         Folder root = store.getDefaultFolder();
         Folder inbox = root.getFolder("inbox");
+
         inbox.open(Folder.READ_WRITE);
+
         Message[] msgs = inbox.getMessages();
+
         numMessages = msgs.length;
-        if (msgs.length == 0 && show) {
+
+        if ((msgs.length == 0) && show) {
             log.info("No messages in inbox");
         }
+
         for (int i = 0; i < msgs.length; i++) {
             MimeMessage msg = (MimeMessage) msgs[i];
+
             if (show) {
                 log.info("    From: " + msg.getFrom()[0]);
                 log.info(" Subject: " + msg.getSubject());
                 log.info(" Content: " + msg.getContent());
             }
+
             if (clear) {
                 msg.setFlag(Flags.Flag.DELETED, true);
             }
         }
+
         inbox.close(true);
         store.close();
+
         return numMessages;
+    }
+
+    public void sendMessage(String to, String subject, String content, String soapAction)
+            throws MessagingException {
+        log.info("SENDING message from " + from + " to " + to);
+
+        MimeMessage msg = new MimeMessage(session);
+
+        msg.setHeader("transport.mail.soapaction", soapAction);
+        msg.addRecipients(Message.RecipientType.TO, to);
+        msg.setSubject(subject);
+        msg.setText(content);
+        Transport.send(msg);
+    }
+
+    public PasswordAuthentication getPasswordAuthentication() {
+        return authentication;
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailTransportSender.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailTransportSender.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.mail;
 
@@ -30,53 +31,61 @@
 import java.io.OutputStream;
 
 public class MailTransportSender extends AbstractTransportSender {
-    private String host;
-    private String user;
-    private String password;
     private String smtpPort = "25";
-
     private ByteArrayOutputStream byteArrayOutputStream;
+    private String host;
+    private String password;
+    private String user;
 
     public MailTransportSender() {
+    }
 
+    /*
+     *  (non-Javadoc)
+     * @see org.apache.axis2.transport.TransportSender#cleanUp()
+     */
+    public void cleanUp(MessageContext msgContext) throws AxisFault {
+
+        // TODO Auto-generated method stub
     }
 
-    public void finalizeSendWithToAddress(
-        MessageContext msgContext,
-        OutputStream out)
-        throws AxisFault {
+    public void finalizeSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
+                                                                   OutputStream out)
+            throws AxisFault {
+    }
+
+    public void finalizeSendWithToAddress(MessageContext msgContext, OutputStream out)
+            throws AxisFault {
         try {
             TransportOutDescription transportOut = msgContext.getTransportOut();
+
             user =
-                Utils.getParameterValue(
-                    transportOut.getParameter(MailSrvConstants.SMTP_USER));
+                    Utils.getParameterValue(transportOut.getParameter(MailSrvConstants.SMTP_USER));
             host =
-                Utils.getParameterValue(
-                    transportOut.getParameter(MailSrvConstants.SMTP_HOST));
+                    Utils.getParameterValue(transportOut.getParameter(MailSrvConstants.SMTP_HOST));
             password =
-                Utils.getParameterValue(
-                    transportOut.getParameter(MailSrvConstants.SMTP_PASSWORD));
+                    Utils.getParameterValue(transportOut.getParameter(MailSrvConstants.SMTP_PASSWORD));
             smtpPort =
-                Utils.getParameterValue(
-                    transportOut.getParameter(MailSrvConstants.SMTP_PORT));
-            if (user != null
-                && host != null
-                && password != null
-                && smtpPort != null) {
-                EMailSender sender =
-                    new EMailSender(user, host, smtpPort, password);
+                    Utils.getParameterValue(transportOut.getParameter(MailSrvConstants.SMTP_PORT));
 
-                //TODO this is just a temporary hack, fix this to use input streams
+            if ((user != null) && (host != null) && (password != null) && (smtpPort != null)) {
+                EMailSender sender = new EMailSender(user, host, smtpPort, password);
 
+                // TODO this is just a temporary hack, fix this to use input streams
                 String eprAddress = msgContext.getTo().getAddress();
+
                 // In mail char set is what is being used. Charset encoding is not what is expected here.
-                String charSet = (String)msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
-                if (charSet == null){
+                String charSet =
+                        (String) msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
+
+                if (charSet == null) {
                     charSet = MailSrvConstants.DEFAULT_CHAR_SET;
                 }
+
                 int index = eprAddress.indexOf('/');
                 String subject = "";
                 String email = null;
+
                 if (index >= 0) {
                     subject = eprAddress.substring(index + 1);
                     email = eprAddress.substring(0, index);
@@ -84,67 +93,40 @@
                     email = eprAddress;
                 }
 
-                sender.send(
-                    subject,
-                    email,
-                    new String(byteArrayOutputStream.toByteArray()), charSet);
+                sender.send(subject, email, new String(byteArrayOutputStream.toByteArray()),
+                        charSet);
             } else {
                 if (user == null) {
-                    throw new AxisFault(
-                        Messages.getMessage("canNotBeNull", "User"));
+                    throw new AxisFault(Messages.getMessage("canNotBeNull", "User"));
                 } else if (smtpPort == null) {
-                    throw new AxisFault(
-                        Messages.getMessage("canNotBeNull", "smtpPort"));
+                    throw new AxisFault(Messages.getMessage("canNotBeNull", "smtpPort"));
                 } else if (host == null) {
-                    throw new AxisFault(
-                        Messages.getMessage("canNotBeNull", "Host"));
+                    throw new AxisFault(Messages.getMessage("canNotBeNull", "Host"));
                 } else if (password == null) {
-                    throw new AxisFault(
-                        Messages.getMessage("canNotBeNull", "password"));
+                    throw new AxisFault(Messages.getMessage("canNotBeNull", "password"));
                 }
             }
         } catch (IOException e) {
             throw new AxisFault(e);
         }
-
     }
 
-    public OutputStream startSendWithToAddress(
-        MessageContext msgContext,
-        OutputStream out)
-        throws AxisFault {
-        return out;
-    }
-
-    protected OutputStream openTheConnection(
-        EndpointReference epr,
-        MessageContext msgContext)
-        throws AxisFault {
+    protected OutputStream openTheConnection(EndpointReference epr, MessageContext msgContext)
+            throws AxisFault {
         byteArrayOutputStream = new ByteArrayOutputStream();
+
         return byteArrayOutputStream;
     }
 
-    //Output Stream based cases are not supported 
-    public OutputStream startSendWithOutputStreamFromIncomingConnection(
-        MessageContext msgContext,
-        OutputStream out)
-        throws AxisFault {
+    // Output Stream based cases are not supported
+    public OutputStream startSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
+                                                                        OutputStream out)
+            throws AxisFault {
         throw new UnsupportedOperationException();
-
     }
 
-    public void finalizeSendWithOutputStreamFromIncomingConnection(
-        MessageContext msgContext,
-        OutputStream out)
-        throws AxisFault {
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.axis2.transport.TransportSender#cleanUp()
-     */
-    public void cleanUp(MessageContext msgContext) throws AxisFault {
-        // TODO Auto-generated method stub
-
+    public OutputStream startSendWithToAddress(MessageContext msgContext, OutputStream out)
+            throws AxisFault {
+        return out;
     }
-
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/MailWorker.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.mail;
 
@@ -46,16 +47,11 @@
 
 public class MailWorker implements Runnable {
     protected static Log log = LogFactory.getLog(MailWorker.class.getName());
-
     private String contentType = "text/xml";
-
     private ConfigurationContext reg = null;
-
-    private MimeMessage mimeMessage;
-
     private Properties prop = new Properties();
-
     private Session session = Session.getDefaultInstance(prop, null);
+    private MimeMessage mimeMessage;
 
     /**
      * Constructor for MailWorker
@@ -74,78 +70,91 @@
     public void run() {
         AxisEngine engine = new AxisEngine(reg);
         MessageContext msgContext = null;
+
         // create and initialize a message context
         try {
             TransportInDescription transportIn =
-                reg.getAxisConfiguration().getTransportIn(new QName(Constants.TRANSPORT_MAIL));
+                    reg.getAxisConfiguration().getTransportIn(new QName(Constants.TRANSPORT_MAIL));
             TransportOutDescription transportOut =
-                reg.getAxisConfiguration().getTransportOut(new QName(Constants.TRANSPORT_MAIL));
-            if (transportIn != null && transportOut != null) {
-                //create Message Context
+                    reg.getAxisConfiguration().getTransportOut(new QName(Constants.TRANSPORT_MAIL));
+
+            if ((transportIn != null) && (transportOut != null)) {
+
+                // create Message Context
                 msgContext = new MessageContext(reg, transportIn, transportOut);
                 msgContext.setServerSide(true);
                 msgContext.setProperty(MailSrvConstants.CONTENT_TYPE, mimeMessage.getContentType());
-                msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING, mimeMessage.getEncoding());
+                msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,
+                        mimeMessage.getEncoding());
 
                 String soapAction = getMailHeader(MailSrvConstants.HEADER_SOAP_ACTION);
+
                 msgContext.setWSAAction(soapAction);
                 msgContext.setSoapAction(soapAction);
 
-                //TODO add the transport Headers to the Message Context                
-
-                //Create Mail EPR, EPR is constructed using the format, foo@bar/axis2/services/echo and is constructed 
-                //using the <to-email-address>/<email-subject>
+                // TODO add the transport Headers to the Message Context
+                // Create Mail EPR, EPR is constructed using the format, foo@bar/axis2/services/echo and is constructed
+                // using the <to-email-address>/<email-subject>
                 InternetAddress[] recepainets = (InternetAddress[]) mimeMessage.getAllRecipients();
-                if (recepainets != null && recepainets.length > 0) {
+
+                if ((recepainets != null) && (recepainets.length > 0)) {
                     String emailAddress = recepainets[0].getAddress();
                     String emailSubject = mimeMessage.getSubject();
-                    EndpointReference to =
-                        new EndpointReference(emailAddress + "/" + (emailSubject != null ? emailSubject : ""));
+                    EndpointReference to = new EndpointReference(emailAddress + "/"
+                            + ((emailSubject != null)
+                            ? emailSubject
+                            : ""));
                 } else {
                     throw new AxisFault(Messages.getMessage("noRecep4Email"));
                 }
-                //try to assume the reply to value
+
+                // try to assume the reply to value
                 InternetAddress[] replyToAs = (InternetAddress[]) mimeMessage.getAllRecipients();
-                if (replyToAs != null && replyToAs.length > 0) {
+
+                if ((replyToAs != null) && (replyToAs.length > 0)) {
                     String replyTo = replyToAs[0].getAddress();
+
                     if (replyTo != null) {
-                        msgContext.setReplyTo(
-                            new EndpointReference(replyTo));
+                        msgContext.setReplyTo(new EndpointReference(replyTo));
                     }
                 }
 
-                //Create the SOAP Message
-                //TODO This can we written better way, to use the streams better
+                // Create the SOAP Message
+                // TODO This can we written better way, to use the streams better
                 String message = mimeMessage.getContent().toString();
-                ByteArrayInputStream bais = new ByteArrayInputStream(message.getBytes());
-                XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
-
+                ByteArrayInputStream bais =
+                        new ByteArrayInputStream(message.getBytes());
+                XMLStreamReader reader =
+                        XMLInputFactory.newInstance().createXMLStreamReader(bais);
                 String soapNamespaceURI = "";
-                if(mimeMessage.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1){
-                   soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
-                }else if(mimeMessage.getContentType().indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1){
-                    soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
 
+                if (mimeMessage.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE)
+                        > -1) {
+                    soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
+                } else if (mimeMessage.getContentType().indexOf(
+                        SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+                    soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
                 }
 
                 StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
-
                 SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
+
                 msgContext.setEnvelope(envelope);
+
                 if (envelope.getBody().hasFault()) {
                     engine.receiveFault(msgContext);
                 } else {
                     engine.receive(msgContext);
                 }
             } else {
-                throw new AxisFault(Messages.getMessage("unknownTransport",Constants.TRANSPORT_MAIL));
+                throw new AxisFault(Messages.getMessage("unknownTransport",
+                        Constants.TRANSPORT_MAIL));
             }
-
         } catch (Exception e) {
             try {
-
                 if (msgContext != null) {
                     MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
+
                     engine.sendFault(faultContext);
                 } else {
                     log.error(e);
@@ -156,10 +165,10 @@
         }
 
         /*
-         * 
+         *
          * This part is ignored for the time being. CT 07-Feb-2005.
-         * 
-         * if (msgContext.getProperty(MessageContext.QUIT_REQUESTED) != null) { //
+         *
+         * if (msgContext.getProperty(MessageContext.QUIT_REQUESTED) != null) { /
          * why then, quit! try { server.stop(); } catch (Exception e) { } }
          */
     }
@@ -167,6 +176,7 @@
     private String getMailHeader(String headerName) throws AxisFault {
         try {
             String values[] = mimeMessage.getHeader(headerName);
+
             if (values != null) {
                 return values[0];
             } else {
@@ -175,7 +185,5 @@
         } catch (MessagingException e) {
             throw new AxisFault(e);
         }
-
     }
-
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/SimpleMailListener.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.mail;
 
@@ -45,46 +46,51 @@
  * TODO ISSUES -- 1. Message.getMessage -- All messages are hardcoded in the
  * code till a replacement or a working verion of this is put into Axis 2. When
  * internationalization work is done this can be fixed. CT 15-Feb-2005
- *  
+ *
  */
-
 public class SimpleMailListener extends TransportListener implements Runnable {
+    protected static Log log = LogFactory.getLog(SimpleMailListener.class.getName());
 
-    protected static Log log =
-        LogFactory.getLog(SimpleMailListener.class.getName());
+    // Are we doing threads?
+    private static boolean doThreads = true;
+    private ConfigurationContext configurationContext = null;
 
+    // are we stopped?
+    // latch to true if stop() is called
+    private boolean stopped = false;
     private String host;
-
-    private String port;
-
-    private String user;
-
     private String password;
-
-    private ConfigurationContext configurationContext = null;
-
+    private String port;
     private String replyTo;
+    private String user;
 
     public SimpleMailListener() {
     }
 
-    public SimpleMailListener(
-        String host,
-        String port,
-        String userid,
-        String password,
-        String dir) {
+    public SimpleMailListener(String host, String port, String userid, String password,
+                              ConfigurationContext er) {
+        this.host = host;
+        this.port = port;
+        this.user = userid;
+        this.password = password;
+        this.configurationContext = er;
+    }
+
+    public SimpleMailListener(String host, String port, String userid, String password,
+                              String dir) {
         this.host = host;
         this.port = port;
         this.user = userid;
         this.password = password;
+
         try {
-            ConfigurationContextFactory builder =
-                new ConfigurationContextFactory();
+            ConfigurationContextFactory builder = new ConfigurationContextFactory();
+
             configurationContext = builder.buildConfigurationContext(dir);
         } catch (Exception e) {
             log.info(e.getMessage());
         }
+
         try {
             log.info("Sleeping for a bit to let the engine start up.");
             Thread.sleep(2000);
@@ -93,93 +99,134 @@
         }
     }
 
-    public SimpleMailListener(
-        String host,
-        String port,
-        String userid,
-        String password,
-        ConfigurationContext er) {
-        this.host = host;
-        this.port = port;
-        this.user = userid;
-        this.password = password;
-        this.configurationContext = er;
-    }
+    /*
+     *  (non-Javadoc)
+     * @see org.apache.axis2.transport.TransportListener#init(org.apache.axis2.context.ConfigurationContext, org.apache.axis2.description.TransportInDescription)
+     */
+    public void init(ConfigurationContext configurationContext, TransportInDescription transportIn)
+            throws AxisFault {
+        this.configurationContext = configurationContext;
+        user =
+                Utils.getParameterValue(transportIn.getParameter(MailSrvConstants.POP3_USER));
+        host =
+                Utils.getParameterValue(transportIn.getParameter(MailSrvConstants.POP3_HOST));
+        password =
+                Utils.getParameterValue(transportIn.getParameter(MailSrvConstants.POP3_PASSWORD));
+        port = Utils.getParameterValue(transportIn.getParameter(MailSrvConstants.POP3_PORT));
+        replyTo = Utils.getParameterValue(transportIn.getParameter(MailSrvConstants.RAPLY_TO));
 
-    // Are we doing threads?
-    private static boolean doThreads = true;
+        if ((user == null) || (host == null) || (password == null) || (port == null)) {
+            if (this.user == null) {
+                throw new AxisFault(Messages.getMessage("canNotBeNull", "User"));
+            }
 
-    public void setDoThreads(boolean value) {
-        doThreads = value;
-    }
+            if (this.host == null) {
+                throw new AxisFault(Messages.getMessage("canNotBeNull", "Host"));
+            }
 
-    public boolean getDoThreads() {
-        return doThreads;
+            if (this.port == null) {
+                throw new AxisFault(Messages.getMessage("canNotBeNull", "Port"));
+            }
+
+            if (this.password == null) {
+                throw new AxisFault(Messages.getMessage("canNotBeNull", "Password"));
+            }
+            ;
+        }
     }
 
-    // are we stopped?
-    // latch to true if stop() is called
-    private boolean stopped = false;
+    /**
+     * Server process.
+     */
+    public static void main(String args[]) throws AxisFault {
+        if (args.length != 1) {
+            log.info("java SimpleMailListener <repository>");
+        } else {
+            ConfigurationContextFactory builder = new ConfigurationContextFactory();
+            ConfigurationContext configurationContext =
+                    builder.buildConfigurationContext(args[0]);
+            SimpleMailListener sas = new SimpleMailListener();
+            TransportInDescription transportIn =
+                    configurationContext.getAxisConfiguration().getTransportIn(
+                            new QName(Constants.TRANSPORT_MAIL));
+
+            if (transportIn != null) {
+                sas.init(configurationContext, transportIn);
+                log.info("Starting the SimpleMailListener with repository "
+                        + new File(args[0]).getAbsolutePath());
+                sas.start();
+            } else {
+                log.info(
+                        "Startup failed, mail transport not configured, Configure the mail trnasport in the axis2.xml file");
+            }
+        }
+    }
 
     /**
      * Accept requests from a given TCP port and send them through the Axis
      * engine for processing.
      */
     public void run() {
+
         // log.info(Message.getMessage("start00", "SimpleMailListner", host + ":" +
         // port)); TODO Issue #1 CT 07-Feb-2005.
         // Accept and process requests from the socket
         if (!stopped) {
-            String logMessage =
-                "Mail listner is being setup to listen to the address "
-                    + user
-                    + "@"
-                    + host
-                    + " On port "
-                    + port;
+            String logMessage = "Mail listner is being setup to listen to the address " + user
+                    + "@" + host + " On port " + port;
+
             log.info(logMessage);
         }
+
         while (!stopped) {
             try {
+                EmailReceiver receiver = new EmailReceiver(user, host, port, password);
 
-                EmailReceiver receiver =
-                    new EmailReceiver(user, host, port, password);
                 receiver.connect();
+
                 Message[] msgs = receiver.receive();
 
-                if (msgs != null && msgs.length > 0) {
+                if ((msgs != null) && (msgs.length > 0)) {
                     log.info(msgs.length + " Message Found");
+
                     for (int i = 0; i < msgs.length; i++) {
                         MimeMessage msg = (MimeMessage) msgs[i];
+
                         if (msg != null) {
-                            MailWorker worker =
-                                new MailWorker(msg, configurationContext);
+                            MailWorker worker = new MailWorker(msg, configurationContext);
+
                             worker.run();
                         }
+
                         msg.setFlag(Flags.Flag.DELETED, true);
                     }
-
                 }
 
                 receiver.disconnect();
-                //Waiting for 3 seconds.
-                Thread.sleep(3000);
 
+                // Waiting for 3 seconds.
+                Thread.sleep(3000);
             } catch (Exception e) {
-                //log.debug(Messages.getMessage("exception00"), e); TODO Issue
+
+                // log.debug(Messages.getMessage("exception00"), e); TODO Issue
                 // #1 CT 07-Feb-2005.
-                log.debug(
-                    "An error occured when running the mail listner."
-                        + e.getMessage(),
-                    e);
+                log.debug("An error occured when running the mail listner." + e.getMessage(), e);
+
                 break;
             }
         }
 
         log.info("Mail listner has been stoped.");
-        //log.info(Messages.getMessage("quit00", "SimpleMailListner")); TODO Issue #1
+
+        // log.info(Messages.getMessage("quit00", "SimpleMailListner")); TODO Issue #1
         // CT 07-Feb-2005.
+    }
 
+    /**
+     * Start this server as a NON-daemon.
+     */
+    public void start() throws AxisFault {
+        start(false);
     }
 
     /**
@@ -193,126 +240,59 @@
         if (this.user == null) {
             throw new AxisFault(Messages.getMessage("canNotBeNull", "User"));
         }
+
         if (this.host == null) {
             throw new AxisFault(Messages.getMessage("canNotBeNull", "Host"));
         }
+
         if (this.port == null) {
             throw new AxisFault(Messages.getMessage("canNotBeNull", "Port"));
         }
+
         if (this.password == null) {
-            throw new AxisFault(
-                Messages.getMessage("canNotBeNull", "Password"));
+            throw new AxisFault(Messages.getMessage("canNotBeNull", "Password"));
         }
 
         if (doThreads) {
-        	this.configurationContext.getThreadPool().execute(this);
+            this.configurationContext.getThreadPool().execute(this);
         } else {
             run();
         }
     }
 
     /**
-     * Start this server as a NON-daemon.
-     */
-    public void start() throws AxisFault {
-        start(false);
-    }
-
-    /**
      * Stop this server.
      * <p/>
      * This will interrupt any pending accept().
      */
     public void stop() {
+
         /*
          * Close the server socket cleanly, but avoid fresh accepts while the
          * socket is closing.
          */
         stopped = true;
-        //log.info(Messages.getMessage("quit00", "SimpleMailListner")); TODO Issue #1
+
+        // log.info(Messages.getMessage("quit00", "SimpleMailListner")); TODO Issue #1
         // CT 07-Feb-2005.
         log.info("Quiting the mail listner");
     }
 
-    /**
-     * Server process.
-     */
-    public static void main(String args[]) throws AxisFault {
-        if (args.length != 1) {
-            log.info("java SimpleMailListener <repository>");
-        } else {
-            ConfigurationContextFactory builder =
-                new ConfigurationContextFactory();
-            ConfigurationContext configurationContext =
-                builder.buildConfigurationContext(args[0]);
-            SimpleMailListener sas = new SimpleMailListener();
-            TransportInDescription transportIn =
-                configurationContext.getAxisConfiguration().getTransportIn(
-                    new QName(Constants.TRANSPORT_MAIL));
-            if (transportIn != null) {
-                sas.init(configurationContext, transportIn);
-                log.info(
-                    "Starting the SimpleMailListener with repository "
-                        + new File(args[0]).getAbsolutePath());
-                sas.start();
-            } else {
-                log.info(
-                    "Startup failed, mail transport not configured, Configure the mail trnasport in the axis2.xml file");
-            }
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.axis2.transport.TransportListener#init(org.apache.axis2.context.ConfigurationContext, org.apache.axis2.description.TransportInDescription)
-     */
-    public void init(
-        ConfigurationContext configurationContext,
-        TransportInDescription transportIn)
-        throws AxisFault {
-        this.configurationContext = configurationContext;
-
-        user =
-            Utils.getParameterValue(
-                transportIn.getParameter(MailSrvConstants.POP3_USER));
-        host =
-            Utils.getParameterValue(
-                transportIn.getParameter(MailSrvConstants.POP3_HOST));
-        password =
-            Utils.getParameterValue(
-                transportIn.getParameter(MailSrvConstants.POP3_PASSWORD));
-        port =
-            Utils.getParameterValue(
-                transportIn.getParameter(MailSrvConstants.POP3_PORT));
-        replyTo =
-            Utils.getParameterValue(
-                transportIn.getParameter(MailSrvConstants.RAPLY_TO));
-        if (user == null || host == null || password == null || port == null) {
-            if (this.user == null) {
-                throw new AxisFault(
-                    Messages.getMessage("canNotBeNull", "User"));
-            }
-            if (this.host == null) {
-                throw new AxisFault(
-                    Messages.getMessage("canNotBeNull", "Host"));
-            }
-            if (this.port == null) {
-                throw new AxisFault(
-                    Messages.getMessage("canNotBeNull", "Port"));
-            }
-            if (this.password == null) {
-                throw new AxisFault(
-                    Messages.getMessage("canNotBeNull", "Password"));
-            };
-        }
-
+    public boolean getDoThreads() {
+        return doThreads;
     }
 
-    /* (non-Javadoc)
+    /*
+     *  (non-Javadoc)
      * @see org.apache.axis2.transport.TransportListener#replyToEPR(java.lang.String)
      */
     public EndpointReference getReplyToEPR(String serviceName) throws AxisFault {
+
         // TODO Auto-generated method stub
         return new EndpointReference(replyTo + "/services/" + serviceName);
     }
 
-}
\ No newline at end of file
+    public void setDoThreads(boolean value) {
+        doThreads = value;
+    }
+}

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailAddress.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailAddress.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailAddress.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailAddress.java Fri Dec 16 09:13:57 2005
@@ -17,11 +17,11 @@
         return this.mailAddy.equals(addr);
     }
 
-    public String getType() {
-        return "text/plain";
-    }
-
     public String toString() {
         return this.mailAddy;
     }
-}
\ No newline at end of file
+
+    public String getType() {
+        return "text/plain";
+    }
+}

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java Fri Dec 16 09:13:57 2005
@@ -8,41 +8,52 @@
 import org.apache.commons.logging.LogFactory;
 
 public class MailServer {
+    protected static Log log =
+            LogFactory.getLog(SimpleMailListener.class.getName());
     Storage st = null;
+    public ConfigurationContext configurationContext = null;
+    private POP3Server pop3Server;
     private SMTPServer smtpServer;
-    private POP3Server pop3Server; 
 
-    public ConfigurationContext configurationContext = null;
+    public MailServer(int popPort, int smtpPort) throws AxisFault {
+        st = new Storage();
 
-    protected static Log log = LogFactory.getLog(SimpleMailListener.class
-            .getName());
+        // Start up the two servers and lets have some fun. - CT
+        smtpServer = new SMTPServer(st, smtpPort);
+        smtpServer.start();
+        pop3Server = new POP3Server(st, popPort);
+        pop3Server.start();
+    }
+
+    public MailServer(ConfigurationContext configurationContext, int popPort, int smtpPort)
+            throws AxisFault {
+        this.configurationContext = configurationContext;
 
-    public MailServer(String dir, int popPort, int smtpPort) throws AxisFault {
-        try {
-            ConfigurationContextFactory builder = new ConfigurationContextFactory();
-            configurationContext = builder.buildConfigurationContext(dir);
-        } catch (Exception e) {
-            log.error(e);
-        }
         try {
             log.info("Sleeping for a bit to let the engine start up.");
             Thread.sleep(2000);
         } catch (InterruptedException e1) {
             log.error(e1);
         }
+
         st = new Storage();
+
         // Start up the two servers and lets have some fun. - CT
-        smtpServer = new SMTPServer(st, configurationContext,
-                smtpPort);
+        smtpServer = new SMTPServer(st, configurationContext, smtpPort);
         smtpServer.start();
         pop3Server = new POP3Server(st, popPort);
         pop3Server.start();
-
     }
 
-    public MailServer(ConfigurationContext configurationContext, int popPort,
-            int smtpPort) throws AxisFault {
-        this.configurationContext = configurationContext;
+    public MailServer(String dir, int popPort, int smtpPort) throws AxisFault {
+        try {
+            ConfigurationContextFactory builder = new ConfigurationContextFactory();
+
+            configurationContext = builder.buildConfigurationContext(dir);
+        } catch (Exception e) {
+            log.error(e);
+        }
+
         try {
             log.info("Sleeping for a bit to let the engine start up.");
             Thread.sleep(2000);
@@ -51,37 +62,24 @@
         }
 
         st = new Storage();
-        // Start up the two servers and lets have some fun. - CT
-        smtpServer = new SMTPServer(st, configurationContext,
-                smtpPort);
-        smtpServer.start();
-        pop3Server = new POP3Server(st, popPort);
-        pop3Server.start();
-    }
 
-    public MailServer(int popPort, int smtpPort) throws AxisFault {
-        st = new Storage();
         // Start up the two servers and lets have some fun. - CT
-        smtpServer = new SMTPServer(st, smtpPort);
+        smtpServer = new SMTPServer(st, configurationContext, smtpPort);
         smtpServer.start();
         pop3Server = new POP3Server(st, popPort);
         pop3Server.start();
     }
-    
-    public void stop() throws AxisFault{
-        smtpServer.stopServer();
-        pop3Server.stopServer();
-    }
 
-    public static void main(String args[]){
+    public static void main(String args[]) {
         int smtpPost = MailSrvConstants.SMTP_SERVER_PORT;
         int popPort = MailSrvConstants.POP_SERVER_PORT;
+
         if (args.length == 2) {
             try {
                 smtpPost = Integer.parseInt(args[0]);
                 popPort = Integer.parseInt(args[1]);
             } catch (NumberFormatException e1) {
-               log.info("Error in parsing the custom ports.");
+                log.info("Error in parsing the custom ports.");
             }
         } else {
             log.info("Usage MailServer <SMTP_PORT> <POP_PORT>");
@@ -93,5 +91,10 @@
         } catch (AxisFault e) {
             log.info(e.getMessage());
         }
+    }
+
+    public void stop() throws AxisFault {
+        smtpServer.stopServer();
+        pop3Server.stopServer();
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java Fri Dec 16 09:13:57 2005
@@ -30,17 +30,19 @@
  * and the receive method is called.
  */
 public class MailSorter {
+    protected static Log log = LogFactory.getLog(MailSorter.class.getName());
     Storage st = null;
     private ArrayList sUsers = new ArrayList();
+
     // Special users. They are hard coded for the time being to axis2-server@localhost and axis2-server@127.0.0.1
     private ConfigurationContext configurationContext = null;
-    protected static Log log = LogFactory.getLog(MailSorter.class.getName());
     private boolean actAsMailet = false;
 
     public MailSorter(Storage st, ConfigurationContext configurationContext) {
         this.st = st;
         sUsers.add("axis2-server@localhost");
         sUsers.add("axis2-server@127.0.0.1");
+
         if (configurationContext == null) {
             actAsMailet = false;
         } else {
@@ -49,40 +51,34 @@
         }
     }
 
-    public void sort(String user, MimeMessage msg) {
-        if (actAsMailet) {
-            if (sUsers.contains(user)) {
-                processMail(configurationContext, msg);
-            } else {
-                st.addMail(user, msg);
-            }
-        } else {
-            st.addMail(user, msg);
-        }
-
-    }
-
     public void processMail(ConfigurationContext confContext, MimeMessage mimeMessage) {
+
         // create an Axis server
         AxisEngine engine = new AxisEngine(confContext);
         MessageContext msgContext = null;
+
         // create and initialize a message context
         try {
             msgContext =
                     new MessageContext(confContext,
-                            confContext.getAxisConfiguration().getTransportIn(new QName(Constants.TRANSPORT_MAIL)),
-                            confContext.getAxisConfiguration().getTransportOut(new QName(Constants.TRANSPORT_MAIL)));
+                            confContext.getAxisConfiguration()
+                                    .getTransportIn(new QName(Constants
+                                    .TRANSPORT_MAIL)), confContext.getAxisConfiguration()
+                            .getTransportOut(new QName(Constants
+                            .TRANSPORT_MAIL)));
             msgContext.setServerSide(true);
-
             msgContext.setProperty(MailSrvConstants.CONTENT_TYPE, mimeMessage.getContentType());
-            msgContext.setWSAAction(getMailHeader(MailSrvConstants.HEADER_SOAP_ACTION, mimeMessage));
+            msgContext.setWSAAction(getMailHeader(MailSrvConstants.HEADER_SOAP_ACTION,
+                    mimeMessage));
 
             String serviceURL = mimeMessage.getSubject();
+
             if (serviceURL == null) {
                 serviceURL = "";
             }
 
             String replyTo = ((InternetAddress) mimeMessage.getReplyTo()[0]).getAddress();
+
             if (replyTo != null) {
                 msgContext.setReplyTo(new EndpointReference(replyTo));
             }
@@ -95,21 +91,26 @@
 
             // add the SOAPEnvelope
             String message = mimeMessage.getContent().toString();
+
             log.info("message[" + message + "]");
-            ByteArrayInputStream bais = new ByteArrayInputStream(message.getBytes());
-            XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(bais);
 
+            ByteArrayInputStream bais = new ByteArrayInputStream(message.getBytes());
+            XMLStreamReader reader =
+                    XMLInputFactory.newInstance().createXMLStreamReader(bais);
             String soapNamespaceURI = "";
+
             if (mimeMessage.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
                 soapNamespaceURI = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI;
-            } else if (mimeMessage.getContentType().indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+            } else if (mimeMessage.getContentType().indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE)
+                    > -1) {
                 soapNamespaceURI = SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI;
-
             }
-            StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
 
+            StAXBuilder builder = new StAXSOAPModelBuilder(reader, soapNamespaceURI);
             SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
+
             msgContext.setEnvelope(envelope);
+
             if (envelope.getBody().hasFault()) {
                 engine.receiveFault(msgContext);
             } else {
@@ -119,6 +120,7 @@
             try {
                 if (msgContext != null) {
                     MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
+
                     engine.sendFault(faultContext);
                 }
             } catch (Exception e1) {
@@ -127,9 +129,22 @@
         }
     }
 
+    public void sort(String user, MimeMessage msg) {
+        if (actAsMailet) {
+            if (sUsers.contains(user)) {
+                processMail(configurationContext, msg);
+            } else {
+                st.addMail(user, msg);
+            }
+        } else {
+            st.addMail(user, msg);
+        }
+    }
+
     private String getMailHeader(String headerName, MimeMessage mimeMessage) throws AxisFault {
         try {
             String values[] = mimeMessage.getHeader(headerName);
+
             if (values != null) {
                 return values[0];
             } else {
@@ -138,6 +153,5 @@
         } catch (MessagingException e) {
             throw new AxisFault(e);
         }
-
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSrvConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSrvConstants.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSrvConstants.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/MailSrvConstants.java Fri Dec 16 09:13:57 2005
@@ -1,64 +1,52 @@
 /*
- * Created on Jan 28, 2005
- * 
- * TODO To change the template for this generated file go to Window -
- * Preferences - Java - Code Style - Code Templates
- */
+* Created on Jan 28, 2005
+*
+* TODO To change the template for this generated file go to Window -
+* Preferences - Java - Code Style - Code Templates
+*/
 package org.apache.axis2.transport.mail.server;
 
 public class MailSrvConstants {
     public final static String FROM_ADDRESS = "transport.mail.from";
-
     public final static String TO_ADDRESS = "transport.mail.to";
-
     public final static String SUBJECT = "transport.mail.subject";
-
-
-    public final static String POP3_HOST = "transport.mail.pop3.host";
-    public final static String POP3_USER = "transport.mail.pop3.user";
-    public final static String POP3_PASSWORD = "transport.mail.pop3.password";
-    public final static String POP3_PORT = "transport.mail.pop3.port";
-
-    public final static String RAPLY_TO = "transport.mail.replyToAddress";
-    public final static String HEADER_SOAP_ACTION = "transport.mail.soapaction";
-
-    public final static String CONTENT_TYPE = "transport.mail.contenttype";
-
-    public final static String CONTENT_LOCAION = "transport.mail.contentlocation";
-
-
-    public final static String SMTP_HOST = "transport.mail.smtp.host";
     public final static String SMTP_USER = "transport.mail.smtp.user";
-    public final static String SMTP_PASSWORD = "transport.mail.smtp.password";
-    public final static String SMTP_PORT = "transport.mail.smtp.port";
-    
-    public final static String DEFAULT_CHAR_SET = "us-ascii";
-    public final static String DEFAULT_CHAR_SET_ENCODING = "7bit";
-    public final static String DEFAULT_CONTENT_TYPE = "text/xml";
-
     public final static int SMTP_SERVER_PORT = (1024 + 25);
+    public final static String SMTP_PORT = "transport.mail.smtp.port";
+    public final static String SMTP_PASSWORD = "transport.mail.smtp.password";
+    public final static String SMTP_HOST = "transport.mail.smtp.host";
     public final static String SERVER_DOMAIN = "localhost";
+    public final static String RCPT_OK = "250 OK performed command RCPT";
+    public final static String RCPT_ERROR = "550 Unknown recipient";
+    public final static String RAPLY_TO = "transport.mail.replyToAddress";
     public final static int POP_SERVER_PORT = (1024 + 110);
-
-    public final static String COMMAND_UNKNOWN = "550 Unknown command";
-    public final static String COMMAND_EXIT = "EXIT";
+    public final static String POP3_USER = "transport.mail.pop3.user";
+    public final static String POP3_PORT = "transport.mail.pop3.port";
+    public final static String POP3_PASSWORD = "transport.mail.pop3.password";
+    public final static String POP3_HOST = "transport.mail.pop3.host";
+    public final static String OK = "+OK ";
     public final static String MAIL_OK = "250 OK performed command MAIL";
     public final static String MAIL_ERROR = "550 Error processign MAIL command";
-    public final static String RCPT_OK = "250 OK performed command RCPT";
-    public final static String RCPT_ERROR = "550 Unknown recipient";
+    public final static String HELO_REPLY = "250 OK";
+    public final static String HEADER_SOAP_ACTION = "transport.mail.soapaction";
+    public final static String ERR = "-ERR ";
+    public final static String DEFAULT_CONTENT_TYPE = "text/xml";
+    public final static String DEFAULT_CHAR_SET_ENCODING = "7bit";
+    public final static String DEFAULT_CHAR_SET = "us-ascii";
     public final static String DATA_START_SUCCESS = "354 OK Ready for data";
     public final static String DATA_END_SUCCESS = "250 OK finished adding data";
+    public final static String CONTENT_TYPE = "transport.mail.contenttype";
+    public final static String CONTENT_LOCAION = "transport.mail.contentlocation";
+    public final static String COMMAND_UNKNOWN = "550 Unknown command";
     public final static String COMMAND_TRANSMISSION_END = "221 Closing SMTP service.";
-    public final static String HELO_REPLY = "250 OK";
-    public final static String OK = "+OK ";
-    public final static String ERR = "-ERR ";
+    public final static String COMMAND_EXIT = "EXIT";
     public final static String USER = "USER";
-    public final static String PASS = "PASS";
     public final static String STAT = "STAT";
-    public final static String LIST = "LIST";
-    public final static String RETR = "RETR";
-    public final static String DELE = "DELE";
-    public final static String NOOP = "NOOP";
     public final static String RSET = "RSET";
+    public final static String RETR = "RETR";
     public final static String QUIT = "QUIT";
+    public final static String PASS = "PASS";
+    public final static String NOOP = "NOOP";
+    public final static String LIST = "LIST";
+    public final static String DELE = "DELE";
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Server.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Server.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Server.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Server.java Fri Dec 16 09:13:57 2005
@@ -10,12 +10,13 @@
 
 public class POP3Server extends Thread {
     protected static Log log = LogFactory.getLog(POP3Server.class.getName());
-    private ServerSocket serverSocket;
     private Storage st = null;
     private boolean running = false;
+    private ServerSocket serverSocket;
 
     public POP3Server(Storage st, int port) throws AxisFault {
         this.st = st;
+
         try {
             synchronized (this) {
                 running = true;
@@ -32,6 +33,7 @@
             try {
                 Socket socket = serverSocket.accept();
                 POP3Worker thread = new POP3Worker(socket, st);
+
                 thread.start();
             } catch (Exception e) {
                 log.error(e);
@@ -45,9 +47,8 @@
                 running = false;
                 serverSocket.close();
             }
-
         } catch (IOException e) {
             throw new AxisFault(e);
         }
     }
-}
\ No newline at end of file
+}

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Worker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Worker.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Worker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/POP3Worker.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.transport.mail.server;
 
@@ -31,112 +32,92 @@
 import java.util.StringTokenizer;
 
 public class POP3Worker extends Thread {
+    protected static Log log = LogFactory.getLog(POP3Server.class.getName());
+    boolean doneProcess = false;
+    int numDeleted = 0;    // This is a small hack to get the deleting working with the ArrayList. To keep it simple.
+    ArrayList messages = new ArrayList();
     private Socket socket;
     private Storage st;
-    boolean doneProcess = false;
-    protected static Log log = LogFactory.getLog(POP3Server.class.getName());
-    int numDeleted = 0; //This is a small hack to get the deleting working with the ArrayList. To keep it simple.
 
     public POP3Worker(Socket socket, Storage st) {
         this.socket = socket;
         this.st = st;
     }
 
-    public void run() {
-        try {
-            InputStream inputStream = socket.getInputStream();
-            BufferedReader bufferedReader = new BufferedReader(
-                    new InputStreamReader(inputStream));
-
-            PrintWriter printWriter = new PrintWriter(socket.getOutputStream(),
-                    true);
-
-            printWriter.println(MailSrvConstants.OK + " POP3 server ready");
-            String s;
-            String ps; //ProcessedString
-            while (!doneProcess) {
-                s = bufferedReader.readLine();
-                processInput(s, printWriter);
-            }
-            socket.close();
-        } catch (Exception e) {
-            log.error(e);
-        }
-
-    }
-
-    ArrayList messages = new ArrayList();
-
     private void processInput(String input, PrintWriter printWriter) {
         int listLen = (MailSrvConstants.LIST + " ").length();
         byte[] CR_LF = new byte[]{0x0D, 0x0A};
         byte[] CR_LF_DOT_CR_LF = new byte[]{0x0D, 0x0A, '.', 0x0D, 0x0A};
         String user = "";
+
         if (input == null) {
-            this.doneProcess = true; // This should not be happening
+            this.doneProcess = true;    // This should not be happening
         } else {
             ArrayList tokens = new ArrayList();
             StringTokenizer stk = new StringTokenizer(input);
+
             while (stk.hasMoreTokens()) {
                 tokens.add(stk.nextToken());
             }
+
             if (tokens.get(0).equals(MailSrvConstants.USER)) {
                 user = (String) tokens.get(1);
                 messages = st.popUserMails(user);
                 printWriter.println(MailSrvConstants.OK);
             } else if (tokens.get(0).equals(MailSrvConstants.PASS)) {
-                printWriter.println(MailSrvConstants.OK); // Passwords are not checked.
+                printWriter.println(MailSrvConstants.OK);    // Passwords are not checked.
             } else if (input.equals(MailSrvConstants.QUIT)) {
-                printWriter.println(
-                        MailSrvConstants.OK + "POP3 server signing off");
+                printWriter.println(MailSrvConstants.OK + "POP3 server signing off");
                 doneProcess = true;
             } else if (input.equals(MailSrvConstants.STAT)) {
-                printWriter.println(MailSrvConstants.OK + messages.size() + " 1"); // We take the maildrop size as one.
-            } else if (tokens.get(0).equals(MailSrvConstants.LIST)) { // scan listing
+                printWriter.println(MailSrvConstants.OK + messages.size() + " 1");    // We take the maildrop size as one.
+            } else if (tokens.get(0).equals(MailSrvConstants.LIST)) {                               // scan listing
                 if (tokens.size() > 1) {
                     try {
                         int optArg = Integer.parseInt((String) tokens.get(1));
                         int messageArrayIndex = optArg - 1;
-                        if ((messageArrayIndex < messages.size()) &&
-                                (messageArrayIndex >= 0)) { // that is OK careful with numbering
-                            printWriter.println(
-                                    MailSrvConstants.OK + messageArrayIndex + 1 +
-                                    " 120"); // Mail size of 120 is just some number.
+
+                        if ((messageArrayIndex < messages.size()) && (messageArrayIndex >= 0))
+                        {    // that is OK careful with numbering
+                            printWriter.println(MailSrvConstants.OK + messageArrayIndex + 1
+                                    + " 120");    // Mail size of 120 is just some number.
                         } else {
-                            printWriter.println(
-                                    MailSrvConstants.ERR +
-                                    "no such message, only " +
-                                    (messages.size() + 1) +
-                                    " messages in maildrop");
+                            printWriter.println(MailSrvConstants.ERR + "no such message, only "
+                                    + (messages.size() + 1) + " messages in maildrop");
                         }
                     } catch (NumberFormatException e) {
                         log.info(e.getMessage());
-                        printWriter.println(
-                                MailSrvConstants.ERR +
-                                "problem passing the index. Index submited was " +
-                                tokens.get(1));
+                        printWriter.println(MailSrvConstants.ERR
+                                + "problem passing the index. Index submited was "
+                                + tokens.get(1));
                     }
                 } else {
                     printWriter.println(MailSrvConstants.OK + messages.size());
+
                     for (int i = 0; i < messages.size(); i++) {
                         int messageIndex = i + 1;
-                        printWriter.println(messageIndex + " 120"); // List out all the messages with a message size octet of 120
+
+                        printWriter.println(messageIndex + " 120");    // List out all the messages with a message size octet of 120
                     }
+
                     printWriter.println(".");
                 }
             } else if (tokens.get(0).equals(MailSrvConstants.RETR)) {
                 String i = (String) tokens.get(1);
+
                 try {
                     int index = Integer.parseInt(i);
+
                     printWriter.println(MailSrvConstants.OK);
+
                     MimeMessage m = (MimeMessage) messages.get(index - 1);
 
                     m.writeTo(socket.getOutputStream());
-                    //System.out.println("\n\n\n\n ========This is the mail========");
-                    //m.writeTo(System.out);//socket.getOutputStream());
-                    //System.out.println("\n\n\n\n ========This is the mail========");
 
-                    socket.getOutputStream().write(CR_LF_DOT_CR_LF);// This is a bit of a hack to get it working. Have to find a bette way to handle this.
+                    // System.out.println("\n\n\n\n ========This is the mail========");
+                    // m.writeTo(System.out);//socket.getOutputStream());
+                    // System.out.println("\n\n\n\n ========This is the mail========");
+                    socket.getOutputStream().write(CR_LF_DOT_CR_LF);    // This is a bit of a hack to get it working. Have to find a bette way to handle this.
                     socket.getOutputStream().flush();
                 } catch (NumberFormatException e) {
                     printWriter.println(MailSrvConstants.ERR);
@@ -147,8 +128,10 @@
                 }
             } else if (tokens.get(0).equals(MailSrvConstants.DELE)) {
                 String smIndex = (String) tokens.get(1);
+
                 try {
-                    int mIndex = Integer.parseInt(smIndex) - 1 - numDeleted; // When one mail is deleted the index of the other mails will reduce. Asumed that the delete will occure from bottom up.
+                    int mIndex = Integer.parseInt(smIndex) - 1 - numDeleted;    // When one mail is deleted the index of the other mails will reduce. Asumed that the delete will occure from bottom up.
+
                     if ((mIndex >= 0) && (mIndex < messages.size())) {
                         messages.remove(mIndex);
                         numDeleted++;
@@ -159,12 +142,34 @@
                 } catch (NumberFormatException e) {
                     printWriter.println(MailSrvConstants.ERR);
                 }
-            } else if (tokens.get(0).equals(MailSrvConstants.NOOP) ||
-                    tokens.get(0).equals(MailSrvConstants.RSET)) {
+            } else if (tokens.get(0).equals(MailSrvConstants.NOOP)
+                    || tokens.get(0).equals(MailSrvConstants.RSET)) {
                 printWriter.println(MailSrvConstants.OK);
             } else {
                 printWriter.println(MailSrvConstants.ERR);
             }
+        }
+    }
+
+    public void run() {
+        try {
+            InputStream inputStream = socket.getInputStream();
+            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
+            PrintWriter printWriter = new PrintWriter(socket.getOutputStream(), true);
+
+            printWriter.println(MailSrvConstants.OK + " POP3 server ready");
+
+            String s;
+            String ps;    // ProcessedString
+
+            while (!doneProcess) {
+                s = bufferedReader.readLine();
+                processInput(s, printWriter);
+            }
+
+            socket.close();
+        } catch (Exception e) {
+            log.error(e);
         }
     }
 }



Mime
View raw message