[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sup-devel] [PATCH 09/10] use header from the RMail::Message in Message#parse_header
---
lib/sup/message.rb | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index f3ac874..519243a 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -31,6 +31,7 @@ class Message
MAX_SIG_DISTANCE = 15 # lines from the end
DEFAULT_SUBJECT = ""
DEFAULT_SENDER = "(missing sender)"
+ MAX_HEADER_VALUE_SIZE = 4096
attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source,
:cc, :bcc, :labels, :attachments, :list_address, :recipient_email, :replyto,
@@ -59,13 +60,15 @@ class Message
#parse_header(opts[:header] || @source.load_header(@source_info))
end
- def parse_header header
- ## forcibly decode these headers from and to the current encoding,
- ## which serves to strip out characters that aren't displayable
- ## (and which would otherwise be screwing up the display)
- %w(from to subject cc bcc).each do |f|
- header[f] = Iconv.easy_decode($encoding, $encoding, header[f]) if header[f]
- end
+ def decode_header_field v
+ return unless v
+ return v unless v.is_a? String
+ return unless v.size < MAX_HEADER_VALUE_SIZE # avoid regex blowup on spam
+ Rfc2047.decode_to $encoding, Iconv.easy_decode($encoding, 'ASCII', v)
+ end
+
+ def parse_header encoded_header
+ header = SavingHash.new { |k| decode_header_field encoded_header[k] }
@id = if header["message-id"]
mid = header["message-id"] =~ /<(.+?)>/ ? $1 : header["message-id"]
@@ -100,7 +103,7 @@ class Message
Time.now
end
- @subj = header.member?("subject") ? header["subject"].gsub(/\s+/, " ").gsub(/\s+$/, "") : DEFAULT_SUBJECT
+ @subj = header["subject"] ? header["subject"].gsub(/\s+/, " ").gsub(/\s+$/, "") : DEFAULT_SUBJECT
@to = Person.from_address_list header["to"]
@cc = Person.from_address_list header["cc"]
@bcc = Person.from_address_list header["bcc"]
@@ -235,8 +238,9 @@ class Message
## bloat the index.
## actually, it's also the differentiation between to/cc/bcc,
## so i will keep this.
- parse_header @source.load_header(@source_info)
- message_to_chunks @source.load_message(@source_info)
+ rmsg = @source.load_message(@source_info)
+ parse_header rmsg.header
+ message_to_chunks rmsg
rescue SourceError, SocketError => e
warn "problem getting messages from #{@source}: #{e.message}"
## we need force_to_top here otherwise this window will cover
--
1.6.3.3
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel