lib/dkim/dkim_header.rb in dkim-0.2.0 vs lib/dkim/dkim_header.rb in dkim-1.0.0
- old
+ new
@@ -1,28 +1,37 @@
require 'dkim/header'
+require 'dkim/tag_value_list'
+require 'dkim/encodings'
module Dkim
class DkimHeader < Header
+ attr_reader :list
def initialize values={}
self.key = 'DKIM-Signature'
- @values = values.to_a.flatten.each_slice(2).to_a
+ @list = TagValueList.new values
end
def value
- @values.map do |(k, v)|
- " #{k}=#{v}"
- end.join(';')
+ " #{@list}"
end
def [] k
- value = @values.detect {|(a,b)| a == k }
- value && value[1]
+ encoder_for(k).decode(@list[k])
end
def []= k, v
- value = @values.detect {|(a,b)| a == k }
- if !value
- value = [k, nil]
- @values << value
- end
- value[1] = v
+ @list[k] = encoder_for(k).encode(v)
+ end
+
+ private
+ def encoder_for key
+ case key
+ when *%w{v a c d h l q s t x}
+ Encodings::PlainText
+ when *%w{i z}
+ Encodings::DkimQuotedPrintable
+ when *%w{b bh}
+ Encodings::Base64
+ else
+ raise "unknown key: #{key}"
+ end.new
end
end
end