--- projects/cms/source/util/uk/org/iscream/cms/util/Smtp.java 2002/02/07 17:57:06 1.7 +++ projects/cms/source/util/uk/org/iscream/cms/util/Smtp.java 2002/02/08 16:09:27 1.8 @@ -10,7 +10,7 @@ import java.io.*; * for the GJT, and scaled to do just what we require. * * @author $Author: tdb $ - * @version $Id: Smtp.java,v 1.7 2002/02/07 17:57:06 tdb Exp $ + * @version $Id: Smtp.java,v 1.8 2002/02/08 16:09:27 tdb Exp $ */ public class Smtp { @@ -19,7 +19,7 @@ public class Smtp { /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.7 $"; + public static final String REVISION = "$Revision: 1.8 $"; //---STATIC METHODS--- @@ -47,8 +47,7 @@ public class Smtp { _socket = new Socket(server, port); _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream())); _socketOut = new PrintWriter(_socket.getOutputStream(), true); - _socketIn.readLine(); // get 220 welcome header - sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250); + init(); } //---PUBLIC METHODS--- @@ -141,6 +140,26 @@ public class Smtp { } //---PRIVATE METHODS--- + + /** + * Check the server sends a 220 message, and + * then send our HELO. + * + * @throws IOException if something goes wrong + */ + private void init() throws IOException { + String temp = _socketIn.readLine(); + // skip over any 220- lines + while(temp != null && temp.startsWith("220-")) { + temp = _socketIn.readLine(); + } + // check if we got a 220 welcome header + if(temp == null || !temp.startsWith("220 ")) { + throw new IOException ("Server did not initialise with a 220 message"); + } + // server gave a 220, it's ok to do a HELO + sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250); + } //---ACCESSOR/MUTATOR METHODS---