Bug 5273 - Mail task throws IndexOutOfBoundsException on send QUIT
Summary: Mail task throws IndexOutOfBoundsException on send QUIT
Status: RESOLVED FIXED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.4.1
Hardware: PC All
: P3 major (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-12-04 17:20 UTC by William Ferguson
Modified: 2005-03-20 17:06 UTC (History)
1 user (show)



Attachments
log of telnet session with mailserver (697 bytes, text/plain)
2001-12-05 14:27 UTC, William Ferguson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description William Ferguson 2001-12-04 17:20:05 UTC
The mail is actually sent, but the Mail task claims failure.

This appears to be due to send QUIT returning a blank line, which causes the 
mail task to generate an IndexOutOfBoundsException in line 87 of 
SmtpResponseReader.

I believe my mail server is probably MS-Exchange pretending to be a smtp mail 
server.

Using the MimeMail task works perfectly.
Comment 1 Stefan Bodewig 2001-12-04 23:55:19 UTC
I wouldn't be all that surprised to see Exchange not following the RFCs - on the
other hand, I already had to modify Jason's original code as it couldn't deal
with perfectly legal continuation lines ...

Can you give me the protocol of a complete SMTP session that you run by using
telnet to the offending server's SMTP port?  Something like

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 xxxxxxxxxxxxxxxx ESMTP Sendmail 8.11.6/8.11.6; Wed, 5 Dec 2001 08:45:01
+0100helo xxxxxxxxxxxxxxxx
250 xxxxxxxxxxxxxxxx Hello IDENT:0fcKw84eikv1kInYntvVQBPPFsMI8DQ8@localhost
[127.0.0.1], pleased to meet you
mail from: <some@legal.address>
250 2.1.0 <some@legal.address>... Sender ok
rcpt to: <someother@legal.address>
250 2.1.5 <someother@legal.address>... Recipient ok
data
354 Enter mail, end with "." on a line by itself
Subject: Dummymail

some text here
.
250 2.0.0 fB57jc804797 Message accepted for delivery
quit
221 2.0.0 xxxxxxxxxxxxxxx closing connection
Connection closed by foreign host.
Comment 2 William Ferguson 2001-12-05 14:27:57 UTC
Created attachment 878 [details]
log of telnet session with mailserver
Comment 3 Stefan Bodewig 2001-12-06 08:10:42 UTC
Hmm, the log looks the way it should (except for some stray white space in front
of your quit command).

Are you sure, you are talking about Ant 1.4.1?  line 87 is

result.setLength(0);

which shouldn't throw and IndexOutOfBoundsException (can it?).

Can you give us a complete stack trace please?
Comment 4 William Ferguson 2001-12-06 13:53:32 UTC
The offending line is
            result.append(line.substring(0, 3));
which is line 87 in the source I have.
Since the source can only be downloaded from the Nightly build section it is 
probably slightly newer than 1.4.1

But this is the staktrace I get using the a straight Ant 1.4.1 install

java.lang.StringIndexOutOfBoundsException: String index out of range: 3
        at java.lang.String.substring(String.java:1522)
        at org.apache.tools.mail.SmtpResponseReader.getResponse
(SmtpResponseReader.java:87)
        at org.apache.tools.mail.MailMessage.send(MailMessage.java:374)
        at org.apache.tools.mail.MailMessage.sendQuit(MailMessage.java:368)
        at org.apache.tools.mail.MailMessage.sendAndClose(MailMessage.java:279)
        at org.apache.tools.ant.taskdefs.SendEmail.execute(SendEmail.java:246)
        at org.apache.tools.ant.Task.perform(Task.java:217)
        at org.apache.tools.ant.Target.execute(Target.java:164)
        at org.apache.tools.ant.Target.performTasks(Target.java:182)
        at org.apache.tools.ant.Project.executeTarget(Project.java:601)
        at org.apache.tools.ant.Project.executeTargets(Project.java:560)
        at org.apache.tools.ant.Main.runBuild(Main.java:454)
        at org.apache.tools.ant.Main.start(Main.java:153)
        at org.apache.tools.ant.Main.main(Main.java:176)


It the substring that is throwing the IndexOutOfBounds.
As will the other uses of substring, and charAt in this class, as none of them 
check for String length first.


Comment 5 Stefan Bodewig 2001-12-10 05:21:18 UTC
OK, the sources have changed because all * imports have been changed to explicit
ones - that's why the line numbers have changed.

Looking at your trace, the response is longer than three characters and follows
all rules for SMTP.  I'll add some explicit checks, but they'll probably only
lead to "protocol error" exceptions instead of this one.  Could you please try
the next nightly build (2001-12-11) and see what happens?
Comment 6 William Ferguson 2001-12-11 20:41:41 UTC
Ran with nightly build from 11-DEC-2001
Build output was:


BUILD FAILED

D:\source\main\buildScripts\NightlyBuild.xml:167: IO error sending mail
	at org.apache.tools.ant.taskdefs.SendEmail.execute(SendEmail.java:289)
	at org.apache.tools.ant.Task.perform(Task.java:217)
	at org.apache.tools.ant.Target.execute(Target.java:186)
	at org.apache.tools.ant.Target.performTasks(Target.java:204)
	at org.apache.tools.ant.Project.executeTarget(Project.java:855)
	at org.apache.tools.ant.Project.executeTargets(Project.java:809)
	at org.apache.tools.ant.Main.runBuild(Main.java:468)
	at org.apache.tools.ant.Main.start(Main.java:159)
	at org.apache.tools.ant.Main.main(Main.java:182)
--- Nested Exception ---
java.io.IOException: Unexpected reply to command: QUIT: 
	at org.apache.tools.mail.MailMessage.send(MailMessage.java:412)
	at org.apache.tools.mail.MailMessage.sendQuit(MailMessage.java:403)
	at org.apache.tools.mail.MailMessage.sendAndClose(MailMessage.java:314)
	at org.apache.tools.ant.taskdefs.SendEmail.execute(SendEmail.java:287)
	at org.apache.tools.ant.Task.perform(Task.java:217)
	at org.apache.tools.ant.Target.execute(Target.java:186)
	at org.apache.tools.ant.Target.performTasks(Target.java:204)
	at org.apache.tools.ant.Project.executeTarget(Project.java:855)
	at org.apache.tools.ant.Project.executeTargets(Project.java:809)
	at org.apache.tools.ant.Main.runBuild(Main.java:468)
	at org.apache.tools.ant.Main.start(Main.java:159)
	at org.apache.tools.ant.Main.main(Main.java:182)
Comment 7 Stefan Bodewig 2001-12-14 08:01:14 UTC
But it does send a response, doesn't it?  From your trace:

221 retro.xedoc.com.au closing connection

I'll see whether I can change the class so that a bad response on QUIT isn't
treated as a problem - does the mail get sent?
Comment 8 William Ferguson 2001-12-16 14:14:49 UTC
Yeah - it sends a response. But it appears to be an empty String.
The mail always gets sent.
Comment 9 Stefan Bodewig 2002-01-08 02:53:06 UTC
OK, I finally changed the code to deal with errors in the QUIT command a little
differently.  Could you please try the nightly build 2002-01-09 and see whether
the problem does away?
Comment 10 Magesh Umasankar 2002-02-07 18:15:11 UTC
It's been a month now since Stefan's fix went in place.  This should have fixed 
this issue because we haven't heard back a nagative response from William.
Marking it as fixed.  William, you may reopen it if the problem persists.