Browse Source

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
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274582 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
27b9f24bf2
8 changed files with 99 additions and 15 deletions
  1. +11
    -4
      docs/manual/CoreTasks/mail.html
  2. +6
    -1
      docs/manual/listeners.html
  3. +10
    -4
      src/main/org/apache/tools/ant/listener/MailLogger.java
  4. +32
    -1
      src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
  5. +12
    -0
      src/main/org/apache/tools/ant/taskdefs/email/Mailer.java
  6. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java
  7. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java
  8. +20
    -2
      src/main/org/apache/tools/mail/MailMessage.java

+ 11
- 4
docs/manual/CoreTasks/mail.html View File

@@ -32,6 +32,11 @@ Library Dependencies</a> for more information.
<td align="center" valign="top">Either a <code>from</code> attribute, or a <code>&lt;from&gt;</code> <td align="center" valign="top">Either a <code>from</code> attribute, or a <code>&lt;from&gt;</code>
element.</td> element.</td>
</tr> </tr>
<tr>
<td valign="top">replyto</td>
<td valign="top">Replyto email address.</td>
<td align="center" valign="top">No</td>
</tr>
<tr> <tr>
<td valign="top">tolist</td> <td valign="top">tolist</td>
<td valign="top">Comma-separated list of recipients.</td> <td valign="top">Comma-separated list of recipients.</td>
@@ -116,7 +121,7 @@ Library Dependencies</a> for more information.


<h3>Parameters specified as nested elements</h3> <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> <p>Adds an email address element. It takes the following attributes:</p>


<table width="60%" border="1" cellpadding="2" cellspacing="0"> <table width="60%" border="1" cellpadding="2" cellspacing="0">
@@ -187,7 +192,8 @@ the <code>&lt;message&gt;</code> element.</p>


<blockquote><pre> <blockquote><pre>
&lt;mail mailhost=&quot;smtp.myisp.com&quot; mailport=&quot;1025&quot; subject=&quot;Test build&quot;&gt; &lt;mail mailhost=&quot;smtp.myisp.com&quot; mailport=&quot;1025&quot; subject=&quot;Test build&quot;&gt;
&lt;from address=&quot;me@myisp.com&quot;/&gt;
&lt;from address=&quot;config@myisp.com&quot;/&gt;
&lt;replyto address=&quot;me@myisp.com&quot;/&gt;
&lt;to address=&quot;all@xyz.com&quot;/&gt; &lt;to address=&quot;all@xyz.com&quot;/&gt;
&lt;message&gt;The ${buildname} nightly build has completed&lt;/message&gt; &lt;message&gt;The ${buildname} nightly build has completed&lt;/message&gt;
&lt;fileset dir=&quot;dist&quot;&gt; &lt;fileset dir=&quot;dist&quot;&gt;
@@ -196,8 +202,9 @@ the <code>&lt;message&gt;</code> element.</p>
&lt;/mail&gt; &lt;/mail&gt;
</pre></blockquote> </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.&nbsp; 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.&nbsp; The
task will attempt to use JavaMail and fall back to UU encoding or no encoding in 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> that order depending on what support classes are available. <code>${buildname}</code>
will be replaced with the <code>buildname</code> property's value.</p> will be replaced with the <code>buildname</code> property's value.</p>


+ 6
- 1
docs/manual/listeners.html View File

@@ -130,6 +130,11 @@ control for turning off success or failure messages individually.</p>
<td width="63%">Mail &quot;from&quot; address</td> <td width="63%">Mail &quot;from&quot; address</td>
<td width="63%">Yes, if mail needs to be sent</td> <td width="63%">Yes, if mail needs to be sent</td>
</tr> </tr>
<tr>
<td width="337">MailLogger.replyto</td>
<td width="63%">Mail &quot;replyto&quot; address(es), comma-separated</td>
<td width="63%">No</td>
</tr>
<tr> <tr>
<td width="337">MailLogger.failure.notify </td> <td width="337">MailLogger.failure.notify </td>
<td width="63%">Send build failure e-mails?</td> <td width="63%">Send build failure e-mails?</td>
@@ -314,7 +319,7 @@ developers.</p>
</ul> </ul>


<hr> <hr>
<p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
Reserved.</p> Reserved.</p>


</body> </body>


+ 10
- 4
src/main/org/apache/tools/ant/listener/MailLogger.java View File

@@ -153,12 +153,12 @@ public class MailLogger extends DefaultLogger {
String mailhost = getValue(properties, "mailhost", "localhost"); String mailhost = getValue(properties, "mailhost", "localhost");
int port = Integer.parseInt(getValue(properties,"port",String.valueOf(MailMessage.DEFAULT_PORT))); int port = Integer.parseInt(getValue(properties,"port",String.valueOf(MailMessage.DEFAULT_PORT)));
String from = getValue(properties, "from", null); String from = getValue(properties, "from", null);
String replytoList = getValue(properties,"replyto","");
String toList = getValue(properties, prefix + ".to", null); String toList = getValue(properties, prefix + ".to", null);
String subject = getValue(properties, prefix + ".subject", String subject = getValue(properties, prefix + ".subject",
(success) ? "Build Success" : "Build Failure"); (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) { } catch (Exception e) {
System.out.println("MailLogger failed to send e-mail!"); System.out.println("MailLogger failed to send e-mail!");
e.printStackTrace(System.err); e.printStackTrace(System.err);
@@ -211,18 +211,24 @@ public class MailLogger extends DefaultLogger {
* @param mailhost mail server * @param mailhost mail server
* @param port mail server port number * @param port mail server port number
* @param from from address * @param from from address
* @param replyToList comma-separated replyto list
* @param toList comma-separated recipient list * @param toList comma-separated recipient list
* @param subject mail subject * @param subject mail subject
* @param message mail body * @param message mail body
* @exception IOException thrown if sending message fails * @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 { String subject, String message) throws IOException {
MailMessage mailMessage = new MailMessage(mailhost, port); MailMessage mailMessage = new MailMessage(mailhost, port);
mailMessage.setHeader("Date", DateUtils.getDateForHeader()); mailMessage.setHeader("Date", DateUtils.getDateForHeader());


mailMessage.from(from); 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); StringTokenizer t = new StringTokenizer(toList, ", ", false);
while (t.hasMoreTokens()) { while (t.hasMoreTokens()) {
mailMessage.to(t.nextToken()); mailMessage.to(t.nextToken());


+ 32
- 1
src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java View File

@@ -77,6 +77,7 @@ import org.apache.tools.ant.types.FileSet;
* @author paulo.gaspar@krankikom.de Paulo Gaspar * @author paulo.gaspar@krankikom.de Paulo Gaspar
* @author roxspring@imapmail.org Rob Oxspring * @author roxspring@imapmail.org Rob Oxspring
* @author <a href="mailto:ishu@akm.ru">Aleksandr Ishutin</a> * @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 * @since Ant 1.5
* @ant.task name="mail" category="network" * @ant.task name="mail" category="network"
*/ */
@@ -120,9 +121,11 @@ public class EmailTask
private boolean failOnError = true; private boolean failOnError = true;
private boolean includeFileNames = false; private boolean includeFileNames = false;
private String messageMimeType = null; private String messageMimeType = null;
/** special headers */
/** sender */ /** sender */
private EmailAddress from = null; private EmailAddress from = null;
/** replyto */
private Vector replyToList = new Vector();
/** TO recipients */ /** TO recipients */
private Vector toList = new Vector(); private Vector toList = new Vector();
/** CC (Carbon Copy) recipients */ /** CC (Carbon Copy) recipients */
@@ -135,6 +138,10 @@ public class EmailTask
private Vector filesets = new Vector(); private Vector filesets = new Vector();
/** Character set for MimeMailer*/ /** Character set for MimeMailer*/
private String charset=null; 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;




/** /**
@@ -265,6 +272,28 @@ public class EmailTask
} }




/**
* 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 * Adds a to address element
* *
@@ -501,6 +530,7 @@ public class EmailTask
// let the user know what's going to happen // let the user know what's going to happen
log("Sending email: " + subject, Project.MSG_INFO); log("Sending email: " + subject, Project.MSG_INFO);
log("From " + from, Project.MSG_VERBOSE); log("From " + from, Project.MSG_VERBOSE);
log("ReplyTo " + replyToList,Project.MSG_VERBOSE);
log("To " + toList, Project.MSG_VERBOSE); log("To " + toList, Project.MSG_VERBOSE);
log("Cc " + ccList, Project.MSG_VERBOSE); log("Cc " + ccList, Project.MSG_VERBOSE);
log("Bcc " + bccList, Project.MSG_VERBOSE); log("Bcc " + bccList, Project.MSG_VERBOSE);
@@ -510,6 +540,7 @@ public class EmailTask
mailer.setPort(port); mailer.setPort(port);
mailer.setMessage(message); mailer.setMessage(message);
mailer.setFrom(from); mailer.setFrom(from);
mailer.setReplyToList(replyToList);
mailer.setToList(toList); mailer.setToList(toList);
mailer.setCcList(ccList); mailer.setCcList(ccList);
mailer.setBccList(bccList); mailer.setBccList(bccList);


+ 12
- 0
src/main/org/apache/tools/ant/taskdefs/email/Mailer.java View File

@@ -69,6 +69,7 @@ abstract class Mailer {
protected int port = -1; protected int port = -1;
protected Message message; protected Message message;
protected EmailAddress from; protected EmailAddress from;
protected Vector replyToList = null;
protected Vector toList = null; protected Vector toList = null;
protected Vector ccList = null; protected Vector ccList = null;
protected Vector bccList = null; protected Vector bccList = null;
@@ -117,6 +118,17 @@ abstract class Mailer {
} }




/**
* Sets the replyto addresses
*
* @param list
* @since ant 1.6
*/
public void setReplyToList(Vector list) {
this.replyToList = list;
}


/** /**
* Set the to addresses * Set the to addresses
* *


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java View File

@@ -170,7 +170,8 @@ class MimeMailer extends Mailer {
msg.setFrom(new InternetAddress(from.getAddress(), msg.setFrom(new InternetAddress(from.getAddress(),
from.getName())); from.getName()));
} }

// set the reply to addresses
msg.setReplyTo(internetAddresses(replyToList));
msg.setRecipients(Message.RecipientType.TO, msg.setRecipients(Message.RecipientType.TO,
internetAddresses(toList)); internetAddresses(toList));
msg.setRecipients(Message.RecipientType.CC, msg.setRecipients(Message.RecipientType.CC,


+ 6
- 2
src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -82,6 +82,11 @@ class PlainMailer extends Mailer {


Enumeration e; Enumeration e;


e = replyToList.elements();
while (e.hasMoreElements()) {
mailMessage.replyto(e.nextElement().toString());
}

e = toList.elements(); e = toList.elements();
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
mailMessage.to(e.nextElement().toString()); mailMessage.to(e.nextElement().toString());
@@ -122,7 +127,6 @@ class PlainMailer extends Mailer {


} }



/** /**
* Attaches a file to this email * Attaches a file to this email
* *


+ 20
- 2
src/main/org/apache/tools/mail/MailMessage.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -143,6 +143,9 @@ public class MailMessage {
/** sender email address */ /** sender email address */
private String from; private String from;


/** list of email addresses to reply to */
private Vector replyto;

/** list of email addresses to send to */ /** list of email addresses to send to */
private Vector to; private Vector to;


@@ -190,10 +193,11 @@ public class MailMessage {
public MailMessage(String host, int port) throws IOException{ public MailMessage(String host, int port) throws IOException{
this.port = port; this.port = port;
this.host = host; this.host = host;
replyto = new Vector();
to = new Vector(); to = new Vector();
cc = new Vector(); cc = new Vector();
headers = new Hashtable(); 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(); connect();
sendHelo(); sendHelo();
} }
@@ -218,6 +222,16 @@ public class MailMessage {
this.from = from; 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 * Sets the to address. Also sets the "To" header. This method may be
* called multiple times. * called multiple times.
@@ -277,6 +291,7 @@ public class MailMessage {
*/ */
public PrintStream getPrintStream() throws IOException { public PrintStream getPrintStream() throws IOException {
setFromHeader(); setFromHeader();
setReplyToHeader();
setToHeader(); setToHeader();
setCcHeader(); setCcHeader();
sendData(); sendData();
@@ -288,6 +303,9 @@ public class MailMessage {
setHeader("From", from); setHeader("From", from);
} }


void setReplyToHeader() {
setHeader("Reply-To", vectorToList(replyto));
}
void setToHeader() { void setToHeader() {
setHeader("To", vectorToList(to)); setHeader("To", vectorToList(to));
} }


Loading…
Cancel
Save