Encode a string with Base64 Encoding and returns it ready to be inserted as a value for a field, that is, in the =?<charset>?B?<string>?= format
Example:
Encodings.b_value_encode('This is あ string', 'UTF-8') #=> "=?UTF-8?B?VGhpcyBpcyDjgYIgc3RyaW5n?="
Decodes or encodes a string as needed for either Base64 or QP encoding types in the =?<encoding>?[QB]?<string>?=" format.
The output type needs to be :decode to decode the input string or :encode to encode the input string. The character set used for encoding will either be the value of $KCODE for Ruby < 1.9 or the encoding on the string passed in.
On encoding, will only send out Base64 encoded strings.
Gets a defined encoding type, QuotedPrintable or Base64 for now.
Each encoding needs to be defined as a Mail::Encodings::ClassName for this to work, allows us to add other encodings in the future.
Example:
Encodings.get_encoding(:base64) #=> Mail::Encodings::Base64
Decodes a parameter value using URI Escaping.
Example:
Mail::Encodings.param_decode("This%20is%20fun", 'us-ascii') #=> "This is fun" str = Mail::Encodings.param_decode("This%20is%20fun", 'iso-8559-1') str.encoding #=> 'ISO-8859-1' ## Only on Ruby 1.9 str #=> "This is fun"
Encodes a parameter value using URI Escaping, note the language field ‘en’ can be set using Mail::Configuration, like so:
Mail.defaults do param_encode_language 'jp' end
The character set used for encoding will either be the value of $KCODE for Ruby < 1.9 or the encoding on the string passed in.
Example:
Mail::Encodings.param_encode("This is fun") #=> "us-ascii'en'This%20is%20fun"
Encode a string with Quoted-Printable Encoding and returns it ready to be inserted as a value for a field, that is, in the =?<charset>?Q?<string>?= format
Example:
Encodings.q_value_encode('This is あ string', 'UTF-8') #=> "=?UTF-8?Q?This_is_=E3=81=82_string?="
Decodes a given string as Base64 or Quoted Printable, depending on what type it is.
String has to be of the format =?<encoding>?[QB]?<string>?=