Sha256: b10fc37d915049b43bd6773b9ff1e7a7b76fc0c8d33843ee5c11e8c60e683f13

Contents?: true

Size: 1.63 KB

Versions: 126

Compression:

Stored size: 1.63 KB

Contents

# encoding: utf-8
# 
# = Date Field
# 
# The Date field inherits from StructuredField and handles the Date: header
# field in the email.
# 
# Sending date to a mail message will instantiate a Mail::Field object that
# has a DateField as it's field type.  This includes all Mail::CommonAddress
# module instance methods.
# 
# There must be excatly one Date field in an RFC2822 email.
# 
# == Examples:
# 
#  mail = Mail.new
#  mail.date = 'Mon, 24 Nov 1997 14:22:01 -0800'
#  mail.date       #=> #<DateTime: 211747170121/86400,-1/3,2299161>
#  mail.date.to_s  #=> 'Mon, 24 Nov 1997 14:22:01 -0800'
#  mail[:date]     #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
#  mail['date']    #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
#  mail['Date']    #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
# 
require 'mail/fields/common/common_date'

module Mail
  class DateField < StructuredField
    
    include Mail::CommonDate
    
    FIELD_NAME = 'date'
    CAPITALIZED_FIELD = "Date"
    
    def initialize(value = nil, charset = 'utf-8')
      self.charset = charset
      if value.blank?
        value = ::DateTime.now.strftime('%a, %d %b %Y %H:%M:%S %z')
      else
        value = strip_field(FIELD_NAME, value)
        value.to_s.gsub!(/\(.*?\)/, '')
        value = ::DateTime.parse(value.to_s.squeeze(" ")).strftime('%a, %d %b %Y %H:%M:%S %z')
      end
      super(CAPITALIZED_FIELD, value, charset)
    rescue ArgumentError => e
      raise e unless "invalid date"==e.message
    end
    
    def encoded
      do_encode(CAPITALIZED_FIELD)
    end
    
    def decoded
      do_decode
    end
    
  end
end

Version data entries

126 entries across 115 versions & 12 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.7.4 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.7.3 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.7.2 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.7.1 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.7.0 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
mail-2.2.20 lib/mail/fields/date_field.rb
challah-1.0.0.beta vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
challah-0.9.1.beta.3 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
devise_sociable-0.1.0 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
challah-0.9.1.beta vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb