Make mailinglist gateway more reliable, probably.
authorcli
Sat May 01 14:27:30 2010 +0200 (2010-05-01)
changeset 2815d14b110240
parent 27 d879bab39600
child 29 60c237bb677a
Make mailinglist gateway more reliable, probably.
org/sonews/daemon/Connections.java
org/sonews/mlgw/SMTPTransport.java
     1.1 --- a/org/sonews/daemon/Connections.java	Tue Apr 27 22:11:30 2010 +0200
     1.2 +++ b/org/sonews/daemon/Connections.java	Sat May 01 14:27:30 2010 +0200
     1.3 @@ -20,6 +20,7 @@
     1.4  
     1.5  import org.sonews.config.Config;
     1.6  import org.sonews.util.Log;
     1.7 +import org.sonews.util.Stats;
     1.8  import java.io.IOException;
     1.9  import java.net.InetSocketAddress;
    1.10  import java.net.Socket;
    1.11 @@ -29,7 +30,6 @@
    1.12  import java.util.List;
    1.13  import java.util.ListIterator;
    1.14  import java.util.Map;
    1.15 -import org.sonews.util.Stats;
    1.16  
    1.17  /**
    1.18   * Daemon thread collecting all NNTPConnection instances. The thread
    1.19 @@ -146,6 +146,9 @@
    1.20              
    1.21              try
    1.22              {
    1.23 +              assert channel != null;
    1.24 +              assert channel.socket() != null;
    1.25 +      
    1.26                // Close the channel; implicitely cancels all selectionkeys
    1.27                channel.close();
    1.28                Log.get().info("Disconnected: " + channel.socket().getRemoteSocketAddress() +
     2.1 --- a/org/sonews/mlgw/SMTPTransport.java	Tue Apr 27 22:11:30 2010 +0200
     2.2 +++ b/org/sonews/mlgw/SMTPTransport.java	Sat May 01 14:27:30 2010 +0200
     2.3 @@ -20,10 +20,8 @@
     2.4  
     2.5  import java.io.BufferedOutputStream;
     2.6  import java.io.BufferedReader;
     2.7 -import java.io.FileOutputStream;
     2.8  import java.io.IOException;
     2.9  import java.io.InputStreamReader;
    2.10 -import java.io.PrintWriter;
    2.11  import java.net.Socket;
    2.12  import java.net.UnknownHostException;
    2.13  import org.sonews.config.Config;
    2.14 @@ -33,20 +31,21 @@
    2.15  /**
    2.16   * Connects to a SMTP server and sends a given Article to it.
    2.17   * @author Christian Lins
    2.18 + * @since sonews/1.0
    2.19   */
    2.20  class SMTPTransport
    2.21  {
    2.22  
    2.23 -  protected BufferedReader in;
    2.24 -  protected PrintWriter    out;
    2.25 -  protected Socket         socket;
    2.26 +  protected BufferedReader       in;
    2.27 +  protected BufferedOutputStream out;
    2.28 +  protected Socket               socket;
    2.29  
    2.30    public SMTPTransport(String host, int port)
    2.31      throws IOException, UnknownHostException
    2.32    {
    2.33      socket = new Socket(host, port);
    2.34      this.in  = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    2.35 -    this.out = new PrintWriter(socket.getOutputStream());
    2.36 +    this.out = new BufferedOutputStream(socket.getOutputStream());
    2.37  
    2.38      // Read helo from server
    2.39      String line = this.in.readLine();
    2.40 @@ -56,7 +55,8 @@
    2.41      }
    2.42  
    2.43      // Send HELO to server
    2.44 -    this.out.println("HELO " + Config.inst().get(Config.HOSTNAME, "localhost"));
    2.45 +    this.out.write(
    2.46 +      ("HELO " + Config.inst().get(Config.HOSTNAME, "localhost") + "\r\n").getBytes("UTF-8"));
    2.47      this.out.flush();
    2.48      line = this.in.readLine();
    2.49      if(line == null || !line.startsWith("250 "))
    2.50 @@ -74,7 +74,7 @@
    2.51    public void close()
    2.52      throws IOException
    2.53    {
    2.54 -    this.out.println("QUIT");
    2.55 +    this.out.write("QUIT".getBytes("UTF-8"));
    2.56      this.out.flush();
    2.57      this.in.readLine();
    2.58  
    2.59 @@ -88,7 +88,7 @@
    2.60      assert(mailFrom != null);
    2.61      assert(rcptTo != null);
    2.62  
    2.63 -    this.out.println("MAIL FROM: " + mailFrom);
    2.64 +    this.out.write(("MAIL FROM: " + mailFrom).getBytes("UTF-8"));
    2.65      this.out.flush();
    2.66      String line = this.in.readLine();
    2.67      if(line == null || !line.startsWith("250 "))
    2.68 @@ -96,7 +96,7 @@
    2.69        throw new IOException("Unexpected reply: " + line);
    2.70      }
    2.71  
    2.72 -    this.out.println("RCPT TO: " + rcptTo);
    2.73 +    this.out.write(("RCPT TO: " + rcptTo).getBytes("UTF-8"));
    2.74      this.out.flush();
    2.75      line  = this.in.readLine();
    2.76      if(line == null || !line.startsWith("250 "))
    2.77 @@ -104,7 +104,7 @@
    2.78        throw new IOException("Unexpected reply: " + line);
    2.79      }
    2.80  
    2.81 -    this.out.println("DATA");
    2.82 +    this.out.write("DATA".getBytes("UTF-8"));
    2.83      this.out.flush();
    2.84      line = this.in.readLine();
    2.85      if(line == null || !line.startsWith("354 "))
    2.86 @@ -113,20 +113,15 @@
    2.87      }
    2.88  
    2.89      ArticleInputStream   artStream = new ArticleInputStream(article);
    2.90 -    BufferedOutputStream outStream = new BufferedOutputStream(socket.getOutputStream());
    2.91 -    FileOutputStream     fileStream = new FileOutputStream("smtp.dump");
    2.92      for(int b = artStream.read(); b >= 0; b = artStream.read())
    2.93      {
    2.94 -      outStream.write(b);
    2.95 -      fileStream.write(b);
    2.96 +      this.out.write(b);
    2.97      }
    2.98  
    2.99      // Flush the binary stream; important because otherwise the output
   2.100      // will be mixed with the PrintWriter.
   2.101 -    outStream.flush();
   2.102 -    fileStream.flush();
   2.103 -    fileStream.close();
   2.104 -    this.out.print("\r\n.\r\n");
   2.105 +    this.out.flush();
   2.106 +    this.out.write("\r\n.\r\n".getBytes("UTF-8"));
   2.107      this.out.flush();
   2.108      line = this.in.readLine();
   2.109      if(line == null || !line.startsWith("250 "))