Subject: [sup-talk] Maildir source with one message

From: [email-masked] (Christopher Warrington)
Date: Mon, 03 Mar 2008 01:07:55 -0600

In playing with offline IMAP and Maildir sources (much faster than a native IMAP source and it can be used offline!), I noticed an odd bug.

If there is only one message in a Maildir source, neither sup not
sup-sync can see this message. Adding another message makes both
visible messages visible.

--- here begins speculation ---

I *THINK* that this has to do with the definitions Source.start_offset
and Source.end_offset. As I understand it, they should define a range
of message ids [start_offset, end_offset).

Now, when start_offset = end_offset--as is the case when there is only
one message, bad things happen. As I understand the math:
(a,a) = {}
[a,a) = {} *our case
(a,a] = {}
[a,a] = {a.

Changing maildir.rb:126 from:
    @ids.last
to
    @ids.last + 1
appears to have fixed the problem without ill-effect.

Simple inspection of imap.rp leads be to believe that it will have the
same problem.

A mbox source will have the same problem iff the mbox is empty.

--- here ends speculation ---

-- 
Christopher Warrington <chrisw at rice.edu>

---

From: [email-masked] (Christopher Warrington)
Date: Mon, 3 Mar 2008 02:00:33 -0600

The end_offset reported by imap and maildir sources was incorrect if there was
only one message in the source. Since end_offset is exclusive, we must add one to
the last known id to get include all valid message ids in the range.
---
 lib/sup/imap.rb    |    2 +-
 lib/sup/maildir.rb |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb
index e785597..1d36976 100644
--- a/lib/sup/imap.rb
+++ b/lib/sup/imap.rb
@@ -176,7 +176,7 @@ class IMAP < Source
 
   def end_offset
     unsynchronized_scan_mailbox
-    @ids.last
+    @ids.last + 1
   end
   synchronized :end_offset
 
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
index 5c9600d..584e657 100644
--- a/lib/sup/maildir.rb
+++ b/lib/sup/maildir.rb
@@ -123,7 +123,7 @@ class Maildir < Source
 
   def end_offset
     scan_mailbox :rescan => true
-    @ids.last
+    @ids.last + 1
   end
 
   def pct_done; 100.0 * (@ids.index(cur_offset) || 0).to_f / (@ids.length - 1).to_f; end
-- 
1.5.3.7

---

From: [email-masked] (William Morgan)
Date: Wed, 26 Mar 2008 09:04:10 -0700

Reformatted excerpts from Christopher Warrington's message of 2008-03-03:
> The end_offset reported by imap and maildir sources was incorrect if
> there was only one message in the source. Since end_offset is
> exclusive, we must add one to the last known id to get include all
> valid message ids in the range.

Precisely so. Applied. Thanks!

-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Grant Hollingworth)
Date: Thu, 03 Apr 2008 12:35:54 -0400

> Precisely so. Applied. Thanks!

This breaks Source#done?, so every poll the last message of each source gets reloaded. The state gets fixed from the index but it's still ugly.

---

From: [email-masked] (William Morgan)
Date: Fri, 04 Apr 2008 10:48:01 -0700

Reformatted excerpts from Grant Hollingworth's message of 2008-04-03:
> This breaks Source#done?, so every poll the last message of each
> source gets reloaded. The state gets fixed from the index but it's
> still ugly.

Gah. I will take a look.