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.3 by tdb, Mon Feb 5 20:46:28 2001 UTC vs.
Revision 1.8 by tdb, Fri Feb 8 16:09:27 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.util;
2 > package uk.org.iscream.cms.server.util;
3  
4   //---IMPORTS---
5   import java.net.*;
# Line 47 | Line 47 | public class Smtp {
47          _socket = new Socket(server, port);
48          _socketIn = new BufferedReader(new InputStreamReader(_socket.getInputStream()));
49          _socketOut = new PrintWriter(_socket.getOutputStream(), true);
50 <        _socketIn.readLine(); // get 220 welcome header
51 <        sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250);
50 >        init();
51      }
52  
53   //---PUBLIC METHODS---
# Line 116 | Line 115 | public class Smtp {
115      public void sendCommand(String cmd, int reply) throws IOException {
116          _socketOut.println(cmd);
117          String temp = _socketIn.readLine();
118 <        if (!temp.startsWith(new String(reply))) {
118 >        if (temp == null) {
119 >            throw new IOException ("IO error reading from socket, connection to server died?");
120 >        }
121 >        if (!temp.startsWith(String.valueOf(reply))) {
122              throw new IOException ("Expected " + reply + ", got " + temp);
123          }
124      }
# Line 125 | Line 127 | public class Smtp {
127       * Overrides the {@link java.lang.Object#toString() Object.toString()}
128       * method to provide clean logging (every class should have this).
129       *
130 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
130 >     * This uses the uk.org.iscream.cms.server.util.FormatName class
131       * to format the toString()
132       *
133       * @return the name of this class and its CVS revision
# Line 138 | Line 140 | public class Smtp {
140      }
141  
142   //---PRIVATE METHODS---
143 +
144 +    /**
145 +     * Check the server sends a 220 message, and
146 +     * then send our HELO.
147 +     *
148 +     * @throws IOException if something goes wrong
149 +     */
150 +    private void init() throws IOException {
151 +        String temp = _socketIn.readLine();
152 +        // skip over any 220- lines
153 +        while(temp != null && temp.startsWith("220-")) {
154 +            temp = _socketIn.readLine();
155 +        }
156 +        // check if we got a 220 welcome header
157 +        if(temp == null || !temp.startsWith("220 ")) {
158 +            throw new IOException ("Server did not initialise with a 220 message");
159 +        }
160 +        // server gave a 220, it's ok to do a HELO
161 +        sendCommand("HELO " + InetAddress.getLocalHost().getHostName(), 250);
162 +    }
163  
164   //---ACCESSOR/MUTATOR METHODS---
165  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines