commit b373993123f79a03ec8f6e01a771604efc32e067
parent 6ca6ae8ad3185d7b46d6ba6a41f200ac8b6521b5
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Thu, 14 Jan 2010 08:51:08 -0500
Merge commit 'origin/list-post-improvements'; branch 'toggle-line-wrap'
Diffstat:
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/lib/sup/message-chunks.rb b/lib/sup/message-chunks.rb
@@ -41,8 +41,6 @@ end
module Redwood
module Chunk
- WRAP_LEN = 80 # wrap messages and text attachments at this width
-
class Attachment
HookManager.register "mime-decode", <<EOS
Decodes a MIME attachment into text form. The text will be displayed
@@ -110,7 +108,6 @@ EOS
@lines = nil
if text
@lines = text.gsub("\r\n", "\n").gsub(/\t/, " ").gsub(/\r/, "").split("\n")
- @lines = lines.map {|l| l.chomp.wrap WRAP_LEN}.flatten
@quotable = true
end
end
@@ -167,8 +164,7 @@ EOS
attr_reader :lines
def initialize lines
- @lines = lines.map { |l| l.chomp.wrap WRAP_LEN }.flatten # wrap
-
+ @lines = lines
## trim off all empty lines except one
@lines.pop while @lines.length > 1 && @lines[-1] =~ /^\s*$/ && @lines[-2] =~ /^\s*$/
end
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -114,12 +114,16 @@ class Message
@replytos = (header["in-reply-to"] || "").scan(/<(.+?)>/).map { |x| sanitize_message_id x.first }
@replyto = Person.from_address header["reply-to"]
- @list_address =
- if header["list-post"]
- @list_address = Person.from_address header["list-post"].gsub(/^<mailto:|>$/, "")
- else
- nil
+ @list_address = if header["list-post"]
+ address = if header["list-post"] =~ /mailto:(.*?)[>\s$]/
+ $1
+ elsif header["list-post"] =~ /@/
+ header["list-post"] # just try the whole fucking thing
end
+ address && Person.from_address(address)
+ elsif header["x-mailing-list"]
+ Person.from_address header["x-mailing-list"]
+ end
@recipient_email = header["envelope-to"] || header["x-original-to"] || header["delivered-to"]
@source_marked_read = header["status"] == "RO"
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -67,6 +67,7 @@ EOS
k.add :archive_and_next, "Archive this thread, kill buffer, and view next", 'a'
k.add :delete_and_next, "Delete this thread, kill buffer, and view next", 'd'
+ k.add :toggle_wrap, "Toggle wrapping of text", 'w'
k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read:", '.' do |kk|
kk.add :archive_and_kill, "Archive this thread and kill buffer", 'a'
@@ -128,11 +129,18 @@ EOS
end
end
+ @wrap = true
+
@layout[latest].state = :open if @layout[latest].state == :closed
@layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1
@thread.remove_label :unread
+ end
+
+ def toggle_wrap
+ @wrap = !@wrap
regen_text
+ buffer.mark_dirty if buffer
end
def draw_line ln, opts={}
@@ -145,6 +153,14 @@ EOS
def lines; @text.length; end
def [] i; @text[i]; end
+ ## a little hacky---since regen_text can depend on buffer features like the
+ ## content_width, we don't call it in the constructor, and instead call it
+ ## here, which is set before we're responsible for drawing ourself.
+ def buffer= b
+ super
+ regen_text
+ end
+
def show_header
m = @message_lines[curpos] or return
BufferManager.spawn_unless_exists("Full header for #{m.id}") do
@@ -763,7 +779,12 @@ private
else
raise "Bad chunk: #{chunk.inspect}" unless chunk.respond_to?(:inlineable?) ## debugging
if chunk.inlineable?
- chunk.lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] }
+ lines = chunk.lines
+ if @wrap
+ width = buffer.content_width
+ lines = lines.map { |l| l.chomp.wrap width }.flatten
+ end
+ lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] }
elsif chunk.expandable?
case state
when :closed