Hi Dion, all,

I'm still alive ;)
Attached you can find my reworked patch to fix many problems you can have if 
using commons-email with a MailSession mainly caused by typos in constant 
declaration or missing constant declaration.
It fixes bugs 38538 and 38656 (just opened to hold the patch): please have a 
look and let me know.
Probably tomorrow I will test what is in the repository.

Thanks for your attention
Bye
Piero


> Ping?
> 
> On 2/12/06, Dion Gillard <[EMAIL PROTECTED]> wrote:
> > Hi Piero,
> >
> > some comments inline.
> >
> > On 2/9/06, Piero Ottuzzi <[EMAIL PROTECTED]> wrote:
> > > Hi Hen,
> > >
> > > many thanks for your answer.
> > > Here is a long mail on commons-email status :)
> > >
> > > SVN Repository
> > > The activity on SVN repository (speaking of the src/java dir) is stalled 
> > > about
> > > 5 month ago. What you can find in SVN repository compiles fine and looks 
> > > like
> > > what has been released as 'Commons Email 1.0' on 2005-09-27.
> > >
> > > Bugs
> > > As you can see in [1] there are 11 bug open
> > > [37344] This bug provide a patch (in reality it provides a whole new 
> > > class).
> > > I'm using this provided class with my patched version of commons-email 
> > > and it
> > > is working fine without any issue so far.
> >
> > The issue here is the way the patch has been implemented.
> > I'd be happier to see this implemented as a fix to HtmlEmail, rather
> > than a new class
> >
> > > [37178] Can be resolved using the new class provided in previous bug.
> > See above.
> >
> > > [38538] This is fixed in my own attached patch.
> >
> > Unfortunately your patch does more than fix 38538. It adds new
> > functionality as well, and this makes it hard to apply. e.g. there is
> > code there to set the Mail Session from JNDI, which is a nice to have
> > feature and means we now need to include the jndi dependency. It would
> > be nicer to split these into separate enhancement requests as well as
> > the bug fix.
> >
> > > [37902] Trivial ;)
> > Sounds reasonable. Fixed.
> >
> > > [37783] Includes a patch. I'm using this provided patch with my patched
> > > version of commons-email and it is working fine without any issue so far.
> > Looks reasonable. Will apply and test. Done.
> >
> > > [37782] Includes a patch which forces a new dependency on javax.naming.* 
> > > I'm
> > > using this provided patch with my patched version of commons-email and it 
> > > is
> > > working fine without any issue so far.
> >
> > it also includes the TLS authentication helpers. I'm committing this one as:
> > a) The TLS helpers are useful
> > b) jndi is in jdk1.3 and above
> >
> > > [36856] Includes patches I cannot test and I do not need
> > Looks like it needs some testing.
> >
> > > [36844] Includes patches I did not test
> > Introduces a dependency on commons-lang, something I'd rather not do.
> >
> > > [37363] Don't have a clue on this one.
> > That one needs some more working out by the looks.
> >
> > > Patch
> > > Attached you can find a SVN patch that fixes many problems you can see if
> > > using a MailSession that needs authentication. It includes also the patch
> > > from bug [37782]. I'm using this provided patch with my patched version of
> > > commons-email and it is working fine without any issue so far.
> >
> > let me know if my recent commits are working for you.
> >
> > --
> > http://www.multitask.com.au/people/dion/
> > "If I close my eyes it doesn't seem so dark." - SpongeBob SquarePants
> >
> 
> 
> --
> http://www.multitask.com.au/people/dion/
> Chuck Norris sleeps with a night light. Not because Chuck Norris is
> afraid of the dark, but because the dark is afraid of Chuck Norris


Index: trunk/src/java/org/apache/commons/mail/Email.java
===================================================================
--- trunk/src/java/org/apache/commons/mail/Email.java   (revisione 377993)
+++ trunk/src/java/org/apache/commons/mail/Email.java   (copia locale)
@@ -77,7 +77,7 @@
     public static final String CONTENT_TYPE = "content.type";
 
     /** */
-    public static final String MAIL_HOST = "mail.host";
+    public static final String MAIL_HOST = "mail.smtp.host";
     /** */
     public static final String MAIL_PORT = "mail.smtp.port";
     /** */
@@ -85,6 +85,10 @@
     /** */
     public static final String MAIL_SMTP_AUTH = "mail.smtp.auth";
     /** */
+    public static final String MAIL_SMTP_USER = "mail.smtp.user";
+    /** */
+    public static final String MAIL_SMTP_PASSWORD = "mail.smtp.password";
+    /** */
     public static final String MAIL_TRANSPORT_PROTOCOL =
         "mail.transport.protocol";
     /**
@@ -360,7 +364,19 @@
      */
     public void setMailSession(Session aSession)
     {
-        this.session = aSession;
+        Properties sessionProperties = aSession.getProperties();
+        String auth = sessionProperties.getProperty(MAIL_SMTP_AUTH);
+        if ("true".equalsIgnoreCase(auth))
+        {
+            String userName = sessionProperties.getProperty(MAIL_SMTP_USER);
+            String password = 
sessionProperties.getProperty(MAIL_SMTP_PASSWORD);
+            this.authenticator = new DefaultAuthenticator(userName, password);
+            this.session = Session.getInstance(sessionProperties, 
this.authenticator);
+        }
+        else
+        {
+            this.session = aSession;
+        }
     }
 
     /**
@@ -387,7 +403,7 @@
             ctx = (Context) new InitialContext().lookup("java:comp/env");
 
         }
-        this.session = ((Session) ctx.lookup(jndiName));
+        this.setMailSession((Session) ctx.lookup(jndiName));
     }
 
     /**
@@ -1005,7 +1021,14 @@
      */
     public String getHostName()
     {
-        return this.hostName;
+        if (EmailUtils.isNotEmpty(this.hostName))
+        {
+            return this.hostName;
+        }
+        else
+        {
+            return this.session.getProperty(MAIL_HOST);
+        }
     }
 
     /**
@@ -1015,7 +1038,14 @@
      */
     public String getSmtpPort()
     {
-        return this.smtpPort;
+        if (EmailUtils.isNotEmpty(this.smtpPort))
+        {
+            return this.smtpPort;
+        }
+        else
+        {
+            return this.session.getProperty(MAIL_PORT);
+        }
     }
 
     /**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to