Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 93585 invoked from network); 14 Jul 2005 04:49:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 14 Jul 2005 04:49:02 -0000 Received: (qmail 38776 invoked by uid 500); 14 Jul 2005 04:48:57 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 38762 invoked by uid 500); 14 Jul 2005 04:48:57 -0000 Mailing-List: contact axis-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-dev@ws.apache.org Received: (qmail 38741 invoked by uid 99); 14 Jul 2005 04:48:56 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jul 2005 21:48:56 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [209.68.5.15] (HELO relay01.pair.com) (209.68.5.15) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 13 Jul 2005 21:48:53 -0700 Received: (qmail 89904 invoked from network); 14 Jul 2005 04:48:51 -0000 Received: from unknown (HELO ?192.168.101.104?) (unknown) by unknown with SMTP; 14 Jul 2005 04:48:51 -0000 X-pair-Authenticated: 220.247.245.249 Message-ID: <42D5F124.2030302@opensource.lk> Date: Thu, 14 Jul 2005 10:59:16 +0600 From: Chamil Thanthrimudalige User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: axis-dev@ws.apache.org Subject: [Axis2] Mailserver patch Content-Type: multipart/mixed; boundary="------------040302030705040905070507" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------040302030705040905070507 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, I have done some changes to the mail server code. So that it can be used independent of an Axis configuration. Can some kind soul please apply the attached patch. -- Best Regards, Chamil Thanthrimudalige Lanka Software Foundation (http://www.opensource.lk) --------------040302030705040905070507 Content-Type: text/plain; name="maildiff.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="maildiff.txt" Index: modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java =================================================================== --- modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java (revision 218983) +++ modules/core/src/org/apache/axis2/transport/mail/server/MailSorter.java (working copy) @@ -36,20 +36,30 @@ 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"); - this.configurationContext = configurationContext; + if (configurationContext == null){ + actAsMailet = false; + } else { + this.configurationContext = configurationContext; + actAsMailet = true; + } } public void sort(String user, MimeMessage msg) { - if (sUsers.contains(user)) { - processMail(configurationContext, 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, Index: modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java =================================================================== --- modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java (revision 218983) +++ modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java (working copy) @@ -62,4 +62,14 @@ POP3Server 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 smtpServer = new SMTPServer(st, smtpPort); +smtpServer.start(); +POP3Server pop3Server = new POP3Server(st, popPort); +pop3Server.start(); } + +} Index: modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java =================================================================== --- modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java (revision 218983) +++ modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java (working copy) @@ -6,7 +6,6 @@ import java.net.ServerSocket; import java.net.Socket; - /** * @author Chamil Thanthrimudalige * @author Chamikara Jayalath @@ -14,17 +13,27 @@ public class SMTPServer extends Thread { private Storage st; + private ConfigurationContext configurationContext; + private int port; - public SMTPServer(Storage st, - ConfigurationContext configurationContext, - int port) { + private boolean actAsMailet = false; + + public SMTPServer(Storage st, ConfigurationContext configurationContext, + int port) { this.st = st; this.configurationContext = configurationContext; this.port = port; + actAsMailet = true; } + public SMTPServer(Storage st, int port) { + this.st = st; + this.port = port; + actAsMailet = false; + } + public void run() { runServer(); } @@ -42,10 +51,12 @@ try { //wait for a client Socket socket = ss.accept(); - - SMTPWorker thread = new SMTPWorker(socket, - st, - configurationContext); + SMTPWorker thread = null; + if (actAsMailet) + thread = new SMTPWorker(socket, st, configurationContext); + else { + thread = new SMTPWorker(socket, st); + } thread.start(); } catch (IOException ex) { Index: modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java =================================================================== --- modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java (revision 218983) +++ modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java (working copy) @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.Properties; - /** * @author Chamil Thanthrimudalige * @author Chamikara Jayalath @@ -25,40 +24,53 @@ public class SMTPWorker extends Thread { - BufferedReader reader = null; + private BufferedReader reader = null; - BufferedWriter writer = null; + private BufferedWriter writer = null; - ArrayList receivers = new ArrayList(); + private boolean actAsMailet = false; - Storage st = null; + private ArrayList receivers = new ArrayList(); + + private Storage st = null; + boolean runThread = true; private MimeMessage mail = null; + private ConfigurationContext configurationContext = null; - String temp = ""; - boolean dataWriting = false; - boolean transmitionEnd = false; + private String temp = ""; - boolean bodyData = false; + private boolean dataWriting = false; - public SMTPWorker(Socket socket, - Storage st, - ConfigurationContext configurationContext) { + private boolean transmitionEnd = false; + + private boolean bodyData = false; + + public SMTPWorker(Socket socket, Storage st, + ConfigurationContext configurationContext) { + doWork(socket, st, configurationContext); + } + + public SMTPWorker(Socket socket, Storage st) { + doWork(socket, st, null); + } + + private void doWork(Socket socket, Storage st, + ConfigurationContext configurationContext) { try { this.st = st; - this.configurationContext = configurationContext; + if (configurationContext == null) { + actAsMailet = false; + } else { + this.configurationContext = configurationContext; + actAsMailet = true; + } //get the streams from the socket and save in instance variables. - reader = - new BufferedReader( - new InputStreamReader( - socket + reader = new BufferedReader(new InputStreamReader(socket .getInputStream())); - writer = - new BufferedWriter( - new OutputStreamWriter( - socket + writer = new BufferedWriter(new OutputStreamWriter(socket .getOutputStream())); } catch (IOException ex) { ex.printStackTrace(); @@ -70,7 +82,7 @@ try { //do initial transmission. initializeClient(); - + //analyze all the inputs from client and work accordingly. while (runThread) { String input = null; @@ -93,10 +105,15 @@ } for (int idx = 0; idx < receivers.size(); idx++) { try { - MailSorter mSort = new MailSorter(this.st, - this.configurationContext); - mSort.sort((String) receivers.get(idx), - new MimeMessage(mail)); + MailSorter mSort = null; + if (actAsMailet) { + mSort = new MailSorter(this.st, + this.configurationContext); + } else { + mSort = new MailSorter(this.st, null); + } + mSort.sort((String) receivers.get(idx), new MimeMessage( + mail)); } catch (MessagingException e1) { e1.printStackTrace(); } @@ -115,16 +132,19 @@ } private String processInput(String input) { - byte[] CR_LF = new byte[]{0x0D, 0x0A}; - if (input == null) return MailConstants.COMMAND_UNKNOWN; - if (mail != null && transmitionEnd) return MailConstants.COMMAND_TRANSMISSION_END; + byte[] CR_LF = new byte[] { 0x0D, 0x0A }; + if (input == null) + return MailConstants.COMMAND_UNKNOWN; + if (mail != null && transmitionEnd) + return MailConstants.COMMAND_TRANSMISSION_END; if (input.startsWith("MAIL")) { - mail = new MimeMessage(Session.getInstance(new Properties(), new Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - return null; - } - })); + mail = new MimeMessage(Session.getInstance(new Properties(), + new Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return null; + } + })); int start = input.indexOf("<") + 1; int end; @@ -139,7 +159,8 @@ String from = input.substring(start, end); if (from != null && !from.trim().equals("")) { - //TODO this is an ugly hack to get the from address in. There should be a better way to do this. + //TODO this is an ugly hack to get the from address in. There + // should be a better way to do this. MailAddress mailFrom[] = new MailAddress[1]; mailFrom[0] = new MailAddress(from); try { @@ -160,29 +181,29 @@ String domain = MailConstants.SERVER_DOMAIN; //System.out.println("RCPT:" + input); - //temp += input + "\n"; TODO Check this + //temp += input + "\n"; TODO Check this int start = input.indexOf("<") + 1; int end; if (start <= 0) { start = input.indexOf("TO:") + 3; -/* if(!input.endsWith(domain)){ - System.out.println("ERROR: wrong donmain name"); - return MailConstants.RCPT_ERROR; - }*/ + /* + * if(!input.endsWith(domain)){ System.out.println("ERROR: wrong + * donmain name"); return MailConstants.RCPT_ERROR; } + */ } else { -/* if(!input.endsWith(domain + ">")){ - System.out.println("ERROR: wrong donmain name"); - return MailConstants.RCPT_ERROR; - }*/ + /* + * if(!input.endsWith(domain + ">")){ System.out.println("ERROR: + * wrong donmain name"); return MailConstants.RCPT_ERROR; } + */ } end = input.indexOf(">"); String toStr = input.substring(start, end); try { - mail.addRecipient(Message.RecipientType.TO, - new MailAddress(toStr)); + mail.addRecipient(Message.RecipientType.TO, new MailAddress( + toStr)); receivers.add(toStr); } catch (MessagingException e) { // TODO Auto-generated catch block @@ -210,9 +231,8 @@ if (bodyData) { temp += input; mail.setContent(temp, "text/plain"); - System.out.println( - "\n\n\n---------------" + temp + - "---------------\n\n\n"); + System.out.println("\n\n\n---------------" + temp + + "---------------\n\n\n"); } else { mail.addHeaderLine(input); } --------------040302030705040905070507--