Author: norman
Date: Thu Aug 25 16:14:28 2011
New Revision: 1161625
URL: http://svn.apache.org/viewvc?rev=1161625&view=rev
Log:
Decode the mailbox name before base it to the mailboxmanager and encode it
before pass it back to the client. So we don't have the utf7 encoded
mailboxname in the mailboxmanager. See IMAP-330
Modified:
james/imap/trunk/api/pom.xml
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
james/imap/trunk/pom.xml
Modified: james/imap/trunk/api/pom.xml
URL:
http://svn.apache.org/viewvc/james/imap/trunk/api/pom.xml?rev=1161625&r1=1161624&r2=1161625&view=diff
==============================================================================
--- james/imap/trunk/api/pom.xml (original)
+++ james/imap/trunk/api/pom.xml Thu Aug 25 16:14:28 2011
@@ -37,7 +37,10 @@
<groupId>org.apache.james</groupId>
<artifactId>apache-james-mailbox-api</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>jutf7</groupId>
+ <artifactId>jutf7</artifactId>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Modified:
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java?rev=1161625&r1=1161624&r2=1161625&view=diff
==============================================================================
---
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
(original)
+++
james/imap/trunk/api/src/main/java/org/apache/james/imap/api/display/CharsetUtil.java
Thu Aug 25 16:14:28 2011
@@ -18,14 +18,19 @@
****************************************************************/
package org.apache.james.imap.api.display;
+import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import com.beetstra.jutf7.CharsetProvider;
+
/**
- * Utility class which can be used to get a list of supported Charsets
+ * Utility class which can be used to get a list of supported {@link
Charset}'s
+ *
+ * Beside this it has some methods included which helps to encode/decode
modified UTF7
*
*
*/
@@ -33,6 +38,8 @@ public class CharsetUtil {
private static Set<String> charsetNames;
private static Set<Charset> charsets;
+ private static final String X_MODIFIED_UTF_7 = "X-MODIFIED-UTF-7";
+ private static final Charset X_MODIFIED_UTF_7_CHARSET = new
CharsetProvider().charsetForName(X_MODIFIED_UTF_7);
// build the sets which holds the charsets and names
@@ -70,4 +77,30 @@ public class CharsetUtil {
return charsets;
}
+
+ /**
+ * Decode the given UTF7 encoded <code>String</code>
+ *
+ * @param string
+ * @return decoded
+ */
+ public static String decodeModifiedUTF7(String string) {
+ return
X_MODIFIED_UTF_7_CHARSET.decode(ByteBuffer.wrap(string.getBytes())).toString();
+
+ }
+
+
+ /**
+ * Encode the given <code>String</code> to modified UTF7.
+ * See RFC3501 for more details
+ *
+ * @param string
+ * @return encoded
+ */
+
+ public static String encodeModifiedUTF7(String string) {
+ ByteBuffer encode = X_MODIFIED_UTF_7_CHARSET.encode(string);
+ return new String(encode.array(), 0, encode.remaining());
+
+ }
}
Modified:
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java?rev=1161625&r1=1161624&r2=1161625&view=diff
==============================================================================
---
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
(original)
+++
james/imap/trunk/message/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
Thu Aug 25 16:14:28 2011
@@ -37,6 +37,7 @@ import java.util.List;
import javax.mail.Flags;
import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.display.CharsetUtil;
import org.apache.james.imap.api.display.HumanReadableText;
import org.apache.james.imap.api.message.IdRange;
import org.apache.james.imap.api.message.request.DayMonthYear;
@@ -240,6 +241,19 @@ public abstract class ImapRequestLineRea
}
/**
+ *
+ * Reads the mailbox name via {@link #mailboxUTF7()} but also decode it
via {@link CharsetUtil#decodeModifiedUTF7(String)}
+ *
+ * If you really want to get the modified UTF7 version you should use
{@link #mailboxUTF7()}
+ *
+ * @return decodedMailbox
+ *
+ */
+ public String mailbox() throws DecodingException {
+ return CharsetUtil.decodeModifiedUTF7(mailboxUTF7());
+ }
+
+ /**
* Reads a "mailbox" argument from the request. Not implemented *exactly*
as
* per spec, since a quoted or literal "inbox" still yeilds "INBOX" (ie
* still case-insensitive if quoted or literal). I think this makes sense.
@@ -247,8 +261,13 @@ public abstract class ImapRequestLineRea
* mailbox ::= "INBOX" / astring ;; INBOX is case-insensitive. All case
* variants of ;; INBOX (e.g. "iNbOx") MUST be interpreted as INBOX ;; not
* as an astring.
+ *
+ * Be aware that mailbox names are encoded via a modified UTF7. For more
informations RFC3501
+ *
+ *
+ *
*/
- public String mailbox() throws DecodingException {
+ public String mailboxUTF7() throws DecodingException {
String mailbox = astring();
if (mailbox.equalsIgnoreCase(ImapConstants.INBOX_NAME)) {
return ImapConstants.INBOX_NAME;
@@ -256,7 +275,6 @@ public abstract class ImapRequestLineRea
return mailbox;
}
}
-
/**
* Reads one <code>date</code> argument from the request.
*
Modified:
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java?rev=1161625&r1=1161624&r2=1161625&view=diff
==============================================================================
---
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
(original)
+++
james/imap/trunk/message/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
Thu Aug 25 16:14:28 2011
@@ -19,6 +19,7 @@
package org.apache.james.imap.message.response;
+import org.apache.james.imap.api.display.CharsetUtil;
import org.apache.james.imap.api.process.MailboxType;
/**
@@ -52,7 +53,7 @@ public abstract class AbstractListingRes
this.unmarked = unmarked;
this.children = hasChildren;
this.noChildren = hasNoChildren;
- this.name = name;
+ this.name = CharsetUtil.encodeModifiedUTF7(name);
this.hierarchyDelimiter = hierarchyDelimiter;
this.type = type;
}
Modified: james/imap/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/james/imap/trunk/pom.xml?rev=1161625&r1=1161624&r2=1161625&view=diff
==============================================================================
--- james/imap/trunk/pom.xml (original)
+++ james/imap/trunk/pom.xml Thu Aug 25 16:14:28 2011
@@ -61,6 +61,12 @@
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
+ <repository>
+ <id>maven.alfresco.com</id>
+ <name>Alfresco Repository for Maven</name>
+ <url>http://maven.alfresco.com/nexus/content/repositories/public/</url>
+ <layout>default</layout>
+ </repository>
</repositories>
<build>
@@ -519,6 +525,11 @@
<!--
END Commons
-->
+ <dependency>
+ <groupId>jutf7</groupId>
+ <artifactId>jutf7</artifactId>
+ <version>1.0.0</version>
+ </dependency>
<!--
START Testing
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]