Sha256: 5b9c6d96e7fd367bdf2d7aae5a8140a55f98a9db1b31e72fd21c3f794ffc81bc

Contents?: true

Size: 620 Bytes

Versions: 6

Compression:

Stored size: 620 Bytes

Contents

require 'mail'

module Email
  module 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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
imap-backup-1.0.5 lib/email/mboxrd/message.rb
imap-backup-1.0.4 lib/email/mboxrd/message.rb
imap-backup-1.0.3 lib/email/mboxrd/message.rb
imap-backup-1.0.2 lib/email/mboxrd/message.rb
imap-backup-1.0.1 lib/email/mboxrd/message.rb
imap-backup-1.0.0 lib/email/mboxrd/message.rb