Browse Source

bug 7552 audit of <mail> - reset internal state.

Cosmetics.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272393 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
b5b99c769a
10 changed files with 178 additions and 95 deletions
  1. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/LoadFile.java
  2. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
  3. +2
    -0
      src/main/org/apache/tools/ant/taskdefs/SendEmail.java
  4. +14
    -8
      src/main/org/apache/tools/ant/taskdefs/email/EmailAddress.java
  5. +81
    -42
      src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
  6. +26
    -14
      src/main/org/apache/tools/ant/taskdefs/email/Mailer.java
  7. +20
    -11
      src/main/org/apache/tools/ant/taskdefs/email/Message.java
  8. +17
    -10
      src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java
  9. +9
    -5
      src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java
  10. +4
    -3
      src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java

+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/LoadFile.java View File

@@ -72,6 +72,7 @@ import java.util.Vector;
* *
* @author Steve Loughran * @author Steve Loughran
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
* @since Ant 1.5
* @ant.task category="utility" * @ant.task category="utility"
*/ */
public final class LoadFile extends Task { public final class LoadFile extends Task {
@@ -103,7 +104,7 @@ public final class LoadFile extends Task {
private final Vector filterChains = new Vector(); private final Vector filterChains = new Vector();


/** /**
* Encoding to use for filenames, defaults to the platform's default
* Encoding to use for input, defaults to the platform's default
* encoding. <p> * encoding. <p>
* *
* For a list of possible values see <a href="http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html"> * For a list of possible values see <a href="http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html">
@@ -192,7 +193,8 @@ public final class LoadFile extends Task {


if (text != null) { if (text != null) {
project.setNewProperty(property, text); project.setNewProperty(property, text);
log("loaded " + text.length() + " characters",Project.MSG_VERBOSE);
log("loaded " + text.length() + " characters",
Project.MSG_VERBOSE);
log(property+" := "+text,Project.MSG_DEBUG); log(property+" := "+text,Project.MSG_DEBUG);
} }




+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/LoadProperties.java View File

@@ -73,6 +73,7 @@ import java.util.Vector;
* Load a file's contents as Ant Properties. * Load a file's contents as Ant Properties.
* *
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
* @since Ant 1.5
* @ant.task category="utility" * @ant.task category="utility"
*/ */
public final class LoadProperties extends Task { public final class LoadProperties extends Task {


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

@@ -106,6 +106,8 @@ import org.apache.tools.ant.taskdefs.email.EmailTask;
* @author glenn_twiggs@bmc.com * @author glenn_twiggs@bmc.com
* @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a> * @author <a href="mailto:umagesh@rediffmail.com">Magesh Umasankar</a>
* *
* @since Ant 1.2
*
* @ant.task name="mail" category="network" * @ant.task name="mail" category="network"
*/ */
public class SendEmail extends EmailTask public class SendEmail extends EmailTask


+ 14
- 8
src/main/org/apache/tools/ant/taskdefs/email/EmailAddress.java View File

@@ -57,7 +57,7 @@ package org.apache.tools.ant.taskdefs.email;
* Holds an email address. * Holds an email address.
* *
* @author roxspring@yahoo.com Rob Oxspring * @author roxspring@yahoo.com Rob Oxspring
* @since 1.5
* @since Ant 1.5
*/ */
public class EmailAddress public class EmailAddress
{ {
@@ -70,7 +70,8 @@ public class EmailAddress
{ {
} }


/** Creates a new email address based on the given string
/**
* Creates a new email address based on the given string
* @param address the email address * @param address the email address
*/ */
public EmailAddress( String address ) public EmailAddress( String address )
@@ -78,7 +79,8 @@ public class EmailAddress
this.address = address; this.address = address;
} }


/** sets the personal / display name of the address
/**
* Sets the personal / display name of the address
* @param name the display name * @param name the display name
*/ */
public void setName( String name ) public void setName( String name )
@@ -86,7 +88,8 @@ public class EmailAddress
this.name = name; this.name = name;
} }


/** sets the email address
/**
* Sets the email address
* @param address the actual email address * @param address the actual email address
*/ */
public void setAddress( String address ) public void setAddress( String address )
@@ -94,7 +97,8 @@ public class EmailAddress
this.address = address; this.address = address;
} }


/** Constructs a string "name &lt;address&gt;" or "address"
/**
* Constructs a string "name &lt;address&gt;" or "address"
* @return a string representation of the address * @return a string representation of the address
*/ */
public String toString() public String toString()
@@ -109,7 +113,8 @@ public class EmailAddress
} }
} }


/** returns the address
/**
* Returns the address
* @return the address part * @return the address part
*/ */
public String getAddress() public String getAddress()
@@ -117,11 +122,12 @@ public class EmailAddress
return address; return address;
} }


/** returns the display name
/**
* Returns the display name
* @return the display name part * @return the display name part
*/ */
public String getName() public String getName()
{ {
return name; return name;
} }
}
}

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

@@ -67,8 +67,8 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;


/** /**
* A task to send SMTP email. This is a refactoring of the SendMail and MimeMail
* tasks such that both are within a single task.
* A task to send SMTP email. This is a refactoring of the SendMail
* and MimeMail tasks such that both are within a single task.
* *
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
* @author glenn_twiggs@bmc.com * @author glenn_twiggs@bmc.com
@@ -76,7 +76,7 @@ import org.apache.tools.ant.types.FileSet;
* @author ehatcher@apache.org Erik Hatcher * @author ehatcher@apache.org Erik Hatcher
* @author paulo.gaspar@krankikom.de Paulo Gaspar * @author paulo.gaspar@krankikom.de Paulo Gaspar
* @author roxspring@yahoo.com Rob Oxspring * @author roxspring@yahoo.com Rob Oxspring
* @since 1.5
* @since Ant 1.5
* *
* @ant.task name="mail" category="network" * @ant.task name="mail" category="network"
*/ */
@@ -152,7 +152,8 @@ public class EmailTask
private Vector files = new Vector(); private Vector files = new Vector();
private Vector filesets = new Vector(); private Vector filesets = new Vector();


/** Allows the build writer to choose the preferred encoding method
/**
* Allows the build writer to choose the preferred encoding method
* @param encoding The encoding (one of AUTO,MIME,UU,PLAIN) * @param encoding The encoding (one of AUTO,MIME,UU,PLAIN)
*/ */
public void setEncoding( Encoding encoding ) public void setEncoding( Encoding encoding )
@@ -160,7 +161,8 @@ public class EmailTask
this.encoding = encoding.getValue(); this.encoding = encoding.getValue();
} }


/** Sets the mail server port
/**
* Sets the mail server port
* @param port The port to use * @param port The port to use
*/ */
public void setMailport( int port ) public void setMailport( int port )
@@ -168,7 +170,8 @@ public class EmailTask
this.port = port; this.port = port;
} }


/** Sets the host
/**
* Sets the host
* @param host The host to connect to * @param host The host to connect to
*/ */
public void setMailhost( String host ) public void setMailhost( String host )
@@ -176,7 +179,8 @@ public class EmailTask
this.host = host; this.host = host;
} }


/** Sets the subject line of the email
/**
* Sets the subject line of the email
* *
* @param subject Subject of this email. * @param subject Subject of this email.
*/ */
@@ -185,34 +189,39 @@ public class EmailTask
this.subject = subject; this.subject = subject;
} }


/** Shorthand method to set the message
/**
* Shorthand method to set the message
* @param message Message body of this email. * @param message Message body of this email.
*/ */
public void setMessage( String message ) public void setMessage( String message )
{ {
if( this.message != null ) if( this.message != null )
{ {
throw new BuildException( "Only one message can be sent in an email" );
throw new BuildException( "Only one message can be sent in an "
+ "email" );
} }


this.message = new Message( message ); this.message = new Message( message );
} }


/** Shorthand method to set the message from a file
/**
* Shorthand method to set the message from a file
* @param file The file from which to take the message * @param file The file from which to take the message
*/ */
public void setMessageFile( File file ) public void setMessageFile( File file )
{ {
if( this.message != null ) if( this.message != null )
{ {
throw new BuildException( "Only one message can be sent in an email" );
throw new BuildException( "Only one message can be sent in an "
+ "email" );
} }


this.message = new Message( file ); this.message = new Message( file );
} }


/** Shorthand method to set type of the text message, text/plain by default but text/html
* or text/xml is quite feasible.
/**
* Shorthand method to set type of the text message, text/plain by
* default but text/html or text/xml is quite feasible.
* *
* @param type The new MessageMimeType value * @param type The new MessageMimeType value
*/ */
@@ -221,7 +230,8 @@ public class EmailTask
this.messageMimeType = type; this.messageMimeType = type;
} }


/** Add a message elemnt
/**
* Add a message elemnt
* @param message The message object * @param message The message object
* @throws BuildException if a message has already been added * @throws BuildException if a message has already been added
*/ */
@@ -230,13 +240,15 @@ public class EmailTask
{ {
if( this.message != null ) if( this.message != null )
{ {
throw new BuildException( "Only one message can be sent in an email" );
throw new BuildException( "Only one message can be sent in an "
+ "email" );
} }


this.message = message; this.message = message;
} }


/** Adds a from address element
/**
* Adds a from address element
* @param address The address to send from * @param address The address to send from
*/ */
public void addFrom( EmailAddress address ) public void addFrom( EmailAddress address )
@@ -249,7 +261,8 @@ public class EmailTask
this.from = address; this.from = address;
} }


/** Shorthand to set the from address element
/**
* Shorthand to set the from address element
* *
* @param address The address to send mail from * @param address The address to send mail from
*/ */
@@ -263,7 +276,8 @@ public class EmailTask
this.from = new EmailAddress( address ); this.from = new EmailAddress( address );
} }


/** Adds a to address element
/**
* Adds a to address element
* @param address An email address * @param address An email address
*/ */
public void addTo( EmailAddress address ) public void addTo( EmailAddress address )
@@ -271,8 +285,8 @@ public class EmailTask
toList.addElement( address ); toList.addElement( address );
} }


/** Adds "to" address elements
*
/**
* Adds "to" address elements
* *
* @param list Comma separated list of addresses * @param list Comma separated list of addresses
*/ */
@@ -286,7 +300,8 @@ public class EmailTask
} }
} }


/** Adds "cc" address element
/**
* Adds "cc" address element
* @param address The email address * @param address The email address
*/ */
public void addCc( EmailAddress address ) public void addCc( EmailAddress address )
@@ -294,8 +309,8 @@ public class EmailTask
ccList.addElement( address ); ccList.addElement( address );
} }


/** Adds "cc" address elements
*
/**
* Adds "cc" address elements
* *
* @param list Comma separated list of addresses * @param list Comma separated list of addresses
*/ */
@@ -309,7 +324,8 @@ public class EmailTask
} }
} }


/** Adds "bcc" address elements
/**
* Adds "bcc" address elements
* @param address The email address * @param address The email address
*/ */
public void addBcc( EmailAddress address ) public void addBcc( EmailAddress address )
@@ -317,8 +333,8 @@ public class EmailTask
bccList.addElement( address ); bccList.addElement( address );
} }


/** Adds "bcc" address elements
*
/**
* Adds "bcc" address elements
* *
* @param list comma separated list of addresses * @param list comma separated list of addresses
*/ */
@@ -332,7 +348,8 @@ public class EmailTask
} }
} }


/** Indicates whether BuildExceptions should be passed back to the core
/**
* Indicates whether BuildExceptions should be passed back to the core
* *
* @param failOnError The new FailOnError value * @param failOnError The new FailOnError value
*/ */
@@ -341,7 +358,8 @@ public class EmailTask
this.failOnError = failOnError; this.failOnError = failOnError;
} }


/** Adds a list of files to be attached
/**
* Adds a list of files to be attached
* *
* @param filenames Comma separated list of files * @param filenames Comma separated list of files
*/ */
@@ -355,7 +373,8 @@ public class EmailTask
} }
} }


/** Adds a set of files (nested fileset attribute).
/**
* Adds a set of files (nested fileset attribute).
* @param fs The fileset * @param fs The fileset
*/ */
public void addFileset( FileSet fs ) public void addFileset( FileSet fs )
@@ -363,16 +382,19 @@ public class EmailTask
filesets.addElement( fs ); filesets.addElement( fs );
} }


/** Sets Includefilenames attribute
/**
* Sets Includefilenames attribute
* *
* @param includeFileNames Whether to include filenames in the text of the message
* @param includeFileNames Whether to include filenames in the
* text of the message
*/ */
public void setIncludefilenames( boolean includeFileNames ) public void setIncludefilenames( boolean includeFileNames )
{ {
this.includeFileNames = includeFileNames; this.includeFileNames = includeFileNames;
} }


/** Identifies whether file names should be included
/**
* Identifies whether file names should be included
* @return Identifies whether file names should be included * @return Identifies whether file names should be included
*/ */
public boolean getIncludeFileNames() public boolean getIncludeFileNames()
@@ -380,10 +402,13 @@ public class EmailTask
return includeFileNames; return includeFileNames;
} }


/** Sends an email
/**
* Sends an email
*/ */
public void execute() public void execute()
{ {
Message savedMessage = message;
Vector savedFiles = (Vector) files.clone();
try try
{ {
Mailer mailer = null; Mailer mailer = null;
@@ -392,11 +417,14 @@ public class EmailTask
boolean autoFound = false; boolean autoFound = false;


// try MIME format // try MIME format
if( encoding.equals( MIME ) || ( encoding.equals( AUTO ) && !autoFound ) )
if( encoding.equals( MIME )
|| ( encoding.equals( AUTO ) && !autoFound ) )
{ {
try try
{ {
mailer = (Mailer)Class.forName( "org.apache.tools.ant.taskdefs.email.MimeMailer" ).newInstance();
mailer =
(Mailer) Class.forName( "org.apache.tools.ant.taskdefs.email.MimeMailer" )
.newInstance();
autoFound = true; autoFound = true;
log( "Using MIME mail", Project.MSG_VERBOSE ); log( "Using MIME mail", Project.MSG_VERBOSE );
} }
@@ -407,11 +435,14 @@ public class EmailTask
} }


// try UU format // try UU format
if( encoding.equals( UU ) || ( encoding.equals( AUTO ) && !autoFound ) )
if( encoding.equals( UU )
|| ( encoding.equals( AUTO ) && !autoFound ) )
{ {
try try
{ {
mailer = (Mailer)Class.forName( "org.apache.tools.ant.taskdefs.email.UUMailer" ).newInstance();
mailer =
(Mailer)Class.forName( "org.apache.tools.ant.taskdefs.email.UUMailer" )
.newInstance();
autoFound = true; autoFound = true;
log( "Using UU mail", Project.MSG_VERBOSE ); log( "Using UU mail", Project.MSG_VERBOSE );
} }
@@ -422,7 +453,8 @@ public class EmailTask
} }


// try plain format // try plain format
if( encoding.equals( PLAIN ) || ( encoding.equals( AUTO ) && !autoFound ) )
if( encoding.equals( PLAIN )
|| ( encoding.equals( AUTO ) && !autoFound ) )
{ {
mailer = new PlainMailer(); mailer = new PlainMailer();
autoFound = true; autoFound = true;
@@ -432,7 +464,8 @@ public class EmailTask
// a valid mailer must be present by now // a valid mailer must be present by now
if( mailer == null ) if( mailer == null )
{ {
throw new BuildException( "Failed to initialise encoding: " + encoding );
throw new BuildException( "Failed to initialise encoding: "
+ encoding );
} }


// a valid message is required // a valid message is required
@@ -450,7 +483,8 @@ public class EmailTask
// at least one address to send to/cc/bcc is required // at least one address to send to/cc/bcc is required
if( toList.isEmpty() && ccList.isEmpty() && bccList.isEmpty() ) if( toList.isEmpty() && ccList.isEmpty() && bccList.isEmpty() )
{ {
throw new BuildException( "At least one of to,cc or bcc must be supplied" );
throw new BuildException( "At least one of to,cc or bcc must "
+ "be supplied" );
} }


// set the mimetype if not done already (and required) // set the mimetype if not done already (and required)
@@ -458,7 +492,8 @@ public class EmailTask
{ {
if( message.isMimeTypeSpecified() ) if( message.isMimeTypeSpecified() )
{ {
throw new BuildException( "The mime type can only be specified in one location" );
throw new BuildException( "The mime type can only be "
+ "specified in one location" );
} }
else else
{ {
@@ -508,7 +543,8 @@ public class EmailTask


// let the user know what happened // let the user know what happened
int count = files.size(); int count = files.size();
log( "Sent email with " + count + " attachment" + ( count == 1?"":"s" ), Project.MSG_INFO );
log( "Sent email with " + count + " attachment"
+ ( count == 1?"":"s" ), Project.MSG_INFO );
} }
catch( BuildException e ) catch( BuildException e )
{ {
@@ -517,6 +553,9 @@ public class EmailTask
{ {
throw e; throw e;
} }
} finally {
message = savedMessage;
files = savedFiles;
} }
} }
} }


+ 26
- 14
src/main/org/apache/tools/ant/taskdefs/email/Mailer.java View File

@@ -61,7 +61,7 @@ import org.apache.tools.ant.Task;
* Base class for the various emailing implementations. * Base class for the various emailing implementations.
* *
* @author roxspring@yahoo.com Rob Oxspring * @author roxspring@yahoo.com Rob Oxspring
* @since 1.5
* @since Ant 1.5
*/ */
abstract class Mailer abstract class Mailer
{ {
@@ -77,7 +77,8 @@ abstract class Mailer
protected Task task; protected Task task;
protected boolean includeFileNames = false; protected boolean includeFileNames = false;


/** sets the mail server
/**
* Sets the mail server
* @param host * @param host
*/ */
public void setHost( String host ) public void setHost( String host )
@@ -85,7 +86,8 @@ abstract class Mailer
this.host = host; this.host = host;
} }


/** sets the smtp port
/**
* Sets the smtp port
* @param port * @param port
*/ */
public void setPort( int port ) public void setPort( int port )
@@ -93,7 +95,8 @@ abstract class Mailer
this.port = port; this.port = port;
} }


/** sets the message
/**
* Sets the message
* @param m * @param m
*/ */
public void setMessage( Message m ) public void setMessage( Message m )
@@ -101,7 +104,8 @@ abstract class Mailer
this.message = m; this.message = m;
} }


/** sets the address to send from
/**
* Sets the address to send from
* @param from * @param from
*/ */
public void setFrom( EmailAddress from ) public void setFrom( EmailAddress from )
@@ -109,7 +113,8 @@ abstract class Mailer
this.from = from; this.from = from;
} }


/** set the to addresses
/**
* Set the to addresses
* @param list * @param list
*/ */
public void setToList( Vector list ) public void setToList( Vector list )
@@ -117,7 +122,8 @@ abstract class Mailer
this.toList = list; this.toList = list;
} }


/** sets the cc addresses
/**
* Sets the cc addresses
* @param list * @param list
*/ */
public void setCcList( Vector list ) public void setCcList( Vector list )
@@ -125,7 +131,8 @@ abstract class Mailer
this.ccList = list; this.ccList = list;
} }


/** sets the bcc addresses
/**
* Sets the bcc addresses
* @param list * @param list
*/ */
public void setBccList( Vector list ) public void setBccList( Vector list )
@@ -133,7 +140,8 @@ abstract class Mailer
this.bccList = list; this.bccList = list;
} }


/** sets the files to attach
/**
* Sets the files to attach
* @param files * @param files
*/ */
public void setFiles( Vector files ) public void setFiles( Vector files )
@@ -141,7 +149,8 @@ abstract class Mailer
this.files = files; this.files = files;
} }


/** sets the subject
/**
* Sets the subject
* @param subject * @param subject
*/ */
public void setSubject( String subject ) public void setSubject( String subject )
@@ -149,7 +158,8 @@ abstract class Mailer
this.subject = subject; this.subject = subject;
} }


/** sets the owning task
/**
* Sets the owning task
* @param task * @param task
*/ */
public void setTask( Task task ) public void setTask( Task task )
@@ -157,7 +167,8 @@ abstract class Mailer
this.task = task; this.task = task;
} }


/** indicates whether filenames should be listed in the body
/**
* Indicates whether filenames should be listed in the body
* @param b * @param b
*/ */
public void setIncludeFileNames( boolean b ) public void setIncludeFileNames( boolean b )
@@ -165,9 +176,10 @@ abstract class Mailer
this.includeFileNames = b; this.includeFileNames = b;
} }


/** This method should send the email
/**
* This method should send the email
* @throws BuildException * @throws BuildException
*/ */
public abstract void send() public abstract void send()
throws BuildException; throws BuildException;
}
}

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

@@ -63,7 +63,7 @@ import java.io.PrintStream;
* Class representing an email message. * Class representing an email message.
* *
* @author roxspring@yahoo.com Rob Oxspring * @author roxspring@yahoo.com Rob Oxspring
* @since 1.5
* @since Ant 1.5
*/ */
public class Message public class Message
{ {
@@ -72,13 +72,15 @@ public class Message
private String mimeType = "text/plain"; private String mimeType = "text/plain";
private boolean specified = false; private boolean specified = false;


/** creates a new empty message
/**
* Creates a new empty message
*/ */
public Message() public Message()
{ {
} }


/** Creates a new message based on the given string
/**
* Creates a new message based on the given string
* @param text the message * @param text the message
*/ */
public Message( String text ) public Message( String text )
@@ -86,7 +88,8 @@ public class Message
addText( text ); addText( text );
} }


/** Creates a new message using the contents of the given file.
/**
* Creates a new message using the contents of the given file.
* @param file the source of the message * @param file the source of the message
*/ */
public Message( File file ) public Message( File file )
@@ -94,7 +97,8 @@ public class Message
messageSource = file; messageSource = file;
} }


/** Adds a textual part of the message
/**
* Adds a textual part of the message
* @param text some text to add * @param text some text to add
*/ */
public void addText( String text ) public void addText( String text )
@@ -102,7 +106,8 @@ public class Message
buffer.append( text ); buffer.append( text );
} }


/** Sets the source file of the message
/**
* Sets the source file of the message
* @param src the source of the message * @param src the source of the message
*/ */
public void setSrc( File src ) public void setSrc( File src )
@@ -110,7 +115,8 @@ public class Message
this.messageSource = src; this.messageSource = src;
} }


/** Sets the content type for the message
/**
* Sets the content type for the message
* @param mimeType a mime type e.g. "text/plain" * @param mimeType a mime type e.g. "text/plain"
*/ */
public void setMimeType( String mimeType ) public void setMimeType( String mimeType )
@@ -119,7 +125,8 @@ public class Message
specified = true; specified = true;
} }


/** Returns the content type
/**
* Returns the content type
* @return the mime type * @return the mime type
*/ */
public String getMimeType() public String getMimeType()
@@ -127,7 +134,8 @@ public class Message
return mimeType; return mimeType;
} }


/** prints the message onto an output stream
/**
* Prints the message onto an output stream
* @param out The print stream to write to * @param out The print stream to write to
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
@@ -158,11 +166,12 @@ public class Message
} }
} }


/** returns true iff the mimeType has been set.
/**
* Returns true iff the mimeType has been set.
* @return false if the default value is in use * @return false if the default value is in use
*/ */
public boolean isMimeTypeSpecified() public boolean isMimeTypeSpecified()
{ {
return specified; return specified;
} }
}
}

+ 17
- 10
src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java View File

@@ -78,7 +78,7 @@ import org.apache.tools.ant.BuildException;
* Uses the JavaMail classes to send Mime format email. * Uses the JavaMail classes to send Mime format email.
* *
* @author roxspring@yahoo.com Rob Oxspring * @author roxspring@yahoo.com Rob Oxspring
* @since 1.5
* @since Ant 1.5
*/ */
class MimeMailer class MimeMailer
extends Mailer extends Mailer
@@ -93,8 +93,9 @@ class MimeMailer
props.put( "mail.smtp.host", host ); props.put( "mail.smtp.host", host );
props.put( "mail.smtp.port", String.valueOf( port ) ); props.put( "mail.smtp.port", String.valueOf( port ) );


//Aside, the JDK is clearly unaware of the scottish 'session', which
//involves excessive quantities of alcohol :-)
// Aside, the JDK is clearly unaware of the scottish
// 'session', which //involves excessive quantities of
// alcohol :-)
Session sesh = Session.getDefaultInstance( props, null ); Session sesh = Session.getDefaultInstance( props, null );


//create the message //create the message
@@ -108,12 +109,16 @@ class MimeMailer
} }
else else
{ {
msg.setFrom( new InternetAddress( from.getAddress(), from.getName() ) );
msg.setFrom( new InternetAddress( from.getAddress(),
from.getName() ) );
} }


msg.setRecipients( Message.RecipientType.TO, internetAddresses( toList ) );
msg.setRecipients( Message.RecipientType.CC, internetAddresses( ccList ) );
msg.setRecipients( Message.RecipientType.BCC, internetAddresses( bccList ) );
msg.setRecipients( Message.RecipientType.TO,
internetAddresses( toList ) );
msg.setRecipients( Message.RecipientType.CC,
internetAddresses( ccList ) );
msg.setRecipients( Message.RecipientType.BCC,
internetAddresses( bccList ) );


if( subject != null ) if( subject != null )
{ {
@@ -139,7 +144,8 @@ class MimeMailer
if( !file.exists() || !file.canRead() ) if( !file.exists() || !file.canRead() )
{ {
throw new BuildException( "File \"" + file.getAbsolutePath() throw new BuildException( "File \"" + file.getAbsolutePath()
+ "\" does not exist or is not readable." );
+ "\" does not exist or is not "
+ "readable." );
} }
FileDataSource fileData = new FileDataSource( file ); FileDataSource fileData = new FileDataSource( file );
DataHandler fileDataHandler = new DataHandler( fileData ); DataHandler fileDataHandler = new DataHandler( fileData );
@@ -175,10 +181,11 @@ class MimeMailer
} }
else else
{ {
addrs[ i ] = new InternetAddress( addr.getAddress(), addr.getName() );
addrs[ i ] = new InternetAddress( addr.getAddress(),
addr.getName() );
} }
} }


return addrs; return addrs;
} }
}
}

+ 9
- 5
src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java View File

@@ -66,12 +66,14 @@ import org.apache.tools.mail.MailMessage;
* Class responsible for sending email through raw protocol methods. * Class responsible for sending email through raw protocol methods.
* *
* @author roxspring@yahoo.com Rob Oxspring * @author roxspring@yahoo.com Rob Oxspring
* @since 1.5
* @since Ant 1.5
*/ */
class PlainMailer class PlainMailer
extends Mailer extends Mailer
{ {
/** Sends the email using the apache {@link org.apache.tools.mail.MailMessage MailMessage} class.
/**
* Sends the email using the apache MailMessage class.
* @see org.apache.tools.mail.MailMessage
*/ */
public void send() public void send()
{ {
@@ -129,7 +131,8 @@ class PlainMailer


} }


/** Attaches a file to this email
/**
* Attaches a file to this email
* @param file The file to attache * @param file The file to attache
* @param out The message stream to add to * @param out The message stream to add to
* @throws IOException if errors occur * @throws IOException if errors occur
@@ -140,7 +143,8 @@ class PlainMailer
if( !file.exists() || !file.canRead() ) if( !file.exists() || !file.canRead() )
{ {
throw new BuildException( "File \"" + file.getName() throw new BuildException( "File \"" + file.getName()
+ "\" does not exist or is not readable." );
+ "\" does not exist or is not "
+ "readable." );
} }


if( includeFileNames ) if( includeFileNames )
@@ -172,4 +176,4 @@ class PlainMailer
finstr.close(); finstr.close();
} }
} }
}
}

+ 4
- 3
src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java View File

@@ -65,7 +65,7 @@ import sun.misc.UUEncoder;
* An emailer that uuencodes attachments. * An emailer that uuencodes attachments.
* *
* @author roxspring@yahoo.com Rob Oxspring * @author roxspring@yahoo.com Rob Oxspring
* @since 1.5
* @since Ant 1.5
*/ */
class UUMailer class UUMailer
extends PlainMailer extends PlainMailer
@@ -76,7 +76,8 @@ class UUMailer
if( !file.exists() || !file.canRead() ) if( !file.exists() || !file.canRead() )
{ {
throw new BuildException( "File \"" + file.getName() throw new BuildException( "File \"" + file.getName()
+ "\" does not exist or is not readable." );
+ "\" does not exist or is not "
+ "readable." );
} }


FileInputStream finstr = new FileInputStream( file ); FileInputStream finstr = new FileInputStream( file );
@@ -92,4 +93,4 @@ class UUMailer
finstr.close(); finstr.close();
} }
} }
}
}

Loading…
Cancel
Save