42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/mail/jdec/decoder.rb', line 42
def value_decode(str)
return str unless str =~ ENCODED_VALUE
lines = Mail::Encodings.send(:collapse_adjacent_encodings, str)
lines = lines.chunk do |value|
if value =~ ENCODED_VALUE
$1
else
''
end
end
lines.map do |charset, values|
content = values.join
if content =~ ENCODED_VALUE
bytes = content.scan(/\=\?([^?]+)\?([QB])\?([^?]*?)\?\=/mi).map do |_, encoding, encoded|
case encoding
when *B_VALUES then Mail::Utilities.decode_base64(encoded)
when *Q_VALUES then Mail::Encodings::QuotedPrintable.decode(encoded.gsub(/_/, '=20').sub(/\=$/, ''))
end
end.join('')
Mail::Encodings.transcode_charset(bytes, charset)
else
content
end
end.join('')
end
|