lib/sup/message.rb in sup-0.0.4 vs lib/sup/message.rb in sup-0.0.5
- old
+ new
@@ -80,20 +80,21 @@
DEFAULT_SUBJECT = "(missing subject)"
DEFAULT_SENDER = "(missing sender)"
attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source,
:cc, :bcc, :labels, :list_address, :recipient_email, :replyto,
- :source_info, :status
+ :source_info
- bool_reader :dirty
+ bool_reader :dirty, :source_marked_read
## if you specify a :header, will use values from that. otherwise, will try and
## load the header from the source.
def initialize opts
@source = opts[:source] or raise ArgumentError, "source can't be nil"
@source_info = opts[:source_info] or raise ArgumentError, "source_info can't be nil"
@snippet = opts[:snippet] || ""
+ @have_snippet = !opts[:snippet].nil?
@labels = opts[:labels] || []
@dirty = false
read_header(opts[:header] || @source.load_header(@source_info))
end
@@ -127,12 +128,12 @@
@list_address = Person.for header["list-post"].gsub(/^<mailto:|>$/, "")
else
nil
end
- @recipient_email = header["delivered-to"]
- @status = header["status"]
+ @recipient_email = header["x-original-to"] || header["envelope-to"] || header["delivered-to"]
+ @source_marked_read = header["status"] == "RO"
end
private :read_header
def broken?; @source.broken?; end
def snippet; @snippet || to_chunks && @snippet; end
@@ -175,13 +176,19 @@
@chunks ||=
if @source.broken?
[Text.new(error_message(@source.broken_msg.split("\n")))]
else
begin
+ ## we need to re-read the header because it contains information
+ ## that we don't store in the index. actually i think it's just
+ ## the mailing list address (if any), so this is kinda overkill.
+ ## 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.
read_header @source.load_header(@source_info)
message_to_chunks @source.load_message(@source_info)
- rescue SourceError, SocketError => e
+ rescue SourceError, SocketError, MessageFormatError => e
[Text.new(error_message(e.message))]
end
end
end
@@ -244,13 +251,11 @@
## everything RubyMail-specific goes here.
def message_to_chunks m
ret = [] <<
case m.header.content_type
when "text/plain", nil
- raise MessageFormatError, "no message body before decode (source #@source info #@source_info)" unless
- m.body
- body = m.decode or raise MessageFormatError, "no message body"
+ m.body && body = m.decode or raise MessageFormatError, "for some bizarre reason, RubyMail was unable to parse this message."
text_to_chunks body.normalize_whitespace.split("\n")
when /^multipart\//
nil
else
disp = m.header["Content-Disposition"] || ""
@@ -320,11 +325,10 @@
when :sig
chunk_lines << line
end
- if state == :text && (@snippet.nil? || @snippet.length < SNIPPET_LEN) &&
- line !~ /[=\*#_-]{3,}/ && line !~ /^\s*$/
+ if !@have_snippet && state == :text && (@snippet.nil? || @snippet.length < SNIPPET_LEN) && line !~ /[=\*#_-]{3,}/ && line !~ /^\s*$/
@snippet += " " unless @snippet.empty?
@snippet += line.gsub(/^\s+/, "").gsub(/[\r\n]/, "").gsub(/\s+/, " ")
@snippet = @snippet[0 ... SNIPPET_LEN].chomp
end
end