From 447533afd212ee3080ffac85aa56b30180fce1ec Mon Sep 17 00:00:00 2001 From: William Morgan Date: Sun, 26 Apr 2009 18:18:26 -0400 Subject: [PATCH] don't automatically parse header on Message#new You must now explicitly call #parse_header (e.g. when loading from the index) or #load_from_source! (e.g. when loading from disk). This prevents redundant loading from the source when adding to the index, as #snippet must be called before adding, and that requires loading the entire message from the source. --- lib/sup/index.rb | 6 ++++-- lib/sup/message.rb | 3 +-- lib/sup/poll.rb | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/sup/index.rb b/lib/sup/index.rb index 725dda6..c66a24e 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -413,9 +413,11 @@ EOS "references" => doc[:refs].split(/\s+/).map { |x| "<#{x}>" }.join(" "), } - Message.new :source => source, :source_info => doc[:source_info].to_i, + m = Message.new :source => source, :source_info => doc[:source_info].to_i, :labels => doc[:label].split(" ").map { |s| s.intern }, - :snippet => doc[:snippet], :header => fake_header + :snippet => doc[:snippet] + m.parse_header fake_header + m end end diff --git a/lib/sup/message.rb b/lib/sup/message.rb index dea54ac..263fde3 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -60,7 +60,7 @@ class Message ## why. @refs = [] - parse_header(opts[:header] || @source.load_header(@source_info)) + #parse_header(opts[:header] || @source.load_header(@source_info)) end def parse_header header @@ -123,7 +123,6 @@ class Message @list_subscribe = header["list-subscribe"] @list_unsubscribe = header["list-unsubscribe"] end - private :parse_header def add_ref ref @refs << ref diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb index afda64f..de3fbcb 100644 --- a/lib/sup/poll.rb +++ b/lib/sup/poll.rb @@ -149,6 +149,8 @@ EOS begin m = Message.new :source => source, :source_info => offset, :labels => labels + m.load_from_source! + if m.source_marked_read? m.remove_label :unread labels.delete :unread -- 2.45.2