1 require "sup/mbox/loader"
2 require "sup/mbox/ssh-file"
3 require "sup/mbox/ssh-loader"
8 ## some utility functions. actually these are not mbox-specific at all
9 ## and should be moved somewhere else.
11 ## TODO: move functionality to somewhere better, like message.rb
13 BREAK_RE = /^From \S+/
19 ## i do it in this weird way because i am trying to speed things up
20 ## when scanning over large mbox files.
23 when /^(From):\s+(.*?)\s*$/i,
24 /^(To):\s+(.*?)\s*$/i,
25 /^(Cc):\s+(.*?)\s*$/i,
26 /^(Bcc):\s+(.*?)\s*$/i,
27 /^(Subject):\s+(.*?)\s*$/i,
28 /^(Date):\s+(.*?)\s*$/i,
29 /^(References):\s+(.*?)\s*$/i,
30 /^(In-Reply-To):\s+(.*?)\s*$/i,
31 /^(Reply-To):\s+(.*?)\s*$/i,
32 /^(List-Post):\s+(.*?)\s*$/i,
33 /^(Status):\s+(.*?)\s*$/i: header[last = $1] = $2
34 when /^(Message-Id):\s+(.*?)\s*$/i: header[mid_field = last = $1] = $2
36 ## these next three can occur multiple times, and we want the
38 when /^(Delivered-To):\s+(.*)$/i,
39 /^(X-Original-To):\s+(.*)$/i,
40 /^(Envelope-To):\s+(.*)$/i: header[last = $1] ||= $2
43 when /:/: last = nil # some other header we don't care about
45 header[last] += " " + line.chomp.gsub(/^\s+/, "") if last
49 if mid_field && header[mid_field] && header[mid_field] =~ /<(.*?)>/
50 header[mid_field] = $1
54 next unless Rfc2047.is_encoded? v
57 Rfc2047.decode_to $encoding, v
58 rescue Errno::EINVAL, Icon::InvalidEncoding, Iconv::IllegalSequence => e
59 Redwood::log "warning: error decoding RFC 2047 header: #{e.message}"
69 break if l =~ BREAK_RE
75 module_function :read_header, :read_body