You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/10/14 13:28:13 UTC
svn commit: r704471 - in /ant/core/trunk: WHATSNEW docs/manual/listeners.html
src/main/org/apache/tools/ant/listener/MailLogger.java
Author: bodewig
Date: Tue Oct 14 04:28:11 2008
New Revision: 704471
URL: http://svn.apache.org/viewvc?rev=704471&view=rev
Log:
Add charset and MIME-Type properties to MailLogger. PR 27211.
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/listeners.html
ant/core/trunk/src/main/org/apache/tools/ant/listener/MailLogger.java
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=704471&r1=704470&r2=704471&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Oct 14 04:28:11 2008
@@ -414,6 +414,10 @@
to really close the file.
Bugzilla Report 45960.
+ * two new properties can be used to set the MIME-Type and charset
+ used by MailLogger.
+ Bugzilla Report 27211.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/docs/manual/listeners.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/listeners.html?rev=704471&r1=704470&r2=704471&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/listeners.html (original)
+++ ant/core/trunk/docs/manual/listeners.html Tue Oct 14 04:28:11 2008
@@ -228,6 +228,16 @@
<td width="63%">Filename of properties file that will override other values.</td>
<td width="63%">No</td>
</tr>
+ <tr>
+ <td width="337">MailLogger.mimeType</td>
+ <td width="63%">MIME-Type of the message. <em>Since Ant 1.8.0</em></td>
+ <td width="63%">No, default is text/plain</td>
+ </tr>
+ <tr>
+ <td width="337">MailLogger.charset</td>
+ <td width="63%">Character set of the message. <em>Since Ant 1.8.0</em></td>
+ <td width="63%">No</td>
+ </tr>
</table>
<blockquote>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/listener/MailLogger.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/listener/MailLogger.java?rev=704471&r1=704470&r2=704471&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/listener/MailLogger.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/listener/MailLogger.java Tue Oct 14 04:28:11 2008
@@ -36,6 +36,7 @@
import org.apache.tools.ant.taskdefs.email.Mailer;
import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.DateUtils;
+import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.mail.MailMessage;
@@ -70,6 +71,8 @@
/** Buffer in which the message is constructed prior to sending */
private StringBuffer buffer = new StringBuffer();
+ private static final String DEFAULT_MIME_TYPE = "text/plain";
+
/**
* Sends an e-mail with the log results.
*
@@ -93,13 +96,7 @@
} catch (IOException ioe) {
// ignore because properties file is not required
} finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- // ignore
- }
- }
+ FileUtils.close(is);
}
}
@@ -132,6 +129,8 @@
.from(getValue(properties, "from", null))
.replytoList(getValue(properties, "replyto", ""))
.toList(getValue(properties, prefix + ".to", null))
+ .mimeType(getValue(properties, "mimeType", DEFAULT_MIME_TYPE))
+ .charset(getValue(properties, "charset", ""))
.subject(getValue(
properties, prefix + ".subject",
(success) ? "Build Success" : "Build Failure"));
@@ -222,6 +221,22 @@
this.subject = subject;
return this;
}
+ private String charset;
+ public String charset() {
+ return charset;
+ }
+ public Values charset(String charset) {
+ this.charset = charset;
+ return this;
+ }
+ private String mimeType;
+ public String mimeType() {
+ return mimeType;
+ }
+ public Values mimeType(String mimeType) {
+ this.mimeType = mimeType;
+ return this;
+ }
}
/**
@@ -289,6 +304,13 @@
mailMessage.setSubject(values.subject());
+ if (values.charset().length() > 0) {
+ mailMessage.setHeader("Content-Type", values.mimeType()
+ + "; charset=\"" + values.charset() + "\"");
+ } else {
+ mailMessage.setHeader("Content-Type", values.mimeType());
+ }
+
PrintStream ps = mailMessage.getPrintStream();
ps.println(message);
@@ -301,7 +323,6 @@
* @param message mail body
*/
private void sendMimeMail(Project project, Values values, String message) {
- // convert the replyTo string into a vector of emailaddresses
Mailer mailer = null;
try {
mailer = (Mailer) ClasspathUtils.newInstance(
@@ -312,6 +333,7 @@
log("Failed to initialise MIME mail: " + t.getMessage());
return;
}
+ // convert the replyTo string into a vector of emailaddresses
Vector replyToList = vectorizeEmailAddresses(values.replytoList());
mailer.setHost(values.mailhost());
mailer.setPort(values.port());
@@ -320,6 +342,10 @@
mailer.setSSL(values.ssl());
Message mymessage = new Message(message);
mymessage.setProject(project);
+ mymessage.setMimeType(values.mimeType());
+ if (values.charset().length() > 0) {
+ mymessage.setCharset(values.charset());
+ }
mailer.setMessage(mymessage);
mailer.setFrom(new EmailAddress(values.from()));
mailer.setReplyToList(replyToList);