This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git
The following commit(s) were added to refs/heads/master by this push:
new 8ce2df1 Remove 'this' redundancies
8ce2df1 is described below
commit 8ce2df13eae592631f9cd44656b1ea4900ac57f1
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Dec 15 15:53:40 2023 -0500
Remove 'this' redundancies
---
.../apache/commons/mail/ByteArrayDataSource.java | 2 +-
.../apache/commons/mail/DefaultAuthenticator.java | 2 +-
src/main/java/org/apache/commons/mail/Email.java | 250 ++++++++--------
.../org/apache/commons/mail/EmailException.java | 9 +
.../java/org/apache/commons/mail/HtmlEmail.java | 36 +--
.../org/apache/commons/mail/MultiPartEmail.java | 2 +-
.../org/apache/commons/mail/AbstractEmailTest.java | 22 +-
.../org/apache/commons/mail/HtmlEmailTest.java | 314 ++++++++++-----------
.../apache/commons/mail/InvalidAddressTest.java | 2 +-
.../apache/commons/mail/MultiPartEmailTest.java | 94 +++---
.../commons/mail/SendWithAttachmentsTest.java | 78 ++---
.../org/apache/commons/mail/SimpleEmailTest.java | 68 ++---
.../commons/mail/mocks/MockEmailConcrete.java | 24 +-
.../commons/mail/mocks/MockHtmlEmailConcrete.java | 8 +-
.../mail/mocks/MockImageHtmlEmailConcrete.java | 4 +-
.../mail/mocks/MockMultiPartEmailConcrete.java | 6 +-
.../apache/commons/mail/mocks/MockSimpleEmail.java | 4 +-
17 files changed, 467 insertions(+), 458 deletions(-)
diff --git a/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
b/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
index 008aa13..b9e8b67 100644
--- a/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
+++ b/src/main/java/org/apache/commons/mail/ByteArrayDataSource.java
@@ -70,7 +70,7 @@ public class ByteArrayDataSource implements DataSource {
public ByteArrayDataSource(final byte[] data, final String contentType)
throws IOException {
this.contentType = contentType;
try (ByteArrayInputStream bis = new ByteArrayInputStream(data)) {
- this.read(bis);
+ read(bis);
}
}
diff --git a/src/main/java/org/apache/commons/mail/DefaultAuthenticator.java
b/src/main/java/org/apache/commons/mail/DefaultAuthenticator.java
index 8861e4c..6afc9f4 100644
--- a/src/main/java/org/apache/commons/mail/DefaultAuthenticator.java
+++ b/src/main/java/org/apache/commons/mail/DefaultAuthenticator.java
@@ -48,6 +48,6 @@ public class DefaultAuthenticator extends Authenticator {
*/
@Override
protected PasswordAuthentication getPasswordAuthentication() {
- return this.authentication;
+ return authentication;
}
}
diff --git a/src/main/java/org/apache/commons/mail/Email.java
b/src/main/java/org/apache/commons/mail/Email.java
index ff4b6b5..c2d0856 100644
--- a/src/main/java/org/apache/commons/mail/Email.java
+++ b/src/main/java/org/apache/commons/mail/Email.java
@@ -333,7 +333,7 @@ public abstract class Email {
* @since 1.0
*/
public Email addBcc(final String email) throws EmailException {
- return this.addBcc(email, null);
+ return addBcc(email, null);
}
/**
@@ -366,7 +366,7 @@ public abstract class Email {
* @since 1.0
*/
public Email addBcc(final String email, final String name) throws
EmailException {
- return addBcc(email, name, this.charset);
+ return addBcc(email, name, charset);
}
/**
@@ -380,7 +380,7 @@ public abstract class Email {
* @since 1.1
*/
public Email addBcc(final String email, final String name, final String
charset) throws EmailException {
- this.bccList.add(createInternetAddress(email, name, charset));
+ bccList.add(createInternetAddress(email, name, charset));
return this;
}
@@ -395,7 +395,7 @@ public abstract class Email {
* @since 1.0
*/
public Email addCc(final String email) throws EmailException {
- return this.addCc(email, null);
+ return addCc(email, null);
}
/**
@@ -428,7 +428,7 @@ public abstract class Email {
* @since 1.0
*/
public Email addCc(final String email, final String name) throws
EmailException {
- return addCc(email, name, this.charset);
+ return addCc(email, name, charset);
}
/**
@@ -442,7 +442,7 @@ public abstract class Email {
* @since 1.1
*/
public Email addCc(final String email, final String name, final String
charset) throws EmailException {
- this.ccList.add(createInternetAddress(email, name, charset));
+ ccList.add(createInternetAddress(email, name, charset));
return this;
}
@@ -461,7 +461,7 @@ public abstract class Email {
if (EmailUtils.isEmpty(value)) {
throw new IllegalArgumentException("value can not be null or
empty");
}
- this.headers.put(name, value);
+ headers.put(name, value);
}
/**
@@ -475,7 +475,7 @@ public abstract class Email {
* @since 1.0
*/
public Email addReplyTo(final String email) throws EmailException {
- return this.addReplyTo(email, null);
+ return addReplyTo(email, null);
}
/**
@@ -490,7 +490,7 @@ public abstract class Email {
* @since 1.0
*/
public Email addReplyTo(final String email, final String name) throws
EmailException {
- return addReplyTo(email, name, this.charset);
+ return addReplyTo(email, name, charset);
}
/**
@@ -504,7 +504,7 @@ public abstract class Email {
* @since 1.1
*/
public Email addReplyTo(final String email, final String name, final
String charset) throws EmailException {
- this.replyList.add(createInternetAddress(email, name, charset));
+ replyList.add(createInternetAddress(email, name, charset));
return this;
}
@@ -552,7 +552,7 @@ public abstract class Email {
* @since 1.0
*/
public Email addTo(final String email, final String name) throws
EmailException {
- return addTo(email, name, this.charset);
+ return addTo(email, name, charset);
}
/**
@@ -566,7 +566,7 @@ public abstract class Email {
* @since 1.1
*/
public Email addTo(final String email, final String name, final String
charset) throws EmailException {
- this.toList.add(createInternetAddress(email, name, charset));
+ toList.add(createInternetAddress(email, name, charset));
return this;
}
@@ -579,85 +579,85 @@ public abstract class Email {
* @since 1.0
*/
public void buildMimeMessage() throws EmailException {
- if (this.message != null) {
+ if (message != null) {
// [EMAIL-95] we assume that an email is not reused therefore
invoking
// buildMimeMessage() more than once is illegal.
throw new IllegalStateException("The MimeMessage is already
built.");
}
try {
- this.message = this.createMimeMessage(this.getMailSession());
+ message = createMimeMessage(getMailSession());
- if (EmailUtils.isNotEmpty(this.subject)) {
- if (EmailUtils.isNotEmpty(this.charset)) {
- this.message.setSubject(this.subject, this.charset);
+ if (EmailUtils.isNotEmpty(subject)) {
+ if (EmailUtils.isNotEmpty(charset)) {
+ message.setSubject(subject, charset);
} else {
- this.message.setSubject(this.subject);
+ message.setSubject(subject);
}
}
// update content type (and encoding)
- this.updateContentType(this.contentType);
+ updateContentType(contentType);
- if (this.content != null) {
- if
(EmailConstants.TEXT_PLAIN.equalsIgnoreCase(this.contentType) && this.content
instanceof String) {
+ if (content != null) {
+ if (EmailConstants.TEXT_PLAIN.equalsIgnoreCase(contentType) &&
content instanceof String) {
// EMAIL-104: call explicitly setText to use default mime
charset
// (property "mail.mime.charset") in case none has been set
- this.message.setText(this.content.toString(),
this.charset);
+ message.setText(content.toString(), charset);
} else {
- this.message.setContent(this.content, this.contentType);
+ message.setContent(content, contentType);
}
- } else if (this.emailBody != null) {
- if (this.contentType == null) {
- this.message.setContent(this.emailBody);
+ } else if (emailBody != null) {
+ if (contentType == null) {
+ message.setContent(emailBody);
} else {
- this.message.setContent(this.emailBody, this.contentType);
+ message.setContent(emailBody, contentType);
}
} else {
- this.message.setText("");
+ message.setText("");
}
- if (this.fromAddress != null) {
- this.message.setFrom(this.fromAddress);
+ if (fromAddress != null) {
+ message.setFrom(fromAddress);
} else if (session.getProperty(EmailConstants.MAIL_SMTP_FROM) ==
null && session.getProperty(EmailConstants.MAIL_FROM) == null) {
throw new EmailException("From address required");
}
- if (this.toList.size() + this.ccList.size() + this.bccList.size()
== 0) {
+ if (toList.size() + ccList.size() + bccList.size() == 0) {
throw new EmailException("At least one receiver address
required");
}
if (!EmailUtils.isEmpty(toList)) {
- this.message.setRecipients(Message.RecipientType.TO,
this.toInternetAddressArray(this.toList));
+ message.setRecipients(Message.RecipientType.TO,
toInternetAddressArray(toList));
}
if (!EmailUtils.isEmpty(ccList)) {
- this.message.setRecipients(Message.RecipientType.CC,
this.toInternetAddressArray(this.ccList));
+ message.setRecipients(Message.RecipientType.CC,
toInternetAddressArray(ccList));
}
if (!EmailUtils.isEmpty(bccList)) {
- this.message.setRecipients(Message.RecipientType.BCC,
this.toInternetAddressArray(this.bccList));
+ message.setRecipients(Message.RecipientType.BCC,
toInternetAddressArray(bccList));
}
if (!EmailUtils.isEmpty(replyList)) {
-
this.message.setReplyTo(this.toInternetAddressArray(this.replyList));
+ message.setReplyTo(toInternetAddressArray(replyList));
}
if (!EmailUtils.isEmpty(headers)) {
- for (final Map.Entry<String, String> entry :
this.headers.entrySet()) {
+ for (final Map.Entry<String, String> entry :
headers.entrySet()) {
final String foldedValue =
createFoldedHeaderValue(entry.getKey(), entry.getValue());
- this.message.addHeader(entry.getKey(), foldedValue);
+ message.addHeader(entry.getKey(), foldedValue);
}
}
- if (this.message.getSentDate() == null) {
- this.message.setSentDate(getSentDate());
+ if (message.getSentDate() == null) {
+ message.setSentDate(getSentDate());
}
- if (this.popBeforeSmtp) {
+ if (popBeforeSmtp) {
// TODO Why is this not a Store leak? When to close?
final Store store = session.getStore("pop3");
- store.connect(this.popHost, this.popUsername,
this.popPassword);
+ store.connect(popHost, popUsername, popPassword);
}
} catch (final MessagingException me) {
throw new EmailException(me);
@@ -670,7 +670,7 @@ public abstract class Email {
* @throws IllegalStateException when the mail session is already
initialized
*/
private void checkSessionAlreadyInitialized() {
- if (this.session != null) {
+ if (session != null) {
throw new IllegalStateException("The mail session is already
initialized");
}
}
@@ -691,7 +691,7 @@ public abstract class Email {
throw new IllegalArgumentException("value can not be null or
empty");
}
try {
- return MimeUtility.fold(name.length() + 2,
MimeUtility.encodeText(value, this.charset, null));
+ return MimeUtility.fold(name.length() + 2,
MimeUtility.encodeText(value, charset, null));
} catch (final UnsupportedEncodingException e) {
return value;
}
@@ -747,7 +747,7 @@ public abstract class Email {
* @return List addresses
*/
public List<InternetAddress> getBccAddresses() {
- return this.bccList;
+ return bccList;
}
/**
@@ -757,7 +757,7 @@ public abstract class Email {
* @since 1.4
*/
public String getBounceAddress() {
- return this.bounceAddress;
+ return bounceAddress;
}
/**
@@ -766,7 +766,7 @@ public abstract class Email {
* @return List addresses
*/
public List<InternetAddress> getCcAddresses() {
- return this.ccList;
+ return ccList;
}
/**
@@ -775,7 +775,7 @@ public abstract class Email {
* @return from address
*/
public InternetAddress getFromAddress() {
- return this.fromAddress;
+ return fromAddress;
}
/**
@@ -786,7 +786,7 @@ public abstract class Email {
* @since 1.5
*/
public String getHeader(final String header) {
- return this.headers.get(header);
+ return headers.get(header);
}
/**
@@ -796,7 +796,7 @@ public abstract class Email {
* @since 1.5
*/
public Map<String, String> getHeaders() {
- return this.headers;
+ return headers;
}
/**
@@ -805,11 +805,11 @@ public abstract class Email {
* @return host name
*/
public String getHostName() {
- if (this.session != null) {
- return this.session.getProperty(EmailConstants.MAIL_HOST);
+ if (session != null) {
+ return session.getProperty(EmailConstants.MAIL_HOST);
}
- if (EmailUtils.isNotEmpty(this.hostName)) {
- return this.hostName;
+ if (EmailUtils.isNotEmpty(hostName)) {
+ return hostName;
}
return null;
}
@@ -823,19 +823,19 @@ public abstract class Email {
* @since 1.0
*/
public Session getMailSession() throws EmailException {
- if (this.session == null) {
+ if (session == null) {
final Properties properties = new
Properties(System.getProperties());
properties.setProperty(EmailConstants.MAIL_TRANSPORT_PROTOCOL,
EmailConstants.SMTP);
- if (EmailUtils.isEmpty(this.hostName)) {
- this.hostName =
properties.getProperty(EmailConstants.MAIL_HOST);
+ if (EmailUtils.isEmpty(hostName)) {
+ hostName = properties.getProperty(EmailConstants.MAIL_HOST);
}
EmailException.checkNonEmpty(hostName, () -> "Cannot find valid
hostname for mail session");
- properties.setProperty(EmailConstants.MAIL_PORT, this.smtpPort);
- properties.setProperty(EmailConstants.MAIL_HOST, this.hostName);
- properties.setProperty(EmailConstants.MAIL_DEBUG,
String.valueOf(this.debug));
+ properties.setProperty(EmailConstants.MAIL_PORT, smtpPort);
+ properties.setProperty(EmailConstants.MAIL_HOST, hostName);
+ properties.setProperty(EmailConstants.MAIL_DEBUG,
String.valueOf(debug));
properties.setProperty(EmailConstants.MAIL_TRANSPORT_STARTTLS_ENABLE,
Boolean.toString(isStartTLSEnabled()));
properties.setProperty(EmailConstants.MAIL_TRANSPORT_STARTTLS_REQUIRED,
Boolean.toString(isStartTLSRequired()));
@@ -843,13 +843,13 @@ public abstract class Email {
properties.setProperty(EmailConstants.MAIL_SMTP_SEND_PARTIAL,
Boolean.toString(isSendPartial()));
properties.setProperty(EmailConstants.MAIL_SMTPS_SEND_PARTIAL,
Boolean.toString(isSendPartial()));
- if (this.authenticator != null) {
+ if (authenticator != null) {
properties.setProperty(EmailConstants.MAIL_SMTP_AUTH, "true");
}
if (isSSLOnConnect()) {
- properties.setProperty(EmailConstants.MAIL_PORT,
this.sslSmtpPort);
-
properties.setProperty(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_PORT,
this.sslSmtpPort);
+ properties.setProperty(EmailConstants.MAIL_PORT, sslSmtpPort);
+
properties.setProperty(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_PORT,
sslSmtpPort);
properties.setProperty(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_CLASS,
"javax.net.ssl.SSLSocketFactory");
properties.setProperty(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_FALLBACK,
"false");
}
@@ -858,23 +858,23 @@ public abstract class Email {
properties.setProperty(EmailConstants.MAIL_SMTP_SSL_CHECKSERVERIDENTITY,
"true");
}
- if (this.bounceAddress != null) {
- properties.setProperty(EmailConstants.MAIL_SMTP_FROM,
this.bounceAddress);
+ if (bounceAddress != null) {
+ properties.setProperty(EmailConstants.MAIL_SMTP_FROM,
bounceAddress);
}
- if (this.socketTimeout > 0) {
- properties.setProperty(EmailConstants.MAIL_SMTP_TIMEOUT,
Integer.toString(this.socketTimeout));
+ if (socketTimeout > 0) {
+ properties.setProperty(EmailConstants.MAIL_SMTP_TIMEOUT,
Integer.toString(socketTimeout));
}
- if (this.socketConnectionTimeout > 0) {
-
properties.setProperty(EmailConstants.MAIL_SMTP_CONNECTIONTIMEOUT,
Integer.toString(this.socketConnectionTimeout));
+ if (socketConnectionTimeout > 0) {
+
properties.setProperty(EmailConstants.MAIL_SMTP_CONNECTIONTIMEOUT,
Integer.toString(socketConnectionTimeout));
}
// changed this (back) to getInstance due to security exceptions
// caused when testing using Maven
- this.session = Session.getInstance(properties, this.authenticator);
+ session = Session.getInstance(properties, authenticator);
}
- return this.session;
+ return session;
}
/**
@@ -883,7 +883,7 @@ public abstract class Email {
* @return the MimeMessage
*/
public MimeMessage getMimeMessage() {
- return this.message;
+ return message;
}
/**
@@ -892,7 +892,7 @@ public abstract class Email {
* @return List addresses
*/
public List<InternetAddress> getReplyToAddresses() {
- return this.replyList;
+ return replyList;
}
/**
@@ -902,10 +902,10 @@ public abstract class Email {
* @since 1.0
*/
public Date getSentDate() {
- if (this.sentDate == null) {
+ if (sentDate == null) {
return new Date();
}
- return new Date(this.sentDate.getTime());
+ return new Date(sentDate.getTime());
}
/**
@@ -914,11 +914,11 @@ public abstract class Email {
* @return SMTP port
*/
public String getSmtpPort() {
- if (this.session != null) {
- return this.session.getProperty(EmailConstants.MAIL_PORT);
+ if (session != null) {
+ return session.getProperty(EmailConstants.MAIL_PORT);
}
- if (EmailUtils.isNotEmpty(this.smtpPort)) {
- return this.smtpPort;
+ if (EmailUtils.isNotEmpty(smtpPort)) {
+ return smtpPort;
}
return null;
}
@@ -930,7 +930,7 @@ public abstract class Email {
* @since 1.2
*/
public int getSocketConnectionTimeout() {
- return this.socketConnectionTimeout;
+ return socketConnectionTimeout;
}
/**
@@ -940,7 +940,7 @@ public abstract class Email {
* @since 1.2
*/
public int getSocketTimeout() {
- return this.socketTimeout;
+ return socketTimeout;
}
/**
@@ -949,11 +949,11 @@ public abstract class Email {
* @return the current SSL port used by the SMTP transport
*/
public String getSslSmtpPort() {
- if (this.session != null) {
- return
this.session.getProperty(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_PORT);
+ if (session != null) {
+ return
session.getProperty(EmailConstants.MAIL_SMTP_SOCKET_FACTORY_PORT);
}
- if (EmailUtils.isNotEmpty(this.sslSmtpPort)) {
- return this.sslSmtpPort;
+ if (EmailUtils.isNotEmpty(sslSmtpPort)) {
+ return sslSmtpPort;
}
return null;
}
@@ -964,7 +964,7 @@ public abstract class Email {
* @return email subject
*/
public String getSubject() {
- return this.subject;
+ return subject;
}
/**
@@ -973,7 +973,7 @@ public abstract class Email {
* @return List addresses
*/
public List<InternetAddress> getToAddresses() {
- return this.toList;
+ return toList;
}
/**
@@ -1024,7 +1024,7 @@ public abstract class Email {
* @since 1.3
*/
public boolean isStartTLSEnabled() {
- return this.startTlsEnabled || tls;
+ return startTlsEnabled || tls;
}
/**
@@ -1034,7 +1034,7 @@ public abstract class Email {
* @since 1.3
*/
public boolean isStartTLSRequired() {
- return this.startTlsRequired;
+ return startTlsRequired;
}
/**
@@ -1057,8 +1057,8 @@ public abstract class Email {
* @throws EmailException the sending failed
*/
public String send() throws EmailException {
- this.buildMimeMessage();
- return this.sendMimeMessage();
+ buildMimeMessage();
+ return sendMimeMessage();
}
/**
@@ -1072,9 +1072,9 @@ public abstract class Email {
Objects.requireNonNull(message, "MimeMessage has not been created
yet");
try {
Transport.send(message);
- return this.message.getMessageID();
+ return message.getMessageID();
} catch (final Throwable t) {
- throw new EmailException("Sending the email to the following
server failed : " + this.getHostName() + ":" + this.getSmtpPort(), t);
+ throw new EmailException("Sending the email to the following
server failed : " + this.getHostName() + ":" + getSmtpPort(), t);
}
}
@@ -1100,12 +1100,12 @@ public abstract class Email {
* This method should be used when your outgoing mail server requires
authentication. Your mail server must also support RFC2554.
* </p>
*
- * @param newAuthenticator the {@code Authenticator} object.
+ * @param authenticator the {@code Authenticator} object.
* @see Authenticator
* @since 1.0
*/
- public void setAuthenticator(final Authenticator newAuthenticator) {
- this.authenticator = newAuthenticator;
+ public void setAuthenticator(final Authenticator authenticator) {
+ this.authenticator = authenticator;
}
/**
@@ -1119,7 +1119,7 @@ public abstract class Email {
*/
public Email setBcc(final Collection<InternetAddress> collection) throws
EmailException {
EmailException.checkNonEmpty(collection, () -> "BCC list invalid");
- this.bccList = new ArrayList<>(collection);
+ bccList = new ArrayList<>(collection);
return this;
}
@@ -1136,13 +1136,13 @@ public abstract class Email {
checkSessionAlreadyInitialized();
if (!EmailUtils.isEmpty(email)) {
try {
- this.bounceAddress = createInternetAddress(email, null,
this.charset).getAddress();
+ bounceAddress = createInternetAddress(email, null,
charset).getAddress();
} catch (final EmailException e) {
// Can't throw 'EmailException' to keep backward-compatibility
throw new IllegalArgumentException("Failed to set the bounce
address : " + email, e);
}
} else {
- this.bounceAddress = email;
+ bounceAddress = email;
}
return this;
@@ -1159,7 +1159,7 @@ public abstract class Email {
*/
public Email setCc(final Collection<InternetAddress> collection) throws
EmailException {
EmailException.checkNonEmpty(collection, () -> "CC list invalid");
- this.ccList = new ArrayList<>(collection);
+ ccList = new ArrayList<>(collection);
return this;
}
@@ -1195,7 +1195,7 @@ public abstract class Email {
*/
public void setContent(final Object content, final String contentType) {
this.content = content;
- this.updateContentType(contentType);
+ updateContentType(contentType);
}
/**
@@ -1234,7 +1234,7 @@ public abstract class Email {
* @since 1.0
*/
public Email setFrom(final String email, final String name) throws
EmailException {
- return setFrom(email, name, this.charset);
+ return setFrom(email, name, charset);
}
/**
@@ -1248,7 +1248,7 @@ public abstract class Email {
* @since 1.1
*/
public Email setFrom(final String email, final String name, final String
charset) throws EmailException {
- this.fromAddress = createInternetAddress(email, name, charset);
+ fromAddress = createInternetAddress(email, name, charset);
return this;
}
@@ -1262,7 +1262,7 @@ public abstract class Email {
* @since 1.0
*/
public void setHeaders(final Map<String, String> map) {
- this.headers.clear();
+ headers.clear();
for (final Map.Entry<String, String> entry : map.entrySet()) {
addHeader(entry.getKey(), entry.getValue());
}
@@ -1271,13 +1271,13 @@ public abstract class Email {
/**
* Sets the hostname of the outgoing mail server.
*
- * @param aHostName aHostName
+ * @param hostName aHostName
* @throws IllegalStateException if the mail session is already initialized
* @since 1.0
*/
- public void setHostName(final String aHostName) {
+ public void setHostName(final String hostName) {
checkSessionAlreadyInitialized();
- this.hostName = aHostName;
+ this.hostName = hostName;
}
/**
@@ -1304,8 +1304,8 @@ public abstract class Email {
if (EmailUtils.isNotEmpty(userName) &&
EmailUtils.isNotEmpty(password)) {
// only create a new mail session with an authenticator if
// authentication is required and no user name is given
- this.authenticator = new DefaultAuthenticator(userName,
password);
- this.session = Session.getInstance(sessionProperties,
this.authenticator);
+ authenticator = new DefaultAuthenticator(userName, password);
+ this.session = Session.getInstance(sessionProperties,
authenticator);
} else {
// assume that the given mail session contains a working
authenticator
this.session = session;
@@ -1334,7 +1334,7 @@ public abstract class Email {
ctx = (Context) new InitialContext().lookup("java:comp/env");
}
- this.setMailSession((Session) ctx.lookup(jndiName));
+ setMailSession((Session) ctx.lookup(jndiName));
}
/**
@@ -1350,17 +1350,17 @@ public abstract class Email {
/**
* Sets details regarding "pop3 before SMTP" authentication.
*
- * @param newPopBeforeSmtp Whether or not to log into pop3 server before
sending mail.
- * @param newPopHost The pop3 host to use.
- * @param newPopUsername The pop3 username.
- * @param newPopPassword The pop3 password.
+ * @param popBeforeSmtp Whether or not to log into pop3 server before
sending mail.
+ * @param popHost The pop3 host to use.
+ * @param popUsername The pop3 username.
+ * @param popPassword The pop3 password.
* @since 1.0
*/
- public void setPopBeforeSmtp(final boolean newPopBeforeSmtp, final String
newPopHost, final String newPopUsername, final String newPopPassword) {
- this.popBeforeSmtp = newPopBeforeSmtp;
- this.popHost = newPopHost;
- this.popUsername = newPopUsername;
- this.popPassword = newPopPassword;
+ public void setPopBeforeSmtp(final boolean popBeforeSmtp, final String
popHost, final String popUsername, final String popPassword) {
+ this.popBeforeSmtp = popBeforeSmtp;
+ this.popHost = popHost;
+ this.popUsername = popUsername;
+ this.popPassword = popPassword;
}
/**
@@ -1375,7 +1375,7 @@ public abstract class Email {
*/
public Email setReplyTo(final Collection<InternetAddress> collection)
throws EmailException {
EmailException.checkNonEmpty(collection, () -> "Reply to list
invalid");
- this.replyList = new ArrayList<>(collection);
+ replyList = new ArrayList<>(collection);
return this;
}
@@ -1407,25 +1407,25 @@ public abstract class Email {
public void setSentDate(final Date date) {
if (date != null) {
// create a separate instance to keep findbugs happy
- this.sentDate = new Date(date.getTime());
+ sentDate = new Date(date.getTime());
}
}
/**
* Sets the non-SSL port number of the outgoing mail server.
*
- * @param aPortNumber aPortNumber
+ * @param portNumber aPortNumber
* @throws IllegalArgumentException if the port number is < 1
* @throws IllegalStateException if the mail session is already
initialized
* @since 1.0
* @see #setSslSmtpPort(String)
*/
- public void setSmtpPort(final int aPortNumber) {
+ public void setSmtpPort(final int portNumber) {
checkSessionAlreadyInitialized();
- if (aPortNumber < 1) {
- throw new IllegalArgumentException("Cannot connect to a port
number that is less than 1 ( " + aPortNumber + " )");
+ if (portNumber < 1) {
+ throw new IllegalArgumentException("Cannot connect to a port
number that is less than 1 ( " + portNumber + " )");
}
- this.smtpPort = Integer.toString(aPortNumber);
+ this.smtpPort = Integer.toString(portNumber);
}
/**
diff --git a/src/main/java/org/apache/commons/mail/EmailException.java
b/src/main/java/org/apache/commons/mail/EmailException.java
index 8f54258..1ac9ef7 100644
--- a/src/main/java/org/apache/commons/mail/EmailException.java
+++ b/src/main/java/org/apache/commons/mail/EmailException.java
@@ -22,6 +22,7 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.Collection;
+import java.util.concurrent.Callable;
import java.util.function.Supplier;
/**
@@ -40,6 +41,14 @@ public class EmailException extends Exception {
/** Serializable version identifier. */
private static final long serialVersionUID = 5550674499282474616L;
+ static <V> V call(final Callable<V> callable) throws EmailException {
+ try {
+ return callable.call();
+ } catch (final Exception e) {
+ throw new EmailException(e);
+ }
+ }
+
static <T> T check(final Supplier<Boolean> test, final T subject, final
Supplier<String> message) throws EmailException {
if (test.get()) {
throw new EmailException(message.get());
diff --git a/src/main/java/org/apache/commons/mail/HtmlEmail.java
b/src/main/java/org/apache/commons/mail/HtmlEmail.java
index ffe967a..b5a8ff6 100644
--- a/src/main/java/org/apache/commons/mail/HtmlEmail.java
+++ b/src/main/java/org/apache/commons/mail/HtmlEmail.java
@@ -98,9 +98,9 @@ public class HtmlEmail extends MultiPartEmail {
/**
* Creates an InlineImage object to represent the specified content ID
and {@code MimeBodyPart}.
*
- * @param cid the generated content ID, not null.
- * @param dataSource the {@code DataSource} that represents the
content, not null.
- * @param mimeBodyPart the {@code MimeBodyPart} that contains
the encoded data, not null.
+ * @param cid the generated content ID, not null.
+ * @param dataSource the {@code DataSource} that represents the
content, not null.
+ * @param mimeBodyPart the {@code MimeBodyPart} that contains the
encoded data, not null.
*/
private InlineImage(final String cid, final DataSource dataSource,
final MimeBodyPart mimeBodyPart) {
this.cid = Objects.requireNonNull(cid, "cid");
@@ -109,14 +109,14 @@ public class HtmlEmail extends MultiPartEmail {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof InlineImage)) {
return false;
}
- InlineImage other = (InlineImage) obj;
+ final InlineImage other = (InlineImage) obj;
return Objects.equals(cid, other.cid);
}
@@ -186,7 +186,7 @@ public class HtmlEmail extends MultiPartEmail {
* @throws MessagingException MessagingException
*/
private void build() throws MessagingException, EmailException {
- final MimeMultipart rootContainer = this.getContainer();
+ final MimeMultipart rootContainer = getContainer();
MimeMultipart bodyEmbedsContainer = rootContainer;
MimeMultipart bodyContainer = rootContainer;
MimeBodyPart msgHtml = null;
@@ -196,14 +196,14 @@ public class HtmlEmail extends MultiPartEmail {
// determine how to form multiparts of email
- if (EmailUtils.isNotEmpty(this.html) &&
!EmailUtils.isEmpty(inlineEmbeds)) {
+ if (EmailUtils.isNotEmpty(html) && !EmailUtils.isEmpty(inlineEmbeds)) {
// If HTML body and embeds are used, create a related container
and add it to the root container
bodyEmbedsContainer = new MimeMultipart("related");
bodyContainer = bodyEmbedsContainer;
- this.addPart(bodyEmbedsContainer, 0);
+ addPart(bodyEmbedsContainer, 0);
// If TEXT body was specified, create a alternative container and
add it to the embeds container
- if (EmailUtils.isNotEmpty(this.text)) {
+ if (EmailUtils.isNotEmpty(text)) {
bodyContainer = new MimeMultipart("alternative");
final BodyPart bodyPart = createBodyPart();
try {
@@ -213,7 +213,7 @@ public class HtmlEmail extends MultiPartEmail {
throw new EmailException(me);
}
}
- } else if (EmailUtils.isNotEmpty(this.text) &&
EmailUtils.isNotEmpty(this.html)) {
+ } else if (EmailUtils.isNotEmpty(text) && EmailUtils.isNotEmpty(html))
{
// EMAIL-142: if we have both an HTML and TEXT body, but no
attachments or
// inline images, the root container should have mimetype
// "multipart/alternative".
@@ -230,13 +230,13 @@ public class HtmlEmail extends MultiPartEmail {
}
}
- if (EmailUtils.isNotEmpty(this.html)) {
+ if (EmailUtils.isNotEmpty(html)) {
msgHtml = new MimeBodyPart();
bodyContainer.addBodyPart(msgHtml, 0);
// EMAIL-104: call explicitly setText to use default mime charset
// (property "mail.mime.charset") in case none has been set
- msgHtml.setText(this.html, this.charset,
EmailConstants.TEXT_SUBTYPE_HTML);
+ msgHtml.setText(html, charset, EmailConstants.TEXT_SUBTYPE_HTML);
// EMAIL-147: work-around for buggy JavaMail implementations;
// in case setText(...) does not set the correct content type,
@@ -244,28 +244,28 @@ public class HtmlEmail extends MultiPartEmail {
final String contentType = msgHtml.getContentType();
if (contentType == null ||
!contentType.equals(EmailConstants.TEXT_HTML)) {
// apply default charset if one has been set
- if (EmailUtils.isNotEmpty(this.charset)) {
- msgHtml.setContent(this.html, EmailConstants.TEXT_HTML +
"; charset=" + this.charset);
+ if (EmailUtils.isNotEmpty(charset)) {
+ msgHtml.setContent(html, EmailConstants.TEXT_HTML + ";
charset=" + charset);
} else {
// unfortunately, MimeUtility.getDefaultMIMECharset() is
package private
// and thus can not be used to set the default system
charset in case
// no charset has been provided by the user
- msgHtml.setContent(this.html, EmailConstants.TEXT_HTML);
+ msgHtml.setContent(html, EmailConstants.TEXT_HTML);
}
}
- for (final InlineImage image : this.inlineEmbeds.values()) {
+ for (final InlineImage image : inlineEmbeds.values()) {
bodyEmbedsContainer.addBodyPart(image.getMimeBodyPart());
}
}
- if (EmailUtils.isNotEmpty(this.text)) {
+ if (EmailUtils.isNotEmpty(text)) {
msgText = new MimeBodyPart();
bodyContainer.addBodyPart(msgText, 0);
// EMAIL-104: call explicitly setText to use default mime charset
// (property "mail.mime.charset") in case none has been set
- msgText.setText(this.text, this.charset);
+ msgText.setText(text, charset);
}
}
diff --git a/src/main/java/org/apache/commons/mail/MultiPartEmail.java
b/src/main/java/org/apache/commons/mail/MultiPartEmail.java
index d65a530..d93fb69 100644
--- a/src/main/java/org/apache/commons/mail/MultiPartEmail.java
+++ b/src/main/java/org/apache/commons/mail/MultiPartEmail.java
@@ -335,7 +335,7 @@ public class MultiPartEmail extends Email {
init();
}
// Add the first body part to the message. The fist body part must be
- if (this.primaryBodyPart == null) {
+ if (primaryBodyPart == null) {
primaryBodyPart = createBodyPart();
getContainer().addBodyPart(primaryBodyPart, 0);
}
diff --git a/src/test/java/org/apache/commons/mail/AbstractEmailTest.java
b/src/test/java/org/apache/commons/mail/AbstractEmailTest.java
index 331922d..81d8d33 100644
--- a/src/test/java/org/apache/commons/mail/AbstractEmailTest.java
+++ b/src/test/java/org/apache/commons/mail/AbstractEmailTest.java
@@ -119,19 +119,19 @@ public abstract class AbstractEmailTest {
* changing the state of the server.
*/
public void getMailServer() {
- if (this.fakeMailServer == null ||
isMailServerStopped(fakeMailServer)) {
+ if (fakeMailServer == null || isMailServerStopped(fakeMailServer)) {
mailServerPort++;
- this.fakeMailServer = new Wiser();
- this.fakeMailServer.setPort(getMailServerPort());
- this.fakeMailServer.start();
+ fakeMailServer = new Wiser();
+ fakeMailServer.setPort(getMailServerPort());
+ fakeMailServer.start();
assertFalse(isMailServerStopped(fakeMailServer), "fake mail server
didn't start");
final Date dtStartWait = new Date();
while (isMailServerStopped(fakeMailServer)) {
// test for connected
- if (this.fakeMailServer != null &&
!isMailServerStopped(fakeMailServer)) {
+ if (fakeMailServer != null &&
!isMailServerStopped(fakeMailServer)) {
break;
}
@@ -294,12 +294,12 @@ public abstract class AbstractEmailTest {
@AfterEach
public void tearDownEmailTest() {
// stop the fake email server (if started)
- if (this.fakeMailServer != null &&
!isMailServerStopped(fakeMailServer)) {
- this.fakeMailServer.stop();
+ if (fakeMailServer != null && !isMailServerStopped(fakeMailServer)) {
+ fakeMailServer.stop();
assertTrue(isMailServerStopped(fakeMailServer), "Mail server
didn't stop");
}
- this.fakeMailServer = null;
+ fakeMailServer = null;
}
/**
@@ -322,7 +322,7 @@ public abstract class AbstractEmailTest {
if (boolSaveToFile) {
try {
- this.saveEmailToFile(emailMessage);
+ saveEmailToFile(emailMessage);
} catch (final MessagingException me) {
final IllegalStateException ise = new
IllegalStateException("caught MessagingException during saving the email");
ise.initCause(me);
@@ -378,7 +378,7 @@ public abstract class AbstractEmailTest {
final List<InternetAddress> toAdd, final List<InternetAddress>
ccAdd, final List<InternetAddress> bccAdd, final boolean boolSaveToFile)
throws IOException {
// test other properties
- final WiserMessage emailMessage = this.validateSend(mailServer,
strSubject, fromAdd, toAdd, ccAdd, bccAdd, boolSaveToFile);
+ final WiserMessage emailMessage = validateSend(mailServer, strSubject,
fromAdd, toAdd, ccAdd, bccAdd, boolSaveToFile);
// test message content
@@ -408,7 +408,7 @@ public abstract class AbstractEmailTest {
final List<InternetAddress> toAdd, final List<InternetAddress>
ccAdd, final List<InternetAddress> bccAdd, final boolean boolSaveToFile)
throws IOException {
// test other properties
- final WiserMessage emailMessage = this.validateSend(mailServer,
strSubject, fromAdd, toAdd, ccAdd, bccAdd, true);
+ final WiserMessage emailMessage = validateSend(mailServer, strSubject,
fromAdd, toAdd, ccAdd, bccAdd, true);
// test message content
assertTrue(getMessageBody(emailMessage).contains(strMessage), "didn't
find expected message content in message body");
diff --git a/src/test/java/org/apache/commons/mail/HtmlEmailTest.java
b/src/test/java/org/apache/commons/mail/HtmlEmailTest.java
index 2046ba5..5032ef4 100644
--- a/src/test/java/org/apache/commons/mail/HtmlEmailTest.java
+++ b/src/test/java/org/apache/commons/mail/HtmlEmailTest.java
@@ -64,8 +64,8 @@ public class HtmlEmailTest extends AbstractEmailTest {
private HtmlEmail createDefaultHtmlEmail() throws EmailException {
final HtmlEmail htmlEmail = new HtmlEmail();
- htmlEmail.setHostName(this.strTestMailServer);
- htmlEmail.setSmtpPort(this.getMailServerPort());
+ htmlEmail.setHostName(strTestMailServer);
+ htmlEmail.setSmtpPort(getMailServerPort());
htmlEmail.setFrom("[email protected]");
htmlEmail.addTo("[email protected]");
return htmlEmail;
@@ -74,7 +74,7 @@ public class HtmlEmailTest extends AbstractEmailTest {
@BeforeEach
public void setUpHtmlEmailTest() {
// reusable objects to be used across multiple tests
- this.email = new MockHtmlEmailConcrete();
+ email = new MockHtmlEmailConcrete();
}
/**
@@ -87,33 +87,33 @@ public class HtmlEmailTest extends AbstractEmailTest {
+ "<a
href=\"http://paradisedelivery.homeip.net/delivery/?file=3DTZC268X93337.zip\">"
+
"http://paradisedelivery.homeip.net/delivery/?file=3DTZC268X93337.zip" +
"</a><br><br>Customer satisfaction is very important for us.";
- this.getMailServer();
+ getMailServer();
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
- this.email.setCharset(EmailConstants.ISO_8859_1);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
+ email.setCharset(EmailConstants.ISO_8859_1);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
final String strSubject = "A dot (\".\") is appended to some ULRs of a
HTML mail.";
- this.email.setSubject(strSubject);
- this.email.setHtmlMsg(htmlMsg);
+ email.setSubject(strSubject);
+ email.setHtmlMsg(htmlMsg);
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate html message
- validateSend(this.fakeMailServer, strSubject, this.email.getHtmlMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), false);
// make sure that no double dots show up
- assertTrue(this.email.getHtmlMsg().contains("3DTZC268X93337.zip"));
- assertFalse(this.email.getHtmlMsg().contains("3DTZC268X93337..zip"));
+ assertTrue(email.getHtmlMsg().contains("3DTZC268X93337.zip"));
+ assertFalse(email.getHtmlMsg().contains("3DTZC268X93337..zip"));
}
/**
@@ -124,26 +124,26 @@ public class HtmlEmailTest extends AbstractEmailTest {
final String htmlMsg = "<b>Hello World</b>";
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
- this.email.setCharset(EmailConstants.ISO_8859_1);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
+ email.setCharset(EmailConstants.ISO_8859_1);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
final String strSubject = "testCallingBuildMimeMessageBeforeSent";
- this.email.setSubject(strSubject);
- this.email.setHtmlMsg(htmlMsg);
+ email.setSubject(strSubject);
+ email.setHtmlMsg(htmlMsg);
// this should NOT be called when sending a message
- this.email.buildMimeMessage();
+ email.buildMimeMessage();
try {
- this.email.send();
+ email.send();
} catch (final IllegalStateException e) {
return;
}
@@ -159,18 +159,18 @@ public class HtmlEmailTest extends AbstractEmailTest {
// does embedding a datasource without a name fail?
try {
- this.email.embed(dataSource, "");
+ email.embed(dataSource, "");
fail("embedding with an empty string for a name should fail");
} catch (final EmailException e) {
// expected
}
// properly embed the datasource
- final String cid = this.email.embed(dataSource, "testname");
+ final String cid = email.embed(dataSource, "testname");
// does embedding the same datasource under the same name return
// the original cid?
- final String sameCid = this.email.embed(dataSource, "testname");
+ final String sameCid = email.embed(dataSource, "testname");
assertEquals(cid, sameCid, "didn't get same CID for embedding same
datasource twice");
@@ -179,7 +179,7 @@ public class HtmlEmailTest extends AbstractEmailTest {
anotherFile.deleteOnExit();
final FileDataSource anotherDS = new FileDataSource(anotherFile);
try {
- this.email.embed(anotherDS, "testname");
+ email.embed(anotherDS, "testname");
} catch (final EmailException e) {
// expected
}
@@ -191,20 +191,20 @@ public class HtmlEmailTest extends AbstractEmailTest {
final File file = File.createTempFile("testEmbedFile", "txt");
file.deleteOnExit();
- final String strEmbed = this.email.embed(file);
+ final String strEmbed = email.embed(file);
assertNotNull(strEmbed);
assertEquals(HtmlEmail.CID_LENGTH, strEmbed.length(), "generated CID
has wrong length");
// if we embed the same file again, do we get the same content ID
// back?
- final String testCid = this.email.embed(file);
+ final String testCid = email.embed(file);
assertEquals(strEmbed, testCid, "didn't get same CID after embedding
same file twice");
// if we embed a new file, is the content ID unique?
final File otherFile = File.createTempFile("testEmbedFile2", "txt");
otherFile.deleteOnExit();
- final String newCid = this.email.embed(otherFile);
+ final String newCid = email.embed(otherFile);
assertNotEquals(strEmbed, newCid, "didn't get unique CID from
embedding new file");
}
@@ -227,13 +227,13 @@ public class HtmlEmailTest extends AbstractEmailTest {
final String encodedCid = EmailUtils.encodeUrl(testCid);
// if we embed a new file, do we get the content ID we specified back?
- final String strEmbed = this.email.embed(file, testCid);
+ final String strEmbed = email.embed(file, testCid);
assertNotNull(strEmbed);
assertEquals(encodedCid, strEmbed, "didn't get same CID when embedding
with a specified CID");
// if we embed the same file again, do we get the same content ID
// back?
- final String returnedCid = this.email.embed(file);
+ final String returnedCid = email.embed(file);
assertEquals(encodedCid, returnedCid, "didn't get same CID after
embedding same file twice");
}
@@ -241,24 +241,24 @@ public class HtmlEmailTest extends AbstractEmailTest {
public void testEmbedUrl() throws Exception {
// Test Success
- final String strEmbed = this.email.embed(new URL(this.strTestURL),
"Test name");
+ final String strEmbed = email.embed(new URL(strTestURL), "Test name");
assertNotNull(strEmbed);
assertEquals(HtmlEmail.CID_LENGTH, strEmbed.length());
// if we embed the same name again, do we get the same content ID
// back?
- final String testCid = this.email.embed(new URL(this.strTestURL),
"Test name");
+ final String testCid = email.embed(new URL(strTestURL), "Test name");
assertEquals(strEmbed, testCid);
// if we embed the same URL under a different name, is the content ID
// unique?
- final String newCid = this.email.embed(new URL(this.strTestURL), "Test
name 2");
+ final String newCid = email.embed(new URL(strTestURL), "Test name 2");
assertNotEquals(strEmbed, newCid);
// Test Exceptions
// Does an invalid URL throw an exception?
try {
- this.email.embed(createInvalidURL(), "Bad URL");
+ email.embed(createInvalidURL(), "Bad URL");
fail("Should have thrown an exception");
} catch (final EmailException e) {
// expected
@@ -267,7 +267,7 @@ public class HtmlEmailTest extends AbstractEmailTest {
// if we try to embed a different URL under a previously used name,
// does it complain?
try {
- this.email.embed(new URL("http://www.google.com"), "Test name");
+ email.embed(new URL("http://www.google.com"), "Test name");
fail("shouldn't be able to use an existing name with a different
URL!");
} catch (final EmailException e) {
// expected
@@ -278,10 +278,10 @@ public class HtmlEmailTest extends AbstractEmailTest {
public void testEmbedUrlAndFile() throws Exception {
final File tmpFile = File.createTempFile("testfile", "txt");
tmpFile.deleteOnExit();
- final String fileCid = this.email.embed(tmpFile);
+ final String fileCid = email.embed(tmpFile);
final URL fileUrl = tmpFile.toURI().toURL();
- final String urlCid = this.email.embed(fileUrl, "urlName");
+ final String urlCid = email.embed(fileUrl, "urlName");
assertNotEquals(fileCid, urlCid, "file and URL cids should be
different even for same resource");
}
@@ -290,13 +290,13 @@ public class HtmlEmailTest extends AbstractEmailTest {
public void testGetSetHtmlMsg() throws EmailException {
// Test Success
for (final String validChar : testCharsValid) {
- this.email.setHtmlMsg(validChar);
- assertEquals(validChar, this.email.getHtmlMsg());
+ email.setHtmlMsg(validChar);
+ assertEquals(validChar, email.getHtmlMsg());
}
// Test Exception
- for (final String invalidChar : this.testCharsNotValid) {
+ for (final String invalidChar : testCharsNotValid) {
try {
- this.email.setHtmlMsg(invalidChar);
+ email.setHtmlMsg(invalidChar);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -309,15 +309,15 @@ public class HtmlEmailTest extends AbstractEmailTest {
public void testGetSetMsg() throws EmailException {
// Test Success
for (final String validChar : testCharsValid) {
- this.email.setMsg(validChar);
- assertEquals(validChar, this.email.getTextMsg());
+ email.setMsg(validChar);
+ assertEquals(validChar, email.getTextMsg());
- assertTrue(this.email.getHtmlMsg().contains(validChar));
+ assertTrue(email.getHtmlMsg().contains(validChar));
}
// Test Exception
- for (final String invalidChar : this.testCharsNotValid) {
+ for (final String invalidChar : testCharsNotValid) {
try {
- this.email.setMsg(invalidChar);
+ email.setMsg(invalidChar);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -330,13 +330,13 @@ public class HtmlEmailTest extends AbstractEmailTest {
public void testGetSetTextMsg() throws EmailException {
// Test Success
for (final String validChar : testCharsValid) {
- this.email.setTextMsg(validChar);
- assertEquals(validChar, this.email.getTextMsg());
+ email.setTextMsg(validChar);
+ assertEquals(validChar, email.getTextMsg());
}
// Test Exception
- for (final String invalidChar : this.testCharsNotValid) {
+ for (final String invalidChar : testCharsNotValid) {
try {
- this.email.setTextMsg(invalidChar);
+ email.setTextMsg(invalidChar);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -364,128 +364,128 @@ public class HtmlEmailTest extends AbstractEmailTest {
final File testFile = File.createTempFile("commons-email-testfile",
".txt");
testFile.deleteOnExit();
// Test Success
- this.getMailServer();
+ getMailServer();
String strSubject = "Test HTML Send #1 Subject (w charset)";
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
/* File to used to test file attachments (Must be valid) */
attachment.setName("Test Attachment");
attachment.setDescription("Test Attachment Desc");
attachment.setPath(testFile.getAbsolutePath());
- this.email.attach(attachment);
+ email.attach(attachment);
- // this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ // email.setAuthentication(strTestUser, strTestPasswd);
- this.email.setCharset(EmailConstants.ISO_8859_1);
- this.email.setSubject(strSubject);
+ email.setCharset(EmailConstants.ISO_8859_1);
+ email.setSubject(strSubject);
final URL url = new URL(EmailConfiguration.TEST_URL);
- final String cid = this.email.embed(url, "Apache Logo");
+ final String cid = email.embed(url, "Apache Logo");
final String strHtmlMsg = "<html>The Apache logo - <img src=\"cid:" +
cid + "\"><html>";
- this.email.setHtmlMsg(strHtmlMsg);
- this.email.setTextMsg("Your email client does not support HTML
emails");
+ email.setHtmlMsg(strHtmlMsg);
+ email.setTextMsg("Your email client does not support HTML emails");
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate txt message
- validateSend(this.fakeMailServer, strSubject, this.email.getTextMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, email.getTextMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
// validate html message
- validateSend(this.fakeMailServer, strSubject, this.email.getHtmlMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), false);
// validate attachment
- validateSend(this.fakeMailServer, strSubject, attachment.getName(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject, attachment.getName(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), false);
- this.getMailServer();
+ getMailServer();
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
strSubject = "Test HTML Send #1 Subject (wo charset)";
- this.email.setSubject(strSubject);
- this.email.setTextMsg("Test message");
+ email.setSubject(strSubject);
+ email.setTextMsg("Test message");
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate txt message
- validateSend(this.fakeMailServer, strSubject, this.email.getTextMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, email.getTextMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
}
@Test
public void testSend2() throws Exception {
// Test Success
- this.getMailServer();
+ getMailServer();
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
String strSubject = "Test HTML Send #2 Subject (wo charset)";
- this.email.setSubject(strSubject);
- this.email.setMsg("Test txt msg");
+ email.setSubject(strSubject);
+ email.setMsg("Test txt msg");
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate txt message
- validateSend(this.fakeMailServer, strSubject, this.email.getTextMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, email.getTextMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
// validate html message
- validateSend(this.fakeMailServer, strSubject, this.email.getHtmlMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), false);
- this.getMailServer();
+ getMailServer();
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setFrom(this.strTestMailFrom);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.addTo(this.strTestMailTo);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setFrom(strTestMailFrom);
+ email.setSmtpPort(getMailServerPort());
+ email.addTo(strTestMailTo);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
strSubject = "Test HTML Send #2 Subject (w charset)";
- this.email.setCharset(EmailConstants.ISO_8859_1);
- this.email.setSubject(strSubject);
- this.email.setMsg("Test txt msg");
+ email.setCharset(EmailConstants.ISO_8859_1);
+ email.setSubject(strSubject);
+ email.setMsg("Test txt msg");
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate txt message
- validateSend(this.fakeMailServer, strSubject, this.email.getTextMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, email.getTextMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
// validate html message
- validateSend(this.fakeMailServer, strSubject, this.email.getHtmlMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), false);
}
@@ -500,27 +500,27 @@ public class HtmlEmailTest extends AbstractEmailTest {
System.setProperty(EmailConstants.MAIL_MIME_CHARSET, "iso-8859-15");
- this.getMailServer();
+ getMailServer();
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
final String strSubject = "Test HTML Send Subject (w default charset)";
- this.email.setSubject(strSubject);
- this.email.setMsg("Test txt msg ä"); // add non-ascii character,
otherwise us-ascii will be used
+ email.setSubject(strSubject);
+ email.setMsg("Test txt msg ä"); // add non-ascii character, otherwise
us-ascii will be used
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate charset
- validateSend(this.fakeMailServer, strSubject, "charset=iso-8859-15",
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, "charset=iso-8859-15",
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
System.clearProperty(EmailConstants.MAIL_MIME_CHARSET);
@@ -531,26 +531,26 @@ public class HtmlEmailTest extends AbstractEmailTest {
*/
@Test
public void testSendWithPlainTextButNoHtmlContent() throws EmailException,
IOException {
- this.getMailServer();
+ getMailServer();
final String strSubject = "testSendWithPlainTextButNoHtmlContent";
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
- this.email.setCharset(EmailConstants.ISO_8859_1);
- this.email.setSubject(strSubject);
- this.email.setMsg("This is a plain text content :
<b><&npsb;></html></b>");
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
+ email.setAuthentication(strTestUser, strTestPasswd);
+ email.setCharset(EmailConstants.ISO_8859_1);
+ email.setSubject(strSubject);
+ email.setMsg("This is a plain text content : <b><&npsb;></html></b>");
- this.email.send();
+ email.send();
- this.fakeMailServer.stop();
+ fakeMailServer.stop();
// validate text message
- validateSend(this.fakeMailServer, strSubject, this.email.getTextMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, email.getTextMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
}
}
diff --git a/src/test/java/org/apache/commons/mail/InvalidAddressTest.java
b/src/test/java/org/apache/commons/mail/InvalidAddressTest.java
index bae77bb..849c347 100644
--- a/src/test/java/org/apache/commons/mail/InvalidAddressTest.java
+++ b/src/test/java/org/apache/commons/mail/InvalidAddressTest.java
@@ -46,7 +46,7 @@ public class InvalidAddressTest extends AbstractEmailTest {
@BeforeEach
public void setUpInvalidAddressTest() {
// reusable objects to be used across multiple tests
- this.email = new MockEmailConcrete();
+ email = new MockEmailConcrete();
}
@Test
diff --git a/src/test/java/org/apache/commons/mail/MultiPartEmailTest.java
b/src/test/java/org/apache/commons/mail/MultiPartEmailTest.java
index 4a0b675..b229601 100644
--- a/src/test/java/org/apache/commons/mail/MultiPartEmailTest.java
+++ b/src/test/java/org/apache/commons/mail/MultiPartEmailTest.java
@@ -44,7 +44,7 @@ public class MultiPartEmailTest extends AbstractEmailTest {
@BeforeEach
public void setUpMultiPartEmailTest() throws Exception {
// reusable objects to be used across multiple tests
- this.email = new MockMultiPartEmailConcrete();
+ email = new MockMultiPartEmailConcrete();
testFile = File.createTempFile("testfile", ".txt");
}
@@ -52,16 +52,16 @@ public class MultiPartEmailTest extends AbstractEmailTest {
public void testAddPart() throws Exception {
// setup
- this.email = new MockMultiPartEmailConcrete();
+ email = new MockMultiPartEmailConcrete();
final String strMessage = "hello";
final String strContentType = "text/plain";
// add part
- this.email.addPart(strMessage, strContentType);
+ email.addPart(strMessage, strContentType);
// validate
- assertEquals(strContentType,
this.email.getContainer().getBodyPart(0).getContentType());
- assertEquals(strMessage,
this.email.getContainer().getBodyPart(0).getDataHandler().getContent());
+ assertEquals(strContentType,
email.getContainer().getBodyPart(0).getContentType());
+ assertEquals(strMessage,
email.getContainer().getBodyPart(0).getDataHandler().getContent());
}
@@ -69,14 +69,14 @@ public class MultiPartEmailTest extends AbstractEmailTest {
public void testAddPart2() throws Exception {
// setup
- this.email = new MockMultiPartEmailConcrete();
+ email = new MockMultiPartEmailConcrete();
final String strSubtype = "subtype/abc123";
// add part
- this.email.addPart(new MimeMultipart(strSubtype));
+ email.addPart(new MimeMultipart(strSubtype));
// validate
-
assertTrue(this.email.getContainer().getBodyPart(0).getDataHandler().getContentType().contains(strSubtype));
+
assertTrue(email.getContainer().getBodyPart(0).getDataHandler().getContentType().contains(strSubtype));
}
@@ -88,21 +88,21 @@ public class MultiPartEmailTest extends AbstractEmailTest {
attachment.setName("Test Attachment");
attachment.setDescription("Test Attachment Desc");
attachment.setPath(testFile.getAbsolutePath());
- this.email.attach(attachment);
- assertTrue(this.email.isBoolHasAttachments());
+ email.attach(attachment);
+ assertTrue(email.isBoolHasAttachments());
// Test Success - URL
attachment = new EmailAttachment();
attachment.setName("Test Attachment");
attachment.setDescription("Test Attachment Desc");
- attachment.setURL(new URL(this.strTestURL));
- this.email.attach(attachment);
+ attachment.setURL(new URL(strTestURL));
+ email.attach(attachment);
// Test Success - File
- this.email.attach(testFile);
- assertTrue(this.email.isBoolHasAttachments());
+ email.attach(testFile);
+ assertTrue(email.isBoolHasAttachments());
// Test Exceptions
// null attachment
try {
- this.email.attach((EmailAttachment) null);
+ email.attach((EmailAttachment) null);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -112,7 +112,7 @@ public class MultiPartEmailTest extends AbstractEmailTest {
attachment = new EmailAttachment();
try {
attachment.setURL(createInvalidURL());
- this.email.attach(attachment);
+ email.attach(attachment);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -122,7 +122,7 @@ public class MultiPartEmailTest extends AbstractEmailTest {
attachment = new EmailAttachment();
try {
attachment.setPath("");
- this.email.attach(attachment);
+ email.attach(attachment);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -136,21 +136,21 @@ public class MultiPartEmailTest extends AbstractEmailTest
{
@Test
public void testAttach2() throws MalformedURLException, EmailException {
// Test Success - URL
- this.email.attach(new URL(this.strTestURL), "Test Attachment", "Test
Attachment Desc");
+ email.attach(new URL(strTestURL), "Test Attachment", "Test Attachment
Desc");
// bad name
- this.email.attach(new URL(this.strTestURL), null, "Test Attachment
Desc");
+ email.attach(new URL(strTestURL), null, "Test Attachment Desc");
}
@Test
public void testAttach3() throws Exception {
// Test Success - URL
- this.email.attach(new URLDataSource(new URL(this.strTestURL)), "Test
Attachment", "Test Attachment Desc");
+ email.attach(new URLDataSource(new URL(strTestURL)), "Test
Attachment", "Test Attachment Desc");
// Test Exceptions
// null datasource
try {
final URLDataSource urlDs = null;
- this.email.attach(urlDs, "Test Attachment", "Test Attachment
Desc");
+ email.attach(urlDs, "Test Attachment", "Test Attachment Desc");
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -159,7 +159,7 @@ public class MultiPartEmailTest extends AbstractEmailTest {
// invalid datasource
try {
final URLDataSource urlDs = new URLDataSource(createInvalidURL());
- this.email.attach(urlDs, "Test Attachment", "Test Attachment
Desc");
+ email.attach(urlDs, "Test Attachment", "Test Attachment Desc");
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -173,7 +173,7 @@ public class MultiPartEmailTest extends AbstractEmailTest {
final File tmpFile = File.createTempFile("attachment", ".eml");
- this.email.attach(new FileDataSource(tmpFile), "Test Attachment",
"Test Attachment Desc");
+ email.attach(new FileDataSource(tmpFile), "Test Attachment", "Test
Attachment Desc");
assertTrue(tmpFile.delete());
}
@@ -188,8 +188,8 @@ public class MultiPartEmailTest extends AbstractEmailTest {
@Test
public void testGetSetSubType() {
for (final String validChar : testCharsValid) {
- this.email.setSubType(validChar);
- assertEquals(validChar, this.email.getSubType());
+ email.setSubType(validChar);
+ assertEquals(validChar, email.getSubType());
}
}
@@ -198,8 +198,8 @@ public class MultiPartEmailTest extends AbstractEmailTest {
public void testInit() {
// call the init function twice to trigger the IllegalStateException
try {
- this.email.init();
- this.email.init();
+ email.init();
+ email.init();
fail("Should have thrown an exception");
} catch (final IllegalStateException e) {
assertTrue(true);
@@ -213,7 +213,7 @@ public class MultiPartEmailTest extends AbstractEmailTest {
@Test
public void testSend() throws EmailException, IOException {
// Test Success
- this.getMailServer();
+ getMailServer();
final String strSubject = "Test Multipart Send Subject";
@@ -224,15 +224,15 @@ public class MultiPartEmailTest extends AbstractEmailTest
{
attachment.setDescription("Test Attachment Desc");
final MockMultiPartEmailConcrete testEmail = new
MockMultiPartEmailConcrete();
- testEmail.setHostName(this.strTestMailServer);
- testEmail.setSmtpPort(this.getMailServerPort());
- testEmail.setFrom(this.strTestMailFrom);
- testEmail.addTo(this.strTestMailTo);
+ testEmail.setHostName(strTestMailServer);
+ testEmail.setSmtpPort(getMailServerPort());
+ testEmail.setFrom(strTestMailFrom);
+ testEmail.addTo(strTestMailTo);
testEmail.attach(attachment);
testEmail.setSubType("subType");
- if (EmailUtils.isNotEmpty(this.strTestUser) &&
EmailUtils.isNotEmpty(this.strTestPasswd)) {
- testEmail.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (EmailUtils.isNotEmpty(strTestUser) &&
EmailUtils.isNotEmpty(strTestPasswd)) {
+ testEmail.setAuthentication(strTestUser, strTestPasswd);
}
testEmail.setSubject(strSubject);
@@ -241,29 +241,29 @@ public class MultiPartEmailTest extends AbstractEmailTest
{
final Map<String, String> ht = new HashMap<>();
ht.put("X-Priority", "2");
- ht.put("Disposition-Notification-To", this.strTestMailFrom);
+ ht.put("Disposition-Notification-To", strTestMailFrom);
ht.put("X-Mailer", "Sendmail");
testEmail.setHeaders(ht);
testEmail.send();
- this.fakeMailServer.stop();
+ fakeMailServer.stop();
// validate message
- validateSend(this.fakeMailServer, strSubject, testEmail.getMsg(),
testEmail.getFromAddress(), testEmail.getToAddresses(),
testEmail.getCcAddresses(),
+ validateSend(fakeMailServer, strSubject, testEmail.getMsg(),
testEmail.getFromAddress(), testEmail.getToAddresses(),
testEmail.getCcAddresses(),
testEmail.getBccAddresses(), true);
// validate attachment
- validateSend(this.fakeMailServer, strSubject, attachment.getName(),
testEmail.getFromAddress(), testEmail.getToAddresses(),
testEmail.getCcAddresses(),
+ validateSend(fakeMailServer, strSubject, attachment.getName(),
testEmail.getFromAddress(), testEmail.getToAddresses(),
testEmail.getCcAddresses(),
testEmail.getBccAddresses(), false);
// Test Exceptions
try {
- this.getMailServer();
+ getMailServer();
- this.email.send();
+ email.send();
fail("Should have thrown an exception");
} catch (final EmailException e) {
- this.fakeMailServer.stop();
+ fakeMailServer.stop();
}
}
@@ -273,20 +273,20 @@ public class MultiPartEmailTest extends AbstractEmailTest
{
// without charset set
for (final String validChar : testCharsValid) {
- this.email.setMsg(validChar);
- assertEquals(validChar, this.email.getMsg());
+ email.setMsg(validChar);
+ assertEquals(validChar, email.getMsg());
}
// with charset set
- this.email.setCharset(EmailConstants.US_ASCII);
+ email.setCharset(EmailConstants.US_ASCII);
for (final String validChar : testCharsValid) {
- this.email.setMsg(validChar);
- assertEquals(validChar, this.email.getMsg());
+ email.setMsg(validChar);
+ assertEquals(validChar, email.getMsg());
}
// Test Exceptions
for (final String invalidChar : testCharsNotValid) {
try {
- this.email.setMsg(invalidChar);
+ email.setMsg(invalidChar);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
diff --git a/src/test/java/org/apache/commons/mail/SendWithAttachmentsTest.java
b/src/test/java/org/apache/commons/mail/SendWithAttachmentsTest.java
index 0efe4ac..d5a4837 100644
--- a/src/test/java/org/apache/commons/mail/SendWithAttachmentsTest.java
+++ b/src/test/java/org/apache/commons/mail/SendWithAttachmentsTest.java
@@ -38,7 +38,7 @@ public class SendWithAttachmentsTest extends
AbstractEmailTest {
@BeforeEach
public void setUpSendWithAttachmentsTest() {
// reusable objects to be used across multiple tests
- this.email = new MockHtmlEmailConcrete();
+ email = new MockHtmlEmailConcrete();
}
/**
@@ -47,39 +47,39 @@ public class SendWithAttachmentsTest extends
AbstractEmailTest {
*/
@Test
public void testSendNoAttachments() throws EmailException, IOException {
- this.getMailServer();
+ getMailServer();
final String strSubject = "Test HTML Send #1 Subject (w charset)";
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ email.setAuthentication(strTestUser, strTestPasswd);
- this.email.setCharset(EmailConstants.ISO_8859_1);
- this.email.setSubject(strSubject);
+ email.setCharset(EmailConstants.ISO_8859_1);
+ email.setSubject(strSubject);
final URL url = new URL(EmailConfiguration.TEST_URL);
- final String cid = this.email.embed(url, "Apache Logo");
+ final String cid = email.embed(url, "Apache Logo");
final String strHtmlMsg = "<html>The Apache logo - <img src=\"cid:" +
cid + "\"><html>";
- this.email.setHtmlMsg(strHtmlMsg);
- this.email.setTextMsg("Your email client does not support HTML
emails");
+ email.setHtmlMsg(strHtmlMsg);
+ email.setTextMsg("Your email client does not support HTML emails");
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate txt message
- validateSend(this.fakeMailServer, strSubject, this.email.getTextMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, email.getTextMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
// validate html message
- validateSend(this.fakeMailServer, strSubject, this.email.getHtmlMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), false);
}
/**
@@ -93,15 +93,15 @@ public class SendWithAttachmentsTest extends
AbstractEmailTest {
/** File to used to test file attachments (Must be valid) */
final File testFile = File.createTempFile("commons-email-testfile",
".txt");
// Test Success
- this.getMailServer();
+ getMailServer();
final String strSubject = "Test HTML Send #1 Subject (w charset)";
- this.email = new MockHtmlEmailConcrete();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockHtmlEmailConcrete();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
/** File to be used to test file attachments (Must be valid) */
/** Use umlaut characters to test if the file name is properly encoded
*/
@@ -109,31 +109,31 @@ public class SendWithAttachmentsTest extends
AbstractEmailTest {
attachment.setName("a>ä, o>ö, u>ü, au>äu");
attachment.setDescription("Test Attachment Desc");
attachment.setPath(testFile.getAbsolutePath());
- this.email.attach(attachment);
+ email.attach(attachment);
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ email.setAuthentication(strTestUser, strTestPasswd);
- this.email.setCharset(EmailConstants.ISO_8859_1);
- this.email.setSubject(strSubject);
+ email.setCharset(EmailConstants.ISO_8859_1);
+ email.setSubject(strSubject);
final String strHtmlMsg = "<html>Test Message<html>";
- this.email.setHtmlMsg(strHtmlMsg);
- this.email.setTextMsg("Your email client does not support HTML
emails");
+ email.setHtmlMsg(strHtmlMsg);
+ email.setTextMsg("Your email client does not support HTML emails");
- this.email.send();
- this.fakeMailServer.stop();
+ email.send();
+ fakeMailServer.stop();
// validate txt message
- validateSend(this.fakeMailServer, strSubject, this.email.getTextMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ validateSend(fakeMailServer, strSubject, email.getTextMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
// validate html message
- validateSend(this.fakeMailServer, strSubject, this.email.getHtmlMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), false);
// validate attachment
- validateSend(this.fakeMailServer, strSubject,
MimeUtility.encodeText(attachment.getName()), this.email.getFromAddress(),
this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
false);
+ validateSend(fakeMailServer, strSubject,
MimeUtility.encodeText(attachment.getName()), email.getFromAddress(),
email.getToAddresses(),
+ email.getCcAddresses(), email.getBccAddresses(), false);
}
}
diff --git a/src/test/java/org/apache/commons/mail/SimpleEmailTest.java
b/src/test/java/org/apache/commons/mail/SimpleEmailTest.java
index b1fb3dd..449a5de 100644
--- a/src/test/java/org/apache/commons/mail/SimpleEmailTest.java
+++ b/src/test/java/org/apache/commons/mail/SimpleEmailTest.java
@@ -38,7 +38,7 @@ public class SimpleEmailTest extends AbstractEmailTest {
@BeforeEach
public void setUpSimpleEmailTest() {
// reusable objects to be used across multiple tests
- this.email = new MockSimpleEmail();
+ email = new MockSimpleEmail();
}
@Test
@@ -50,30 +50,30 @@ public class SimpleEmailTest extends AbstractEmailTest {
*/
System.setProperty(EmailConstants.MAIL_MIME_CHARSET, "utf-8");
// Test Success
- this.getMailServer();
+ getMailServer();
- this.email = new MockSimpleEmail();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockSimpleEmail();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
final String strSubject = "Test Msg Subject";
final String strMessage = "Test Msg Body ä"; // add non-ascii
character, otherwise us-ascii will be used
- this.email.setSubject(strSubject);
- this.email.setMsg(strMessage);
+ email.setSubject(strSubject);
+ email.setMsg(strMessage);
- this.email.send();
+ email.send();
- this.fakeMailServer.stop();
+ fakeMailServer.stop();
- validateSend(this.fakeMailServer, strSubject,
this.email.getMsg().substring(0, 13), // only check the start, the ä will be
encoded
- this.email.getFromAddress(), this.email.getToAddresses(),
this.email.getCcAddresses(), this.email.getBccAddresses(), true);
+ validateSend(fakeMailServer, strSubject, email.getMsg().substring(0,
13), // only check the start, the ä will be encoded
+ email.getFromAddress(), email.getToAddresses(),
email.getCcAddresses(), email.getBccAddresses(), true);
final String message = getMessageAsString(0);
// check that the charset has been correctly set
@@ -86,13 +86,13 @@ public class SimpleEmailTest extends AbstractEmailTest {
public void testGetSetMsg() throws EmailException {
// Test Success
for (final String validChar : testCharsValid) {
- this.email.setMsg(validChar);
- assertEquals(validChar, this.email.getMsg());
+ email.setMsg(validChar);
+ assertEquals(validChar, email.getMsg());
}
// Test Exception
- for (final String invalidChar : this.testCharsNotValid) {
+ for (final String invalidChar : testCharsNotValid) {
try {
- this.email.setMsg(invalidChar);
+ email.setMsg(invalidChar);
fail("Should have thrown an exception");
} catch (final EmailException e) {
assertTrue(true);
@@ -108,30 +108,30 @@ public class SimpleEmailTest extends AbstractEmailTest {
@Test
public void testSend() throws EmailException, IOException {
// Test Success
- this.getMailServer();
+ getMailServer();
- this.email = new MockSimpleEmail();
- this.email.setHostName(this.strTestMailServer);
- this.email.setSmtpPort(this.getMailServerPort());
- this.email.setFrom(this.strTestMailFrom);
- this.email.addTo(this.strTestMailTo);
+ email = new MockSimpleEmail();
+ email.setHostName(strTestMailServer);
+ email.setSmtpPort(getMailServerPort());
+ email.setFrom(strTestMailFrom);
+ email.addTo(strTestMailTo);
- if (this.strTestUser != null && this.strTestPasswd != null) {
- this.email.setAuthentication(this.strTestUser, this.strTestPasswd);
+ if (strTestUser != null && strTestPasswd != null) {
+ email.setAuthentication(strTestUser, strTestPasswd);
}
final String strSubject = "Test Msg Subject";
final String strMessage = "Test Msg Body";
- this.email.setCharset(EmailConstants.ISO_8859_1);
- this.email.setSubject(strSubject);
+ email.setCharset(EmailConstants.ISO_8859_1);
+ email.setSubject(strSubject);
- this.email.setMsg(strMessage);
+ email.setMsg(strMessage);
- this.email.send();
+ email.send();
- this.fakeMailServer.stop();
- validateSend(this.fakeMailServer, strSubject, this.email.getMsg(),
this.email.getFromAddress(), this.email.getToAddresses(),
- this.email.getCcAddresses(), this.email.getBccAddresses(),
true);
+ fakeMailServer.stop();
+ validateSend(fakeMailServer, strSubject, email.getMsg(),
email.getFromAddress(), email.getToAddresses(), email.getCcAddresses(),
+ email.getBccAddresses(), true);
}
}
diff --git a/src/test/java/org/apache/commons/mail/mocks/MockEmailConcrete.java
b/src/test/java/org/apache/commons/mail/mocks/MockEmailConcrete.java
index f9bd985..138c80c 100644
--- a/src/test/java/org/apache/commons/mail/mocks/MockEmailConcrete.java
+++ b/src/test/java/org/apache/commons/mail/mocks/MockEmailConcrete.java
@@ -37,28 +37,28 @@ public class MockEmailConcrete extends Email {
* @return Authenticator Authenticator
*/
public Authenticator getAuthenticator() {
- return this.authenticator;
+ return authenticator;
}
/**
* @return charset
*/
public String getCharset() {
- return this.charset;
+ return charset;
}
/**
* @return content
*/
public MimeMultipart getContentMimeMultipart() {
- return this.emailBody;
+ return emailBody;
}
/**
* @return content
*/
public Object getContentObject() {
- return this.content;
+ return content;
}
/**
@@ -72,7 +72,7 @@ public class MockEmailConcrete extends Email {
* @return emailBody
*/
public MimeMultipart getEmailBody() {
- return this.emailBody;
+ return emailBody;
}
/**
@@ -80,35 +80,35 @@ public class MockEmailConcrete extends Email {
*/
@Override
public String getHostName() {
- return this.hostName;
+ return hostName;
}
/**
* @return message
*/
public MimeMessage getMessage() {
- return this.message;
+ return message;
}
/**
* @return popHost
*/
public String getPopHost() {
- return this.popHost;
+ return popHost;
}
/**
* @return popPassword
*/
public String getPopPassword() {
- return this.popPassword;
+ return popPassword;
}
/**
* @return popUsername
*/
public String getPopUsername() {
- return this.popUsername;
+ return popUsername;
}
/**
@@ -116,7 +116,7 @@ public class MockEmailConcrete extends Email {
* @throws EmailException EmailException
*/
public Session getSession() throws EmailException {
- return this.getMailSession();
+ return getMailSession();
}
/**
@@ -125,7 +125,7 @@ public class MockEmailConcrete extends Email {
* @return debug
*/
public boolean isDebug() {
- return this.debug;
+ return debug;
}
/**
diff --git
a/src/test/java/org/apache/commons/mail/mocks/MockHtmlEmailConcrete.java
b/src/test/java/org/apache/commons/mail/mocks/MockHtmlEmailConcrete.java
index 5f22b49..40afc4e 100644
--- a/src/test/java/org/apache/commons/mail/mocks/MockHtmlEmailConcrete.java
+++ b/src/test/java/org/apache/commons/mail/mocks/MockHtmlEmailConcrete.java
@@ -35,7 +35,7 @@ public class MockHtmlEmailConcrete extends HtmlEmail {
*/
@Override
public InternetAddress getFromAddress() {
- return this.fromAddress;
+ return fromAddress;
}
/**
@@ -44,7 +44,7 @@ public class MockHtmlEmailConcrete extends HtmlEmail {
* @return Message Content
*/
public String getHtmlMsg() {
- return this.html;
+ return html;
}
/**
@@ -54,7 +54,7 @@ public class MockHtmlEmailConcrete extends HtmlEmail {
*/
public String getMsg() {
try {
- return this.getPrimaryBodyPart().getContent().toString();
+ return getPrimaryBodyPart().getContent().toString();
} catch (final IOException | MessagingException msgE) {
return null;
}
@@ -66,7 +66,7 @@ public class MockHtmlEmailConcrete extends HtmlEmail {
* @return Message Content
*/
public String getTextMsg() {
- return this.text;
+ return text;
}
}
diff --git
a/src/test/java/org/apache/commons/mail/mocks/MockImageHtmlEmailConcrete.java
b/src/test/java/org/apache/commons/mail/mocks/MockImageHtmlEmailConcrete.java
index 7ccc4b6..2a9d260 100644
---
a/src/test/java/org/apache/commons/mail/mocks/MockImageHtmlEmailConcrete.java
+++
b/src/test/java/org/apache/commons/mail/mocks/MockImageHtmlEmailConcrete.java
@@ -32,7 +32,7 @@ public class MockImageHtmlEmailConcrete extends
ImageHtmlEmail {
* @return Message Content
*/
public String getHtmlMsg() {
- return this.html;
+ return html;
}
/**
@@ -42,7 +42,7 @@ public class MockImageHtmlEmailConcrete extends
ImageHtmlEmail {
*/
public String getMsg() {
try {
- return this.getPrimaryBodyPart().getContent().toString();
+ return getPrimaryBodyPart().getContent().toString();
} catch (final IOException | MessagingException msgE) {
return null;
}
diff --git
a/src/test/java/org/apache/commons/mail/mocks/MockMultiPartEmailConcrete.java
b/src/test/java/org/apache/commons/mail/mocks/MockMultiPartEmailConcrete.java
index 892102e..f1676f5 100644
---
a/src/test/java/org/apache/commons/mail/mocks/MockMultiPartEmailConcrete.java
+++
b/src/test/java/org/apache/commons/mail/mocks/MockMultiPartEmailConcrete.java
@@ -35,7 +35,7 @@ public class MockMultiPartEmailConcrete extends
MultiPartEmail {
*/
@Override
public InternetAddress getFromAddress() {
- return this.fromAddress;
+ return fromAddress;
}
/**
@@ -45,7 +45,7 @@ public class MockMultiPartEmailConcrete extends
MultiPartEmail {
*/
public String getMsg() {
try {
- return this.getPrimaryBodyPart().getContent().toString();
+ return getPrimaryBodyPart().getContent().toString();
} catch (final IOException | MessagingException msgE) {
return null;
}
@@ -54,7 +54,7 @@ public class MockMultiPartEmailConcrete extends
MultiPartEmail {
/**
*/
public void initTest() {
- this.init();
+ init();
}
}
diff --git a/src/test/java/org/apache/commons/mail/mocks/MockSimpleEmail.java
b/src/test/java/org/apache/commons/mail/mocks/MockSimpleEmail.java
index 1427051..a5b5476 100644
--- a/src/test/java/org/apache/commons/mail/mocks/MockSimpleEmail.java
+++ b/src/test/java/org/apache/commons/mail/mocks/MockSimpleEmail.java
@@ -31,7 +31,7 @@ public class MockSimpleEmail extends SimpleEmail {
*/
@Override
public InternetAddress getFromAddress() {
- return this.fromAddress;
+ return fromAddress;
}
/**
@@ -40,7 +40,7 @@ public class MockSimpleEmail extends SimpleEmail {
* @return Message Content
*/
public String getMsg() {
- return (String) this.content;
+ return (String) content;
}
}