antoine 2003/05/15 04:30:27
Modified: docs/manual/CoreTasks mail.html
src/main/org/apache/tools/ant/taskdefs/email EmailTask.java
Mailer.java MimeMailer.java PlainMailer.java
src/main/org/apache/tools/ant/listener MailLogger.java
src/main/org/apache/tools/mail MailMessage.java
docs/manual listeners.html
Log:
implemented replyto in the EmailTask and the MailLogger.
I have implemented it similarly to the other lists of email addresses (To, CC, Bcc)
because it might actually be easier that way
We might still need a generic parameter collection for other header elements
PR: 19141
Revision Changes Path
1.18 +11 -4 ant/docs/manual/CoreTasks/mail.html
Index: mail.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/mail.html,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- mail.html 17 Apr 2003 17:09:35 -0000 1.17
+++ mail.html 15 May 2003 11:30:26 -0000 1.18
@@ -33,6 +33,11 @@
element.</td>
</tr>
<tr>
+ <td valign="top">replyto</td>
+ <td valign="top">Replyto email address.</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
<td valign="top">tolist</td>
<td valign="top">Comma-separated list of recipients.</td>
<td align="center" valign="middle" rowspan="3">At least one of these, or the
@@ -116,7 +121,7 @@
<h3>Parameters specified as nested elements</h3>
-<h4>to / cc / bcc / from</h4>
+<h4>to / cc / bcc / from/ replyto </h4>
<p>Adds an email address element. It takes the following attributes:</p>
<table width="60%" border="1" cellpadding="2" cellspacing="0">
@@ -187,7 +192,8 @@
<blockquote><pre>
<mail mailhost="smtp.myisp.com" mailport="1025"
subject="Test build">
- <from address="me@myisp.com"/>
+ <from address="config@myisp.com"/>
+ <replyto address="me@myisp.com"/>
<to address="all@xyz.com"/>
<message>The ${buildname} nightly build has completed</message>
<fileset dir="dist">
@@ -196,8 +202,9 @@
</mail>
</pre></blockquote>
-<p>Sends an eMail from <i>me@myisp.com</i> to <i>all@xyz.com</i>
with a subject of
-<i>Test Build</i> and attaches any zip files from the dist directory.
The
+<p>Sends an eMail from <i>config@myisp.com</i> to <i>all@xyz.com</i>
with a subject of
+<i>Test Build</i>. Replies to this email will go to <i>me@myisp.com</i>.
+Any zip files from the dist directory are attached. The
task will attempt to use JavaMail and fall back to UU encoding or no encoding in
that order depending on what support classes are available. <code>${buildname}</code>
will be replaced with the <code>buildname</code> property's value.</p>
1.18 +32 -1 ant/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
Index: EmailTask.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- EmailTask.java 17 Apr 2003 17:09:35 -0000 1.17
+++ EmailTask.java 15 May 2003 11:30:26 -0000 1.18
@@ -77,6 +77,7 @@
* @author paulo.gaspar@krankikom.de Paulo Gaspar
* @author roxspring@imapmail.org Rob Oxspring
* @author <a href="mailto:ishu@akm.ru">Aleksandr Ishutin</a>
+ * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a>
* @since Ant 1.5
* @ant.task name="mail" category="network"
*/
@@ -120,9 +121,11 @@
private boolean failOnError = true;
private boolean includeFileNames = false;
private String messageMimeType = null;
-
+ /** special headers */
/** sender */
private EmailAddress from = null;
+ /** replyto */
+ private Vector replyToList = new Vector();
/** TO recipients */
private Vector toList = new Vector();
/** CC (Carbon Copy) recipients */
@@ -135,6 +138,10 @@
private Vector filesets = new Vector();
/** Character set for MimeMailer*/
private String charset=null;
+ /** if set to true, the email will not be actually sent */
+ private boolean debugonly=false;
+ /** a location where to print the email message */
+ private File debugoutput;
/**
@@ -266,6 +273,28 @@
/**
+ * Adds a replyto address element
+ *
+ * @param address The address to reply to
+ * @since ant 1.6
+ */
+ public void addReplyTo(EmailAddress address) {
+ this.replyToList.add(address);
+ }
+
+
+ /**
+ * Shorthand to set the replyto address element
+ *
+ * @param address The address to which replies should be directed
+ * @since ant 1.6
+ */
+ public void setReplyTo(String address) {
+ this.replyToList.add(new EmailAddress(address));
+ }
+
+
+ /**
* Adds a to address element
*
* @param address An email address
@@ -501,6 +530,7 @@
// let the user know what's going to happen
log("Sending email: " + subject, Project.MSG_INFO);
log("From " + from, Project.MSG_VERBOSE);
+ log("ReplyTo " + replyToList,Project.MSG_VERBOSE);
log("To " + toList, Project.MSG_VERBOSE);
log("Cc " + ccList, Project.MSG_VERBOSE);
log("Bcc " + bccList, Project.MSG_VERBOSE);
@@ -510,6 +540,7 @@
mailer.setPort(port);
mailer.setMessage(message);
mailer.setFrom(from);
+ mailer.setReplyToList(replyToList);
mailer.setToList(toList);
mailer.setCcList(ccList);
mailer.setBccList(bccList);
1.8 +12 -0 ant/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java
Index: Mailer.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Mailer.java 10 Feb 2003 14:13:45 -0000 1.7
+++ Mailer.java 15 May 2003 11:30:26 -0000 1.8
@@ -69,6 +69,7 @@
protected int port = -1;
protected Message message;
protected EmailAddress from;
+ protected Vector replyToList = null;
protected Vector toList = null;
protected Vector ccList = null;
protected Vector bccList = null;
@@ -114,6 +115,17 @@
*/
public void setFrom(EmailAddress from) {
this.from = from;
+ }
+
+
+ /**
+ * Sets the replyto addresses
+ *
+ * @param list
+ * @since ant 1.6
+ */
+ public void setReplyToList(Vector list) {
+ this.replyToList = list;
}
1.10 +2 -1 ant/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java
Index: MimeMailer.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MimeMailer.java 17 Apr 2003 17:09:35 -0000 1.9
+++ MimeMailer.java 15 May 2003 11:30:26 -0000 1.10
@@ -170,7 +170,8 @@
msg.setFrom(new InternetAddress(from.getAddress(),
from.getName()));
}
-
+ // set the reply to addresses
+ msg.setReplyTo(internetAddresses(replyToList));
msg.setRecipients(Message.RecipientType.TO,
internetAddresses(toList));
msg.setRecipients(Message.RecipientType.CC,
1.9 +6 -2 ant/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java
Index: PlainMailer.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PlainMailer.java 10 Feb 2003 14:13:45 -0000 1.8
+++ PlainMailer.java 15 May 2003 11:30:26 -0000 1.9
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -82,6 +82,11 @@
Enumeration e;
+ e = replyToList.elements();
+ while (e.hasMoreElements()) {
+ mailMessage.replyto(e.nextElement().toString());
+ }
+
e = toList.elements();
while (e.hasMoreElements()) {
mailMessage.to(e.nextElement().toString());
@@ -121,7 +126,6 @@
}
}
-
/**
* Attaches a file to this email
1.16 +10 -4 ant/src/main/org/apache/tools/ant/listener/MailLogger.java
Index: MailLogger.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/listener/MailLogger.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- MailLogger.java 4 Apr 2003 13:51:11 -0000 1.15
+++ MailLogger.java 15 May 2003 11:30:26 -0000 1.16
@@ -153,12 +153,12 @@
String mailhost = getValue(properties, "mailhost", "localhost");
int port = Integer.parseInt(getValue(properties,"port",String.valueOf(MailMessage.DEFAULT_PORT)));
String from = getValue(properties, "from", null);
-
+ String replytoList = getValue(properties,"replyto","");
String toList = getValue(properties, prefix + ".to", null);
String subject = getValue(properties, prefix + ".subject",
(success) ? "Build Success" : "Build Failure");
- sendMail(mailhost, port, from, toList, subject, buffer.substring(0));
+ sendMail(mailhost, port, from, replytoList, toList, subject, buffer.substring(0));
} catch (Exception e) {
System.out.println("MailLogger failed to send e-mail!");
e.printStackTrace(System.err);
@@ -211,18 +211,24 @@
* @param mailhost mail server
* @param port mail server port number
* @param from from address
+ * @param replyToList comma-separated replyto list
* @param toList comma-separated recipient list
* @param subject mail subject
* @param message mail body
* @exception IOException thrown if sending message fails
*/
- private void sendMail(String mailhost, int port, String from, String toList,
+ private void sendMail(String mailhost, int port, String from, String replyToList, String
toList,
String subject, String message) throws IOException {
MailMessage mailMessage = new MailMessage(mailhost, port);
mailMessage.setHeader("Date", DateUtils.getDateForHeader());
mailMessage.from(from);
-
+ if (!replyToList.equals("")) {
+ StringTokenizer t = new StringTokenizer(replyToList, ", ", false);
+ while (t.hasMoreTokens()) {
+ mailMessage.replyto(t.nextToken());
+ }
+ }
StringTokenizer t = new StringTokenizer(toList, ", ", false);
while (t.hasMoreTokens()) {
mailMessage.to(t.nextToken());
1.14 +20 -2 ant/src/main/org/apache/tools/mail/MailMessage.java
Index: MailMessage.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/mail/MailMessage.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MailMessage.java 10 Feb 2003 14:14:42 -0000 1.13
+++ MailMessage.java 15 May 2003 11:30:26 -0000 1.14
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -143,6 +143,9 @@
/** sender email address */
private String from;
+ /** list of email addresses to reply to */
+ private Vector replyto;
+
/** list of email addresses to send to */
private Vector to;
@@ -190,10 +193,11 @@
public MailMessage(String host, int port) throws IOException{
this.port = port;
this.host = host;
+ replyto = new Vector();
to = new Vector();
cc = new Vector();
headers = new Hashtable();
- setHeader("X-Mailer", "org.apache.tools.mail.MailMessage (jakarta.apache.org)");
+ setHeader("X-Mailer", "org.apache.tools.mail.MailMessage (ant.apache.org)");
connect();
sendHelo();
}
@@ -218,6 +222,16 @@
this.from = from;
}
+ /**
+ * Sets the replyto address
+ * This method may be
+ * called multiple times.
+ *
+ */
+ public void replyto(String rto) {
+ this.replyto.addElement(rto);
+ }
+
/**
* Sets the to address. Also sets the "To" header. This method may be
* called multiple times.
@@ -277,6 +291,7 @@
*/
public PrintStream getPrintStream() throws IOException {
setFromHeader();
+ setReplyToHeader();
setToHeader();
setCcHeader();
sendData();
@@ -288,6 +303,9 @@
setHeader("From", from);
}
+ void setReplyToHeader() {
+ setHeader("Reply-To", vectorToList(replyto));
+ }
void setToHeader() {
setHeader("To", vectorToList(to));
}
1.12 +6 -1 ant/docs/manual/listeners.html
Index: listeners.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/listeners.html,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- listeners.html 3 Sep 2002 15:24:07 -0000 1.11
+++ listeners.html 15 May 2003 11:30:27 -0000 1.12
@@ -131,6 +131,11 @@
<td width="63%">Yes, if mail needs to be sent</td>
</tr>
<tr>
+ <td width="337">MailLogger.replyto</td>
+ <td width="63%">Mail "replyto" address(es), comma-separated</td>
+ <td width="63%">No</td>
+ </tr>
+ <tr>
<td width="337">MailLogger.failure.notify </td>
<td width="63%">Send build failure e-mails?</td>
<td width="63%">No, default "true"</td>
@@ -314,7 +319,7 @@
</ul>
<hr>
-<p align="center">Copyright © 2000-2002 Apache Software Foundation. All
rights
+<p align="center">Copyright © 2000-2003 Apache Software Foundation. All
rights
Reserved.</p>
</body>
|