commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1342888 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/imap/IMAP.java main/java/org/apache/commons/net/imap/IMAPReply.java
Date Sat, 26 May 2012 11:56:23 GMT
Author: sebb
Date: Sat May 26 11:56:22 2012
New Revision: 1342888

URL: http://svn.apache.org/viewvc?rev=1342888&view=rev
Log:
NET-467 - IMAPClient#fetch() does not handle literal strings

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/IMAPReply.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=1342888&r1=1342887&r2=1342888&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Sat May 26 11:56:22 2012
@@ -65,6 +65,9 @@ The <action> type attribute can be add,u
         <release version="3.2" date="TBA" description="
 TBA
         ">
+            <action issue="NET-467" dev="sebb" type="fix">
+            IMAPClient#fetch() does not handle literal strings.
+            </action>
             <action issue="NET-458" dev="sebb" type="fix" due-to="Denis Molony">
             MVSFTPEntryParser.parseSimpleEntry - ArrayIndexOutOfBoundsException.
             </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=1342888&r1=1342887&r2=1342888&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 Sat May 26
11:56:22 2012
@@ -110,6 +110,15 @@ public class IMAP extends SocketClient
 
         if (wantTag) {
             while(IMAPReply.isUntagged(line)) {
+                int literalCount = IMAPReply.literalCount(line);
+                while (literalCount >= 0) {
+                    line=_reader.readLine();
+                    if (line == null) {
+                        throw new EOFException("Connection closed without indication.");
+                    }
+                    _replyLines.add(line);
+                    literalCount -= (line.length() + 2); // Allow for CRLF
+                }
                 line = _reader.readLine();
                 if (line == null) {
                     throw new EOFException("Connection closed without indication.");

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPReply.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPReply.java?rev=1342888&r1=1342887&r2=1342888&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPReply.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/imap/IMAPReply.java Sat
May 26 11:56:22 2012
@@ -78,6 +78,7 @@ public final class IMAPReply
         return line.startsWith(IMAP_CONTINUATION_PREFIX);
     }
 
+    // TODO do we need trailing .* ?
     private static final String TAGGED_RESPONSE = "^\\w+ (\\S+).*"; // TODO perhaps be less
strict on tag match?
     // tag cannot contain: + ( ) { SP CTL % * " \ ]
     private static final Pattern TAGGED_PATTERN = Pattern.compile(TAGGED_RESPONSE);
@@ -93,9 +94,24 @@ public final class IMAPReply
         return getReplyCode(line, TAGGED_PATTERN);
     }
 
-    private static final String UNTAGGED_RESPONSE = "^\\* (\\S+).*";
+    private static final String UNTAGGED_RESPONSE = "^\\* (\\S+).*"; // TODO do we need trailing
.* ?
     private static final Pattern UNTAGGED_PATTERN = Pattern.compile(UNTAGGED_RESPONSE);
 
+    private static final Pattern LITERAL_PATTERN = Pattern.compile("\\{(\\d+)\\}$"); // {dd}
+
+    /**
+     * Checks if the line introduces a literal, i.e. ends with {dd}
+     * 
+     * @return the literal count, or -1 if there was no literal.
+     */
+    public static int literalCount(String line) {
+        Matcher m = LITERAL_PATTERN.matcher(line);
+        if (m.find()) {
+            return Integer.parseInt(m.group(1)); // Should always parse because we matched
\d+
+        }
+        return -1;
+    }
+
     /**
      * Intepret the String reply code - OK, NO, BAD - in an untagged response as a integer.
      *



Mime
View raw message