1.1 --- a/org/sonews/mlgw/SMTPTransport.java Tue Apr 27 22:11:30 2010 +0200
1.2 +++ b/org/sonews/mlgw/SMTPTransport.java Sat May 01 14:27:30 2010 +0200
1.3 @@ -20,10 +20,8 @@
1.4
1.5 import java.io.BufferedOutputStream;
1.6 import java.io.BufferedReader;
1.7 -import java.io.FileOutputStream;
1.8 import java.io.IOException;
1.9 import java.io.InputStreamReader;
1.10 -import java.io.PrintWriter;
1.11 import java.net.Socket;
1.12 import java.net.UnknownHostException;
1.13 import org.sonews.config.Config;
1.14 @@ -33,20 +31,21 @@
1.15 /**
1.16 * Connects to a SMTP server and sends a given Article to it.
1.17 * @author Christian Lins
1.18 + * @since sonews/1.0
1.19 */
1.20 class SMTPTransport
1.21 {
1.22
1.23 - protected BufferedReader in;
1.24 - protected PrintWriter out;
1.25 - protected Socket socket;
1.26 + protected BufferedReader in;
1.27 + protected BufferedOutputStream out;
1.28 + protected Socket socket;
1.29
1.30 public SMTPTransport(String host, int port)
1.31 throws IOException, UnknownHostException
1.32 {
1.33 socket = new Socket(host, port);
1.34 this.in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
1.35 - this.out = new PrintWriter(socket.getOutputStream());
1.36 + this.out = new BufferedOutputStream(socket.getOutputStream());
1.37
1.38 // Read helo from server
1.39 String line = this.in.readLine();
1.40 @@ -56,7 +55,8 @@
1.41 }
1.42
1.43 // Send HELO to server
1.44 - this.out.println("HELO " + Config.inst().get(Config.HOSTNAME, "localhost"));
1.45 + this.out.write(
1.46 + ("HELO " + Config.inst().get(Config.HOSTNAME, "localhost") + "\r\n").getBytes("UTF-8"));
1.47 this.out.flush();
1.48 line = this.in.readLine();
1.49 if(line == null || !line.startsWith("250 "))
1.50 @@ -74,7 +74,7 @@
1.51 public void close()
1.52 throws IOException
1.53 {
1.54 - this.out.println("QUIT");
1.55 + this.out.write("QUIT".getBytes("UTF-8"));
1.56 this.out.flush();
1.57 this.in.readLine();
1.58
1.59 @@ -88,7 +88,7 @@
1.60 assert(mailFrom != null);
1.61 assert(rcptTo != null);
1.62
1.63 - this.out.println("MAIL FROM: " + mailFrom);
1.64 + this.out.write(("MAIL FROM: " + mailFrom).getBytes("UTF-8"));
1.65 this.out.flush();
1.66 String line = this.in.readLine();
1.67 if(line == null || !line.startsWith("250 "))
1.68 @@ -96,7 +96,7 @@
1.69 throw new IOException("Unexpected reply: " + line);
1.70 }
1.71
1.72 - this.out.println("RCPT TO: " + rcptTo);
1.73 + this.out.write(("RCPT TO: " + rcptTo).getBytes("UTF-8"));
1.74 this.out.flush();
1.75 line = this.in.readLine();
1.76 if(line == null || !line.startsWith("250 "))
1.77 @@ -104,7 +104,7 @@
1.78 throw new IOException("Unexpected reply: " + line);
1.79 }
1.80
1.81 - this.out.println("DATA");
1.82 + this.out.write("DATA".getBytes("UTF-8"));
1.83 this.out.flush();
1.84 line = this.in.readLine();
1.85 if(line == null || !line.startsWith("354 "))
1.86 @@ -113,20 +113,15 @@
1.87 }
1.88
1.89 ArticleInputStream artStream = new ArticleInputStream(article);
1.90 - BufferedOutputStream outStream = new BufferedOutputStream(socket.getOutputStream());
1.91 - FileOutputStream fileStream = new FileOutputStream("smtp.dump");
1.92 for(int b = artStream.read(); b >= 0; b = artStream.read())
1.93 {
1.94 - outStream.write(b);
1.95 - fileStream.write(b);
1.96 + this.out.write(b);
1.97 }
1.98
1.99 // Flush the binary stream; important because otherwise the output
1.100 // will be mixed with the PrintWriter.
1.101 - outStream.flush();
1.102 - fileStream.flush();
1.103 - fileStream.close();
1.104 - this.out.print("\r\n.\r\n");
1.105 + this.out.flush();
1.106 + this.out.write("\r\n.\r\n".getBytes("UTF-8"));
1.107 this.out.flush();
1.108 line = this.in.readLine();
1.109 if(line == null || !line.startsWith("250 "))