Sha256: 3ab9983fa39d0a042628a63912db0276d4bda781fce91b8e924263fa1e79a1f7

Contents?: true

Size: 576 Bytes

Versions: 4

Compression:

Stored size: 576 Bytes

Contents

require 'mail'

module Email; end

module Email::Mboxrd
  class Message
    def initialize(body)
      @body = body.clone
      @body.force_encoding('binary') if RUBY_VERSION >= '1.9.0'
    end

    def to_s
      'From ' + from + "\n" + body + "\n"
    end

    private

    def parsed
      @parsed ||= Mail.new(@body)
    end

    def from
      parsed.from[0] + ' ' + asctime
    end

    def body
      mbox = @body.gsub(/\n(>*From)/, "\n>\\1")
      mbox + "\n" unless mbox.end_with?("\n")
      mbox
    end

    def asctime
      parsed.date.asctime
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
imap-backup-1.0.9 lib/email/mboxrd/message.rb
imap-backup-1.0.8 lib/email/mboxrd/message.rb
imap-backup-1.0.7 lib/email/mboxrd/message.rb
imap-backup-1.0.6 lib/email/mboxrd/message.rb