sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/

lib/sup/modes/inbox_mode.rb (2133B) - raw

      1 require "sup/modes/thread_index_mode"
      2 
      3 module Redwood
      4 
      5 class InboxMode < ThreadIndexMode
      6   register_keymap do |k|
      7     ## overwrite toggle_archived with archive
      8     k.add :archive, "Archive thread (remove from inbox)", 'a'
      9     k.add :refine_search, "Refine search", '|'
     10   end
     11 
     12   def initialize
     13     super [:inbox, :sent, :draft], { :label => :inbox, :skip_killed => true }
     14     raise "can't have more than one!" if defined? @@instance
     15     @@instance = self
     16   end
     17 
     18   def is_relevant? m; (m.labels & [:spam, :deleted, :killed, :inbox]) == Set.new([:inbox]) end
     19 
     20   def refine_search
     21     text = BufferManager.ask :search, "refine inbox with query: "
     22     return unless text && text !~ /^\s*$/
     23     text = "label:inbox -label:spam -label:deleted " + text
     24     SearchResultsMode.spawn_from_query text
     25   end
     26 
     27   ## label-list-mode wants to be able to raise us if the user selects
     28   ## the "inbox" label, so we need to keep our singletonness around
     29   def self.instance; @@instance; end
     30   def killable?; false; end
     31 
     32   def archive
     33     return unless cursor_thread
     34     thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread
     35 
     36     UndoManager.register "archiving thread" do
     37       thread.apply_label :inbox
     38       add_or_unhide thread.first
     39       Index.save_thread thread
     40     end
     41 
     42     cursor_thread.remove_label :inbox
     43     hide_thread cursor_thread
     44     regen_text
     45     Index.save_thread thread
     46   end
     47 
     48   def multi_archive threads
     49     UndoManager.register "archiving #{threads.size.pluralize 'thread'}" do
     50       threads.map do |t|
     51         t.apply_label :inbox
     52         add_or_unhide t.first
     53         Index.save_thread t
     54       end
     55       regen_text
     56     end
     57 
     58     threads.each do |t|
     59       t.remove_label :inbox
     60       hide_thread t
     61     end
     62     regen_text
     63     threads.each { |t| Index.save_thread t }
     64   end
     65 
     66   def handle_unarchived_update sender, m
     67     add_or_unhide m
     68   end
     69 
     70   def handle_archived_update sender, m
     71     t = thread_containing(m) or return
     72     hide_thread t
     73     regen_text
     74   end
     75 
     76   def handle_idle_update sender, idle_since
     77     flush_index
     78   end
     79 
     80   def status
     81     super + "    #{Index.size} messages in index"
     82   end
     83 end
     84 
     85 end