7 Replies Latest reply on Sep 17, 2005 1:07 PM by Michael Barker

    MailAddress problem (ATTN Mike)

    Andrew Oliver Master

      Hi Mike,

      can you look at this: http://jira.jboss.com/jira/browse/JBMAIL-110

      use this address:
      "Height, Jason" <Jason.Height@asc.com.au>

      I'm presuming this is your mail parsing code, although you very naughtily did not put your name on it so it says I wrote the whole thing but it exceeds my regex-fu abilities (I'm only like a yellow belt or something :-P ).

      Whenever I put that address in I get this:

      16:42:14,405 ERROR [Mail] java.lang.NullPointerException
      at org.jboss.mail.message.MailAddress.parseSMTPStyle(MailAddress.java:262)
      at org.jboss.mail.message.MailAddress.parseSMTPStyle(MailAddress.java:226)
      at org.jboss.mail.message.Mail.isIn(Mail.java:284)
      at org.jboss.mail.message.Mail.envelopeTos(Mail.java:201)
      at org.jboss.mail.message.Mail.constructMessage(Mail.java:180)
      at org.jboss.mail.message.Mail.(Mail.java:153)
      at org.jboss.mail.message.Mail.create(Mail.java:305)
      at org.jboss.mail.smtp.handlers.CmdDATA.handleRequest(CmdDATA.java:79)
      at org.jboss.mail.smtp.handlers.RequireSTARTTLSProxy.handleRequest(RequireSTARTTLSProxy.java:49)
      at org.jboss.mail.smtp.SMTPProtocolInstance.handleRequest(SMTPProtocolInstance.java:167)
      at org.jboss.mail.ConnectionHandler.runSocket(ConnectionHandler.java:168)
      at org.jboss.mail.ConnectionHandler.run(ConnectionHandler.java:73)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
      at java.lang.Thread.run(Thread.java:613)
      16:42:14,506 INFO [STDOUT] Exception in thread "Thread-77"
      16:42:14,507 INFO [STDOUT] java.lang.RuntimeException: Error
      16:42:14,508 INFO [STDOUT] at org.jboss.mail.message.Mail.(Mail.java:159)
      16:42:14,508 INFO [STDOUT] at org.jboss.mail.message.Mail.create(Mail.java:305)
      16:42:14,509 INFO [STDOUT] at org.jboss.mail.smtp.handlers.CmdDATA.handleRequest(CmdDATA.java:79)
      16:42:14,540 INFO [STDOUT] at org.jboss.mail.smtp.handlers.RequireSTARTTLSProxy.handleRequest(RequireSTARTTLSProxy.java:49)
      16:42:14,541 INFO [STDOUT] at org.jboss.mail.smtp.SMTPProtocolInstance.handleRequest(SMTPProtocolInstance.java:167)
      16:42:14,541 INFO [STDOUT] at org.jboss.mail.ConnectionHandler.runSocket(ConnectionHandler.java:168)
      16:42:14,542 INFO [STDOUT] at org.jboss.mail.ConnectionHandler.run(ConnectionHandler.java:73)
      16:42:14,543 INFO [STDOUT] at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
      16:42:14,545 INFO [STDOUT] at java.lang.Thread.run(Thread.java:613)
      16:42:14,546 INFO [STDOUT] Caused by: java.lang.NullPointerException
      16:42:14,546 INFO [STDOUT] at org.jboss.mail.message.MailAddress.parseSMTPStyle(MailAddress.java:262)
      16:42:14,546 INFO [STDOUT] at org.jboss.mail.message.MailAddress.parseSMTPStyle(MailAddress.java:226)
      16:42:14,547 INFO [STDOUT] at org.jboss.mail.message.Mail.isIn(Mail.java:284)
      16:42:14,547 INFO [STDOUT] at org.jboss.mail.message.Mail.envelopeTos(Mail.java:201)
      16:42:14,548 INFO [STDOUT] at org.jboss.mail.message.Mail.constructMessage(Mail.java:180)
      16:42:14,549 INFO [STDOUT] at org.jboss.mail.message.Mail.(Mail.java:153)
      16:42:14,552 INFO [STDOUT] ... 8 more

      It looks like it trips up on the comma. If I use any quoted address with comma it pukes.

        • 1. Re: MailAddress problem (ATTN Mike)
          Michael Barker Apprentice

          I looked at it but couldn't isolate the problem with a unit test:

          public void testQuoted() {
           MailAddress m2 = MailAddress.parseSMTPStyle("\"Height, Jason\" <Jason.Height@asc.com.au>");

          Passes ok. Was this with M3-final or one or the pre releases?

          • 2. Re: MailAddress problem (ATTN Mike)
            Andrew Oliver Master

            This is in head. I just sent an email to him from localhost. It fails reliably for me as does any other with a , in it. Try just setting one up for localhost and sending a mail to Jason. I did this w/tbird btw.

            All other addresses succeed.


            • 3. Re: MailAddress problem (ATTN Mike)
              Andrew Oliver Master

              (oh but no addresses with a comma in the "" do)

              • 4. Re: MailAddress problem (ATTN Mike)
                Michael Barker Apprentice


                public void testQuoted() {
                 MailAddress m2 = MailAddress.parseSMTPStyle("\"Height, Jason\" <Jason.Height@asc.com.au>");
                 MailAddress m3 = MailAddress.parseSMTPStyle("Height, Jason <Jason.Height@asc.com.au>");

                All passes. But I will have a more detailed look with a full system this weekend. Maybe its not just the address parsing.


                • 5. Re: MailAddress problem (ATTN Mike)
                  Michael Barker Apprentice

                  The crux of the problem doesn't lie with the MailAddress parsing. This is the culprit, from Mail.java.

                   * parse only ONE string from the TOs
                   * @param string
                   * containing multiple addresses
                   * @return string array of the parsed addresses
                  private String[] parseMailHeaderAddress(String string) {
                   String[] result = string.split("\\,\\s");
                   for (int k = 0; k < result.length; k++) {
                   result[k] = result[k].trim();
                   return result;

                  Splits the address on a "," therefore an address like "Height, Jason" <Jason.Height@asc.com.au>, will give two addresses: '"Height' and 'Jason" <Jason.Height@asc.com.au>'. Then it will try and pass each of these to the MailAddress.parseSMTPStyle. I need to sit down and understand what the whole envelopTos() portion of the Mail.java code is doing.

                  My naughty changes to the MailAddress.java (to handle source routed addresses) do not handle invalid cases well enough.

                  Do you need a quick fix as a patch to M3, or is fixing this for M4 ok? Hopefully most of this code will be rewritten for M4 and I would like to use Ristretto to handle the parsing of mail addresses.


                  • 6. Re: MailAddress problem (ATTN Mike)
                    Andrew Oliver Master

                    M4 is good. We should maintain some decoupling from Rosretto in case it takes a turn for the worse....I just mean that as a general caution.

                    • 7. Re: MailAddress problem (ATTN Mike)
                      Michael Barker Apprentice

                      Ok. I was going to use their libraries directly (I'm a bit lazy), but it will not be much effort to put a thin adaptor layer between JBMail code and Ristretto. Probably good practise anyway, code to interfaces...etc...