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.5.1 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.5.0 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.4.2 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.4.1 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.4.0 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.3.9 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
challah-0.6.2 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
challah-0.6.2 vendor/bundle/gems/mail-2.4.1/lib/mail/fields/date_field.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
initforthe-cookies-0.0.1 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rails-uploader-0.0.1/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
rails-uploader-0.0.4 vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/fields/date_field.rb
classiccms-0.3.8 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb
challah-0.6.1 vendor/bundle/gems/mail-2.4.4/lib/mail/fields/date_field.rb