You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/12/13 21:15:17 UTC
(commons-email) 03/07: Simplify if-else
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 b708879d13be5c9cd8465153abb0605b1886fb42
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Dec 13 15:53:39 2023 -0500
Simplify if-else
---
src/main/java/org/apache/commons/mail/Email.java | 22 +++++--------
.../mail/resolver/DataSourceFileResolver.java | 6 ++--
.../commons/mail/util/MimeMessageParser.java | 38 ++++++++++------------
3 files changed, 28 insertions(+), 38 deletions(-)
diff --git a/src/main/java/org/apache/commons/mail/Email.java b/src/main/java/org/apache/commons/mail/Email.java
index 87c075c..515e6f4 100644
--- a/src/main/java/org/apache/commons/mail/Email.java
+++ b/src/main/java/org/apache/commons/mail/Email.java
@@ -619,10 +619,8 @@ public abstract class Email {
if (this.fromAddress != null) {
this.message.setFrom(this.fromAddress);
- } else {
- if (session.getProperty(EmailConstants.MAIL_SMTP_FROM) == null && session.getProperty(EmailConstants.MAIL_FROM) == null) {
- throw new EmailException("From address required");
- }
+ } 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) {
@@ -1640,15 +1638,13 @@ public abstract class Email {
} else {
this.charset = aContentType.substring(charsetPos);
}
- } else {
- // use the default charset, if one exists, for messages
- // whose content-type is some form of text.
- if (this.contentType.startsWith("text/") && EmailUtils.isNotEmpty(this.charset)) {
- final StringBuilder contentTypeBuf = new StringBuilder(this.contentType);
- contentTypeBuf.append(strMarker);
- contentTypeBuf.append(this.charset);
- this.contentType = contentTypeBuf.toString();
- }
+ } else // use the default charset, if one exists, for messages
+ // whose content-type is some form of text.
+ if (this.contentType.startsWith("text/") && EmailUtils.isNotEmpty(this.charset)) {
+ final StringBuilder contentTypeBuf = new StringBuilder(this.contentType);
+ contentTypeBuf.append(strMarker);
+ contentTypeBuf.append(this.charset);
+ this.contentType = contentTypeBuf.toString();
}
}
}
diff --git a/src/main/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java b/src/main/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java
index e45b42f..321a55d 100644
--- a/src/main/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java
+++ b/src/main/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java
@@ -88,10 +88,8 @@ public class DataSourceFileResolver extends DataSourceBaseResolver {
if (file.exists()) {
result = new FileDataSource(file);
- } else {
- if (!isLenient) {
- throw new IOException("Cant resolve the following file resource :" + file.getAbsolutePath());
- }
+ } else if (!isLenient) {
+ throw new IOException("Cant resolve the following file resource :" + file.getAbsolutePath());
}
}
diff --git a/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java b/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
index be4c8b0..1d0aaf8 100644
--- a/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
+++ b/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
@@ -319,29 +319,25 @@ public class MimeMessageParser {
protected void parse(final Multipart parent, final MimePart part) throws MessagingException, IOException {
if (isMimeType(part, "text/plain") && plainContent == null && !Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
plainContent = (String) part.getContent();
+ } else if (isMimeType(part, "text/html") && htmlContent == null && !Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
+ htmlContent = (String) part.getContent();
+ } else if (isMimeType(part, "multipart/*")) {
+ this.isMultiPart = true;
+ final Multipart mp = (Multipart) part.getContent();
+ final int count = mp.getCount();
+
+ // iterate over all MimeBodyPart
+
+ for (int i = 0; i < count; i++) {
+ parse(mp, (MimeBodyPart) mp.getBodyPart(i));
+ }
} else {
- if (isMimeType(part, "text/html") && htmlContent == null && !Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
- htmlContent = (String) part.getContent();
- } else {
- if (isMimeType(part, "multipart/*")) {
- this.isMultiPart = true;
- final Multipart mp = (Multipart) part.getContent();
- final int count = mp.getCount();
-
- // iterate over all MimeBodyPart
-
- for (int i = 0; i < count; i++) {
- parse(mp, (MimeBodyPart) mp.getBodyPart(i));
- }
- } else {
- final String cid = stripContentId(part.getContentID());
- final DataSource ds = createDataSource(parent, part);
- if (cid != null) {
- this.cidMap.put(cid, ds);
- }
- this.attachmentList.add(ds);
- }
+ final String cid = stripContentId(part.getContentID());
+ final DataSource ds = createDataSource(parent, part);
+ if (cid != null) {
+ this.cidMap.put(cid, ds);
}
+ this.attachmentList.add(ds);
}
}