module Net::IMAP::StringPrep::SASLprep
def saslprep(str, stored: false, exception: false)
Unicode 3.2, and not later versions. See RFC3454 ยง7 for more
For \StringPrep and the \SASLprep profile, "unassigned" refers to
When +stored+ is +true+, "unassigned" codepoints will be prohibited.
+true+, a StringPrepError describing the violation will be raised.
By default, prohibited strings will return +nil+. When +exception+ is
RFC4013 of the StringPrep algorithm RFC3454.
Prepares a UTF-8 +string+ for comparison, using the \SASLprep profile
def saslprep(str, stored: false, exception: false) return str if ASCII_NO_CTRLS.match?(str) # incompatible encoding raises str = str.encode("UTF-8") # also dups (and raises for invalid encoding) str.gsub!(MAP_TO_SPACE, " ") str.gsub!(MAP_TO_NOTHING, "") str.unicode_normalize!(:nfkc) # These regexps combine the prohibited and bidirectional checks return str unless str.match?(stored ? PROHIBITED_STORED : PROHIBITED) return nil unless exception # raise helpful errors to indicate *why* it failed: tables = stored ? TABLES_PROHIBITED_STORED : TABLES_PROHIBITED StringPrep.check_prohibited! str, *tables, bidi: true, profile: "SASLprep" raise InvalidStringError.new( "unknown error", string: string, profile: "SASLprep" ) rescue ArgumentError, Encoding::CompatibilityError => ex if /invalid byte sequence|incompatible encoding/.match? ex.message return nil unless exception raise StringPrepError.new(ex.message, string: str, profile: "saslprep") end raise ex end