# HG changeset patch
# User cli
# Date 1272716850 -7200
# Node ID 15d14b110240b2166422d0948e605097972dd747
# Parent  d879bab396007ac0f57a89bed82bc39058bea5a6
Make mailinglist gateway more reliable, probably.

diff -r d879bab39600 -r 15d14b110240 org/sonews/daemon/Connections.java
--- a/org/sonews/daemon/Connections.java	Tue Apr 27 22:11:30 2010 +0200
+++ b/org/sonews/daemon/Connections.java	Sat May 01 14:27:30 2010 +0200
@@ -20,6 +20,7 @@
 
 import org.sonews.config.Config;
 import org.sonews.util.Log;
+import org.sonews.util.Stats;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
@@ -29,7 +30,6 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
-import org.sonews.util.Stats;
 
 /**
  * Daemon thread collecting all NNTPConnection instances. The thread
@@ -146,6 +146,9 @@
             
             try
             {
+              assert channel != null;
+              assert channel.socket() != null;
+      
               // Close the channel; implicitely cancels all selectionkeys
               channel.close();
               Log.get().info("Disconnected: " + channel.socket().getRemoteSocketAddress() +
diff -r d879bab39600 -r 15d14b110240 org/sonews/mlgw/SMTPTransport.java
--- a/org/sonews/mlgw/SMTPTransport.java	Tue Apr 27 22:11:30 2010 +0200
+++ b/org/sonews/mlgw/SMTPTransport.java	Sat May 01 14:27:30 2010 +0200
@@ -20,10 +20,8 @@
 
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.io.PrintWriter;
 import java.net.Socket;
 import java.net.UnknownHostException;
 import org.sonews.config.Config;
@@ -33,20 +31,21 @@
 /**
  * Connects to a SMTP server and sends a given Article to it.
  * @author Christian Lins
+ * @since sonews/1.0
  */
 class SMTPTransport
 {
 
-  protected BufferedReader in;
-  protected PrintWriter    out;
-  protected Socket         socket;
+  protected BufferedReader       in;
+  protected BufferedOutputStream out;
+  protected Socket               socket;
 
   public SMTPTransport(String host, int port)
     throws IOException, UnknownHostException
   {
     socket = new Socket(host, port);
     this.in  = new BufferedReader(new InputStreamReader(socket.getInputStream()));
-    this.out = new PrintWriter(socket.getOutputStream());
+    this.out = new BufferedOutputStream(socket.getOutputStream());
 
     // Read helo from server
     String line = this.in.readLine();
@@ -56,7 +55,8 @@
     }
 
     // Send HELO to server
-    this.out.println("HELO " + Config.inst().get(Config.HOSTNAME, "localhost"));
+    this.out.write(
+      ("HELO " + Config.inst().get(Config.HOSTNAME, "localhost") + "\r\n").getBytes("UTF-8"));
     this.out.flush();
     line = this.in.readLine();
     if(line == null || !line.startsWith("250 "))
@@ -74,7 +74,7 @@
   public void close()
     throws IOException
   {
-    this.out.println("QUIT");
+    this.out.write("QUIT".getBytes("UTF-8"));
     this.out.flush();
     this.in.readLine();
 
@@ -88,7 +88,7 @@
     assert(mailFrom != null);
     assert(rcptTo != null);
 
-    this.out.println("MAIL FROM: " + mailFrom);
+    this.out.write(("MAIL FROM: " + mailFrom).getBytes("UTF-8"));
     this.out.flush();
     String line = this.in.readLine();
     if(line == null || !line.startsWith("250 "))
@@ -96,7 +96,7 @@
       throw new IOException("Unexpected reply: " + line);
     }
 
-    this.out.println("RCPT TO: " + rcptTo);
+    this.out.write(("RCPT TO: " + rcptTo).getBytes("UTF-8"));
     this.out.flush();
     line  = this.in.readLine();
     if(line == null || !line.startsWith("250 "))
@@ -104,7 +104,7 @@
       throw new IOException("Unexpected reply: " + line);
     }
 
-    this.out.println("DATA");
+    this.out.write("DATA".getBytes("UTF-8"));
     this.out.flush();
     line = this.in.readLine();
     if(line == null || !line.startsWith("354 "))
@@ -113,20 +113,15 @@
     }
 
     ArticleInputStream   artStream = new ArticleInputStream(article);
-    BufferedOutputStream outStream = new BufferedOutputStream(socket.getOutputStream());
-    FileOutputStream     fileStream = new FileOutputStream("smtp.dump");
     for(int b = artStream.read(); b >= 0; b = artStream.read())
     {
-      outStream.write(b);
-      fileStream.write(b);
+      this.out.write(b);
     }
 
     // Flush the binary stream; important because otherwise the output
     // will be mixed with the PrintWriter.
-    outStream.flush();
-    fileStream.flush();
-    fileStream.close();
-    this.out.print("\r\n.\r\n");
+    this.out.flush();
+    this.out.write("\r\n.\r\n".getBytes("UTF-8"));
     this.out.flush();
     line = this.in.readLine();
     if(line == null || !line.startsWith("250 "))