Commit 276d076d154fae41f6a49540810ffcc7209c4756
- Diff rendering mode:
- inline
- side by side
lib/sup/message.rb
(14 / 10)
|   | |||
| 31 | 31 | MAX_SIG_DISTANCE = 15 # lines from the end | |
| 32 | 32 | DEFAULT_SUBJECT = "" | |
| 33 | 33 | DEFAULT_SENDER = "(missing sender)" | |
| 34 | MAX_HEADER_VALUE_SIZE = 4096 | ||
| 34 | 35 | ||
| 35 | 36 | attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source, | |
| 36 | 37 | :cc, :bcc, :labels, :attachments, :list_address, :recipient_email, :replyto, | |
| … | … | ||
| 60 | 60 | #parse_header(opts[:header] || @source.load_header(@source_info)) | |
| 61 | 61 | end | |
| 62 | 62 | ||
| 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 | ||
| 70 | 69 | ||
| 70 | def parse_header encoded_header | ||
| 71 | header = SavingHash.new { |k| decode_header_field encoded_header[k] } | ||
| 72 | |||
| 71 | 73 | @id = if header["message-id"] | |
| 72 | 74 | mid = header["message-id"] =~ /<(.+?)>/ ? $1 : header["message-id"] | |
| 73 | 75 | sanitize_message_id mid | |
| … | … | ||
| 103 | 103 | Time.now | |
| 104 | 104 | end | |
| 105 | 105 | ||
| 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 | ||
| 107 | 107 | @to = Person.from_address_list header["to"] | |
| 108 | 108 | @cc = Person.from_address_list header["cc"] | |
| 109 | 109 | @bcc = Person.from_address_list header["bcc"] | |
| … | … | ||
| 238 | 238 | ## bloat the index. | |
| 239 | 239 | ## actually, it's also the differentiation between to/cc/bcc, | |
| 240 | 240 | ## 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 | ||
| 243 | 244 | rescue SourceError, SocketError => e | |
| 244 | 245 | warn "problem getting messages from #{@source}: #{e.message}" | |
| 245 | 246 | ## we need force_to_top here otherwise this window will cover |

