You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/04/24 02:59:43 UTC
[james-project] 08/17: [Refactoring] avoid using ifPresent for
Optional
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 4045b5f0b95d50fed5fce926cd1fb5d47fc934fa
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Tue Apr 21 19:57:32 2020 +0200
[Refactoring] avoid using ifPresent for Optional
---
.../apache/james/transport/mailets/ContentReplacer.java | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContentReplacer.java b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContentReplacer.java
index 725df64..c3f4b54 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContentReplacer.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/ContentReplacer.java
@@ -34,6 +34,7 @@ import org.apache.mailet.MailetException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.github.fge.lambdas.Throwing;
import com.google.common.base.Strings;
public class ContentReplacer {
@@ -92,23 +93,19 @@ public class ContentReplacer {
}
}
- private boolean applySubjectReplacingUnits(Mail mail, ReplaceConfig replaceConfig, Optional<Charset> charset) throws MessagingException {
+ private boolean applySubjectReplacingUnits(Mail mail, ReplaceConfig replaceConfig, Optional<Charset> maybeCharset) throws MessagingException {
if (!replaceConfig.getSubjectReplacingUnits().isEmpty()) {
String subject = applyPatterns(replaceConfig.getSubjectReplacingUnits(),
Strings.nullToEmpty(mail.getMessage().getSubject()));
- if (charset.isPresent()) {
- mail.getMessage().setSubject(subject, charset.get().name());
- return true;
- } else {
- String previousCharset = previousCharset(mail);
- mail.getMessage().setSubject(subject, previousCharset);
- return true;
- }
+ String charset = maybeCharset.map(Charset::name)
+ .orElseGet(Throwing.supplier(() -> previousCharset(mail)).sneakyThrow());
+ mail.getMessage().setSubject(subject, charset);
+ return true;
}
return false;
}
- private String previousCharset(Mail mail) throws ParseException, MessagingException {
+ private String previousCharset(Mail mail) throws MessagingException {
ContentType contentType = new ContentType(mail.getMessage().getContentType());
return contentType.getParameter("Charset");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org