highly suspicious changes to IMAP.java
[org.ibex.mail.git] / src / org / ibex / mail / IMAP.java
index f97e771..f790298 100644 (file)
@@ -444,8 +444,8 @@ public class IMAP {
 
             lastfetch = t;
             int spec = 0;                              // spec; see constants for flags
+            int start = 0, len = 0;
             String[] headers = null;
-            int start = -1, end = -1;
             StringBuffer r = new StringBuffer();
             if (e) { r.append(num); r.append(" FETCH ("); }
             int initlen = r.length();
@@ -509,19 +509,28 @@ public class IMAP {
                     else if (s.equals("HEADER.FIELDS.NOT")) { spec |= FIELDSNOT;    payload=Fountain.Util.create(headers(r,t[i].l()[1].sl(),true,m,e)); }
                     else if (s.equals("MIME")) {              throw new Server.Bad("MIME not supported"); }
                     else                                      throw new Server.Bad("unknown section type " + s);
+
                     if (i<t.length - 1 && (t[i+1].s != null && t[i+1].s.startsWith("<"))) {
                         i++;
                         s = t[i].s.substring(1, t[i].s.indexOf('>'));
                         int dot = s.indexOf('.');
                         start = dot == -1 ? Integer.parseInt(s) : Integer.parseInt(s.substring(0, s.indexOf('.')));
-                        end = dot == -1 ? -1 : Integer.parseInt(s.substring(s.indexOf('.') + 1));
+                        len   = dot == -1 ? -1 : Integer.parseInt(s.substring(s.indexOf('.') + 1));
                         if (e) {
-                            //payload = payload.substring(start, Math.min(end+1,payload.getLength())); r.append("<"+start+">");
-                            // FIXME
-                            throw new RuntimeException("this had to be disabled");
+                            if (start == 0 && len == -1) {
+                            } else if (len == -1) {
+                                payload = Fountain.Util.subFountain(payload, start);
+                            } else {
+                                len = (int)Math.min(len, payload.getLength()-start);
+                                payload = Fountain.Util.subFountain(payload, start, len);
+                            }
+                            r.append("]");
+                            r.append("<"+start+"> ");
                         }
+                    } else {
+                        if (e) r.append("] ");
                     }
-                    if (e) { r.append("] "); r.append(Printer.qq(payload.getStream())); }
+                    if (e) r.append(Printer.qq(payload.getStream()));
                 }
             }
             if ((spec & PEEK) == 0 && looked_at_body && e)
@@ -530,7 +539,7 @@ public class IMAP {
                r.append(")");
                println("* " + r.toString());
            } else {
-               api.fetch(q, spec, headers, start, end, uid);
+               api.fetch(q, spec, headers, start, (len==-1?0:len), uid);
            }
         }