ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/Smtp.java
(Generate patch)

Comparing projects/cms/source/util/uk/org/iscream/cms/util/Smtp.java (file contents):
Revision 1.6 by tdb, Tue May 29 17:02:35 2001 UTC vs.
Revision 1.10 by tdb, Tue May 21 16:47:19 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org.uk
4 + * Copyright (C) 2000-2002 i-scream
5 + *
6 + * This program is free software; you can redistribute it and/or
7 + * modify it under the terms of the GNU General Public License
8 + * as published by the Free Software Foundation; either version 2
9 + * of the License, or (at your option) any later version.
10 + *
11 + * This program is distributed in the hope that it will be useful,
12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 + * GNU General Public License for more details.
15 + *
16 + * You should have received a copy of the GNU General Public License
17 + * along with this program; if not, write to the Free Software
18 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + */
20 +
21   //---PACKAGE DECLARATION---
22   package uk.org.iscream.cms.server.util;
23  
# Line 6 | Line 26 | import java.net.*;
26   import java.io.*;
27  
28   /**
29 < * The Simple Mail Transfer Protocol class. This class was borrowed
30 < * for the GJT, and scaled to do just what we require.
29 > * The Simple Mail Transfer Protocol class. This class was inspired
30 > * by the GJT.
31   *
32   * @author  $Author$
33   * @version $Id$
# Line 47 | Line 67 | public class Smtp {
67          _socket = new Socket(server, port);
68          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
69          _socketOut = new PrintWriter(_socket.getOutputStream(), true);
70 <        _socketIn.readLine(); // get 220 welcome header
51 <        sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250);
70 >        init();
71      }
72  
73   //---PUBLIC METHODS---
# Line 116 | Line 135 | public class Smtp {
135      public void sendCommand(String cmd, int reply) throws IOException {
136          _socketOut.println(cmd);
137          String temp = _socketIn.readLine();
138 <        if (!temp.startsWith(new Integer(reply).toString())) {
138 >        if (temp == null) {
139 >            throw new IOException ("IO error reading from socket, connection to server died?");
140 >        }
141 >        if (!temp.startsWith(String.valueOf(reply))) {
142              throw new IOException ("Expected " + reply + ", got " + temp);
143          }
144      }
# Line 138 | Line 160 | public class Smtp {
160      }
161  
162   //---PRIVATE METHODS---
163 +
164 +    /**
165 +     * Check the server sends a 220 message, and
166 +     * then send our HELO.
167 +     *
168 +     * @throws IOException if something goes wrong
169 +     */
170 +    private void init() throws IOException {
171 +        String temp = _socketIn.readLine();
172 +        // skip over any 220- lines
173 +        while(temp != null && temp.startsWith("220-")) {
174 +            temp = _socketIn.readLine();
175 +        }
176 +        // check if we got a 220 welcome header
177 +        if(temp == null || !temp.startsWith("220 ")) {
178 +            throw new IOException ("Server did not initialise with a 220 message");
179 +        }
180 +        // server gave a 220, it's ok to do a HELO
181 +        sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250);
182 +    }
183  
184   //---ACCESSOR/MUTATOR METHODS---
185  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines