module Mail::Multibyte

def self.clean(string)

Note: this method is a no-op in Ruby 1.9

Removes all invalid characters from the string.
def self.clean(string)
  string
end

def self.clean(string)

def self.clean(string)
  if expression = valid_character
    # Splits the string on character boundaries, which are determined based on $KCODE.
    string.split(//).grep(expression).join
  else
    string
  end
end

def self.proxy_class

Returns the current proxy class
def self.proxy_class
  @proxy_class ||= Mail::Multibyte::Chars
end

def self.proxy_class=(klass)

Mail::Multibyte.proxy_class = CharsForUTF32
Example:

an example how to do this.
class so you can support other encodings. See the Mail::Multibyte::Chars implementation for
The proxy class returned when calling mb_chars. You can use this accessor to configure your own proxy
def self.proxy_class=(klass)
  @proxy_class = klass
end

def self.valid_character

Returns a regular expression that matches valid characters in the current encoding
def self.valid_character
  VALID_CHARACTER[Encoding.default_external.to_s]
end

def self.valid_character

def self.valid_character
  case $KCODE
  when 'UTF8'
    VALID_CHARACTER['UTF-8']
  when 'SJIS'
    VALID_CHARACTER['Shift_JIS']
  end
end

def self.verify(string)

Verifies the encoding of a string
def self.verify(string)
  string.valid_encoding?
end

def self.verify(string)

def self.verify(string)
  if expression = valid_character
    # Splits the string on character boundaries, which are determined based on $KCODE.
    string.split(//).all? { |c| expression =~ c }
  else
    true
  end
end

def self.verify!(string)

Verifies the encoding of the string and raises an exception when it's not valid
def self.verify!(string)
  raise EncodingError.new("Found characters with invalid encoding") unless verify(string)
end