sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 97f4c1c6a2ff8bc388392afb1f46bcc4ae0a3c04
parent a421969c29c88f1f7a7c191643842b63f8c4c580
Author: Damien Leone <damien.leone@fensalir.fr>
Date:   Sat, 26 Feb 2011 17:11:01 +0100

Add support for merging Maildir flags to Xapian entries, add a merge feature to sup-sync-back-maildir

Diffstat:
M bin/sup-sync-back-maildir | 1 +
M lib/sup/maildir.rb | 4 ++++
M lib/sup/message.rb | 24 ++++++++++++++++++++++++
M lib/sup/source.rb | 4 ++++
4 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/bin/sup-sync-back-maildir b/bin/sup-sync-back-maildir
@@ -62,6 +62,7 @@ begin
       infos.each do |info|
         print "\rSynchronizing '#{s.uri}'... #{((counter += 1)/infos.size.to_f*100).to_i}%"
         index.each_message({:location => [s.id, info]}, false) do |m|
+          m.merge_labels_from_locations [:replied, :forwarded]
           index.save_message m
         end
       end
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
@@ -156,6 +156,10 @@ class Maildir < Source
     nil
   end
 
+  def labels? id
+    maildir_labels id
+  end
+
   def maildir_labels id
     (seen?(id) ? [] : [:unread]) +
       (trashed?(id) ?  [:deleted] : []) +
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -293,6 +293,26 @@ EOS
     end
   end
 
+  def merge_labels_from_locations merge_labels
+    ## Get all labels from all locations
+    location_labels = Set.new([])
+
+    @locations.each do |l|
+      if l.valid?
+        location_labels = location_labels.union(l.labels?)
+      end
+    end
+
+    ## Add to the message labels the intersection between all location
+    ## labels and those we want to merge
+    location_labels = location_labels.intersection(merge_labels.to_set)
+
+    if not location_labels.empty?
+      @labels = @labels.union(location_labels)
+      @dirty = true
+    end
+  end
+
   ## returns all the content from a message that will be indexed
   def indexable_content
     load_from_source!
@@ -722,6 +742,10 @@ class Location
     source.valid? info
   end
 
+  def labels?
+    source.labels? info
+  end
+
   def == o
     o.source.id == source.id and o.info == info
   end
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -91,6 +91,10 @@ class Source
   ## supported by this source
   def supported_labels?; [] end
 
+  ## Returns an array containing all the labels that are currently in
+  ## the location filename
+  def labels? info; [] end
+
   ## Yields values of the form [Symbol, Hash]
   ## add: info, labels, progress
   ## delete: info, progress