# HG changeset patch # User cli # Date 1315990059 -7200 # Node ID 68a6825a4f4d78fd4a332096b2403b88f09ced01 # Parent b2df305a13ce7ff7c4f77eec469ac48c2aa0d69a Work on SMTPTransport. diff -r b2df305a13ce -r 68a6825a4f4d src/org/sonews/mlgw/SMTPTransport.java --- a/src/org/sonews/mlgw/SMTPTransport.java Tue Sep 13 23:34:16 2011 +0200 +++ b/src/org/sonews/mlgw/SMTPTransport.java Wed Sep 14 10:47:39 2011 +0200 @@ -23,6 +23,8 @@ import java.io.InputStreamReader; import java.net.Socket; import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; import org.sonews.config.Config; import org.sonews.storage.Article; import org.sonews.util.io.ArticleInputStream; @@ -73,20 +75,8 @@ this.out.write(strBuf.toString().getBytes("UTF-8")); this.out.flush(); - // Read reply: "250-example.org Hello example.net" - String line = this.in.readLine(); - if (line == null || !line.startsWith("250")) { - throw new IOException("Unexpected reply: " + line); - } + List ehloReplies = readReply("250"); - // FIXME: More 250- lines possible! - - // Read reply: "250 AUTH CRAM-MD5 LOGIN PLAIN" - line = this.in.readLine(); - if (line == null || !line.startsWith("250 ")) { - throw new IOException("Unexpected reply: " + line); - } - String[] authMethods = line.split(" "); // TODO: Check for supported methods // Do a PLAIN login @@ -98,8 +88,13 @@ this.out.write(strBuf.toString().getBytes("UTF-8")); this.out.flush(); + readReply("334"); + + // Send PLAIN credentials to server + + // Read reply - line = this.in.readLine(); + String line = this.in.readLine(); if (line == null || !line.startsWith("250 ")) { throw new IOException("Unexpected reply: " + line); } @@ -116,10 +111,7 @@ this.out.flush(); // Read reply - String line = this.in.readLine(); - if (line == null || !line.startsWith("250 ")) { - throw new IOException("Unexpected reply: " + line); - } + readReply("250"); } public void login() throws IOException { @@ -132,6 +124,32 @@ } } + /** + * Read one or more exspected reply lines. + * @param expectedReply + * @return + * @throws IOException If the reply of the server does not fit the exspected + * reply code. + */ + private List readReply(String expectedReply) throws IOException { + List replyStrings = new ArrayList(); + + for(;;) { + String line = this.in.readLine(); + if (line == null || !line.startsWith(expectedReply)) { + throw new IOException("Unexpected reply: " + line); + } + + replyStrings.add(line); + + if(line.charAt(3) == ' ') { // Last reply line + break; + } + } + + return replyStrings; + } + public void send(Article article, String mailFrom, String rcptTo) throws IOException { assert (article != null);