git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1577617 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -124,6 +124,11 @@ Other changes: | |||||
| Bugzilla Report 55667 | Bugzilla Report 55667 | ||||
| Bugzilla Report 56156 | 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 | Changes from Ant 1.9.2 TO Ant 1.9.3 | ||||
| =================================== | =================================== | ||||
| @@ -98,7 +98,19 @@ | |||||
| <td valign="top">File to send as the body of the email. Property | <td valign="top">File to send as the body of the email. Property | ||||
| values in the file will be expanded.</td> | values in the file will be expanded.</td> | ||||
| </tr> | </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 | <td valign="top">The content type of the message. The default is | ||||
| <code>text/plain</code>.</td> | <code>text/plain</code>.</td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| @@ -253,6 +265,17 @@ attributes:</p> | |||||
| These options are mutually exclusive.</td> | These options are mutually exclusive.</td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </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> | </table> | ||||
| <p>If the <code>src</code> attribute is not specified, then text can be added | <p>If the <code>src</code> attribute is not specified, then text can be added | ||||
| @@ -78,6 +78,7 @@ public class EmailTask extends Task { | |||||
| private boolean failOnError = true; | private boolean failOnError = true; | ||||
| private boolean includeFileNames = false; | private boolean includeFileNames = false; | ||||
| private String messageMimeType = null; | private String messageMimeType = null; | ||||
| private String messageFileInputEncoding; | |||||
| /* special headers */ | /* special headers */ | ||||
| /** sender */ | /** sender */ | ||||
| private EmailAddress from = null; | private EmailAddress from = null; | ||||
| @@ -527,6 +528,7 @@ public class EmailTask extends Task { | |||||
| } | } | ||||
| message.setCharset(charset); | message.setCharset(charset); | ||||
| } | } | ||||
| message.setInputEncoding(messageFileInputEncoding); | |||||
| // identify which files should be attached | // identify which files should be attached | ||||
| Vector<File> files = new Vector<File>(); | Vector<File> files = new Vector<File>(); | ||||
| @@ -601,7 +603,7 @@ public class EmailTask extends Task { | |||||
| /** | /** | ||||
| * Sets the character set of mail message. | * Sets the character set of mail message. | ||||
| * Will be ignored if mimeType contains ....; Charset=... substring or | * 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. | * @param charset the character encoding to use. | ||||
| * @since Ant 1.6 | * @since Ant 1.6 | ||||
| */ | */ | ||||
| @@ -619,5 +621,15 @@ public class EmailTask extends Task { | |||||
| return charset; | 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; | |||||
| } | |||||
| } | } | ||||
| @@ -20,10 +20,13 @@ package org.apache.tools.ant.taskdefs.email; | |||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
| import java.io.BufferedWriter; | import java.io.BufferedWriter; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.FileInputStream; | |||||
| import java.io.FileReader; | import java.io.FileReader; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.InputStreamReader; | |||||
| import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
| import java.io.PrintStream; | import java.io.PrintStream; | ||||
| import java.io.Reader; | |||||
| import org.apache.tools.ant.ProjectComponent; | import org.apache.tools.ant.ProjectComponent; | ||||
| @@ -38,6 +41,7 @@ public class Message extends ProjectComponent { | |||||
| private String mimeType = "text/plain"; | private String mimeType = "text/plain"; | ||||
| private boolean specified = false; | private boolean specified = false; | ||||
| private String charset = null; | private String charset = null; | ||||
| private String inputEncoding; | |||||
| /** Creates a new empty message */ | /** Creates a new empty message */ | ||||
| public Message() { | public Message() { | ||||
| @@ -122,7 +126,7 @@ public class Message extends ProjectComponent { | |||||
| : new BufferedWriter(new OutputStreamWriter(ps)); | : new BufferedWriter(new OutputStreamWriter(ps)); | ||||
| if (messageSource != null) { | if (messageSource != null) { | ||||
| // Read message from a file | // Read message from a file | ||||
| FileReader freader = new FileReader(messageSource); | |||||
| Reader freader = getReader(messageSource); | |||||
| try { | try { | ||||
| BufferedReader in = new BufferedReader(freader); | BufferedReader in = new BufferedReader(freader); | ||||
| @@ -172,5 +176,28 @@ public class Message extends ProjectComponent { | |||||
| public String getCharset() { | public String getCharset() { | ||||
| return charset; | 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); | |||||
| } | |||||
| } | } | ||||