lib/sup/modes/thread-view-mode.rb in sup-0.2 vs lib/sup/modes/thread-view-mode.rb in sup-0.3
- old
+ new
@@ -1,10 +1,8 @@
module Redwood
class ThreadViewMode < LineCursorMode
- include CanSpawnComposeMode
-
## this holds all info we need to lay out a message
class MessageLayout
attr_accessor :top, :bot, :prev, :next, :depth, :width, :state, :color, :star_color, :orig_new
end
@@ -25,20 +23,22 @@
k.add :expand_all_quotes, "Expand/collapse all quotes in a message", 'o'
k.add :jump_to_next_open, "Jump to next open message", 'n'
k.add :jump_to_prev_open, "Jump to previous open message", 'p'
k.add :toggle_starred, "Star or unstar message", '*'
k.add :toggle_new, "Toggle new/read status of message", 'N'
-# k.add :collapse_non_new_messages, "Collapse all but new messages", 'N'
+# k.add :collapse_non_new_messages, "Collapse all but unread messages", 'N'
k.add :reply, "Reply to a message", 'r'
k.add :forward, "Forward a message", 'f'
k.add :alias, "Edit alias/nickname for a person", 'i'
k.add :edit_as_new, "Edit message as new", 'D'
k.add :save_to_disk, "Save message/attachment to disk", 's'
k.add :search, "Search for messages from particular people", 'S'
k.add :compose, "Compose message to person", 'm'
k.add :archive_and_kill, "Archive thread and kill buffer", 'a'
k.add :delete_and_kill, "Delete thread and kill buffer", 'd'
+ k.add :subscribe_to_list, "Subscribe to/unsubscribe from mailing list", "("
+ k.add :unsubscribe_from_list, "Subscribe to/unsubscribe from mailing list", ")"
end
## there are a couple important instance variables we hold to format
## the thread and to provide line-based functionality. @layout is a
## map from Messages to MessageLayouts, and @chunk_layout from
@@ -105,15 +105,31 @@
m = @message_lines[curpos] or return
mode = ReplyMode.new m
BufferManager.spawn "Reply to #{m.subj}", mode
end
+ def subscribe_to_list
+ m = @message_lines[curpos] or return
+ if m.list_subscribe && m.list_subscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
+ ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+ else
+ BufferManager.flash "Can't find List-Subscribe header for this message."
+ end
+ end
+
+ def unsubscribe_from_list
+ m = @message_lines[curpos] or return
+ if m.list_unsubscribe && m.list_unsubscribe =~ /<mailto:(.*?)\?(subject=(.*?))>/
+ ComposeMode.spawn_nicely :from => AccountManager.account_for(m.recipient_email), :to => [PersonManager.person_for($1)], :subj => $3
+ else
+ BufferManager.flash "Can't find List-Unsubscribe header for this message."
+ end
+ end
+
def forward
m = @message_lines[curpos] or return
- mode = ForwardMode.new m
- BufferManager.spawn "Forward of #{m.subj}", mode
- mode.edit_message
+ ForwardMode.spawn_nicely m
end
include CanAliasContacts
def alias
p = @person_lines[curpos] or return
@@ -129,13 +145,13 @@
end
def compose
p = @person_lines[curpos]
if p
- spawn_compose_mode :to => [p]
+ ComposeMode.spawn_nicely :to => [p]
else
- spawn_compose_mode
+ ComposeMode.spawn_nicely
end
end
def edit_labels
reserved_labels = @thread.labels.select { |l| LabelManager::RESERVED_LABELS.include? l }
@@ -143,11 +159,11 @@
return unless new_labels
@thread.labels = (reserved_labels + new_labels).uniq
new_labels.each { |l| LabelManager << l }
update
- UpdateManager.relay self, :label, m
+ UpdateManager.relay self, :label_thread, @thread
end
def toggle_starred
m = @message_lines[curpos] or return
toggle_label m, :starred
@@ -191,11 +207,11 @@
end
end
def edit_as_new
m = @message_lines[curpos] or return
- mode = ComposeMode.new(:body => m.basic_body_lines, :to => m.to, :cc => m.cc, :subj => m.subj, :bcc => m.bcc)
+ mode = ComposeMode.new(:body => m.quotable_body_lines, :to => m.to, :cc => m.cc, :subj => m.subj, :bcc => m.bcc)
BufferManager.spawn "edit as new", mode
mode.edit_message
end
def save_to_disk
@@ -234,9 +250,10 @@
jump_to_next_open
end
end
def jump_to_next_open
+ return continue_search_in_buffer if in_search? # hack: allow 'n' to apply to both operations
m = @message_lines[curpos] or return
while nextm = @layout[m].next
break if @layout[nextm].state != :closed
m = nextm
end