You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Chamil Thanthrimudalige <ch...@opensource.lk> on 2005/08/12 08:33:39 UTC

[Axis2] Mail transport patch

hi,

Can some one with enough karma please apply this patch.

It has some bug fixes to the char set encoding in mail, renaming of the
MailConstants class in the org.apache.axis2.transport.mail.server
package to MailSrvConstans to make a clear distinction with the class in
the transport.mail package and the test case for the mail content type
encoding.

There seems to be a problem with calling multiple tests from the same
test class using the mail transport. So it is still not working fully.
Since all mail related tests have been excluded at the moment this will
not be a problem with the build.

On a separate note the mail transport is not working with the Geronimo
jar files. I will send a separate mail with the parts that are
lacking/problematic in the Geronimo jars.

Best Regards,
Chamil Thanthrimudalige

Re: [Axis2] Mail transport patch

Posted by Deepal Jayasinghe <de...@opensource.lk>.
done

Thanks,
 Deepal
................................................................
~Future is Open~



----- Original Message ----- 
From: "Chamil Thanthrimudalige" <ch...@opensource.lk>
To: <ax...@ws.apache.org>
Sent: Friday, August 12, 2005 12:33 PM
Subject: [Axis2] Mail transport patch


> hi,
>
> Can some one with enough karma please apply this patch.
>
> It has some bug fixes to the char set encoding in mail, renaming of the
> MailConstants class in the org.apache.axis2.transport.mail.server
> package to MailSrvConstans to make a clear distinction with the class in
> the transport.mail package and the test case for the mail content type
> encoding.
>
> There seems to be a problem with calling multiple tests from the same
> test class using the mail transport. So it is still not working fully.
> Since all mail related tests have been excluded at the moment this will
> not be a problem with the build.
>
> On a separate note the mail transport is not working with the Geronimo
> jar files. I will send a separate mail with the parts that are
> lacking/problematic in the Geronimo jars.
>
> Best Regards,
> Chamil Thanthrimudalige
>


--------------------------------------------------------------------------------


> Index: modules/integration/test/org/apache/axis2/mail/UtilsMailServer.java
> ===================================================================
> --- modules/integration/test/org/apache/axis2/mail/UtilsMailServer.java 
> (revision 232201)
> +++ modules/integration/test/org/apache/axis2/mail/UtilsMailServer.java 
> (working copy)
> @@ -22,7 +22,7 @@
> import org.apache.axis2.Constants;
> import org.apache.axis2.context.ConfigurationContext;
> import org.apache.axis2.context.ConfigurationContextFactory;
> -import org.apache.axis2.transport.mail.server.MailConstants;
> +import org.apache.axis2.transport.mail.server.MailSrvConstants;
> import org.apache.axis2.transport.mail.server.MailServer;
>
> import java.io.File;
> @@ -46,8 +46,8 @@
>             server =
>                 new MailServer(
>             SERVER_CONFIG_CONTEXT,
> -                    MailConstants.POP_SERVER_PORT,
> -                    MailConstants.SMTP_SERVER_PORT);
> +                    MailSrvConstants.POP_SERVER_PORT,
> +                    MailSrvConstants.SMTP_SERVER_PORT);
>         }
>         runningServerCount++;
>         return SERVER_CONFIG_CONTEXT;
> Index: modules/core/src/org/apache/axis2/transport/mail/MailConstants.java
> ===================================================================
> --- modules/core/src/org/apache/axis2/transport/mail/MailConstants.java 
> (revision 232201)
> +++ modules/core/src/org/apache/axis2/transport/mail/MailConstants.java 
> (working copy)
> @@ -34,4 +34,5 @@
>
>     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";
> }
> Index: 
> modules/core/src/org/apache/axis2/transport/mail/MailTransportSender.java
> ===================================================================
> ---  
> modules/core/src/org/apache/axis2/transport/mail/MailTransportSender.java 
> (revision 232201)
> +++ 
> modules/core/src/org/apache/axis2/transport/mail/MailTransportSender.java 
> (working copy)
> @@ -68,7 +68,11 @@
>                 //TODO this is just a temporary hack, fix this to use 
> input streams
>
>                 String eprAddress = msgContext.getTo().getAddress();
> -                String charEncoding = 
> (String)msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
> +                // 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){
> +                    charSet = MailConstants.DEFAULT_CHAR_SET;
> +                }
>                 int index = eprAddress.indexOf('/');
>                 String subject = "";
>                 String email = null;
> @@ -82,7 +86,7 @@
>                 sender.send(
>                     subject,
>                     email,
> -                    new String(byteArrayOutputStream.toByteArray()), 
> charEncoding);
> +                    new String(byteArrayOutputStream.toByteArray()), 
> charSet);
>             } else {
>                 if (user == null) {
>                     throw new AxisFault(
> Index: 
> modules/core/src/org/apache/axis2/transport/mail/server/MailConstants.java
> ===================================================================
> ---  
> modules/core/src/org/apache/axis2/transport/mail/server/MailConstants.java 
> (revision 232201)
> +++ 
> modules/core/src/org/apache/axis2/transport/mail/server/MailConstants.java 
> (working copy)
> @@ -1,34 +0,0 @@
> -package org.apache.axis2.transport.mail.server;
> -
> -/**
> - * @author Chamil Thanthrimudalige
> - * @author Chamikara Jayalath
> - */
> -
> -public interface MailConstants {
> -    public final int SMTP_SERVER_PORT = (1024 + 25);
> -    public final String SERVER_DOMAIN = "localhost";
> -    public final int POP_SERVER_PORT = (1024 + 110);
> -
> -    public final String COMMAND_UNKNOWN = "550 Unknown command";
> -    public final String COMMAND_EXIT = "EXIT";
> -    public final String MAIL_OK = "250 OK performed command MAIL";
> -    public final String MAIL_ERROR = "550 Error processign MAIL command";
> -    public final String RCPT_OK = "250 OK performed command RCPT";
> -    public final String RCPT_ERROR = "550 Unknown recipient";
> -    public final String DATA_START_SUCCESS = "354 OK Ready for data";
> -    public final String DATA_END_SUCCESS = "250 OK finished adding data";
> -    public final String COMMAND_TRANSMISSION_END = "221 Closing SMTP 
> service.";
> -    public final String HELO_REPLY = "250 OK";
> -    public final String OK = "+OK ";
> -    public final String ERR = "-ERR ";
> -    public final String USER = "USER";
> -    public final String PASS = "PASS";
> -    public final String STAT = "STAT";
> -    public final String LIST = "LIST";
> -    public final String RETR = "RETR";
> -    public final String DELE = "DELE";
> -    public final String NOOP = "NOOP";
> -    public final String RSET = "RSET";
> -    public final String QUIT = "QUIT";
> -}
> Index: 
> modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java
> ===================================================================
> ---  
> modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java 
> (revision 232201)
> +++ 
> modules/core/src/org/apache/axis2/transport/mail/server/MailServer.java 
> (working copy)
> @@ -77,8 +77,8 @@
>     }
>
>     public static void main(String args[]){
> -        int smtpPost = MailConstants.SMTP_SERVER_PORT;
> -        int popPort = MailConstants.POP_SERVER_PORT;
> +        int smtpPost = MailSrvConstants.SMTP_SERVER_PORT;
> +        int popPort = MailSrvConstants.POP_SERVER_PORT;
>         if (args.length == 2) {
>             try {
>                 smtpPost = Integer.parseInt(args[0]);
> Index: 
> modules/core/src/org/apache/axis2/transport/mail/server/MailSrvConstants.java
> ===================================================================
> ---  
> modules/core/src/org/apache/axis2/transport/mail/server/MailSrvConstants.java 
> (revision 232201)
> +++ 
> modules/core/src/org/apache/axis2/transport/mail/server/MailSrvConstants.java 
> (working copy)
> @@ -5,7 +5,7 @@
>  * @author Chamikara Jayalath
>  */
>
> -public interface MailConstants {
> +public interface MailSrvConstants {
>     public final int SMTP_SERVER_PORT = (1024 + 25);
>     public final String SERVER_DOMAIN = "localhost";
>     public final int POP_SERVER_PORT = (1024 + 110);
> Index: 
> modules/core/src/org/apache/axis2/transport/mail/server/POP3Worker.java
> ===================================================================
> ---  
> modules/core/src/org/apache/axis2/transport/mail/server/POP3Worker.java 
> (revision 232201)
> +++ 
> modules/core/src/org/apache/axis2/transport/mail/server/POP3Worker.java 
> (working copy)
> @@ -34,7 +34,7 @@
>             PrintWriter printWriter = new 
> PrintWriter(socket.getOutputStream(),
>                     true);
>
> -            printWriter.println(MailConstants.OK + " POP3 server ready");
> +            printWriter.println(MailSrvConstants.OK + " POP3 server 
> ready");
>             String s;
>             String ps; //ProcessedString
>             while (!doneProcess) {
> @@ -51,7 +51,7 @@
>     ArrayList messages = new ArrayList();
>
>     private void processInput(String input, PrintWriter printWriter) {
> -        int listLen = (MailConstants.LIST + " ").length();
> +        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 = "";
> @@ -63,19 +63,19 @@
>             while (stk.hasMoreTokens()) {
>                 tokens.add(stk.nextToken());
>             }
> -            if (tokens.get(0).equals(MailConstants.USER)) {
> +            if (tokens.get(0).equals(MailSrvConstants.USER)) {
>                 user = (String) tokens.get(1);
>                 messages = st.popUserMails(user);
> -                printWriter.println(MailConstants.OK);
> -            } else if (tokens.get(0).equals(MailConstants.PASS)) {
> -                printWriter.println(MailConstants.OK); // Passwords are 
> not checked.
> -            } else if (input.equals(MailConstants.QUIT)) {
> +                printWriter.println(MailSrvConstants.OK);
> +            } else if (tokens.get(0).equals(MailSrvConstants.PASS)) {
> +                printWriter.println(MailSrvConstants.OK); // Passwords 
> are not checked.
> +            } else if (input.equals(MailSrvConstants.QUIT)) {
>                 printWriter.println(
> -                        MailConstants.OK + "POP3 server signing off");
> +                        MailSrvConstants.OK + "POP3 server signing off");
>                 doneProcess = true;
> -            } else if (input.equals(MailConstants.STAT)) {
> -                printWriter.println(MailConstants.OK + messages.size() + 
> " 1"); // We take the maildrop size as one.
> -            } else if (tokens.get(0).equals(MailConstants.LIST)) { // 
> scan listing
> +            } 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
>                 if (tokens.size() > 1) {
>                     try {
>                         int optArg = Integer.parseInt((String) 
> tokens.get(1));
> @@ -83,11 +83,11 @@
>                         if ((messageArrayIndex < messages.size()) &&
>                                 (messageArrayIndex >= 0)) { // that is OK 
> careful with numbering
>                             printWriter.println(
> -                                    MailConstants.OK + messageArrayIndex 
> + 1 +
> +                                    MailSrvConstants.OK + 
> messageArrayIndex + 1 +
>                                     " 120"); // Mail size of 120 is just 
> some number.
>                         } else {
>                             printWriter.println(
> -                                    MailConstants.ERR +
> +                                    MailSrvConstants.ERR +
>                                     "no such message, only " +
>                                     (messages.size() + 1) +
>                                     " messages in maildrop");
> @@ -95,23 +95,23 @@
>                     } catch (NumberFormatException e) {
>                         log.info(e.getMessage());
>                         printWriter.println(
> -                                MailConstants.ERR +
> +                                MailSrvConstants.ERR +
>                                 "problem passing the index. Index submited 
> was " +
>                                 tokens.get(1));
>                     }
>                 } else {
> -                    printWriter.println(MailConstants.OK + 
> messages.size());
> +                    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(".");
>                 }
> -            } else if (tokens.get(0).equals(MailConstants.RETR)) {
> +            } else if (tokens.get(0).equals(MailSrvConstants.RETR)) {
>                 String i = (String) tokens.get(1);
>                 try {
>                     int index = Integer.parseInt(i);
> -                    printWriter.println(MailConstants.OK);
> +                    printWriter.println(MailSrvConstants.OK);
>                     MimeMessage m = (MimeMessage) messages.get(index - 1);
>
>                     m.writeTo(socket.getOutputStream());
> @@ -122,31 +122,31 @@
>                     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(MailConstants.ERR);
> +                    printWriter.println(MailSrvConstants.ERR);
>                 } catch (IOException e1) {
> -                    printWriter.println(MailConstants.ERR);
> +                    printWriter.println(MailSrvConstants.ERR);
>                 } catch (MessagingException e2) {
> -                    printWriter.println(MailConstants.ERR);
> +                    printWriter.println(MailSrvConstants.ERR);
>                 }
> -            } else if (tokens.get(0).equals(MailConstants.DELE)) {
> +            } 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.
>                     if ((mIndex >= 0) && (mIndex < messages.size())) {
>                         messages.remove(mIndex);
>                         numDeleted++;
> -                        printWriter.println(MailConstants.OK);
> +                        printWriter.println(MailSrvConstants.OK);
>                     } else {
> -                        printWriter.println(MailConstants.ERR);
> +                        printWriter.println(MailSrvConstants.ERR);
>                     }
>                 } catch (NumberFormatException e) {
> -                    printWriter.println(MailConstants.ERR);
> +                    printWriter.println(MailSrvConstants.ERR);
>                 }
> -            } else if (tokens.get(0).equals(MailConstants.NOOP) ||
> -                    tokens.get(0).equals(MailConstants.RSET)) {
> -                printWriter.println(MailConstants.OK);
> +            } else if (tokens.get(0).equals(MailSrvConstants.NOOP) ||
> +                    tokens.get(0).equals(MailSrvConstants.RSET)) {
> +                printWriter.println(MailSrvConstants.OK);
>             } else {
> -                printWriter.println(MailConstants.ERR);
> +                printWriter.println(MailSrvConstants.ERR);
>             }
>         }
>     }
> Index: 
> modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java
> ===================================================================
> ---  
> modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java 
> (revision 232201)
> +++ 
> modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java 
> (working copy)
> @@ -88,7 +88,7 @@
>
>                 String retString = processInput(input);
>
> -                if (MailConstants.COMMAND_EXIT.equals(retString)) {
> +                if (MailSrvConstants.COMMAND_EXIT.equals(retString)) {
>                     exitWorker();
>                 } else {
>                     if (retString != null) {
> @@ -131,9 +131,9 @@
>     private String processInput(String input) {
>         byte[] CR_LF = new byte[] { 0x0D, 0x0A };
>         if (input == null)
> -            return MailConstants.COMMAND_UNKNOWN;
> +            return MailSrvConstants.COMMAND_UNKNOWN;
>         if (mail != null && transmitionEnd)
> -            return MailConstants.COMMAND_TRANSMISSION_END;
> +            return MailSrvConstants.COMMAND_TRANSMISSION_END;
>
>         if (input.startsWith("MAIL")) {
>             mail = new MimeMessage(Session.getInstance(new Properties(),
> @@ -169,15 +169,15 @@
>                 }
>             }
>
> -            return MailConstants.MAIL_OK;
> +            return MailSrvConstants.MAIL_OK;
>
>         }
>         if (input.startsWith("HELO")) {
> -            return MailConstants.HELO_REPLY;
> +            return MailSrvConstants.HELO_REPLY;
>
>         } else if (input.startsWith("RCPT")) {
>
> -            String domain = MailConstants.SERVER_DOMAIN;
> +            String domain = MailSrvConstants.SERVER_DOMAIN;
>             //System.out.println("RCPT:" + input);
>             //temp += input + "\n"; TODO Check this
>             int start = input.indexOf("<") + 1;
> @@ -187,12 +187,12 @@
>                 start = input.indexOf("TO:") + 3;
>                 /*
>                  * if(!input.endsWith(domain)){ System.out.println("ERROR: 
> wrong
> -                 * donmain name"); return MailConstants.RCPT_ERROR; }
> +                 * donmain name"); return MailSrvConstants.RCPT_ERROR; }
>                  */
>             } else {
>                 /*
>                  * if(!input.endsWith(domain + ">")){ 
> System.out.println("ERROR:
> -                 * wrong donmain name"); return 
> MailConstants.RCPT_ERROR; }
> +                 * wrong donmain name"); return 
> MailSrvConstants.RCPT_ERROR; }
>                  */
>             }
>
> @@ -208,20 +208,20 @@
>                 // TODO Auto-generated catch block
> //                e.printStackTrace();
>             }
> -            return MailConstants.RCPT_OK;
> +            return MailSrvConstants.RCPT_OK;
>
>         } else if (input.equalsIgnoreCase("DATA")) {
>             dataWriting = true;
> -            return MailConstants.DATA_START_SUCCESS;
> +            return MailSrvConstants.DATA_START_SUCCESS;
>
>         } else if (input.equalsIgnoreCase("QUIT")) {
>             dataWriting = true;
>             transmitionEnd = true;
> -            return MailConstants.COMMAND_TRANSMISSION_END;
> +            return MailSrvConstants.COMMAND_TRANSMISSION_END;
>
>         } else if (input.equals(".")) {
>             dataWriting = false;
> -            return MailConstants.DATA_END_SUCCESS;
> +            return MailSrvConstants.DATA_END_SUCCESS;
>         } else if (input.equals("") && !bodyData) {
>             bodyData = true;
>             return null;
> @@ -241,7 +241,7 @@
>             return null;
>
>         } else {
> -            return MailConstants.COMMAND_UNKNOWN;
> +            return MailSrvConstants.COMMAND_UNKNOWN;
>         }
>
>     }
> Index: modules/core/src/org/apache/axis2/transport/mail/EMailSender.java
> ===================================================================
> --- modules/core/src/org/apache/axis2/transport/mail/EMailSender.java 
> (revision 232201)
> +++ modules/core/src/org/apache/axis2/transport/mail/EMailSender.java 
> (working copy)
> @@ -55,7 +55,7 @@
>         this.password = password;
>     }
>
> -    public void send(String subject, String targetEmail, String message, 
> String charSetEn) throws AxisFault {
> +    public void send(String subject, String targetEmail, String message, 
> String charSet) throws AxisFault {
>         try {
>             final PasswordAuthentication authentication =
>                     new PasswordAuthentication(user, password);
> @@ -77,14 +77,14 @@
>                     new InternetAddress(targetEmail));
>             msg.setSubject(subject);
>
> -            if (charSetEn.equals("")){
> -                charSetEn = MailConstants.DEFAULT_CHAR_SET_ENCODING;
> +            if (charSet == null){
> +                charSet = MailConstants.DEFAULT_CHAR_SET;
>             }
>
> -            msg.addHeaderLine("Content-Type: text/plain; charset=" + 
> MailConstants.DEFAULT_CHAR_SET);
> +            msg.addHeaderLine("Content-Type: " + 
> MailConstants.DEFAULT_CONTENT_TYPE + "; charset=" + charSet);
>
>             msg.setText(message);
> -            msg.setHeader("Content-Transfer-Encoding", charSetEn);
> +            msg.setHeader("Content-Transfer-Encoding", 
> MailConstants.DEFAULT_CHAR_SET_ENCODING);
>             Transport.send(msg);
>         } catch (AddressException e) {
>             throw new AxisFault(e);
> @@ -103,7 +103,7 @@
>
>         sender.send("Testing mail sending",
>                 "hemapani@127.0.0.1",
> -                "Hellp, testing", "us-ascii");
> +                "Hellp, testing", MailConstants.DEFAULT_CHAR_SET);
>
>         EmailReceiver receiver = new EmailReceiver(user,
>                 host,
> 



Re: [Axis2] Mail transport patch

Posted by Chamil Thanthrimudalige <ch...@opensource.lk>.
hi,

I need the code refactoring to fix a bug in the code. However since this
is not going to break the build I guess the patch can be applied after
the release.

Best Regards,
Chamil Thanthrimudalige.


Eran Chinthaka wrote:

>Hi Chamil,
>
>The code is freezed at the moment. I saw you have some changes to the codes.
>We are not committing code, unless it is a blocker to the release. 
>
>Can u please wait, till we release 0.91 ?
>
>Thanks.
>
>  
>
>>hi,
>>
>>Can some one with enough karma please apply this patch.
>>
>>It has some bug fixes to the char set encoding in mail, renaming of the
>>MailConstants class in the org.apache.axis2.transport.mail.server
>>package to MailSrvConstans to make a clear distinction with the class in
>>the transport.mail package and the test case for the mail content type
>>encoding.
>>
>>There seems to be a problem with calling multiple tests from the same
>>test class using the mail transport. So it is still not working fully.
>>Since all mail related tests have been excluded at the moment this will
>>not be a problem with the build.
>>
>>On a separate note the mail transport is not working with the Geronimo
>>jar files. I will send a separate mail with the parts that are
>>lacking/problematic in the Geronimo jars.
>>
>>Best Regards,
>>Chamil Thanthrimudalige
>>    
>>
>
>
>
>
>  
>


RE: [Axis2] Mail transport patch

Posted by Eran Chinthaka <ch...@opensource.lk>.
Hi Chamil,

The code is freezed at the moment. I saw you have some changes to the codes.
We are not committing code, unless it is a blocker to the release. 

Can u please wait, till we release 0.91 ?

Thanks.

> 
> hi,
> 
> Can some one with enough karma please apply this patch.
> 
> It has some bug fixes to the char set encoding in mail, renaming of the
> MailConstants class in the org.apache.axis2.transport.mail.server
> package to MailSrvConstans to make a clear distinction with the class in
> the transport.mail package and the test case for the mail content type
> encoding.
> 
> There seems to be a problem with calling multiple tests from the same
> test class using the mail transport. So it is still not working fully.
> Since all mail related tests have been excluded at the moment this will
> not be a problem with the build.
> 
> On a separate note the mail transport is not working with the Geronimo
> jar files. I will send a separate mail with the parts that are
> lacking/problematic in the Geronimo jars.
> 
> Best Regards,
> Chamil Thanthrimudalige