geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r673649 [3/3] - in /geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail: transport/nntp/ transport/smtp/ util/
Date Thu, 03 Jul 2008 10:37:56 GMT
Modified: geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/util/MailConnection.java
URL: http://svn.apache.org/viewvc/geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/util/MailConnection.java?rev=673649&r1=673648&r2=673649&view=diff
==============================================================================
--- geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/util/MailConnection.java
(original)
+++ geronimo/javamail/trunk/geronimo-javamail_1.4/geronimo-javamail_1.4_provider/src/main/java/org/apache/geronimo/javamail/util/MailConnection.java
Thu Jul  3 03:37:56 2008
@@ -122,6 +122,9 @@
     protected InetAddress localAddress;
     // our local port value 
     protected int localPort; 
+    // our local host name
+    protected String localHost;
+    
     // our timeout value 
     protected int timeout; 
     
@@ -219,6 +222,17 @@
     
     
     /**
+     * Establish a connection using an existing socket. 
+     * 
+     * @param s      The socket to use.
+     */
+    public void connect(Socket s) {
+        // just save the socket connection 
+        this.socket = s; 
+    }
+    
+    
+    /**
      * Create a transport connection object and connect it to the
      * target server.
      *
@@ -482,7 +496,6 @@
      * switching to an SSL socket.
      */
     protected void getConnectedTLSSocket() throws MessagingException {
-        debugOut("Attempting to negotiate STARTTLS with server " + serverHost);
      	// it worked, now switch the socket into TLS mode
      	try {
 
@@ -518,6 +531,7 @@
             if (sslSocket instanceof SSLSocket) {
                 ((SSLSocket)sslSocket).setEnabledProtocols(new String[] {"TLSv1"} );
                 ((SSLSocket)sslSocket).setUseClientMode(true);
+                debugOut("Initiating STARTTLS handshake"); 
                 ((SSLSocket)sslSocket).startHandshake();
             }
 
@@ -525,6 +539,7 @@
             // this is our active socket now
             socket = sslSocket;
             getConnectionStreams(); 
+            debugOut("TLS connection established"); 
      	}
         catch (Exception e) {
             debugOut("Failure attempting to convert connection to TLS", e);
@@ -719,7 +734,7 @@
      */
     protected void debugOut(String message) {
         if (debug) {
-            debugStream.println("IMAPStore DEBUG: " + message);
+            debugStream.println(protocol + " DEBUG: " + message);
         }
     }
 
@@ -780,4 +795,48 @@
     public String getHost() {
         return serverHost; 
     }
+    
+
+    /**
+     * Retrieve the local client host name.
+     *
+     * @return The string version of the local host name.
+     * @exception SMTPTransportException
+     */
+    public String getLocalHost() throws MessagingException {
+        if (localHost == null) {
+
+            try {
+                localHost = InetAddress.getLocalHost().getHostName();
+            } catch (UnknownHostException e) {
+                // fine, we're misconfigured - ignore
+            }
+
+            if (localHost == null) {
+                localHost = props.getProperty(MAIL_LOCALHOST);
+            }
+
+            if (localHost == null) {
+                localHost = props.getSessionProperty(MAIL_LOCALHOST);
+            }
+
+            if (localHost == null) {
+                throw new MessagingException("Can't get local hostname. "
+                        + " Please correctly configure JDK/DNS or set mail.smtp.localhost");
+            }
+        }
+
+        return localHost;
+    }
+
+    
+    /**
+     * Explicitly set the local host information.
+     *
+     * @param localHost
+     *            The new localHost name.
+     */
+    public void setLocalHost(String localHost) {
+        this.localHost = localHost;
+    }
 }



Mime
View raw message