## i would like, for example, to be able to add in a ruby-talk
## specific module that would detect and link to /ruby-talk:\d+/
## sequences in the text of an email. (how sweet would that be?)
+##
+## this class cathces all source exceptions. if the underlying source throws
+## an error, it is caught and handled.
+
class Message
SNIPPET_LEN = 80
RE_PATTERN = /^((re|re[\[\(]\d[\]\)]):\s*)+/i
attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source,
:cc, :bcc, :labels, :list_address, :recipient_email, :replyto,
- :source_info, :chunks
+ :source_info, :chunks, :list_subscribe, :list_unsubscribe
bool_reader :dirty, :source_marked_read
def parse_header header
header.each { |k, v| header[k.downcase] = v }
-
- @from = PersonManager.person_for header["from"]
-
- @id = header["message-id"]
- if @id
- id.gsub!(/^\s+|\s+$/, "")
- else
- @id = "sup-faked-" + Digest::MD5.hexdigest(raw_header)
- Redwood::log "faking message-id for message from #@from: #@id"
- end
+
+ @id =
+ if header["message-id"]
+ sanitize_message_id header["message-id"]
+ else
+ returning("sup-faked-" + Digest::MD5.hexdigest(raw_header)) do |id|
+ Redwood::log "faking message-id for message from #@from: #{id}"
+ end
+ end
+
+ @from =
+ if header["from"]
+ PersonManager.person_for header["from"]
+ else
+ name = "Sup Auto-generated Fake Sender <sup@fake.sender.example.com>"
+ Redwood::log "faking from for message #@id: #{name}"
+ PersonManager.person_for name
+ end
date = header["date"]
@date =
@to = PersonManager.people_for header["to"]
@cc = PersonManager.people_for header["cc"]
@bcc = PersonManager.people_for header["bcc"]
- @refs = (header["references"] || "").gsub(/[<>]/, "").split(/\s+/).flatten
- @replytos = (header["in-reply-to"] || "").scan(/<(.*?)>/).flatten
+ @refs = (header["references"] || "").scan(/<(.+?)>/).map { |x| sanitize_message_id x.first }
+ @replytos = (header["in-reply-to"] || "").scan(/<(.+?)>/).map { |x| sanitize_message_id x.first }
+
@replyto = PersonManager.person_for header["reply-to"]
@list_address =
if header["list-post"]
@recipient_email = header["envelope-to"] || header["x-original-to"] || header["delivered-to"]
@source_marked_read = header["status"] == "RO"
+ @list_subscribe = header["list-subscribe"]
+ @list_unsubscribe = header["list-unsubscribe"]
end
private :parse_header
@source.fn_for_offset @source_info
end
+ def sanitize_message_id mid; mid.gsub(/\s/, "") end
+
def save index
index.sync_message self if @dirty
@dirty = false
Redwood::log "problem getting messages from #{@source}: #{e.message}"
## we need force_to_top here otherwise this window will cover
## up the error message one
+ @source.error ||= e
Redwood::report_broken_sources :force_to_top => true
[Chunk::Text.new(error_message(e.message))]
end
EOS
end
+ ## wrap any source methods that might throw sourceerrors
def with_source_errors_handled
begin
yield
rescue SourceError => e
Redwood::log "problem getting messages from #{@source}: #{e.message}"
+ @source.error ||= e
+ Redwood::report_broken_sources :force_to_top => true
error_message e.message
end
end
].flatten.compact.join " "
end
- def basic_body_lines
- chunks.find_all { |c| c.is_a?(Chunk::Text) || c.is_a?(Chunk::Quote) }.map { |c| c.lines }.flatten
+ def quotable_body_lines
+ chunks.find_all { |c| c.quotable? }.map { |c| c.lines }.flatten
end
- def basic_header_lines
+ def quotable_header_lines
["From: #{@from.full_address}"] +
(@to.empty? ? [] : ["To: " + @to.map { |p| p.full_address }.join(", ")]) +
(@cc.empty? ? [] : ["Cc: " + @cc.map { |p| p.full_address }.join(", ")]) +
end
def self.convert_from body, charset
- return body unless charset
-
begin
+ raise MessageFormatError, "RubyMail decode returned a null body" unless body
+ return body unless charset
Iconv.iconv($encoding, charset, body).join
- rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence => e
+ rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence, MessageFormatError => e
Redwood::log "warning: error (#{e.class.name}) decoding message body from #{charset}: #{e.message}"
File.open("sup-unable-to-decode.txt", "w") { |f| f.write body }
body