sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit ff6e6801ea7c2804dc061db00632ac7c0d370d32
parent bbdfa425bffab6afa82c4099dc252071d29bc173
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Thu, 28 Feb 2008 19:11:09 -0800

Merge branch 'speedy-index' into next

Conflicts:

	lib/sup/poll.rb

Diffstat:
M bin/sup-sync | 2 +-
M lib/sup/index.rb | 18 +++++++++++-------
M lib/sup/poll.rb | 4 ++--
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/bin/sup-sync b/bin/sup-sync
@@ -133,7 +133,7 @@ begin
     num_added = num_updated = num_scanned = num_restored = 0
     last_info_time = start_time = Time.now
 
-    Redwood::PollManager.add_messages_from source do |m, offset, entry|
+    Redwood::PollManager.add_messages_from source, :force_overwrite => true do |m, offset, entry|
       num_scanned += 1
       seen[m.id] = true
 
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -161,7 +161,7 @@ EOS
   ## and adding either way. Index state will be determined by m.labels.
   ##
   ## docid and entry can be specified if they're already known.
-  def sync_message m, docid=nil, entry=nil
+  def sync_message m, docid=nil, entry=nil, opts={}
     docid, entry = load_entry_for_id m.id unless docid && entry
 
     raise "no source info for message #{m.id}" unless m.source && m.source_info
@@ -205,16 +205,20 @@ EOS
     if entry[:source_id] && entry[:source_info] && entry[:label] &&
       ((entry[:source_id].to_i > source_id) || (entry[:source_info].to_i < m.source_info))
       labels = (entry[:label].split(/\s+/).map { |l| l.intern } + m.labels).uniq
-      Redwood::log "found updated version of message #{m.id}: #{m.subj}"
-      Redwood::log "previous version was at #{entry[:source_id].inspect}:#{entry[:source_info].inspect}, this version at #{source_id.inspect}:#{m.source_info.inspect}"
-      Redwood::log "merged labels are #{labels.inspect} (index #{entry[:label].inspect}, message #{m.labels.inspect})"
+      #Redwood::log "found updated version of message #{m.id}: #{m.subj}"
+      #Redwood::log "previous version was at #{entry[:source_id].inspect}:#{entry[:source_info].inspect}, this version at #{source_id.inspect}:#{m.source_info.inspect}"
+      #Redwood::log "merged labels are #{labels.inspect} (index #{entry[:label].inspect}, message #{m.labels.inspect})"
       entry = {}
     end
 
+    ## if force_overwite is true, ignore what's in the index. this is used
+    ## primarily by sup-sync to force index updates.
+    entry = {} if opts[:force_overwrite]
+
     d = {
-      :message_id => (entry[:message_id] || m.id),
-      :source_id => (entry[:source_id] || source_id),
-      :source_info => (entry[:source_info] || m.source_info),
+      :message_id => m.id,
+      :source_id => source_id,
+      :source_info => m.source_info,
       :date => (entry[:date] || m.date.to_indexable_s),
       :body => (entry[:body] || m.indexable_content),
       :snippet => snippet, # always override
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
@@ -134,7 +134,7 @@ EOS
   ## labels. it is likely that callers will want to replace these with
   ## the index labels, if they exist, so that state is not lost when
   ## e.g. a new version of a message from a mailing list comes in.
-  def add_messages_from source
+  def add_messages_from source, opts={}
     begin
       return if source.done? || source.has_errors?
       
@@ -157,7 +157,7 @@ EOS
           docid, entry = Index.load_entry_for_id m.id
           HookManager.run "before-add-message", :message => m
           m = yield(m, offset, entry) or next if block_given?
-          Index.sync_message m, docid, entry
+          Index.sync_message m, docid, entry, opts
           UpdateManager.relay self, :added, m unless entry
         rescue MessageFormatError => e
           Redwood::log "ignoring erroneous message at #{source}##{offset}: #{e.message}"