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 /^(List-Subscribe):\s+(.*?)\s*$/i,
34 /^(List-Unsubscribe):\s+(.*?)\s*$/i,
35 /^(Status):\s+(.*?)\s*$/i: header[last = $1] = $2
36 when /^(Message-Id):\s+(.*?)\s*$/i: header[mid_field = last = $1] = $2
38 ## these next three can occur multiple times, and we want the
40 when /^(Delivered-To):\s+(.*)$/i,
41 /^(X-Original-To):\s+(.*)$/i,
42 /^(Envelope-To):\s+(.*)$/i: header[last = $1] ||= $2
45 when /^\S+: /: last = nil # some other header we don't care about
47 header[last] += " " + line.chomp.gsub(/^\s+/, "") if last
51 if mid_field && header[mid_field] && header[mid_field] =~ /<(.*?)>/
52 header[mid_field] = $1
56 next unless Rfc2047.is_encoded? v
59 Rfc2047.decode_to $encoding, v
60 rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence => e
61 Redwood::log "warning: error decoding RFC 2047 header (#{e.class.name}): #{e.message}"
71 break if l =~ BREAK_RE
77 module_function :read_header, :read_body