Browse Source

add inputencoding to mail's message when read from a file. PR 56258

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1577617 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
6e5a68837b
4 changed files with 70 additions and 3 deletions
  1. +5
    -0
      WHATSNEW
  2. +24
    -1
      manual/Tasks/mail.html
  3. +13
    -1
      src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
  4. +28
    -1
      src/main/org/apache/tools/ant/taskdefs/email/Message.java

+ 5
- 0
WHATSNEW View File

@@ -124,6 +124,11 @@ Other changes:
Bugzilla Report 55667
Bugzilla Report 56156

* the nested <message> elements of <mail> now have an optional
inputEncoding attribute that can be used to specify the encoding of
files read that don't use the platform's default encoding.
Bugzilla Report 56258

Changes from Ant 1.9.2 TO Ant 1.9.3
===================================



+ 24
- 1
manual/Tasks/mail.html View File

@@ -98,7 +98,19 @@
<td valign="top">File to send as the body of the email. Property
values in the file will be expanded.</td>
</tr>
<td valign="top">messagemimetype</td>
<tr>
<td valign="top">messagefileinputencoding</td>
<td valign="top">
Specifies the encoding of the input file. Please see
<a href="http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html">
Supported Encodings</a> for a list of possible
values. Defaults to the platform's default character
encoding. <em>Since Ant 1.9.4</em>
</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">messagemimetype</td>
<td valign="top">The content type of the message. The default is
<code>text/plain</code>.</td>
<td align="center" valign="top">No</td>
@@ -253,6 +265,17 @@ attributes:</p>
These options are mutually exclusive.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">inputencoding</td>
<td valign="top">
Specifies the encoding of the input file. Please see
<a href="http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html">
Supported Encodings</a> for a list of possible
values. Defaults to the platform's default character
encoding. <em>Since Ant 1.9.4</em>
</td>
<td valign="top" align="center">No</td>
</tr>
</table>

<p>If the <code>src</code> attribute is not specified, then text can be added


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

@@ -78,6 +78,7 @@ public class EmailTask extends Task {
private boolean failOnError = true;
private boolean includeFileNames = false;
private String messageMimeType = null;
private String messageFileInputEncoding;
/* special headers */
/** sender */
private EmailAddress from = null;
@@ -527,6 +528,7 @@ public class EmailTask extends Task {
}
message.setCharset(charset);
}
message.setInputEncoding(messageFileInputEncoding);

// identify which files should be attached
Vector<File> files = new Vector<File>();
@@ -601,7 +603,7 @@ public class EmailTask extends Task {
/**
* Sets the character set of mail message.
* Will be ignored if mimeType contains ....; Charset=... substring or
* encoding is not a <code>mime</code>.
* encoding is not <code>mime</code>.
* @param charset the character encoding to use.
* @since Ant 1.6
*/
@@ -619,5 +621,15 @@ public class EmailTask extends Task {
return charset;
}

/**
* Sets the encoding to expect when reading the message from a file.
* <p>Will be ignored if the message has been specified inline.</p>
* @param encoding the name of the charset used
* @since Ant 1.9.4
*/
public void setMessageFileInputEncoding(String encoding) {
messageFileInputEncoding = encoding;
}

}


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

@@ -20,10 +20,13 @@ package org.apache.tools.ant.taskdefs.email;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Reader;

import org.apache.tools.ant.ProjectComponent;

@@ -38,6 +41,7 @@ public class Message extends ProjectComponent {
private String mimeType = "text/plain";
private boolean specified = false;
private String charset = null;
private String inputEncoding;

/** Creates a new empty message */
public Message() {
@@ -122,7 +126,7 @@ public class Message extends ProjectComponent {
: new BufferedWriter(new OutputStreamWriter(ps));
if (messageSource != null) {
// Read message from a file
FileReader freader = new FileReader(messageSource);
Reader freader = getReader(messageSource);

try {
BufferedReader in = new BufferedReader(freader);
@@ -172,5 +176,28 @@ public class Message extends ProjectComponent {
public String getCharset() {
return charset;
}

/**
* Sets the encoding to expect when reading the message from a file.
* <p>Will be ignored if the message has been specified inline.</p>
* @param encoding the name of the charset used
* @since Ant 1.9.4
*/
public void setInputEncoding(String encoding) {
this.inputEncoding = encoding;
}

private Reader getReader(File f) throws IOException {
if (inputEncoding != null) {
FileInputStream fis = new FileInputStream(f);
try {
return new InputStreamReader(fis, inputEncoding);
} catch (IOException ex) {
fis.close();
throw ex;
}
}
return new FileReader(f);
}
}


Loading…
Cancel
Save