ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1577617 - in /ant/core/trunk: WHATSNEW manual/Tasks/mail.html src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java src/main/org/apache/tools/ant/taskdefs/email/Message.java
Date Fri, 14 Mar 2014 17:28:53 GMT
Author: bodewig
Date: Fri Mar 14 17:28:53 2014
New Revision: 1577617

URL: http://svn.apache.org/r1577617
Log:
add inputencoding to mail's message when read from a file.  PR 56258

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/manual/Tasks/mail.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1577617&r1=1577616&r2=1577617&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Mar 14 17:28:53 2014
@@ -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
 ===================================
 

Modified: ant/core/trunk/manual/Tasks/mail.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/Tasks/mail.html?rev=1577617&r1=1577616&r2=1577617&view=diff
==============================================================================
--- ant/core/trunk/manual/Tasks/mail.html (original)
+++ ant/core/trunk/manual/Tasks/mail.html Fri Mar 14 17:28:53 2014
@@ -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

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java?rev=1577617&r1=1577616&r2=1577617&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java Fri Mar 14
17:28:53 2014
@@ -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;
+    }
+
 }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java?rev=1577617&r1=1577616&r2=1577617&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/Message.java Fri Mar 14 17:28:53
2014
@@ -20,10 +20,13 @@ package org.apache.tools.ant.taskdefs.em
 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 ProjectComp
     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 ProjectComp
                 : 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 ProjectComp
     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);
+    }
 }
 



Mime
View raw message