Commit 276d076d154fae41f6a49540810ffcc7209c4756

  • avatar
  • William Morgan <wmorgan-sup @masa…in.net> (Committer)
  • Fri Jan 01 18:21:15 CET 2010
  • avatar
  • Rich Lane <rlane @cl…b.cc.cmu.edu> (Author)
  • Fri Jan 01 00:36:57 CET 2010
use header from the RMail::Message in Message#parse_header
  
3131 MAX_SIG_DISTANCE = 15 # lines from the end
3232 DEFAULT_SUBJECT = ""
3333 DEFAULT_SENDER = "(missing sender)"
34 MAX_HEADER_VALUE_SIZE = 4096
3435
3536 attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source,
3637 :cc, :bcc, :labels, :attachments, :list_address, :recipient_email, :replyto,
6060 #parse_header(opts[:header] || @source.load_header(@source_info))
6161 end
6262
63 def parse_header header
64 ## forcibly decode these headers from and to the current encoding,
65 ## which serves to strip out characters that aren't displayable
66 ## (and which would otherwise be screwing up the display)
67 %w(from to subject cc bcc).each do |f|
68 header[f] = Iconv.easy_decode($encoding, $encoding, header[f]) if header[f]
69 end
63 def decode_header_field v
64 return unless v
65 return v unless v.is_a? String
66 return unless v.size < MAX_HEADER_VALUE_SIZE # avoid regex blowup on spam
67 Rfc2047.decode_to $encoding, Iconv.easy_decode($encoding, 'ASCII', v)
68 end
7069
70 def parse_header encoded_header
71 header = SavingHash.new { |k| decode_header_field encoded_header[k] }
72
7173 @id = if header["message-id"]
7274 mid = header["message-id"] =~ /<(.+?)>/ ? $1 : header["message-id"]
7375 sanitize_message_id mid
103103 Time.now
104104 end
105105
106 @subj = header.member?("subject") ? header["subject"].gsub(/\s+/, " ").gsub(/\s+$/, "") : DEFAULT_SUBJECT
106 @subj = header["subject"] ? header["subject"].gsub(/\s+/, " ").gsub(/\s+$/, "") : DEFAULT_SUBJECT
107107 @to = Person.from_address_list header["to"]
108108 @cc = Person.from_address_list header["cc"]
109109 @bcc = Person.from_address_list header["bcc"]
238238 ## bloat the index.
239239 ## actually, it's also the differentiation between to/cc/bcc,
240240 ## so i will keep this.
241 parse_header @source.load_header(@source_info)
242 message_to_chunks @source.load_message(@source_info)
241 rmsg = @source.load_message(@source_info)
242 parse_header rmsg.header
243 message_to_chunks rmsg
243244 rescue SourceError, SocketError => e
244245 warn "problem getting messages from #{@source}: #{e.message}"
245246 ## we need force_to_top here otherwise this window will cover