mirror of
https://github.com/apache/ant.git
synced 2025-05-14 12:11:29 +00:00
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
This commit is contained in:
parent
b35a59d116
commit
47fda4e266
@ -48,6 +48,7 @@ Conor MacNeill
|
|||||||
Craeg Strong
|
Craeg Strong
|
||||||
Craig Cottingham
|
Craig Cottingham
|
||||||
Craig R. McClanahan
|
Craig R. McClanahan
|
||||||
|
Craig Richardson
|
||||||
Craig Ryan
|
Craig Ryan
|
||||||
Craig Sandvik
|
Craig Sandvik
|
||||||
Curtis White
|
Curtis White
|
||||||
|
4
WHATSNEW
4
WHATSNEW
@ -482,6 +482,10 @@ Other changes:
|
|||||||
<cvschangelog>.
|
<cvschangelog>.
|
||||||
Bugzilla Report 27419.
|
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
|
Changes from Ant 1.7.0 TO Ant 1.7.1
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
|
@ -219,6 +219,10 @@
|
|||||||
<first>Craig</first>
|
<first>Craig</first>
|
||||||
<last>Ryan</last>
|
<last>Ryan</last>
|
||||||
</name>
|
</name>
|
||||||
|
<name>
|
||||||
|
<first>Craig</first>
|
||||||
|
<last>Richardson</last>
|
||||||
|
</name>
|
||||||
<name>
|
<name>
|
||||||
<first>Craig</first>
|
<first>Craig</first>
|
||||||
<last>Sandvik</last>
|
<last>Sandvik</last>
|
||||||
|
@ -179,6 +179,14 @@ <h3>Parameters</h3>
|
|||||||
fail if neither is reachable. <em>Since Ant 1.8.0</em>.</td>
|
fail if neither is reachable. <em>Since Ant 1.8.0</em>.</td>
|
||||||
<td align="center" valign="top">No, default is false</td>
|
<td align="center" valign="top">No, default is false</td>
|
||||||
</tr>
|
</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>
|
</table>
|
||||||
|
|
||||||
<h3>Note regarding the attributes containing email addresses</h3>
|
<h3>Note regarding the attributes containing email addresses</h3>
|
||||||
|
@ -245,6 +245,12 @@ <h3><a name="MailLogger">MailLogger</a></h3>
|
|||||||
<td width="63%">Character set of the message. <em>Since Ant 1.8.0</em></td>
|
<td width="63%">Character set of the message. <em>Since Ant 1.8.0</em></td>
|
||||||
<td width="63%">No</td>
|
<td width="63%">No</td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td width="337">MailLogger.properties.file </td>
|
<td width="337">MailLogger.properties.file </td>
|
||||||
<td width="63%">Filename of properties file that will override other values.</td>
|
<td width="63%">Filename of properties file that will override other values.</td>
|
||||||
|
@ -73,6 +73,8 @@ import org.apache.tools.mail.MailMessage;
|
|||||||
* mail body for a successful build, default is to send the logfile</li>
|
* 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.mimeType [default: text/plain] - MIME-Type of email</li>
|
||||||
* <li> MailLogger.charset [no default] - character set 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
|
* <li> MailLogger.properties.file [no default] - Filename of
|
||||||
* properties file that will override other values.</li>
|
* properties file that will override other values.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
@ -142,6 +144,8 @@ public class MailLogger extends DefaultLogger {
|
|||||||
.password(getValue(properties, "password", ""))
|
.password(getValue(properties, "password", ""))
|
||||||
.ssl(Project.toBoolean(getValue(properties,
|
.ssl(Project.toBoolean(getValue(properties,
|
||||||
"ssl", "off")))
|
"ssl", "off")))
|
||||||
|
.starttls(Project.toBoolean(getValue(properties,
|
||||||
|
"starttls.enable", "off")))
|
||||||
.from(getValue(properties, "from", null))
|
.from(getValue(properties, "from", null))
|
||||||
.replytoList(getValue(properties, "replyto", ""))
|
.replytoList(getValue(properties, "replyto", ""))
|
||||||
.toList(getValue(properties, prefix + ".to", null))
|
.toList(getValue(properties, prefix + ".to", null))
|
||||||
@ -153,7 +157,7 @@ public class MailLogger extends DefaultLogger {
|
|||||||
(success) ? "Build Success" : "Build Failure"));
|
(success) ? "Build Success" : "Build Failure"));
|
||||||
if (values.user().equals("")
|
if (values.user().equals("")
|
||||||
&& values.password().equals("")
|
&& values.password().equals("")
|
||||||
&& !values.ssl()) {
|
&& !values.ssl() && !values.starttls()) {
|
||||||
sendMail(values, buffer.substring(0));
|
sendMail(values, buffer.substring(0));
|
||||||
} else {
|
} else {
|
||||||
sendMimeMail(
|
sendMimeMail(
|
||||||
@ -262,6 +266,14 @@ public class MailLogger extends DefaultLogger {
|
|||||||
this.body = body;
|
this.body = body;
|
||||||
return this;
|
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.setUser(values.user());
|
||||||
mailer.setPassword(values.password());
|
mailer.setPassword(values.password());
|
||||||
mailer.setSSL(values.ssl());
|
mailer.setSSL(values.ssl());
|
||||||
|
mailer.setEnableStartTLS(values.ssl());
|
||||||
Message mymessage =
|
Message mymessage =
|
||||||
new Message(values.body().length() > 0 ? values.body() : message);
|
new Message(values.body().length() > 0 ? values.body() : message);
|
||||||
mymessage.setProject(project);
|
mymessage.setProject(project);
|
||||||
|
@ -102,6 +102,8 @@ public class EmailTask extends Task {
|
|||||||
private String password = null;
|
private String password = null;
|
||||||
/** indicate if the user wishes SSL-TLS */
|
/** indicate if the user wishes SSL-TLS */
|
||||||
private boolean ssl = false;
|
private boolean ssl = false;
|
||||||
|
/** indicate if the user wishes support for STARTTLS */
|
||||||
|
private boolean starttls = false;
|
||||||
|
|
||||||
/** ignore invalid recipients? */
|
/** ignore invalid recipients? */
|
||||||
private boolean ignoreInvalidRecipients = false;
|
private boolean ignoreInvalidRecipients = false;
|
||||||
@ -133,6 +135,16 @@ public class EmailTask extends Task {
|
|||||||
this.ssl = ssl;
|
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.
|
* Set the preferred encoding method.
|
||||||
*
|
*
|
||||||
@ -454,9 +466,10 @@ public class EmailTask extends Task {
|
|||||||
throw new BuildException("SMTP auth only possible with MIME mail");
|
throw new BuildException("SMTP auth only possible with MIME mail");
|
||||||
}
|
}
|
||||||
// SSL only allowed with MIME mail
|
// SSL only allowed with MIME mail
|
||||||
if (!autoFound && (ssl)
|
if (!autoFound && (ssl || starttls)
|
||||||
&& (encoding.equals(UU) || encoding.equals(PLAIN))) {
|
&& (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
|
// try UU format
|
||||||
if (encoding.equals(UU)
|
if (encoding.equals(UU)
|
||||||
@ -537,6 +550,7 @@ public class EmailTask extends Task {
|
|||||||
mailer.setUser(user);
|
mailer.setUser(user);
|
||||||
mailer.setPassword(password);
|
mailer.setPassword(password);
|
||||||
mailer.setSSL(ssl);
|
mailer.setSSL(ssl);
|
||||||
|
mailer.setEnableStartTLS(starttls);
|
||||||
mailer.setMessage(message);
|
mailer.setMessage(message);
|
||||||
mailer.setFrom(from);
|
mailer.setFrom(from);
|
||||||
mailer.setReplyToList(replyToList);
|
mailer.setReplyToList(replyToList);
|
||||||
|
@ -49,6 +49,7 @@ public abstract class Mailer {
|
|||||||
protected Vector headers = null;
|
protected Vector headers = null;
|
||||||
// CheckStyle:VisibilityModifier ON
|
// CheckStyle:VisibilityModifier ON
|
||||||
private boolean ignoreInvalidRecipients = false;
|
private boolean ignoreInvalidRecipients = false;
|
||||||
|
private boolean starttls = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the mail server.
|
* Set the mail server.
|
||||||
@ -98,6 +99,20 @@ public abstract class Mailer {
|
|||||||
this.SSL = ssl;
|
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.
|
* Set the message.
|
||||||
*
|
*
|
||||||
|
@ -161,6 +161,9 @@ public class MimeMailer extends Mailer {
|
|||||||
props.put("mail.smtp.auth", "true");
|
props.put("mail.smtp.auth", "true");
|
||||||
auth = new SimpleAuthenticator(user, password);
|
auth = new SimpleAuthenticator(user, password);
|
||||||
}
|
}
|
||||||
|
if (isStartTLSEnabled()) {
|
||||||
|
props.put("mail.smtp.starttls.enable", "true");
|
||||||
|
}
|
||||||
sesh = Session.getInstance(props, auth);
|
sesh = Session.getInstance(props, auth);
|
||||||
|
|
||||||
//create the message
|
//create the message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user