Sha256: a2edfa28178f8e25c4dfce640fc259a1d6ba51807966d9ae5e06dc43c3463777

Contents?: true

Size: 1.55 KB

Versions: 78

Compression:

Stored size: 1.55 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 = Time.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)
    end
    
    def encoded
      do_encode(CAPITALIZED_FIELD)
    end
    
    def decoded
      do_decode
    end
    
  end
end

Version data entries

78 entries across 48 versions & 4 rubygems

Version Path
depengine-0.0.31 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.31 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.30 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.30 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.29 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.29 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.28 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.28 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.27 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.27 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.26 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.26 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.25 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.25 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.24 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.24 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.23 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.23 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.22 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb
depengine-0.0.22 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/fields/date_field.rb