Sha256: b84bf81966aa0ca64ee79f7d9c20fa1da699092c28d9902bd364e62b671e75f1

Contents?: true

Size: 899 Bytes

Versions: 16

Compression:

Stored size: 899 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true
require 'mail/parsers/received_parser'
require 'mail/utilities'
require 'date'

module Mail
  class ReceivedElement #:nodoc:
    attr_reader :info, :date_time

    def initialize(string)
      if Utilities.blank? string
        @date_time = nil
        @info = nil
      else
        received = Mail::Parsers::ReceivedParser.parse(string)
        @date_time = datetime_for(received)
        @info = received.info
      end
    end

    def to_s(*args)
      "#{info}; #{date_time.to_s(*args)}"
    end

    private
      def datetime_for(received)
        ::DateTime.parse("#{received.date} #{received.time}")
      rescue ArgumentError => e
        raise e unless e.message == 'invalid date'
        warn "WARNING: Invalid date field for received element (#{received.date} #{received.time}): #{e.class}: #{e.message}"
        nil
      end
  end
end

Version data entries

16 entries across 15 versions & 6 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/elements/received_element.rb
mail-2.8.1 lib/mail/elements/received_element.rb
mail-2.8.1.rc2 lib/mail/elements/received_element.rb
mail-2.8.0.1 lib/mail/elements/received_element.rb
mail-2.8.0.1.rc1 lib/mail/elements/received_element.rb
mail-2.8.0 lib/mail/elements/received_element.rb
mail-2.8.0.rc3 lib/mail/elements/received_element.rb
mail-2.8.0.rc2 lib/mail/elements/received_element.rb
mail-2.8.0.rc1 lib/mail/elements/received_element.rb