From 1e0ead5e3b880ed11c332c0a730c1f06f3ac4f6c Mon Sep 17 00:00:00 2001 From: wmorgan Date: Mon, 22 Jan 2007 01:21:27 +0000 Subject: [PATCH] fixed loading bug (messages now loaded completely before tehread-view-mode gets them) and reworked the loading timeline for messages. threads also now cloned before passing to thread=-view-mode this should fix some bugs that occur when messages are added to a thread after thread-view-mode has started laying them out goddamn this connection sucks and i don't want to fix my typos git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@272 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- doc/TODO | 3 +-- lib/sup/message.rb | 12 +++++++++--- lib/sup/modes/thread-index-mode.rb | 5 +++++ lib/sup/modes/thread-view-mode.rb | 22 +++------------------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/doc/TODO b/doc/TODO index 47dfd95..2aea338 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,7 +1,5 @@ de-archived messages should be auto-added to inbox drafts sometimes not loaded -bugfix: first time viewing a message only gets the first to:; - subsequent views get them all (wtf) add a flag to sup-import to force the creation of a new source (see http://rubyforge.org/forum/forum.php?thread_id=10973&forum_id=10340) fix bug: when returning from a shelling out, ncurses is crazy batch deletion @@ -25,6 +23,7 @@ move sup-import argument handling to getopt be able to mark individual messages as spam in thread-view-mode toggle wrapping +x bugfix: first time viewing a message only gets the first to:; subsequent views get them all (wtf) x search for other messages from author in thread-view-mode x resuming of arbitrary messages x alias authors in thread-view-mode diff --git a/lib/sup/message.rb b/lib/sup/message.rb index 9a6b2cc..4e7d3ca 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -46,6 +46,7 @@ class Message ## TODO: handle unknown mime-types system "/usr/bin/run-mailcap --action=view #{@content_type}:#{@file.path}" + $? == 0 end def to_s; @part.decode; end @@ -83,7 +84,7 @@ class Message attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source, :cc, :bcc, :labels, :list_address, :recipient_email, :replyto, - :source_info + :source_info, :chunks bool_reader :dirty, :source_marked_read @@ -96,8 +97,11 @@ class Message @have_snippet = !opts[:snippet].nil? @labels = opts[:labels] || [] @dirty = false + @chunks = nil - read_header(opts[:header] || @source.load_header(@source_info)) + raise ArgumentError, "need a header" unless opts[:header] + read_header opts[:header] + #read_header(opts[:header] || @source.load_header(@source_info)) end def read_header header @@ -173,7 +177,7 @@ class Message end ## this is called when the message body needs to actually be loaded. - def chunks + def load_from_source! @chunks ||= if @source.broken? [Text.new(error_message(@source.broken_msg.split("\n")))] @@ -185,6 +189,8 @@ class Message ## i could just store that in the index, but i think there might ## be other things like that in the future, and i'd rather not ## bloat the index. + ## actually, it's also the differentiation between to/cc/bcc, + ## so i will keep this. read_header @source.load_header(@source_info) message_to_chunks @source.load_message(@source_info) rescue SourceError, SocketError, MessageFormatError => e diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index c6baa53..b474a09 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -56,8 +56,13 @@ class ThreadIndexMode < LineCursorMode def select t=nil t ||= @threads[curpos] + t = t.clone # XXXX highly experimental + ## TODO: don't regen text completely Redwood::reporting_thread do + BufferManager.say("Loading message bodies...") do |sid| + t.each { |m, *o| m.load_from_source! } + end mode = ThreadViewMode.new t, @hidden_labels BufferManager.spawn t.subj, mode BufferManager.draw_screen diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb index 2549a1f..897f863 100644 --- a/lib/sup/modes/thread-view-mode.rb +++ b/lib/sup/modes/thread-view-mode.rb @@ -61,7 +61,7 @@ class ThreadViewMode < LineCursorMode @layout[latest].state = :open if @layout[latest].state == :closed @layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1 - BufferManager.say("Loading message bodies...") { update } + regen_text end def draw_line ln, opts={} @@ -287,23 +287,6 @@ private @text += chunk_to_lines m, nil, @text.length, depth, parent next end - - ## we're occasionally called on @threads that have had messages - ## added to them since initialization. luckily we regen_text on - ## the entire thread every time the user does anything besides - ## scrolling (basically), so we can just slap this on here. - ## - ## to pick nits, the niceness that i do in the constructor with - ## 'latest' etc. (for automatically opening just the latest - ## message if everything's been read) will not be valid, but - ## that's just a nicety and hopefully this won't happen too - ## often. - - unless @layout.member? m - l = @layout[m] = Layout.new - l.state = initial_state_for m - l.color = prevm && @layout[prevm].color == :message_patina_color ? :alternate_patina_color : :message_patina_color - end l = @layout[m] ## build the patina @@ -456,9 +439,10 @@ private def view_attachment a BufferManager.flash "viewing #{a.content_type} attachment..." - a.view! + success = a.view! BufferManager.erase_flash BufferManager.completely_redraw_screen + BufferManager.flash "Couldn't execute view command." unless success end end -- 2.45.2