You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2002/01/08 11:50:43 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/mail ErrorInQuitException.java MailMessage.java
bodewig 02/01/08 02:50:43
Modified: src/main/org/apache/tools/ant/taskdefs SendEmail.java
src/main/org/apache/tools/mail MailMessage.java
Added: src/main/org/apache/tools/mail ErrorInQuitException.java
Log:
Help people who's mail server doesn't speak SMTP correctly.
PR: 5273
Revision Changes Path
1.8 +5 -5 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SendEmail.java
Index: SendEmail.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/SendEmail.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SendEmail.java 11 Dec 2001 09:23:56 -0000 1.7
+++ SendEmail.java 8 Jan 2002 10:50:43 -0000 1.8
@@ -62,6 +62,7 @@
import java.util.Vector;
import java.util.StringTokenizer;
import java.util.Enumeration;
+import org.apache.tools.mail.ErrorInQuitException;
import org.apache.tools.mail.MailMessage;
import org.apache.tools.ant.Task;
@@ -305,12 +306,11 @@
log("Sending email");
mailMessage.sendAndClose();
} catch (IOException ioe) {
- String err="IO error sending mail "+ioe.toString();
- if(failOnError) {
+ String err="IO error sending mail: "+ioe.toString();
+ if (!failOnError || ioe instanceof ErrorInQuitException) {
+ log(err, Project.MSG_ERR);
+ } else {
throw new BuildException(err,ioe,location);
- }
- else {
- log(err,Project.MSG_ERR);
}
}
}
1.6 +38 -21 jakarta-ant/src/main/org/apache/tools/mail/MailMessage.java
Index: MailMessage.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/mail/MailMessage.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MailMessage.java 15 Nov 2001 22:11:28 -0000 1.5
+++ MailMessage.java 8 Jan 2002 10:50:43 -0000 1.6
@@ -310,9 +310,12 @@
* @exception IOException if there's any problem reported by the mail server
*/
public void sendAndClose() throws IOException {
- sendDot();
- sendQuit();
- disconnect();
+ try {
+ sendDot();
+ sendQuit();
+ } finally {
+ disconnect();
+ }
}
// Make a limited attempt to extract a sanitized email address
@@ -398,21 +401,23 @@
send("\r\n.", ok); // make sure dot is on new line
}
- void sendQuit() throws IOException {
- int[] ok = { 221 };
- send("QUIT", ok);
- }
+ void sendQuit() throws IOException {
+ int[] ok = { 221 };
+ try {
+ send("QUIT", ok);
+ } catch (IOException e) {
+ throw new ErrorInQuitException(e);
+ }
+ }
- void send(String msg, int[] ok) throws IOException {
- out.rawPrint(msg + "\r\n"); // raw supports <CRLF>.<CRLF>
- //System.out.println("S: " + msg);
- String response = in.getResponse();
- //System.out.println("R: " + response);
- if (!isResponseOK(response, ok)) {
- throw new IOException(
- "Unexpected reply to command: " + msg + ": " + response);
+ void send(String msg, int[] ok) throws IOException {
+ out.rawPrint(msg + "\r\n"); // raw supports <CRLF>.<CRLF>
+ String response = in.getResponse();
+ if (!isResponseOK(response, ok)) {
+ throw new IOException("Unexpected reply to command: "
+ + msg + ": " + response);
+ }
}
- }
boolean isResponseOK(String response, int[] ok) {
// Check that the response is one of the valid codes
@@ -424,11 +429,23 @@
return false;
}
- void disconnect() throws IOException {
- if (out != null) out.close();
- if (in != null) in.close();
- if (socket != null) socket.close();
- }
+ void disconnect() throws IOException {
+ if (out != null) {
+ out.close();
+ }
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ }
+ }
+ if (socket != null) {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ }
+ }
+ }
}
// This PrintStream subclass makes sure that <CRLF>. becomes <CRLF>..
1.1 jakarta-ant/src/main/org/apache/tools/mail/ErrorInQuitException.java
Index: ErrorInQuitException.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
*/
package org.apache.tools.mail;
import java.io.IOException;
/**
* Specialized IOException that get thrown if SMPT's QUIT command fails.
*
* <p>This seems to happen with some version of MS Exchange that
* doesn't respond with a 221 code immediately. See <a
* href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5273">Bug
* report 5273</a>.</p>
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public class ErrorInQuitException extends IOException {
public ErrorInQuitException(IOException e) {
super(e.getMessage());
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>