[kaffe] CVS kaffe (robilad): Resynced with GNU inetlib: imap fixes

Kaffe CVS cvs-commits at kaffe.org
Sun Sep 11 14:56:46 PDT 2005


PatchSet 6891 
Date: 2005/09/11 21:51:48
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU inetlib: imap fixes

Members: 
	ChangeLog:1.4412->1.4413 
	libraries/javalib/Makefile.am:1.389->1.390 
	libraries/javalib/Makefile.in:1.480->1.481 
	libraries/javalib/all.files:1.159->1.160 
	libraries/javalib/gnu/inet/imap/IMAPConnection.java:1.9->1.10 
	libraries/javalib/gnu/inet/imap/IMAPConstants.java:1.7->1.8 
	libraries/javalib/gnu/inet/imap/MessageSetTokenizer.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/imap/UIDPlusHandler.java:INITIAL->1.1 
	libraries/javalib/gnu/inet/imap/package.html:1.2->1.3 
	libraries/javalib/gnu/inet/nntp/ActiveTimesIterator.java:1.6->1.7 
	libraries/javalib/gnu/inet/nntp/ArticleNumberIterator.java:1.6->1.7 
	libraries/javalib/gnu/inet/nntp/ArticleStream.java:1.6->1.7 
	libraries/javalib/gnu/inet/nntp/GroupIterator.java:1.6->1.7 
	libraries/javalib/gnu/inet/nntp/NNTPConnection.java:1.7->1.8 
	libraries/javalib/gnu/inet/nntp/NNTPException.java:1.6->1.7 
	libraries/javalib/gnu/inet/nntp/OverviewIterator.java:1.6->1.7 
	libraries/javalib/gnu/inet/nntp/PostStream.java:1.6->1.7 
	libraries/javalib/gnu/inet/pop3/POP3Connection.java:1.7->1.8 
	libraries/javalib/gnu/inet/util/CRLFInputStream.java:1.11->1.12 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4412 kaffe/ChangeLog:1.4413
--- kaffe/ChangeLog:1.4412	Sun Sep 11 21:16:45 2005
+++ kaffe/ChangeLog	Sun Sep 11 21:51:48 2005
@@ -1,5 +1,19 @@
 2005-09-11  Dalibor Topic  <robilad at kaffe.org>
 
+	Reynced with GNU inetlib.
+
+	2005-09-04  Chris Burdess  <dog at gnu.org>
+
+        * Makefile.am,
+        Makefile.in,
+        source/gnu/inet/imap/IMAPConnection.java,
+        source/gnu/inet/imap/IMAPConstants.java,
+        source/gnu/inet/imap/MessageSetTokenizer.java,
+        source/gnu/inet/imap/UIDPlusHandler.java,
+        source/gnu/inet/imap/package.html: UIDPLUS IMAP extension.
+
+2005-09-11  Dalibor Topic  <robilad at kaffe.org>
+
 	Resynced with GNU Classpath.
 
 	2005-09-10  David Gilbert  <david.gilbert at object-refinery.com>
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.389 kaffe/libraries/javalib/Makefile.am:1.390
--- kaffe/libraries/javalib/Makefile.am:1.389	Sun Sep 11 21:16:47 2005
+++ kaffe/libraries/javalib/Makefile.am	Sun Sep 11 21:51:51 2005
@@ -1124,10 +1124,12 @@
 	gnu/inet/imap/IMAPResponseTokenizer.java \
 	gnu/inet/imap/ListEntry.java \
 	gnu/inet/imap/MailboxStatus.java \
+	gnu/inet/imap/MessageSetTokenizer.java \
 	gnu/inet/imap/MessageStatus.java \
 	gnu/inet/imap/Namespaces.java \
 	gnu/inet/imap/Pair.java \
 	gnu/inet/imap/Quota.java \
+	gnu/inet/imap/UIDPlusHandler.java \
 	gnu/inet/imap/UTF7imap.java
 gnu_inet_ldap_SRCS = \
 	gnu/inet/ldap/AttributeValues.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.480 kaffe/libraries/javalib/Makefile.in:1.481
--- kaffe/libraries/javalib/Makefile.in:1.480	Sun Sep 11 21:16:50 2005
+++ kaffe/libraries/javalib/Makefile.in	Sun Sep 11 21:51:54 2005
@@ -1552,10 +1552,12 @@
 	gnu/inet/imap/IMAPResponseTokenizer.java \
 	gnu/inet/imap/ListEntry.java \
 	gnu/inet/imap/MailboxStatus.java \
+	gnu/inet/imap/MessageSetTokenizer.java \
 	gnu/inet/imap/MessageStatus.java \
 	gnu/inet/imap/Namespaces.java \
 	gnu/inet/imap/Pair.java \
 	gnu/inet/imap/Quota.java \
+	gnu/inet/imap/UIDPlusHandler.java \
 	gnu/inet/imap/UTF7imap.java
 
 gnu_inet_ldap_SRCS = \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.159 kaffe/libraries/javalib/all.files:1.160
--- kaffe/libraries/javalib/all.files:1.159	Sun Sep 11 21:16:51 2005
+++ kaffe/libraries/javalib/all.files	Sun Sep 11 21:51:55 2005
@@ -675,10 +675,12 @@
 gnu/inet/imap/IMAPResponseTokenizer.java
 gnu/inet/imap/ListEntry.java
 gnu/inet/imap/MailboxStatus.java
+gnu/inet/imap/MessageSetTokenizer.java
 gnu/inet/imap/MessageStatus.java
 gnu/inet/imap/Namespaces.java
 gnu/inet/imap/Pair.java
 gnu/inet/imap/Quota.java
+gnu/inet/imap/UIDPlusHandler.java
 gnu/inet/imap/UTF7imap.java
 gnu/inet/ldap/AttributeValues.java
 gnu/inet/ldap/BERConstants.java
Index: kaffe/libraries/javalib/gnu/inet/imap/IMAPConnection.java
diff -u kaffe/libraries/javalib/gnu/inet/imap/IMAPConnection.java:1.9 kaffe/libraries/javalib/gnu/inet/imap/IMAPConnection.java:1.10
--- kaffe/libraries/javalib/gnu/inet/imap/IMAPConnection.java:1.9	Wed Jul  6 23:20:04 2005
+++ kaffe/libraries/javalib/gnu/inet/imap/IMAPConnection.java	Sun Sep 11 21:51:55 2005
@@ -1,6 +1,6 @@
 /*
  * IMAPConnection.java
- * Copyright (C) 2003,2004 The Free Software Foundation
+ * Copyright (C) 2003,2004,2005 The Free Software Foundation
  * 
  * This file is part of GNU inetlib, a library.
  * 
@@ -1233,6 +1233,23 @@
   public boolean append(String mailbox, String[] flags, byte[] content)
     throws IOException
   {
+    return append(mailbox, flags, content, null);
+  }
+  
+  /**
+   * Append a message to the specified mailbox.
+   * This method returns an OutputStream to which the message should be
+   * written and then closed.
+   * @param mailbox the mailbox name
+   * @param flags optional list of flags to specify for the message
+   * @param content the message body(including headers)
+   * @param uidplus handler for any APPENDUID information in the response
+   * @return true if successful, false if error in flags/text
+   */
+  public boolean append(String mailbox, String[] flags, byte[] content,
+                        UIDPlusHandler uidplus)
+    throws IOException
+  {
     String tag = newTag();
     StringBuffer buffer = new StringBuffer(APPEND)
       .append(' ')
@@ -1273,6 +1290,10 @@
             processAlerts(response);
             if (id == OK)
               {
+                if (uidplus != null)
+                  {
+                    processUIDPlus(response.getResponseCode(), uidplus);
+                  }
                 return true;
               }
             else if (id == NO)
@@ -1294,6 +1315,43 @@
           }
       }
   }
+
+  void processUIDPlus(List code, UIDPlusHandler uidplus)
+  {
+    int len = code.size();
+    for (int i = 0; i < len; i++)
+      {
+        Object item = code.get(i);
+        if (item instanceof String)
+          {
+            if ("APPENDUID".equals(item) && i < len - 2)
+              {
+                long uidvalidity = Long.parseLong((String) code.get(i + 1));
+                long uid = Long.parseLong((String) code.get(i + 2));
+                uidplus.appenduid(uidvalidity, uid);
+              }
+            else if ("COPYUID".equals(item) && i < len - 3)
+              {
+                long uidvalidity =
+                  Long.parseLong((String) code.get(i + 1));
+                MessageSetTokenizer oldUIDs =
+                  new MessageSetTokenizer((String) code.get(i + 2));
+                MessageSetTokenizer newUIDs =
+                  new MessageSetTokenizer((String) code.get(i + 3));
+                while (oldUIDs.hasNext())
+                  {
+                    long oldUID = ((Long) oldUIDs.next()).longValue();
+                    long newUID = ((Long) newUIDs.next()).longValue();
+                    uidplus.copyuid(uidvalidity, oldUID, newUID);
+                  }
+              }
+          }
+        else
+          {
+            processUIDPlus((List) item, uidplus);
+          }
+      }
+  }
   
   /**
    * Request a checkpoint of the currently selected mailbox.
@@ -1803,6 +1861,18 @@
   public boolean copy(int[] messages, String mailbox)
     throws IOException
   {
+    return copy(messages, mailbox, null);
+  }
+  
+  /**
+   * Copies the specified messages to the end of the destination mailbox.
+   * @param messages the message numbers
+   * @param mailbox the destination mailbox
+   * @param uidplus UIDPLUS callback for COPYUID information
+   */
+  public boolean copy(int[] messages, String mailbox, UIDPlusHandler uidplus)
+    throws IOException
+  {
     if (messages == null || messages.length < 1)
       {
         return true;
@@ -1818,7 +1888,41 @@
         buffer.append(messages[i]);
       }
     buffer.append(' ').append(quote(UTF7imap.encode(mailbox)));
-    return invokeSimpleCommand(buffer.toString());
+    String tag = newTag();
+    sendCommand(tag, buffer.toString());
+    while (true)
+      {
+        IMAPResponse response = readResponse();
+        String id = response.getID();
+        if (tag.equals(response.getTag()))
+          {
+            processAlerts(response);
+            if (id == OK)
+              {
+                if (uidplus != null)
+                  {
+                    processUIDPlus(response.getResponseCode(), uidplus);
+                  }
+                return true;
+              }
+            else if (id == NO)
+              {
+                return false;
+              }
+            else
+              {
+                throw new IMAPException(id, response.getText());
+              }
+          }
+        else if (response.isUntagged())
+          {
+            asyncResponses.add(response);
+          }
+        else
+          {
+            throw new IMAPException(id, response.getText());
+          }
+      }
   }
 
   /**
@@ -2328,6 +2432,63 @@
             else
               {
                 asyncResponses.add(response);
+              }
+          }
+        else
+          {
+            throw new IMAPException(id, response.getText());
+          }
+      }
+  }
+
+  /**
+   * Expunges the specified range of messages.
+   * See RFC 2359 for details.
+   * @param start the UID of the first message to expunge
+   * @param end the UID of the last message to expunge
+   */
+  public int[] uidExpunge(long start, long end)
+    throws IOException
+  {
+    String tag = newTag();
+    StringBuffer cmd = new StringBuffer(UID_EXPUNGE);
+    cmd.append(' ');
+    cmd.append(start);
+    cmd.append(':');
+    cmd.append(end);
+    sendCommand(tag, cmd.toString());
+    List numbers = new ArrayList();
+    while (true)
+      {
+        IMAPResponse response = readResponse();
+        String id = response.getID();
+        if (response.isUntagged())
+          {
+            if (id == EXPUNGE)
+              {
+                numbers.add(new Integer(response.getCount()));
+              }
+            else
+              {
+                asyncResponses.add(response);
+              }
+          }
+        else if (tag.equals(response.getTag()))
+          {
+            processAlerts(response);
+            if (id == OK)
+              {
+                int len = numbers.size();
+                int[] mn = new int[len];
+                for (int i = 0; i < len; i++)
+                  {
+                    mn[i] = ((Integer) numbers.get(i)).intValue();
+                  }
+                return mn;
+              }
+            else
+              {
+                throw new IMAPException(id, response.getText());
               }
           }
         else
Index: kaffe/libraries/javalib/gnu/inet/imap/IMAPConstants.java
diff -u kaffe/libraries/javalib/gnu/inet/imap/IMAPConstants.java:1.7 kaffe/libraries/javalib/gnu/inet/imap/IMAPConstants.java:1.8
--- kaffe/libraries/javalib/gnu/inet/imap/IMAPConstants.java:1.7	Wed Jul  6 23:20:04 2005
+++ kaffe/libraries/javalib/gnu/inet/imap/IMAPConstants.java	Sun Sep 11 21:51:56 2005
@@ -1,6 +1,6 @@
 /*
  * IMAPConstants.java
- * Copyright (C) 2003,2004 The Free Software Foundation
+ * Copyright (C) 2003,2004,2005 The Free Software Foundation
  * 
  * This file is part of GNU inetlib, a library.
  * 
@@ -81,6 +81,7 @@
   public static final String SETQUOTA = "SETQUOTA";
   public static final String GETQUOTA = "GETQUOTA";
   public static final String GETQUOTAROOT = "GETQUOTAROOT";
+  public static final String UID_EXPUNGE = "UID EXPUNGE";
 
   // Server responses
   public static final String OK = "OK";
@@ -102,6 +103,8 @@
   public static final String ACL = "ACL";
   public static final String QUOTA = "QUOTA";
   public static final String QUOTAROOT = "QUOTAROOT";
+  public static final String APPENDUID = "APPENDUID";
+  public static final String COPYUID = "COPYUID";
 
   // Select responses
   public static final String FLAGS = "FLAGS";
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/imap/MessageSetTokenizer.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/imap/MessageSetTokenizer.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/imap/MessageSetTokenizer.java	Sun Sep 11 21:56:46 2005
@@ -0,0 +1,102 @@
+/*
+ * MessageSetTokenizer.java
+ * Copyright (C) 2005 The Free Software Foundation
+ * 
+ * This file is part of GNU inetlib, a library.
+ * 
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library.  Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on this library.  If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obliged to do so.  If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+package gnu.inet.imap;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * Tokenizer for an IMAP UID message-set.
+ * This iterates over the UIDs specified in the set.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ */
+class MessageSetTokenizer
+  implements Iterator
+{
+
+  private Iterator iterator;
+
+  MessageSetTokenizer(String spec)
+  {
+    LinkedList acc = new LinkedList();
+    for (int ci = spec.indexOf(','); ci != -1; ci = spec.indexOf(','))
+      {
+        addToken(acc, spec.substring(0, ci));
+        spec = spec.substring(ci + 1);
+      }
+    addToken(acc, spec);
+    iterator = acc.iterator();
+  }
+
+  private void addToken(LinkedList acc, String token)
+  {
+    int ci = token.indexOf(':');
+    if (ci == -1)
+      {
+        acc.add(new Long(token));
+      }
+    else
+      {
+        long start = Long.parseLong(token.substring(0, ci));
+        long end = Long.parseLong(token.substring(ci + 1));
+        while (start <= end)
+          {
+            acc.add(new Long(start++));
+          }
+      }
+  }
+
+  public boolean hasNext()
+  {
+    return iterator.hasNext();
+  }
+
+  public Object next()
+  {
+    return iterator.next();
+  }
+
+  public void remove()
+  {
+    iterator.remove();
+  }
+  
+}
+
===================================================================
Checking out kaffe/libraries/javalib/gnu/inet/imap/UIDPlusHandler.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/inet/imap/UIDPlusHandler.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/inet/imap/UIDPlusHandler.java	Sun Sep 11 21:56:46 2005
@@ -0,0 +1,73 @@
+/*
+ * UIDPlusHandler.java
+ * Copyright (C) 2005 The Free Software Foundation
+ * 
+ * This file is part of GNU inetlib, a library.
+ * 
+ * GNU inetlib is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU inetlib is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ * 
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library.  Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on this library.  If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obliged to do so.  If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+package gnu.inet.imap;
+
+/**
+ * Callback interface for receiving APPENDUID and COPYUID responses.
+ * See RFC 2359 for details.
+ *
+ * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
+ */
+public interface UIDPlusHandler
+{
+
+  /**
+   * Notification of an APPENDUID response.
+   * Called on a successful APPEND to a server that supports the UIDPLUS
+   * extension.
+   * @param uidvalidity the UIDVALIDITY of the destination mailbox
+   * @param uid the UID assigned to the appended message.
+   */
+  void appenduid(long uidvalidity, long uid);
+
+  /**
+   * Notification of a COPYUID response.
+   * Called on a successful COPY to a server that supports the UIDPLUS
+   * extension.
+   * If more than one message is copied, this method will be called multiple
+   * times, once for each message copied.
+   * @param uidvalidity the UIDVALIDITY of the destination mailbox
+   * @param oldUID the UID of the message in the source mailbox
+   * @param newUID the UID of the corresponding message in the target
+   * mailbox
+   */
+  void copyuid(long uidvalidity, long oldUID, long newUID);
+  
+}
+
Index: kaffe/libraries/javalib/gnu/inet/imap/package.html
diff -u kaffe/libraries/javalib/gnu/inet/imap/package.html:1.2 kaffe/libraries/javalib/gnu/inet/imap/package.html:1.3
--- kaffe/libraries/javalib/gnu/inet/imap/package.html:1.2	Mon Oct  4 19:34:00 2004
+++ kaffe/libraries/javalib/gnu/inet/imap/package.html	Sun Sep 11 21:51:56 2005
@@ -10,6 +10,7 @@
 <li>IMAP namespaces (RFC 2342)</li>
 <li>IMAP ACLs (RFC 2086)</li>
 <li>IMAP quotas (RFC 2087)</li>
+<li>IMAP UIDPLUS extension (RFC 2359)</li>
 </ul>
 </p>
 
Index: kaffe/libraries/javalib/gnu/inet/nntp/ActiveTimesIterator.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/ActiveTimesIterator.java:1.6 kaffe/libraries/javalib/gnu/inet/nntp/ActiveTimesIterator.java:1.7
--- kaffe/libraries/javalib/gnu/inet/nntp/ActiveTimesIterator.java:1.6	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/ActiveTimesIterator.java	Sun Sep 11 21:51:56 2005
@@ -39,6 +39,7 @@
 package gnu.inet.nntp;
 
 import java.io.IOException;
+import java.net.ProtocolException;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.NoSuchElementException;
@@ -96,7 +97,17 @@
       }
     catch (ParseException e)
       {
-        throw new IOException(e.getMessage());
+        ProtocolException e2 =
+          new ProtocolException("Invalid active time line: " + line);
+        e2.initCause(e);
+        throw e2;
+      }
+    catch (StringIndexOutOfBoundsException e)
+      {
+        ProtocolException e2 =
+          new ProtocolException("Invalid active time line: " + line);
+        e2.initCause(e);
+        throw e2;
       }
   }
 
Index: kaffe/libraries/javalib/gnu/inet/nntp/ArticleNumberIterator.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/ArticleNumberIterator.java:1.6 kaffe/libraries/javalib/gnu/inet/nntp/ArticleNumberIterator.java:1.7
--- kaffe/libraries/javalib/gnu/inet/nntp/ArticleNumberIterator.java:1.6	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/ArticleNumberIterator.java	Sun Sep 11 21:51:56 2005
@@ -39,6 +39,7 @@
 package gnu.inet.nntp;
 
 import java.io.IOException;
+import java.net.ProtocolException;
 import java.util.NoSuchElementException;
 
 /**
@@ -77,7 +78,18 @@
     throws IOException
   {
     String line = nextLine();
-    return Integer.parseInt(line.trim());
+
+    try
+      {
+        return Integer.parseInt(line.trim());
+      }
+    catch (NumberFormatException e)
+      {
+        ProtocolException e2 =
+          new ProtocolException("Invalid article number: " + line);
+        e2.initCause(e);
+        throw e2;
+      }
   }
 
 }
Index: kaffe/libraries/javalib/gnu/inet/nntp/ArticleStream.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/ArticleStream.java:1.6 kaffe/libraries/javalib/gnu/inet/nntp/ArticleStream.java:1.7
--- kaffe/libraries/javalib/gnu/inet/nntp/ArticleStream.java:1.6	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/ArticleStream.java	Sun Sep 11 21:51:56 2005
@@ -38,6 +38,7 @@
 
 package gnu.inet.nntp;
 
+import java.io.BufferedInputStream;
 import java.io.FilterInputStream;
 import java.io.InputStream;
 import java.io.IOException;
@@ -52,9 +53,95 @@
   implements PendingData
 {
 
+  private static final int LF = 0x0a;
+  private static final int DOT = 0x2e;
+
+  boolean eol;
+  boolean eof;
+
   ArticleStream(InputStream in)
   {
-    super(in);
+    super(in.markSupported() ? in : new BufferedInputStream(in));
+    eol = true;
+    eof = false;
+  }
+
+  public int read()
+    throws IOException
+  {
+    if (eof)
+      {
+        return -1;
+      }
+    int c = in.read();
+    // Check for LF
+    if (c == LF)
+      {
+        eol = true;
+      }
+    else if (eol)
+      {
+        if (c == DOT)
+          {
+            in.mark(1);
+            int d = in.read();
+            if (d == DOT)
+              {
+                // Not resetting here means that 2 dots are collapsed into 1
+              }
+            else if (d == LF)
+              {
+                // Check for LF
+                eof = true;
+                return -1;
+              }
+            else
+              {
+                in.reset();
+              }
+          }
+        eol = false;
+      }
+    return c;
+  }
+
+  public int read(byte[] b)
+    throws IOException
+  {
+    return read(b, 0, b.length);
+  }
+
+  public int read(byte[] b, int off, int len)
+    throws IOException
+  {
+    if (eof)
+      {
+        return -1;
+      }
+    int l = in.read(b, off, len);
+    if (l > 0)
+      {
+        if (eol)
+          {
+            if (b[off] == DOT && l > 1)
+              {
+                if (b[off + 1] == DOT)
+                  {
+                    // Truncate b
+                    System.arraycopy(b, off + 1, b, off, l - off);
+                    l--;
+                  }
+                else if (b[off + 1] == LF)
+                  {
+                    // EOF
+                    eof = true;
+                    return -1;
+                  }
+              }
+          }
+        eol = (b[(off + l) - 1] == LF);
+      }
+    return l;
   }
 
   /**
@@ -63,7 +150,7 @@
   public void readToEOF()
     throws IOException
   {
-    if (in.available() == 0)
+    if (available() == 0)
       {
         return;
       }
@@ -71,7 +158,7 @@
     int ret = 0;
     while (ret != -1)
       {
-        ret = in.read(buf);
+        ret = read(buf);
       }
   }
 
Index: kaffe/libraries/javalib/gnu/inet/nntp/GroupIterator.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/GroupIterator.java:1.6 kaffe/libraries/javalib/gnu/inet/nntp/GroupIterator.java:1.7
--- kaffe/libraries/javalib/gnu/inet/nntp/GroupIterator.java:1.6	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/GroupIterator.java	Sun Sep 11 21:51:56 2005
@@ -39,6 +39,7 @@
 package gnu.inet.nntp;
 
 import java.io.IOException;
+import java.net.ProtocolException;
 import java.util.NoSuchElementException;
 
 /**
@@ -81,19 +82,32 @@
     String line = nextLine();
 
     // Parse line
-    int start = 0, end;
-    end = line.indexOf(' ', start);
-    String name = line.substring(start, end);
-    start = end + 1;
-    end = line.indexOf(' ', start);
-    int last = Integer.parseInt(line.substring(start, end));
-    start = end + 1;
-    end = line.indexOf(' ', start);
-    int first = Integer.parseInt(line.substring(start, end));
-    start = end + 1;
-    boolean canPost = CAN_POST.equals(line.substring(start));
+    try
+      {
+        int start = 0, end;
+        end = line.indexOf(' ', start);
+        if (end == -1)
+          return new Group(line, -1, -1, false);
+
+        String name = line.substring(start, end);
+        start = end + 1;
+        end = line.indexOf(' ', start);
+        int last = Integer.parseInt(line.substring(start, end));
+        start = end + 1;
+        end = line.indexOf(' ', start);
+        int first = Integer.parseInt(line.substring(start, end));
+        start = end + 1;
+        boolean canPost = CAN_POST.equals(line.substring(start));
 
-    return new Group(name, last, first, canPost);
+        return new Group(name, last, first, canPost);
+      }
+    catch (StringIndexOutOfBoundsException e)
+      {
+        ProtocolException e2 =
+          new ProtocolException("Invalid group line: " + line);
+        e2.initCause(e);
+        throw e2;
+      }
   }
 
 }
Index: kaffe/libraries/javalib/gnu/inet/nntp/NNTPConnection.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/NNTPConnection.java:1.7 kaffe/libraries/javalib/gnu/inet/nntp/NNTPConnection.java:1.8
--- kaffe/libraries/javalib/gnu/inet/nntp/NNTPConnection.java:1.7	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/NNTPConnection.java	Sun Sep 11 21:51:56 2005
@@ -66,7 +66,6 @@
 import gnu.inet.util.CRLFInputStream;
 import gnu.inet.util.CRLFOutputStream;
 import gnu.inet.util.LineInputStream;
-import gnu.inet.util.MessageInputStream;
 import gnu.inet.util.SaslCallbackHandler;
 import gnu.inet.util.SaslInputStream;
 import gnu.inet.util.SaslOutputStream;
@@ -380,8 +379,7 @@
       case HEAD_FOLLOWS:
       case BODY_FOLLOWS:
         ArticleResponse aresponse = (ArticleResponse) response;
-        ArticleStream astream =
-          new ArticleStream(new MessageInputStream(in));
+        ArticleStream astream = new ArticleStream(in);
         pendingData = astream;
         aresponse.in = astream;
         return aresponse;
Index: kaffe/libraries/javalib/gnu/inet/nntp/NNTPException.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/NNTPException.java:1.6 kaffe/libraries/javalib/gnu/inet/nntp/NNTPException.java:1.7
--- kaffe/libraries/javalib/gnu/inet/nntp/NNTPException.java:1.6	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/NNTPException.java	Sun Sep 11 21:51:56 2005
@@ -1,5 +1,5 @@
 /*
- * $Id: NNTPException.java,v 1.6 2005/07/06 23:20:06 robilad Exp $
+ * $Id: NNTPException.java,v 1.7 2005/09/11 21:51:56 robilad Exp $
  * Copyright (C) 2003 The Free Software Foundation
  * 
  * This file is part of GNU inetlib, a library.
@@ -44,7 +44,7 @@
  * An NNTP exception.
  *
  * @author <a href='mailto:dog at gnu.org'>Chris Burdess</a>
- * @version $Revision: 1.6 $ $Date: 2005/07/06 23:20:06 $
+ * @version $Revision: 1.7 $ $Date: 2005/09/11 21:51:56 $
  */
 public class NNTPException extends IOException
 {
Index: kaffe/libraries/javalib/gnu/inet/nntp/OverviewIterator.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/OverviewIterator.java:1.6 kaffe/libraries/javalib/gnu/inet/nntp/OverviewIterator.java:1.7
--- kaffe/libraries/javalib/gnu/inet/nntp/OverviewIterator.java:1.6	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/OverviewIterator.java	Sun Sep 11 21:51:56 2005
@@ -39,6 +39,7 @@
 package gnu.inet.nntp;
 
 import java.io.IOException;
+import java.net.ProtocolException;
 import java.util.NoSuchElementException;
 
 /**
@@ -78,24 +79,41 @@
   {
     String line = nextLine();
 
-    // Parse line
-    int start = 0, end;
-    end = line.indexOf('\t', start);
-    int articleNumber = Integer.parseInt(line.substring(start, end));
-    start = end + 1;
-    Overview overview = new Overview(articleNumber);
-    end = line.indexOf('\t', start);
-    while(end > -1)
+    try
       {
-        String entry = line.substring(start, end);
-        overview.add(entry);
+        // Parse line
+        int start = 0, end;
+        end = line.indexOf('\t', start);
+        int articleNumber = Integer.parseInt(line.substring(start, end));
         start = end + 1;
+        Overview overview = new Overview(articleNumber);
         end = line.indexOf('\t', start);
+        while(end > -1)
+          {
+            String entry = line.substring(start, end);
+            overview.add(entry);
+            start = end + 1;
+            end = line.indexOf('\t', start);
+          }
+        String entry = line.substring(start);
+        overview.add(entry);
+        
+        return overview;
+      }
+    catch (StringIndexOutOfBoundsException e)
+      {
+        ProtocolException e2 =
+          new ProtocolException("Invalid overview line: " + line);
+        e2.initCause(e);
+        throw e2;
+      }
+    catch (NumberFormatException e)
+      {
+        ProtocolException e2 =
+          new ProtocolException("Invalid overview line: " + line);
+        e2.initCause(e);
+        throw e2;
       }
-    String entry = line.substring(start);
-    overview.add(entry);
-
-    return overview;
   }
 
 }
Index: kaffe/libraries/javalib/gnu/inet/nntp/PostStream.java
diff -u kaffe/libraries/javalib/gnu/inet/nntp/PostStream.java:1.6 kaffe/libraries/javalib/gnu/inet/nntp/PostStream.java:1.7
--- kaffe/libraries/javalib/gnu/inet/nntp/PostStream.java:1.6	Wed Jul  6 23:20:06 2005
+++ kaffe/libraries/javalib/gnu/inet/nntp/PostStream.java	Sun Sep 11 21:51:56 2005
@@ -51,6 +51,9 @@
   extends FilterOutputStream
 {
 
+  private static final int LF = 0x0a;
+  private static final int DOT = 0x2e;
+
   NNTPConnection connection;
   boolean isTakethis;
   byte last;
@@ -66,6 +69,10 @@
     throws IOException
   {
     super.write(c);
+    if (c == DOT && last == LF)
+      {
+        super.write(c); // double up initial dot
+      }
     last = (byte) c;
   }
 
@@ -78,10 +85,31 @@
   public void write(byte[] bytes, int pos, int len)
     throws IOException
   {
-    super.write(bytes, pos, len);
-    if(len > 0)
+    int end = pos + len;
+    for (int i = pos; i < end; i++)
+      {
+        byte c = bytes[i];
+        if (c == DOT && last == LF)
+          {
+            // Double dot
+            if (i > pos)
+              {
+                // Write everything up to i
+                int l = i - pos;
+                super.write(bytes, pos, l);
+                pos += l;
+                len -= l;
+              }
+            else
+              {
+                super.write(DOT);
+              }
+          }
+        last = c;
+      }
+    if (len > 0)
       {
-        last = bytes[pos + len - 1];
+        super.write(bytes, pos, len);
       }
   }
   
Index: kaffe/libraries/javalib/gnu/inet/pop3/POP3Connection.java
diff -u kaffe/libraries/javalib/gnu/inet/pop3/POP3Connection.java:1.7 kaffe/libraries/javalib/gnu/inet/pop3/POP3Connection.java:1.8
--- kaffe/libraries/javalib/gnu/inet/pop3/POP3Connection.java:1.7	Wed Jul  6 23:20:07 2005
+++ kaffe/libraries/javalib/gnu/inet/pop3/POP3Connection.java	Sun Sep 11 21:51:56 2005
@@ -40,6 +40,7 @@
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
+import java.io.EOFException;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -770,6 +771,10 @@
     throws IOException
   {
     response = in.readLine();
+    if (response == null)
+      {
+        throw new EOFException("unexpected EOF");
+      }
     logger.log(POP3_TRACE, "< " + response);
     if (response.indexOf(_OK) == 0)
       {
Index: kaffe/libraries/javalib/gnu/inet/util/CRLFInputStream.java
diff -u kaffe/libraries/javalib/gnu/inet/util/CRLFInputStream.java:1.11 kaffe/libraries/javalib/gnu/inet/util/CRLFInputStream.java:1.12
--- kaffe/libraries/javalib/gnu/inet/util/CRLFInputStream.java:1.11	Wed Jul  6 23:20:09 2005
+++ kaffe/libraries/javalib/gnu/inet/util/CRLFInputStream.java	Sun Sep 11 21:51:58 2005
@@ -146,7 +146,7 @@
     throws IOException
   {

*** Patch too long, truncated ***




More information about the kaffe mailing list