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

commit 0baf0d56cb36758e062054dedab0f81075df7410
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Dec 14 09:24:13 2023 -0500

    Javadoc
    
    Internal refactoring
---
 src/main/java/org/apache/commons/mail/Email.java   | 36 ++++++++--------------
 .../java/org/apache/commons/mail/EmailUtils.java   | 14 +++++++++
 .../java/org/apache/commons/mail/HtmlEmail.java    |  4 +--
 3 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/src/main/java/org/apache/commons/mail/Email.java 
b/src/main/java/org/apache/commons/mail/Email.java
index 035a66d..3466d3a 100644
--- a/src/main/java/org/apache/commons/mail/Email.java
+++ b/src/main/java/org/apache/commons/mail/Email.java
@@ -171,10 +171,6 @@ public abstract class Email {
     @Deprecated
     public static final String MAIL_SMTP_TIMEOUT = 
EmailConstants.MAIL_SMTP_TIMEOUT;
 
-    private static boolean isEmpty(final Collection<?> collection) {
-        return collection == null || collection.isEmpty();
-    }
-
     /** The email message to send. */
     protected MimeMessage message;
 
@@ -339,14 +335,12 @@ public abstract class Email {
      * @since 1.3
      */
     public Email addBcc(final String... emails) throws EmailException {
-        if (isEmpty(emails)) {
+        if (EmailUtils.isEmpty(emails)) {
             throw new EmailException("Address List provided was invalid");
         }
-
         for (final String email : emails) {
             addBcc(email, null);
         }
-
         return this;
     }
 
@@ -405,7 +399,7 @@ public abstract class Email {
      * @since 1.3
      */
     public Email addCc(final String... emails) throws EmailException {
-        if (isEmpty(emails)) {
+        if (EmailUtils.isEmpty(emails)) {
             throw new EmailException("Address List provided was invalid");
         }
         for (final String email : emails) {
@@ -531,7 +525,7 @@ public abstract class Email {
      * @since 1.3
      */
     public Email addTo(final String... emails) throws EmailException {
-        if (isEmpty(emails)) {
+        if (EmailUtils.isEmpty(emails)) {
             throw new EmailException("Address List provided was invalid");
         }
         for (final String email : emails) {
@@ -627,23 +621,23 @@ public abstract class Email {
                 throw new EmailException("At least one receiver address 
required");
             }
 
-            if (!this.toList.isEmpty()) {
+            if (!EmailUtils.isEmpty(toList)) {
                 this.message.setRecipients(Message.RecipientType.TO, 
this.toInternetAddressArray(this.toList));
             }
 
-            if (!this.ccList.isEmpty()) {
+            if (!EmailUtils.isEmpty(ccList)) {
                 this.message.setRecipients(Message.RecipientType.CC, 
this.toInternetAddressArray(this.ccList));
             }
 
-            if (!this.bccList.isEmpty()) {
+            if (!EmailUtils.isEmpty(bccList)) {
                 this.message.setRecipients(Message.RecipientType.BCC, 
this.toInternetAddressArray(this.bccList));
             }
 
-            if (!this.replyList.isEmpty()) {
+            if (!EmailUtils.isEmpty(replyList)) {
                 
this.message.setReplyTo(this.toInternetAddressArray(this.replyList));
             }
 
-            if (!this.headers.isEmpty()) {
+            if (!EmailUtils.isEmpty(headers)) {
                 for (final Map.Entry<String, String> entry : 
this.headers.entrySet()) {
                     final String foldedValue = 
createFoldedHeaderValue(entry.getKey(), entry.getValue());
                     this.message.addHeader(entry.getKey(), foldedValue);
@@ -978,10 +972,6 @@ public abstract class Email {
         return this.toList;
     }
 
-    private boolean isEmpty(final String[] array) {
-        return array == null || array.length == 0;
-    }
-
     /**
      * If partial sending of email enabled.
      *
@@ -1122,7 +1112,7 @@ public abstract class Email {
      * @since 1.0
      */
     public Email setBcc(final Collection<InternetAddress> aCollection) throws 
EmailException {
-        if (isEmpty(aCollection)) {
+        if (EmailUtils.isEmpty(aCollection)) {
             throw new EmailException("Address List provided was invalid");
         }
         this.bccList = new ArrayList<>(aCollection);
@@ -1140,7 +1130,7 @@ public abstract class Email {
      */
     public Email setBounceAddress(final String email) {
         checkSessionAlreadyInitialized();
-        if (email != null && !email.isEmpty()) {
+        if (!EmailUtils.isEmpty(email)) {
             try {
                 this.bounceAddress = createInternetAddress(email, null, 
this.charset).getAddress();
             } catch (final EmailException e) {
@@ -1164,7 +1154,7 @@ public abstract class Email {
      * @since 1.0
      */
     public Email setCc(final Collection<InternetAddress> aCollection) throws 
EmailException {
-        if (isEmpty(aCollection)) {
+        if (EmailUtils.isEmpty(aCollection)) {
             throw new EmailException("Address List provided was invalid");
         }
         this.ccList = new ArrayList<>(aCollection);
@@ -1382,7 +1372,7 @@ public abstract class Email {
      * @since 1.1
      */
     public Email setReplyTo(final Collection<InternetAddress> aCollection) 
throws EmailException {
-        if (isEmpty(aCollection)) {
+        if (EmailUtils.isEmpty(aCollection)) {
             throw new EmailException("Address List provided was invalid");
         }
         this.replyList = new ArrayList<>(aCollection);
@@ -1581,7 +1571,7 @@ public abstract class Email {
      * @since 1.0
      */
     public Email setTo(final Collection<InternetAddress> aCollection) throws 
EmailException {
-        if (isEmpty(aCollection)) {
+        if (EmailUtils.isEmpty(aCollection)) {
             throw new EmailException("Address List provided was invalid");
         }
         this.toList = new ArrayList<>(aCollection);
diff --git a/src/main/java/org/apache/commons/mail/EmailUtils.java 
b/src/main/java/org/apache/commons/mail/EmailUtils.java
index 36a2026..e6dbb6d 100644
--- a/src/main/java/org/apache/commons/mail/EmailUtils.java
+++ b/src/main/java/org/apache/commons/mail/EmailUtils.java
@@ -21,6 +21,8 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.BitSet;
+import java.util.Collection;
+import java.util.Map;
 import java.util.Random;
 
 import javax.mail.MessagingException;
@@ -119,6 +121,18 @@ final class EmailUtils {
         return builder.toString();
     }
 
+    static boolean isEmpty(final Collection<?> collection) {
+        return collection == null || collection.isEmpty();
+    }
+
+    static boolean isEmpty(final Map<?, ?> map) {
+        return map == null || map.isEmpty();
+    }
+
+    static boolean isEmpty(final Object[] array) {
+        return array == null || array.length == 0;
+    }
+
     /**
      * Checks if a String is empty ("") or null.
      * <p>
diff --git a/src/main/java/org/apache/commons/mail/HtmlEmail.java 
b/src/main/java/org/apache/commons/mail/HtmlEmail.java
index 828b60a..45a30b3 100644
--- a/src/main/java/org/apache/commons/mail/HtmlEmail.java
+++ b/src/main/java/org/apache/commons/mail/HtmlEmail.java
@@ -205,7 +205,7 @@ public class HtmlEmail extends MultiPartEmail {
 
         // determine how to form multiparts of email
 
-        if (EmailUtils.isNotEmpty(this.html) && !this.inlineEmbeds.isEmpty()) {
+        if (EmailUtils.isNotEmpty(this.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;
@@ -227,7 +227,7 @@ public class HtmlEmail extends MultiPartEmail {
             // inline images, the root container should have mimetype
             // "multipart/alternative".
             // reference: http://tools.ietf.org/html/rfc2046#section-5.1.4
-            if (!this.inlineEmbeds.isEmpty() || isBoolHasAttachments()) {
+            if (!EmailUtils.isEmpty(inlineEmbeds) || isBoolHasAttachments()) {
                 // If both HTML and TEXT bodies are provided, create an 
alternative
                 // container and add it to the root container
                 bodyContainer = new MimeMultipart("alternative");

Reply via email to