Browse Source

Name of file attachments can be optionally included.

PR: 3024


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270111 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
eed192aac1
2 changed files with 35 additions and 3 deletions
  1. +7
    -1
      docs/manual/CoreTasks/mail.html
  2. +28
    -2
      src/main/org/apache/tools/ant/taskdefs/SendEmail.java

+ 7
- 1
docs/manual/CoreTasks/mail.html View File

@@ -40,10 +40,16 @@ body may be specified. To send binary attachments the optional
<td valign="top">Filename(s) of text to send in the body of the email.
Multiple files are comma-separated.</td>
</tr>
<tr>
<td valign="top">includefilenames</td>
<td valign="top">Include filename(s) before file contents.
Valid only when the files attribute is specified.</td>
<td align="center" valign="top">No, default is <I>false</I></td>
</tr>
<tr>
<td valign="top">mailhost</td>
<td valign="top">Host name of the mail server.</td>
<td align="center" valign="top">No, default to &quot;localhost&quot;</td>
<td align="center" valign="top">No, default is &quot;localhost&quot;</td>
</tr>
<tr>
<td valign="top">mailport</td>


+ 28
- 2
src/main/org/apache/tools/ant/taskdefs/SendEmail.java View File

@@ -107,9 +107,15 @@ import org.apache.tools.ant.BuildException;
* <td>Message to send inthe body of the email.</td>
* </tr>
* </table>
* <tr>
* <td>includefilenames</td>
* <td>Includes filenames before file contents when set to true.</td>
* <td>No, default is <I>false</I></td>
* </tr>
* <p>
*
* @author glenn_twiggs@bmc.com
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
*/
public class SendEmail extends Task {
private String from;
@@ -119,6 +125,7 @@ public class SendEmail extends Task {
private String toList;
private String subject;
private Vector files = new Vector();
private boolean includefilenames;
/** Creates new SendEmail */
public SendEmail() {
@@ -190,6 +197,15 @@ public class SendEmail extends Task {
}
}

/**
* Sets Includefilenames attribute
*
* @param includefilenames Set to true if file names are to be included.
*/
public void setIncludefilenames(boolean includefilenames) {
this.includefilenames = includefilenames;
}

/**
* Executes this build task.
*
@@ -230,15 +246,25 @@ public class SendEmail extends Task {
int bufsize = 1024;
int length;
byte[] buf = new byte[bufsize];

if (includefilenames) {
String filename = file.getName();
int filenamelength = filename.length();
out.println(filename);
for (int star=0; star < filenamelength; star++) {
out.print('=');
}
out.println();
}
BufferedInputStream in = null;
try {
in = new BufferedInputStream(
new FileInputStream(file), bufsize);
while ((length = in.read(buf, 0, bufsize)) != -1) {
out.write(buf, 0, length);
}
if (includefilenames) {
out.println();
}
} finally {
if (in != null) {
in.close();


Loading…
Cancel
Save