Author: sebb
Date: Fri Oct 5 19:23:16 2018
New Revision: 1842969
URL: http://svn.apache.org/viewvc?rev=1842969&view=rev
Log:
NET-614 IMAP fails to quote/encode mailbox names...
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPClient.java
Modified: commons/proper/net/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1842969&r1=1842968&r2=1842969&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/net/trunk/src/changes/changes.xml [utf-8] Fri Oct 5
19:23:16 2018
@@ -74,6 +74,12 @@ This is mainly a bug-fix release. See fu
The examples are not part of the public API, so this does not affect
compatibility.
">
+ <action issue="NET-615" type="add" dev="sebb">
+ IMAPClient could simplify using empty arguments
+ </action>
+ <action issue="NET-614" type="add" dev="sebb">
+ IMAP fails to quote/encode mailbox names
+ </action>
<action issue="NET-643" type="fix" dev="sebb" due-to="Vasily">
NPE when closing telnet stream
</action>
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java?rev=1842969&r1=1842968&r2=1842969&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAP.java
Fri Oct 5 19:23:16 2018
@@ -467,5 +467,36 @@ public class IMAP extends SocketClient
}
return res;
}
+
+ /**
+ * Quote an input string if necessary.
+ * If the string is enclosed in double-quotes it is assumed
+ * to be quoted already and is returned unchanged.
+ * If it is the empty string, "" is returned.
+ * If it contains a space
+ * then it is enclosed in double quotes, escaping the
+ * characters backslash and double-quote.
+ *
+ * @param input the value to be quoted, may be null
+ * @return the quoted value
+ */
+ static String quoteString(String input) {
+ if (input == null) { // Don't throw NPE here
+ return null;
+ }
+ if (input.isEmpty()) {
+ return "\"\""; // return the string ""
+ }
+ // Length check is necessary to ensure a lone double-quote is quoted
+ if (input.length() > 1 && input.startsWith("\"") &&
input.endsWith("\"")) {
+ return input; // Assume already quoted
+ }
+ if (input.contains(" ")) {
+ // quoted strings must escape \ and "
+ return "\"" + input.replaceAll("([\\\\\"])", "\\\\$1") + "\"";
+ }
+ return input;
+
+ }
}
/* kate: indent-width 4; replace-tabs on; */
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPClient.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPClient.java?rev=1842969&r1=1842968&r2=1842969&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPClient.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPClient.java
Fri Oct 5 19:23:16 2018
@@ -184,18 +184,24 @@ public class IMAPClient extends IMAP
/**
* Send a LIST command to the server.
- * @param refName The reference name.
+ * Quotes the parameters if necessary.
+ * @param refName The reference name
+ * If empty, indicates that the mailbox name is interpreted
as by SELECT.
* @param mailboxName The mailbox name.
+ * If empty, this is a special request to
+ * return the hierarchy delimiter and the root name of
the name given
+ * in the reference
* @return {@code true} if the command was successful,{@code false} if not.
* @throws IOException If a network I/O error occurs.
*/
public boolean list(String refName, String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.LIST, refName + " " + mailboxName);
+ return doCommand (IMAPCommand.LIST, quoteString(refName) + " " +
quoteString(mailboxName));
}
/**
* Send an LSUB command to the server.
+ * Quotes the parameters if necessary.
* @param refName The reference name.
* @param mailboxName The mailbox name.
* @return {@code true} if the command was successful,{@code false} if not.
@@ -203,7 +209,7 @@ public class IMAPClient extends IMAP
*/
public boolean lsub(String refName, String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.LSUB, refName + " " + mailboxName);
+ return doCommand (IMAPCommand.LSUB, quoteString(refName) + " " +
quoteString(mailboxName));
}
/**