module Net::IMAP::StringFormatter

def nstring(str)

coerces non-nil using +to_s+
def nstring(str)
  str.nil? ? nil : string(str)
end

def string(str)

coerces using +to_s+
def string(str)
  str = str.to_s
  if str =~ LITERAL_REGEX
    Literal.new(str)
  else
    QuotedString.new(str)
  end
end

def valid_nstring?(str)

Allows nil, symbols, and strings
def valid_nstring?(str)
  str.nil? || valid_string?(str)
end

def valid_string?(str)

Allows symbols in addition to strings
def valid_string?(str)
  str.is_a?(Symbol) || str.respond_to?(:to_str)
end