lib/mail/header.rb in mail-2.5.5 vs lib/mail/header.rb in mail-2.6.0
- old
+ new
@@ -46,15 +46,19 @@
# field and leave it alone. This will mean that the data is preserved but
# no automatic processing of that field will happen. If you find one of
# these cases, please make a patch and send it in, or at the least, send
# me the example so we can fix it.
def initialize(header_text = nil, charset = nil)
- @errors = []
@charset = charset
self.raw_source = header_text.to_crlf.lstrip
split_header if header_text
end
+
+ def initialize_copy(original)
+ super
+ @fields = @fields.dup
+ end
# The preserved raw source of the header as you passed it in, untouched
# for your Regexing glory.
def raw_source
@raw_source
@@ -89,22 +93,21 @@
@fields = Mail::FieldList.new
warn "Warning: more than #{self.class.maximum_amount} header fields only using the first #{self.class.maximum_amount}" if unfolded_fields.length > self.class.maximum_amount
unfolded_fields[0..(self.class.maximum_amount-1)].each do |field|
field = Field.new(field, nil, charset)
- field.errors.each { |error| self.errors << error }
if limited_field?(field.name) && (selected = select_field_for(field.name)) && selected.any?
selected.first.update(field.name, field.value)
else
@fields << field
end
end
end
def errors
- @errors
+ @fields.map(&:errors).flatten(1)
end
# 3.6. Field definitions
#
# The following table indicates limits on the number of times each
@@ -175,11 +178,11 @@
self.fields << Field.new(name.to_s, value, charset)
end
if dasherize(fn) == "content-type"
# Update charset if specified in Content-Type
params = self[:content_type].parameters rescue nil
- @charset = params && params[:charset]
+ @charset = params[:charset] if params && params[:charset]
end
end
def charset
@charset
@@ -244,30 +247,13 @@
def raw_source=(val)
@raw_source = val
end
- # 2.2.3. Long Header Fields
- #
- # The process of moving from this folded multiple-line representation
- # of a header field to its single line representation is called
- # "unfolding". Unfolding is accomplished by simply removing any CRLF
- # that is immediately followed by WSP. Each header field should be
- # treated in its unfolded form for further syntactic and semantic
- # evaluation.
- def unfold(string)
- string.gsub(/#{CRLF}#{WSP}+/, ' ').gsub(/#{WSP}+/, ' ')
- end
-
- # Returns the header with all the folds removed
- def unfolded_header
- @unfolded_header ||= unfold(raw_source)
- end
-
# Splits an unfolded and line break cleaned header into individual field
# strings.
def split_header
- self.fields = unfolded_header.split(CRLF)
+ self.fields = raw_source.split(HEADER_SPLIT)
end
def select_field_for(name)
fields.select { |f| f.responsible_for?(name) }
end