Author: alexlehm Date: 2008-01-14 17:18:29 +0000 (Mon, 14 Jan 2008) New Revision: 17039
Modified: trunk/apps/Freemail/src/freemail/MailMessage.java trunk/apps/Freemail/src/freemail/MessageBank.java trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java Log: 1987: various issues with mail index numbers (https://bugs.freenetproject.org/view.php?id=1987) message sequence numbers were not counted correctly, as replies to the uid command, they always counted from 1. This is probably the cause of the other message related bugs 1160: Messages are not set to read, 1766: Mail disappears from folders, 1779: expunge response breaks Thunderbird, 1986: deleted mail reappears Modified: trunk/apps/Freemail/src/freemail/MailMessage.java =================================================================== --- trunk/apps/Freemail/src/freemail/MailMessage.java 2008-01-14 16:46:46 UTC (rev 17038) +++ trunk/apps/Freemail/src/freemail/MailMessage.java 2008-01-14 17:18:29 UTC (rev 17039) @@ -40,11 +40,13 @@ private PrintStream ps; private final Vector headers; private BufferedReader brdr; + private int msg_seqnum=0; public IMAPMessageFlags flags; - MailMessage(File f) { + MailMessage(File f, int msg_seqnum) { this.file = f; this.headers = new Vector(); + this.msg_seqnum=msg_seqnum; // initialize flags from filename String[] parts = f.getName().split(","); @@ -240,6 +242,10 @@ return Integer.parseInt(parts[0]); } + + public int getSeqNum() { + return msg_seqnum; + } public long getSize() throws IOException { // this is quite arduous since we have to send the message Modified: trunk/apps/Freemail/src/freemail/MessageBank.java =================================================================== --- trunk/apps/Freemail/src/freemail/MessageBank.java 2008-01-14 16:46:46 UTC (rev 17038) +++ trunk/apps/Freemail/src/freemail/MessageBank.java 2008-01-14 17:18:29 UTC (rev 17039) @@ -105,7 +105,7 @@ this.writeNextId(newid); if (newfile != null) { - MailMessage newmsg = new MailMessage(newfile); + MailMessage newmsg = new MailMessage(newfile,0); return newmsg; } @@ -113,15 +113,17 @@ } public SortedMap listMessages() { - File[] files = this.dir.listFiles(); - + File[] files = this.dir.listFiles(new MessageFileNameFilter()); + + Arrays.sort(files, new UIDComparator()); + TreeMap msgs = new TreeMap(); - + + int seq=1; for (int i = 0; i < files.length; i++) { - if (files[i].getName().startsWith(".")) continue; if (files[i].isDirectory()) continue; - MailMessage msg = new MailMessage(files[i]); + MailMessage msg = new MailMessage(files[i],seq++); msgs.put(new Integer(msg.getUID()), msg); } @@ -139,7 +141,7 @@ for (int i = 0; i < files.length; i++) { //if (files[i].getName().startsWith(".")) continue; - MailMessage msg = new MailMessage(files[i]); + MailMessage msg = new MailMessage(files[i],i+1); msgs[i] = msg; } Modified: trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java =================================================================== --- trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java 2008-01-14 16:46:46 UTC (rev 17038) +++ trunk/apps/Freemail/src/freemail/imap/IMAPHandler.java 2008-01-14 17:18:29 UTC (rev 17039) @@ -202,7 +202,7 @@ // '*' needs to be '.*' mbname = mbname.replaceAll("\\*", ".*"); - // and % is a wildcard not inclusing the hierarchy delimiter + // and % is a wildcard not including the hierarchy delimiter mbname = mbname.replaceAll("%", "[^\\.]*"); @@ -368,7 +368,7 @@ } if (i > to) break; - if (!this.fetch_single((MailMessage)msgs.get(msgs.firstKey()), i, msg.args, 1, false)) { + if (!this.fetch_single((MailMessage)msgs.get(msgs.firstKey()), msg.args, 1, false)) { this.reply(msg, "BAD Unknown attribute in list or unterminated list"); return; } @@ -441,7 +441,7 @@ MailMessage mm=(MailMessage)msgs.get(curuid); if(mm!=null) { - if (!this.fetch_single((MailMessage)msgs.get(curuid), msgnum, msg.args, 2, true)) { + if (!this.fetch_single((MailMessage)msgs.get(curuid), msg.args, 2, true)) { this.reply(msg, "BAD Unknown attribute in list or unterminated list"); return; } @@ -461,8 +461,7 @@ targetmsgs[i] = (MailMessage)msgs.get(curuid); i++; } - // FIXME: firstmessage==0 is probably not right - this.do_store(msg.args, 2, targetmsgs, msg, 0, true); + this.do_store(msg.args, 2, targetmsgs, msg, true); this.reply(msg, "OK Store completed"); } else if (msg.args[0].equalsIgnoreCase("copy")) { @@ -502,9 +501,9 @@ } } - private boolean fetch_single(MailMessage msg, int id, String[] args, int firstarg, boolean send_uid_too) { + private boolean fetch_single(MailMessage msg, String[] args, int firstarg, boolean send_uid_too) { String[] imap_args = (String[]) args.clone(); - this.ps.print("* "+id+" FETCH ("); + this.ps.print("* "+msg.getSeqNum()+" FETCH ("); // do the first attribute, if it's a loner. if (!imap_args[firstarg].startsWith("(")) { @@ -528,7 +527,7 @@ imap_args[firstarg] = imap_args[firstarg].substring(1); } - // go through the parenthesised list + // go through the parenthesized list for (int i = firstarg; i < imap_args.length; i++) { String attr; boolean finish = false; @@ -760,12 +759,12 @@ msgs[i - from] = (MailMessage) allmsgs[i]; } - do_store(msg.args, 1, msgs, msg, from + 1, false); + do_store(msg.args, 1, msgs, msg, false); this.reply(msg, "OK Store completed"); } - private void do_store(String[] args, int offset, MailMessage[] mmsgs, IMAPMessage msg, int firstmsgnum, boolean senduid) { + private void do_store(String[] args, int offset, MailMessage[] mmsgs, IMAPMessage msg, boolean senduid) { if (args[offset].toLowerCase().indexOf("flags") < 0) { // IMAP4Rev1 can only store flags, so you're // trying something crazy @@ -805,7 +804,7 @@ for (int i = 0; i < mmsgs.length; i++) { StringBuffer buf = new StringBuffer(""); - buf.append((i+firstmsgnum)); + buf.append(mmsgs[i].getSeqNum()); if (senduid) { buf.append(" FETCH (UID "); buf.append(mmsgs[i].getUID()); @@ -849,10 +848,13 @@ private void expunge(boolean verbose) { MailMessage[] mmsgs = this.mb.listMessagesArray(); + int count_correction=0; for (int i = 0; i < mmsgs.length; i++) { - if (mmsgs[i].flags.get("\\Deleted")) + if (mmsgs[i].flags.get("\\Deleted")) { mmsgs[i].delete(); - if (verbose) this.sendState(i+" EXPUNGE"); + if (verbose) this.sendState((i+1-count_correction)+" EXPUNGE"); + count_correction++; + } } }
