Browse Source

Add STARTTLS support to MimeMailer and use it in MailLogger and <mail>. Part of PR 46063.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@707368 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
47fda4e266
9 changed files with 71 additions and 3 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +8
    -0
      docs/manual/CoreTasks/mail.html
  5. +6
    -0
      docs/manual/listeners.html
  6. +14
    -1
      src/main/org/apache/tools/ant/listener/MailLogger.java
  7. +16
    -2
      src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
  8. +15
    -0
      src/main/org/apache/tools/ant/taskdefs/email/Mailer.java
  9. +3
    -0
      src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java

+ 1
- 0
CONTRIBUTORS View File

@@ -48,6 +48,7 @@ Conor MacNeill
Craeg Strong
Craig Cottingham
Craig R. McClanahan
Craig Richardson
Craig Ryan
Craig Sandvik
Curtis White


+ 4
- 0
WHATSNEW View File

@@ -482,6 +482,10 @@ Other changes:
<cvschangelog>.
Bugzilla Report 27419.

* MailLogger and <mail> can now optionally enable support for
STARTTLS.
Bugzilla Report 46063.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 4
- 0
contributors.xml View File

@@ -219,6 +219,10 @@
<first>Craig</first>
<last>Ryan</last>
</name>
<name>
<first>Craig</first>
<last>Richardson</last>
</name>
<name>
<first>Craig</first>
<last>Sandvik</last>


+ 8
- 0
docs/manual/CoreTasks/mail.html View File

@@ -179,6 +179,14 @@
fail if neither is reachable. <em>Since Ant 1.8.0</em>.</td>
<td align="center" valign="top">No, default is false</td>
</tr>
<tr>
<td valign="top">enableStartTLS</td>
<td valign="top">"true", "on" or "yes" accepted here<br></br>
whether the STARTTLS command used to switch to an encrypted
connection for authentication should be supported. Requires
JavaMail. <em>Since Ant 1.8.0</em></td>
<td valign="center">No</td>
</tr>
</table>

<h3>Note regarding the attributes containing email addresses</h3>


+ 6
- 0
docs/manual/listeners.html View File

@@ -245,6 +245,12 @@ control for turning off success or failure messages individually.</p>
<td width="63%">Character set of the message. <em>Since Ant 1.8.0</em></td>
<td width="63%">No</td>
</tr>
<tr>
<td width="337">MailLogger.starttls.enable</td>
<td width="63%">on or true if STARTTLS should be supported
(requires JavaMail). <em>Since Ant 1.8.0</em></td>
<td width="63%">No, default is false</td>
</tr>
<tr>
<td width="337">MailLogger.properties.file </td>
<td width="63%">Filename of properties file that will override other values.</td>


+ 14
- 1
src/main/org/apache/tools/ant/listener/MailLogger.java View File

@@ -73,6 +73,8 @@ import org.apache.tools.mail.MailMessage;
* mail body for a successful build, default is to send the logfile</li>
* <li> MailLogger.mimeType [default: text/plain] - MIME-Type of email</li>
* <li> MailLogger.charset [no default] - character set of email</li>
* <li> Maillogger.starttls.enable [default: false] - on or true if
* STARTTLS should be supported (requires JavaMail)</li>
* <li> MailLogger.properties.file [no default] - Filename of
* properties file that will override other values.</li>
* </ul>
@@ -142,6 +144,8 @@ public class MailLogger extends DefaultLogger {
.password(getValue(properties, "password", ""))
.ssl(Project.toBoolean(getValue(properties,
"ssl", "off")))
.starttls(Project.toBoolean(getValue(properties,
"starttls.enable", "off")))
.from(getValue(properties, "from", null))
.replytoList(getValue(properties, "replyto", ""))
.toList(getValue(properties, prefix + ".to", null))
@@ -153,7 +157,7 @@ public class MailLogger extends DefaultLogger {
(success) ? "Build Success" : "Build Failure"));
if (values.user().equals("")
&& values.password().equals("")
&& !values.ssl()) {
&& !values.ssl() && !values.starttls()) {
sendMail(values, buffer.substring(0));
} else {
sendMimeMail(
@@ -262,6 +266,14 @@ public class MailLogger extends DefaultLogger {
this.body = body;
return this;
}
private boolean starttls;
public boolean starttls() {
return starttls;
}
public Values starttls(boolean starttls) {
this.starttls = starttls;
return this;
}
}

/**
@@ -365,6 +377,7 @@ public class MailLogger extends DefaultLogger {
mailer.setUser(values.user());
mailer.setPassword(values.password());
mailer.setSSL(values.ssl());
mailer.setEnableStartTLS(values.ssl());
Message mymessage =
new Message(values.body().length() > 0 ? values.body() : message);
mymessage.setProject(project);


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

@@ -102,6 +102,8 @@ public class EmailTask extends Task {
private String password = null;
/** indicate if the user wishes SSL-TLS */
private boolean ssl = false;
/** indicate if the user wishes support for STARTTLS */
private boolean starttls = false;

/** ignore invalid recipients? */
private boolean ignoreInvalidRecipients = false;
@@ -133,6 +135,16 @@ public class EmailTask extends Task {
this.ssl = ssl;
}

/**
* Set whether to allow authentication to switch to a TLS
* connection via STARTTLS.
* @param b boolean; if true STARTTLS will be supported.
* @since Ant 1.8.0
*/
public void setEnableStartTLS(boolean b) {
this.starttls = b;
}

/**
* Set the preferred encoding method.
*
@@ -454,9 +466,10 @@ public class EmailTask extends Task {
throw new BuildException("SMTP auth only possible with MIME mail");
}
// SSL only allowed with MIME mail
if (!autoFound && (ssl)
if (!autoFound && (ssl || starttls)
&& (encoding.equals(UU) || encoding.equals(PLAIN))) {
throw new BuildException("SSL only possible with MIME mail");
throw new BuildException("SSL and STARTTLS only possible with"
+ " MIME mail");
}
// try UU format
if (encoding.equals(UU)
@@ -537,6 +550,7 @@ public class EmailTask extends Task {
mailer.setUser(user);
mailer.setPassword(password);
mailer.setSSL(ssl);
mailer.setEnableStartTLS(starttls);
mailer.setMessage(message);
mailer.setFrom(from);
mailer.setReplyToList(replyToList);


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

@@ -49,6 +49,7 @@ public abstract class Mailer {
protected Vector headers = null;
// CheckStyle:VisibilityModifier ON
private boolean ignoreInvalidRecipients = false;
private boolean starttls = false;

/**
* Set the mail server.
@@ -98,6 +99,20 @@ public abstract class Mailer {
this.SSL = ssl;
}

/**
* Set whether to allow authentication to switch to a TLS
* connection via STARTTLS.
* @param b boolean; if true STARTTLS will be supported.
* @since Ant 1.8.0
*/
public void setEnableStartTLS(boolean b) {
this.starttls = b;
}

protected boolean isStartTLSEnabled() {
return starttls;
}

/**
* Set the message.
*


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

@@ -161,6 +161,9 @@ public class MimeMailer extends Mailer {
props.put("mail.smtp.auth", "true");
auth = new SimpleAuthenticator(user, password);
}
if (isStartTLSEnabled()) {
props.put("mail.smtp.starttls.enable", "true");
}
sesh = Session.getInstance(props, auth);

//create the message


Loading…
Cancel
Save