--- 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/05/18 18:16:04 1.9 @@ -1,3 +1,22 @@ +/* + * i-scream central monitoring system + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + //---PACKAGE DECLARATION--- package uk.org.iscream.cms.server.util; @@ -6,11 +25,11 @@ import java.net.*; import java.io.*; /** - * The Simple Mail Transfer Protocol class. This class was borrowed - * for the GJT, and scaled to do just what we require. + * The Simple Mail Transfer Protocol class. This class was inspired + * by the GJT. * * @author $Author: tdb $ - * @version $Id: Smtp.java,v 1.7 2002/02/07 17:57:06 tdb Exp $ + * @version $Id: Smtp.java,v 1.9 2002/05/18 18:16:04 tdb Exp $ */ public class Smtp { @@ -19,7 +38,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.9 $"; //---STATIC METHODS--- @@ -47,8 +66,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 +159,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---