Sha256: f1cd3062012bd020c5e16703b2c3fe2f9559b11217fe693372d8e7e5eb5eca69

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require "sup/mbox/loader"
require "sup/mbox/ssh-file"
require "sup/mbox/ssh-loader"

module Redwood

## some utility functions
module MBox
  BREAK_RE = /^From \S+/

  def read_header f
    header = {}
    last = nil

    ## i do it in this weird way because i am trying to speed things up
    ## when scanning over large mbox files.
    while(line = f.gets)
      case line
      when /^(From):\s+(.*)$/i,
        /^(To):\s+(.*)$/i,
        /^(Cc):\s+(.*)$/i,
        /^(Bcc):\s+(.*)$/i,
        /^(Subject):\s+(.*)$/i,
        /^(Date):\s+(.*)$/i,
        /^(Message-Id):\s+<(.*)>$/i,
        /^(References):\s+(.*)$/i,
        /^(In-Reply-To):\s+(.*)$/i,
        /^(Reply-To):\s+(.*)$/i,
        /^(List-Post):\s+(.*)$/i,
        /^(Status):\s+(.*)$/i: header[last = $1] = $2

      ## these next three can occur multiple times, and we want the
      ## first one
      when /^(Delivered-To):\s+(.*)$/i,
        /^(X-Original-To):\s+(.*)$/i,
        /^(Envelope-To):\s+(.*)$/i: header[last = $1.downcase] ||= $2

      when /^$/: break
      when /:/: last = nil
      else
        header[last] += " " + line.chomp.gsub(/^\s+/, "") if last
      end
    end
    header
  end
  
  def read_body f
    body = []
    f.each_line do |l|
      break if l =~ BREAK_RE
      body << l.chomp
    end
    body
  end

  module_function :read_header, :read_body
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sup-0.0.8 lib/sup/mbox.rb
sup-0.0.7 lib/sup/mbox.rb