Merge branch 'master' into trunk
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
old mode 100755
new mode 100644
diff --git a/README.md b/README.md
index d2a83a8..fba39b6 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,7 @@
-------------
More information can be found on the [Apache Commons Net homepage](https://commons.apache.org/proper/commons-net).
-The [JavaDoc](https://commons.apache.org/proper/commons-net/javadocs/api-release) can be browsed.
+The [Javadoc](https://commons.apache.org/proper/commons-net/javadocs/api-release) can be browsed.
Questions related to the usage of Apache Commons Net should be posted to the [user mailing list][ml].
Where can I get the latest release?
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index bbaf6c2..8b480cb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -74,6 +74,12 @@
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>
diff --git a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
index 74067ad..839f09c 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
@@ -375,12 +375,16 @@
for(int i=1; i< replyStrings.length - 1; i++) {
final String line = replyStrings[i];
if (line.startsWith("Return-Path: ")) {
- String[] parts = line.split(" ", 2);
- replyTo = parts[1];
- if (replyTo.startsWith("<")) {
- replyTo = replyTo.substring(1,replyTo.length()-1); // drop <> wrapper
- } else {
- System.err.println("Unexpected Return-path:" + line+ " in " + firstLine);
+ String[] parts = line.split(" ", 2);
+ if (!parts[1].equals("<>")) {// Don't replace default with blank
+ replyTo = parts[1];
+ if (replyTo.startsWith("<")) {
+ if (replyTo.endsWith(">")) {
+ replyTo = replyTo.substring(1,replyTo.length()-1); // drop <> wrapper
+ } else {
+ System.err.println("Unexpected Return-path: '" + line+ "' in " + firstLine);
+ }
+ }
}
break;
}
diff --git a/src/main/java/org/apache/commons/net/examples/mail/IMAPMail.java b/src/main/java/org/apache/commons/net/examples/mail/IMAPMail.java
index d1f3995..8929905 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/IMAPMail.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/IMAPMail.java
@@ -66,6 +66,8 @@
imap.status("inbox", new String[]{"MESSAGES"});
+ imap.list("", "*"); // Show the folders
+
} catch (IOException e) {
System.out.println(imap.getReplyString());
e.printStackTrace();
diff --git a/src/main/java/org/apache/commons/net/imap/IMAP.java b/src/main/java/org/apache/commons/net/imap/IMAP.java
index 5469116..272a534 100644
--- a/src/main/java/org/apache/commons/net/imap/IMAP.java
+++ b/src/main/java/org/apache/commons/net/imap/IMAP.java
@@ -467,5 +467,36 @@
}
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 quoteMailboxName(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; */
diff --git a/src/main/java/org/apache/commons/net/imap/IMAPClient.java b/src/main/java/org/apache/commons/net/imap/IMAPClient.java
index 5ae1487..fd243a3 100644
--- a/src/main/java/org/apache/commons/net/imap/IMAPClient.java
+++ b/src/main/java/org/apache/commons/net/imap/IMAPClient.java
@@ -112,7 +112,7 @@
*/
public boolean select(String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.SELECT, mailboxName);
+ return doCommand (IMAPCommand.SELECT, quoteMailboxName(mailboxName));
}
/**
@@ -123,7 +123,7 @@
*/
public boolean examine(String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.EXAMINE, mailboxName);
+ return doCommand (IMAPCommand.EXAMINE, quoteMailboxName(mailboxName));
}
/**
@@ -134,7 +134,7 @@
*/
public boolean create(String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.CREATE, mailboxName);
+ return doCommand (IMAPCommand.CREATE, quoteMailboxName(mailboxName));
}
/**
@@ -145,7 +145,7 @@
*/
public boolean delete(String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.DELETE, mailboxName);
+ return doCommand (IMAPCommand.DELETE, quoteMailboxName(mailboxName));
}
/**
@@ -157,7 +157,7 @@
*/
public boolean rename(String oldMailboxName, String newMailboxName) throws IOException
{
- return doCommand (IMAPCommand.RENAME, oldMailboxName + " " + newMailboxName);
+ return doCommand (IMAPCommand.RENAME, quoteMailboxName(oldMailboxName) + " " + quoteMailboxName(newMailboxName));
}
/**
@@ -168,7 +168,7 @@
*/
public boolean subscribe(String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.SUBSCRIBE, mailboxName);
+ return doCommand (IMAPCommand.SUBSCRIBE, quoteMailboxName(mailboxName));
}
/**
@@ -179,23 +179,29 @@
*/
public boolean unsubscribe(String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.UNSUBSCRIBE, mailboxName);
+ return doCommand (IMAPCommand.UNSUBSCRIBE, quoteMailboxName(mailboxName));
}
/**
* 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, quoteMailboxName(refName) + " " + quoteMailboxName(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 boolean lsub(String refName, String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.LSUB, refName + " " + mailboxName);
+ return doCommand (IMAPCommand.LSUB, quoteMailboxName(refName) + " " + quoteMailboxName(mailboxName));
}
/**
@@ -220,7 +226,7 @@
}
StringBuilder sb = new StringBuilder();
- sb.append(mailboxName);
+ sb.append(quoteMailboxName(mailboxName));
sb.append(" (");
for ( int i = 0; i < itemNames.length; i++ )
@@ -247,7 +253,7 @@
*/
public boolean append(String mailboxName, String flags, String datetime, String message) throws IOException
{
- StringBuilder args = new StringBuilder(mailboxName);
+ StringBuilder args = new StringBuilder(quoteMailboxName(mailboxName));
if (flags != null) {
args.append(" ").append(flags);
}
@@ -411,7 +417,7 @@
*/
public boolean copy(String sequenceSet, String mailboxName) throws IOException
{
- return doCommand (IMAPCommand.COPY, sequenceSet + " " + mailboxName);
+ return doCommand (IMAPCommand.COPY, sequenceSet + " " + quoteMailboxName(mailboxName));
}
/**
diff --git a/src/site/xdoc/code-standards.xml b/src/site/xdoc/code-standards.xml
index 6cc29a3..24b782e 100644
--- a/src/site/xdoc/code-standards.xml
+++ b/src/site/xdoc/code-standards.xml
@@ -115,10 +115,10 @@
</p>
<p>
-5. JavaDoc <strong>MUST</strong> exist on all public and protected methods.
-JavaDoc on private and default access methods and members is preferred and
+5. Javadoc <strong>MUST</strong> exist on all public and protected methods.
+Javadoc on private and default access methods and members is preferred and
encouraged. If your code modifications use an existing class/method/variable
-which lacks JavaDoc, it is required that you add it. This will improve the
+which lacks Javadoc, it is required that you add it. This will improve the
project as a whole.
</p>
diff --git a/src/site/xdoc/download_net.xml b/src/site/xdoc/download_net.xml
index 1766846..2ecc3f4 100644
--- a/src/site/xdoc/download_net.xml
+++ b/src/site/xdoc/download_net.xml
@@ -102,7 +102,7 @@
It is essential that you
<a href="https://www.apache.org/info/verification.html">verify the integrity</a>
of downloaded files, preferably using the <code>PGP</code> signature (<code>*.asc</code> files);
- failing that using the <code>MD5</code> hash (<code>*.md5</code> checksum files).
+ failing that using the <code>SHA256</code> hash (<code>*.sha256</code> checksum files).
</p>
<p>
The <a href="https://www.apache.org/dist/commons/KEYS">KEYS</a>
@@ -116,12 +116,12 @@
<table>
<tr>
<td><a href="[preferred]/commons/net/binaries/commons-net-3.6-bin.tar.gz">commons-net-3.6-bin.tar.gz</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-3.6-bin.tar.gz.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-3.6-bin.tar.gz.sha256">sha256</a></td>
<td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-3.6-bin.tar.gz.asc">pgp</a></td>
</tr>
<tr>
<td><a href="[preferred]/commons/net/binaries/commons-net-3.6-bin.zip">commons-net-3.6-bin.zip</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-3.6-bin.zip.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-3.6-bin.zip.sha256">sha256</a></td>
<td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-3.6-bin.zip.asc">pgp</a></td>
</tr>
</table>
@@ -130,47 +130,17 @@
<table>
<tr>
<td><a href="[preferred]/commons/net/source/commons-net-3.6-src.tar.gz">commons-net-3.6-src.tar.gz</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-3.6-src.tar.gz.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-3.6-src.tar.gz.sha256">sha256</a></td>
<td><a href="https://www.apache.org/dist/commons/net/source/commons-net-3.6-src.tar.gz.asc">pgp</a></td>
</tr>
<tr>
<td><a href="[preferred]/commons/net/source/commons-net-3.6-src.zip">commons-net-3.6-src.zip</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-3.6-src.zip.md5">md5</a></td>
+ <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-3.6-src.zip.sha256">sha256</a></td>
<td><a href="https://www.apache.org/dist/commons/net/source/commons-net-3.6-src.zip.asc">pgp</a></td>
</tr>
</table>
</subsection>
</section>
- <section name="Apache Commons Net 1.4.1 (Requires Java 1.3 or later)">
- <subsection name="Binaries">
- <table>
- <tr>
- <td><a href="[preferred]/commons/net/binaries/commons-net-1.4.1.tar.gz">commons-net-1.4.1.tar.gz</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-1.4.1.tar.gz.md5">md5</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-1.4.1.tar.gz.asc">pgp</a></td>
- </tr>
- <tr>
- <td><a href="[preferred]/commons/net/binaries/commons-net-1.4.1.zip">commons-net-1.4.1.zip</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-1.4.1.zip.md5">md5</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/binaries/commons-net-1.4.1.zip.asc">pgp</a></td>
- </tr>
- </table>
- </subsection>
- <subsection name="Source">
- <table>
- <tr>
- <td><a href="[preferred]/commons/net/source/commons-net-1.4.1-src.tar.gz">commons-net-1.4.1-src.tar.gz</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-1.4.1-src.tar.gz.md5">md5</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-1.4.1-src.tar.gz.asc">pgp</a></td>
- </tr>
- <tr>
- <td><a href="[preferred]/commons/net/source/commons-net-1.4.1-src.zip">commons-net-1.4.1-src.zip</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-1.4.1-src.zip.md5">md5</a></td>
- <td><a href="https://www.apache.org/dist/commons/net/source/commons-net-1.4.1-src.zip.asc">pgp</a></td>
- </tr>
- </table>
- </subsection>
- </section>
<section name="Archives">
<p>
Older releases can be obtained from the archives.
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml
index 9c739df..deef7ef 100644
--- a/src/site/xdoc/index.xml
+++ b/src/site/xdoc/index.xml
@@ -210,7 +210,7 @@
</section>
<section name="Further Information">
<p>
- For more info, see the JavaDoc, or look at some of the following articles:
+ For more info, see the Javadoc, or look at some of the following articles:
<ul>
<li><a href="http://www.informit.com/guides/content.asp?g=java&seqNum=40">http://www.informit.com/guides/content.asp?g=java&seqNum=40</a>Jakarta Commons - Net Class Library</li>
<li><a href="http://www.onjava.com/pub/a/onjava/2003/06/25/commons.html?page=3">http://www.onjava.com/pub/a/onjava/2003/06/25/commons.html?page=3</a>Using the Jakarta Commons, Part 1</li>