Sending SMTP message gets stuck upon exception

Øyvind Harboe <[email protected]> Sat, 24 Jan 2004 12:56:13 +0100
Newsgroups gmane.comp.java.classpath.extensions.discuss
Organization Zylin AS
Message-ID <1074945372.18250.16.camel@famine>
If an exception is thrown while an SMTP message body is being written,
the subsequent "QUIT" command is ignored, because it is considered part of the
message body which then causes the app to wait indefinitely for the QUIT command 
to complete.



Øyvind

_______________________________________________
Classpathx-discuss mailing list
[email protected]
http://mail.gnu.org/mailman/listinfo/classpathx-discuss
patch.txt (text/x-patch, 5.8 KB)
Index: SMTPConnection.java
===================================================================
retrieving revision 1.5
diff -u -r1.5 SMTPConnection.java
--- SMTPConnection.java	16 Jan 2004 08:25:00 -0000	1.5
+++ SMTPConnection.java	24 Jan 2004 11:46:45 -0000
@@ -517,88 +517,89 @@
   public boolean authenticate(String mechanism, String username,
                               String password) throws IOException
   {
-    try
-    {
-      String[] m = new String[] { mechanism };
-      CallbackHandler ch = new SaslCallbackHandler(username, password);
-      // Avoid lengthy callback procedure for GNU Crypto
-      Properties p = new Properties();
-      p.put("gnu.crypto.sasl.username", username);
-      p.put("gnu.crypto.sasl.password", password);
-      SaslClient sasl = Sasl.createSaslClient(m, null, "smtp",
-					socket.getInetAddress().
-					getHostName(), p, ch);
-			if (sasl == null)
-				return false;
-
-      StringBuffer cmd = new StringBuffer(AUTH);
-      cmd.append(' ');
-      cmd.append(mechanism);
-      if (sasl.hasInitialResponse())
-      {
-        cmd.append(' ');
-        byte[]init = sasl.evaluateChallenge(new byte[0]);
-        cmd.append(new String(init, "US-ASCII"));
-      }
-      send(cmd.toString());
-      while (true)
-      {
-        switch (getResponse())
-        {
-        case 334:
-          try
-          {
-            byte[]c0 = response.getBytes("US-ASCII");
-            byte[]c1 = BASE64.decode(c0);       // challenge
-            byte[]r0 = sasl.evaluateChallenge(c1);
-            byte[]r1 = BASE64.encode(r0);       // response
-            out.write(r1);
-            out.write(0x0d);
-            out.flush();
-          }
-          catch(SaslException e)
-          {
-            // Error in SASL challenge evaluation - cancel exchange
-            out.write(0x2a);
-            out.write(0x0d);
-            out.flush();
-          }
-          break;
-        case 235:
-          String qop = (String) sasl.getNegotiatedProperty(Sasl.QOP);
-          if ("auth-int".equalsIgnoreCase(qop)
-              || "auth-conf".equalsIgnoreCase(qop))
-          {
-            InputStream in = socket.getInputStream();
-            in = new BufferedInputStream(in);
-            in = new SaslInputStream(sasl, in);
-            in = new CRLFInputStream(in);
-            this.in = new LineInputStream(in);
-            OutputStream out = socket.getOutputStream();
-            out = new BufferedOutputStream(out);
-            out = new SaslOutputStream(sasl, out);
-            this.out = new CRLFOutputStream(out);
-          }
-          return true;
-        default:
-          return false;
-        }
-      }
-    }
-    catch (SaslException e)
-    {
-      return false;             // No provider for mechanism
-    }
-    catch (RuntimeException e)
-    {
-      return false;             // No javax.security.sasl classes
-    }
+  	return authLogin(username, password);
+//    try
+//    {
+//      String[] m = new String[] { mechanism };
+//      CallbackHandler ch = new SaslCallbackHandler(username, password);
+//      // Avoid lengthy callback procedure for GNU Crypto
+//      Properties p = new Properties();
+//      p.put("gnu.crypto.sasl.username", username);
+//      p.put("gnu.crypto.sasl.password", password);
+//      SaslClient sasl = Sasl.createSaslClient(m, null, "smtp",
+//					socket.getInetAddress().
+//					getHostName(), p, ch);
+//			if (sasl == null)
+//				return false;
+//
+//      StringBuffer cmd = new StringBuffer(AUTH);
+//      cmd.append(' ');
+//      cmd.append(mechanism);
+//      if (sasl.hasInitialResponse())
+//      {
+//        cmd.append(' ');
+//        byte[]init = sasl.evaluateChallenge(new byte[0]);
+//        cmd.append(new String(init, "US-ASCII"));
+//      }
+//      send(cmd.toString());
+//      while (true)
+//      {
+//        switch (getResponse())
+//        {
+//        case 334:
+//          try
+//          {
+//            byte[]c0 = response.getBytes("US-ASCII");
+//            byte[]c1 = BASE64.decode(c0);       // challenge
+//            byte[]r0 = sasl.evaluateChallenge(c1);
+//            byte[]r1 = BASE64.encode(r0);       // response
+//            out.write(r1);
+//            out.write(0x0d);
+//            out.flush();
+//          }
+//          catch(SaslException e)
+//          {
+//            // Error in SASL challenge evaluation - cancel exchange
+//            out.write(0x2a);
+//            out.write(0x0d);
+//            out.flush();
+//          }
+//          break;
+//        case 235:
+//          String qop = (String) sasl.getNegotiatedProperty(Sasl.QOP);
+//          if ("auth-int".equalsIgnoreCase(qop)
+//              || "auth-conf".equalsIgnoreCase(qop))
+//          {
+//            InputStream in = socket.getInputStream();
+//            in = new BufferedInputStream(in);
+//            in = new SaslInputStream(sasl, in);
+//            in = new CRLFInputStream(in);
+//            this.in = new LineInputStream(in);
+//            OutputStream out = socket.getOutputStream();
+//            out = new BufferedOutputStream(out);
+//            out = new SaslOutputStream(sasl, out);
+//            this.out = new CRLFOutputStream(out);
+//          }
+//          return true;
+//        default:
+//          return false;
+//        }
+//      }
+//    }
+//    catch (SaslException e)
+//    {
+//      return false;             // No provider for mechanism
+//    }
+//    catch (RuntimeException e)
+//    {
+//      return false;             // No javax.security.sasl classes
+//    }
   }
 
   /**
    * LOGIN authentication mechanism.
    * If this returns true, EHLO should be re-issued.
-   *
+   **/
   public boolean authLogin(String username, String password)
     throws IOException
   {
@@ -619,7 +620,7 @@
       }
     }
     return false;
-  }*/
+  }
 
   /**
    * PLAIN authentication mechanism.