diff --git a/src/main/org/apache/tools/mail/SmtpResponseReader.java b/src/main/org/apache/tools/mail/SmtpResponseReader.java index a2a8f450c..2f220e49b 100644 --- a/src/main/org/apache/tools/mail/SmtpResponseReader.java +++ b/src/main/org/apache/tools/mail/SmtpResponseReader.java @@ -86,7 +86,7 @@ public class SmtpResponseReader { public String getResponse() throws IOException { result.setLength(0); String line = reader.readLine(); - if (line != null) { + if (line != null && line.length() >= 3) { result.append(line.substring(0, 3)); result.append(" "); } @@ -112,14 +112,16 @@ public class SmtpResponseReader { * Should we expect more input? */ protected boolean hasMoreLines(String line) { - return line.charAt(3) == '-'; + return line.length() > 3 && line.charAt(3) == '-'; } /** * Append the text from this line of the resonse. */ private void append(String line) { - result.append(line.substring(4)); - result.append(" "); + if (line.length() > 4) { + result.append(line.substring(4)); + result.append(" "); + } } }