]> git.cworth.org Git - sup/blobdiff - lib/sup/index.rb
sort contacts when saving contacts.txt
[sup] / lib / sup / index.rb
index 0af66befb4c80d4acf2e2ebba2faa118c7ace5e6..e6e91984332a24cf0a281f3ad8646a24c6a3008d 100644 (file)
@@ -125,9 +125,13 @@ EOS
     @sources[source.id] = source
   end
 
-  def source_for uri; @sources.values.find { |s| s.is_source_for? uri }; end
-  def usual_sources; @sources.values.find_all { |s| s.usual? }; end
-  def sources; @sources.values; end
+  def sources
+    ## favour the inbox by listing non-archived sources first
+    @sources.values.sort_by { |s| s.id }.partition { |s| !s.archived? }.flatten
+  end
+
+  def source_for uri; sources.find { |s| s.is_source_for? uri }; end
+  def usual_sources; sources.find_all { |s| s.usual? }; end
 
   def load_index dir=File.join(@dir, "ferret")
     if File.exists? dir
@@ -186,8 +190,8 @@ EOS
       :body => m.indexable_content,
       :snippet => snippet,
       :label => m.labels.uniq.join(" "),
-      :from => m.from ? m.from.email : "",
-      :to => (m.to + m.cc + m.bcc).map { |x| x.email }.join(" "),
+      :from => m.from ? m.from.indexable_content : "",
+      :to => (m.to + m.cc + m.bcc).map { |x| x.indexable_content }.join(" "),
       :subject => wrap_subj(m.subj),
       :refs => (m.refs + m.replytos).uniq.join(" "),
     }
@@ -512,7 +516,7 @@ protected
         File.chmod 0600, fn
         FileUtils.mv fn, bakfn, :force => true unless File.exists?(bakfn) && File.size(fn) == 0
       end
-      Redwood::save_yaml_obj @sources.values.sort_by { |s| s.id.to_i }, fn, true
+      Redwood::save_yaml_obj sources.sort_by { |s| s.id.to_i }, fn, true
       File.chmod 0600, fn
     end
     @sources_dirty = false