Author: dbkr
Date: 2006-08-10 12:31:23 +0000 (Thu, 10 Aug 2006)
New Revision: 10021

Modified:
   trunk/apps/Freemail/src/freemail/Freemail.java
   trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java
Log:
Build #6: Now fetchmail really works! (fetch body[text] support). Also fixes 
with the IMAP STORE command.


Modified: trunk/apps/Freemail/src/freemail/Freemail.java
===================================================================
--- trunk/apps/Freemail/src/freemail/Freemail.java      2006-08-10 11:01:52 UTC 
(rev 10020)
+++ trunk/apps/Freemail/src/freemail/Freemail.java      2006-08-10 12:31:23 UTC 
(rev 10021)
@@ -12,7 +12,7 @@
        // version info
        public static final int VER_MAJOR = 0;
        public static final int VER_MINOR = 1;
-       public static final int BUILD_NO = 5;
+       public static final int BUILD_NO = 6;
        public static final String VERSION_TAG = "Pet Shop";

        private static final String TEMPDIRNAME = "temp";

Modified: trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java
===================================================================
--- trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java      2006-08-10 
11:01:52 UTC (rev 10020)
+++ trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java      2006-08-10 
12:31:23 UTC (rev 10021)
@@ -357,7 +357,7 @@
                                targetmsgs[i] = 
(MailMessage)msgs.values().toArray()[i];
                        }

-                       this.do_store(msg.args, 2, targetmsgs, msg, true);
+                       this.do_store(msg.args, 2, targetmsgs, msg, -1);

                        this.reply(msg, "OK Store completed");
                } else {
@@ -529,6 +529,22 @@
                                }

                                buf.append(mmsg.getAllHeadersAsString());
+                       } else if (parts[i].equalsIgnoreCase("text")) {
+                               // just send the text of the message without 
headers
+                               mmsg.closeStream();
+                               String line;
+                               // fast forward past the headers
+                               try {
+                                       while ( (line = mmsg.readLine()) != 
null) {
+                                               if (line.length() == 0) break;
+                                       }
+                                       while ( (line = mmsg.readLine()) != 
null) {
+                                               buf.append(line+"\r\n");
+                                       }
+                                       mmsg.closeStream();
+                               } catch (IOException ioe) {
+                                       // just return whatever we got
+                               }
                        }

                        this.ps.print("{"+buf.length()+"}\r\n"+buf.toString());
@@ -575,27 +591,26 @@
                        to = from;
                }

-               MailMessage[] msgs = new MailMessage[(to - from) + 1];
-               
                // convert to zero based array
                from--;
                to--;

-               if (from < 0 || to < 0 || from > msgs.length || to > 
msgs.length) {
+               if (from < 0 || to < 0 || from > allmsgs.length || to > 
allmsgs.length) {
                        this.reply(msg, "NO No such message");
                        return;
                }

+               MailMessage[] msgs = new MailMessage[(to - from) + 1];
                for (int i = from; i <= to; i++) {
                        msgs[i - from] = (MailMessage) allmsgs[i];
                }

-               do_store(msg.args, 1, msgs, msg, false);
+               do_store(msg.args, 1, msgs, msg, from + 1);

                this.reply(msg, "OK Store completed");
        }

-       private void do_store(String[] args, int offset, MailMessage[] mmsgs, 
IMAPMessage msg, boolean UIDMode) {
+       private void do_store(String[] args, int offset, MailMessage[] mmsgs, 
IMAPMessage msg, int firstmsgnum) {
                if (args[offset].toLowerCase().indexOf("flags") < 0) {
                        // IMAP4Rev1 can only store flags, so you're
                        // trying something crazy
@@ -635,10 +650,10 @@
                        for (int i = 0; i < mmsgs.length; i++) {
                                StringBuffer buf = new StringBuffer("");

-                               if (UIDMode) {
+                               if (firstmsgnum < 0) {
                                        buf.append(mmsgs[i].getUID() + " FETCH 
FLAGS (");
                                } else {
-                                       buf.append((i+1) + " FETCH FLAGS (");
+                                       buf.append((i+firstmsgnum) + " FETCH 
FLAGS (");
                                }

                                buf.append(mmsgs[i].flags.getFlags());


Reply via email to