Skip to content

Commit

Permalink
support new (not unread) messages
Browse files Browse the repository at this point in the history
messages added to the index are marked as new
new state is shown in thread-index-mode and label-list-mode
in thread-index-mode new state can be cleared with refresh (@)
without marking mails as read
list-label-mode sorts labels by latest new message
or if no messages are new, the latest message
TODO: :new label should be made special
  • Loading branch information
eMBee committed Mar 30, 2014
1 parent 7a1cecb commit 9debc5b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/sup/maildir.rb
Expand Up @@ -155,7 +155,7 @@ def poll
added.each_with_index do |id,i|
yield :add,
:info => id,
:labels => @labels + maildir_labels(id) + [:inbox],
:labels => @labels + maildir_labels(id) + [:inbox, :new],
:progress => i.to_f/total_size
end

Expand Down
2 changes: 1 addition & 1 deletion lib/sup/mbox.rb
Expand Up @@ -130,7 +130,7 @@ def each_raw_message_line offset
end

def default_labels
[:inbox, :unread]
[:inbox, :unread, :new]
end

def poll
Expand Down
28 changes: 22 additions & 6 deletions lib/sup/modes/label_list_mode.rb
Expand Up @@ -82,13 +82,19 @@ def regen_text
string = LabelManager.string_for label
total = Index.num_results_for :label => label
unread = (label == :unread)? total : Index.num_results_for(:labels => [label, :unread])
[label, string, total, unread]
new = (label == :new)? total : Index.num_results_for(:labels => [label, :new])
last_update = nil
Index.each_message(:labels => [label, :new]) { |m| last_update = m.date; break if m.date < Time.now }
if not last_update
Index.each_message(:label => label) { |m| last_update = m.date; break if m.date < Time.now }
end
[label, string, total, unread, new, last_update]
end

if HookManager.enabled? "label-list-filter"
counts = HookManager.run "label-list-filter", :counted => counted
else
counts = counted.sort_by { |l, s, t, u| s.downcase }
counts = counted.sort_by { |l, s, t, u, n, d| d or Time.at 0 }.reverse # s.downcase } ## sort by date
end

width = counts.max_of { |l, s, t, u| s.length }
Expand All @@ -100,7 +106,7 @@ def regen_text
end

@labels = []
counts.map do |label, string, total, unread|
counts.map do |label, string, total, unread, new, date|
## if we've done a search and there are no messages for this label, we can delete it from the
## list. BUT if it's a brand-new label, the user may not have sync'ed it to the index yet, so
## don't delete it in this case.
Expand All @@ -116,11 +122,21 @@ def regen_text

fmt = HookManager.run "label-list-format", :width => width, :tmax => tmax, :umax => umax
if !fmt
fmt = "%#{width + 1}s %5d %s, %5d unread"
fmt = "%#{width + 1}s %6d %s, %6d unread, %3d new - %10s"
end

if date
begin
datestr = date.getlocal.to_nice_s
rescue
datestr = date.to_s
end
else
datestr = ""
end

@text << [[(unread == 0 ? :labellist_old_color : :labellist_new_color),
sprintf(fmt, string, total, total == 1 ? " message" : "messages", unread)]]
@text << [[(new == 0 ? :labellist_old_color : :labellist_new_color),
sprintf(fmt, string, total, total == 1 ? " message" : "messages", unread, new, datestr)]]
@labels << [label, unread]
yield i if block_given?
end.compact
Expand Down
5 changes: 5 additions & 0 deletions lib/sup/modes/thread_index_mode.rb
Expand Up @@ -97,6 +97,10 @@ def [] i; @text[i]; end
def contains_thread? t; @threads.include?(t) end

def reload
@ts.threads.each do |th|
th.remove_label :new
Index.save_thread th
end
drop_all_threads
UndoManager.clear
BufferManager.draw_screen
Expand Down Expand Up @@ -126,6 +130,7 @@ def select t=nil, when_done=nil
## are set, and the second to show the cursor having moved

t.remove_label :unread
t.remove_label :new
Index.save_thread t

update_text_for_line curpos
Expand Down

0 comments on commit 9debc5b

Please sign in to comment.