Method: Mail::Encodings.value_decode

Defined in:
lib/mail/encodings.rb

.value_decode(str) ⇒ Object

Decodes a given string as Base64 or Quoted Printable, depending on what type it is.

String has to be of the format =?<encoding>??<string>?=



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/mail/encodings.rb', line 123

def Encodings.value_decode(str)
  # Optimization: If there's no encoded-words in the string, just return it
  return str unless str =~ ENCODED_VALUE

  lines = collapse_adjacent_encodings(str)

  # Split on white-space boundaries with capture, so we capture the white-space as well
  lines.each do |line|
    line.gsub!(ENCODED_VALUE) do |string|
      case $2
      when *B_VALUES then b_value_decode(string)
      when *Q_VALUES then q_value_decode(string)
      end
    end
  end.join("")
end