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 ad...@apache.org on 2017/11/08 07:29:53 UTC
[6/9] james-project git commit: PROTOCOL-117 refactor
ListingEncodingUtils to a more straightforward style
PROTOCOL-117 refactor ListingEncodingUtils to a more straightforward style
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/86214d8a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/86214d8a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/86214d8a
Branch: refs/heads/master
Commit: 86214d8a1920c705c0a1f0c9d52d0aabc71a95d8
Parents: 1411959
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Nov 7 16:44:44 2017 +0100
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Tue Nov 7 17:55:48 2017 +0100
----------------------------------------------------------------------
.../james/imap/encode/ListingEncodingUtils.java | 68 ++++++++------------
.../response/AbstractListingResponse.java | 10 ---
2 files changed, 28 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/86214d8a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
index 81b7309..f152cbc 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
@@ -27,64 +27,52 @@ import org.apache.james.imap.api.ImapConstants;
import org.apache.james.imap.api.process.MailboxType;
import org.apache.james.imap.message.response.AbstractListingResponse;
-/**
- * Utilities for encoding LIST and LSUB responses.
- */
public class ListingEncodingUtils {
public static void encodeListingResponse(String responseTypeName, ImapResponseComposer composer, AbstractListingResponse response) throws IOException {
- final List<String> attributes = getNameAttributes(response);
- final String name = response.getName();
- final char hierarchyDelimiter = response.getHierarchyDelimiter();
-
composer.untagged();
composer.message(responseTypeName);
composer.openParen();
- if (attributes != null) {
- for (String attribute : attributes) {
- composer.message(attribute);
- }
+ for (String attribute : getNameAttributes(response)) {
+ composer.message(attribute);
}
composer.closeParen();
+ writeDelimiter(composer, response.getHierarchyDelimiter());
+ composer.mailbox(response.getName());
+ composer.end();
+ }
+ private static void writeDelimiter(ImapResponseComposer composer, char hierarchyDelimiter) throws IOException {
if (hierarchyDelimiter == Character.UNASSIGNED) {
composer.nil();
} else {
composer.quote(Character.toString(hierarchyDelimiter));
}
- composer.mailbox(name);
-
- composer.end();
}
private static List<String> getNameAttributes(AbstractListingResponse response) {
- final List<String> attributes;
- if (response.isNameAttributed()) {
- attributes = new ArrayList<>();
- if (response.isNoInferiors()) {
- attributes.add(ImapConstants.NAME_ATTRIBUTE_NOINFERIORS);
- }
- if (response.isNoSelect()) {
- attributes.add(ImapConstants.NAME_ATTRIBUTE_NOSELECT);
- }
- if (response.isMarked()) {
- attributes.add(ImapConstants.NAME_ATTRIBUTE_MARKED);
- }
- if (response.isUnmarked()) {
- attributes.add(ImapConstants.NAME_ATTRIBUTE_UNMARKED);
- }
- if (response.hasChildren()) {
- attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_CHILDREN);
- }
- if (response.hasNoChildren()) {
- attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_NO_CHILDREN);
- }
- if (!MailboxType.OTHER.equals(response.getType())) {
- attributes.add(response.getType().getAttributeName());
- }
- } else {
- attributes = null;
+ final List<String> attributes = new ArrayList<>();
+ if (response.isNoInferiors()) {
+ attributes.add(ImapConstants.NAME_ATTRIBUTE_NOINFERIORS);
+ }
+ if (response.isNoSelect()) {
+ attributes.add(ImapConstants.NAME_ATTRIBUTE_NOSELECT);
+ }
+ if (response.isMarked()) {
+ attributes.add(ImapConstants.NAME_ATTRIBUTE_MARKED);
+ }
+ if (response.isUnmarked()) {
+ attributes.add(ImapConstants.NAME_ATTRIBUTE_UNMARKED);
+ }
+ if (response.hasChildren()) {
+ attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_CHILDREN);
+ }
+ if (response.hasNoChildren()) {
+ attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_NO_CHILDREN);
+ }
+ if (!MailboxType.OTHER.equals(response.getType())) {
+ attributes.add(response.getType().getAttributeName());
}
return attributes;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/86214d8a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
index a66ffb5..53fcf78 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
@@ -138,16 +138,6 @@ public abstract class AbstractListingResponse {
return type;
}
- /**
- * Are any name attributes set?
- *
- * @return true if {@link #isNoInferiors()}, {@link #isNoSelect()},
- * {@link #isMarked()} or {@link #isUnmarked()}
- */
- public final boolean isNameAttributed() {
- return noInferiors || noSelect || marked || unmarked || children || noChildren || (!MailboxType.OTHER.equals(type));
- }
-
@Override
public int hashCode() {
final int PRIME = 31;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org